- getMyPrivateCert,
- getMyPublicCert,
- sign
-}
-
-// ---------------------------------------------------------------------------
-
-function certsExist () {
- const certPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME)
-
- // If there is an error the certificates do not exist
- return accessPromise(certPath)
- .then(() => true)
- .catch(() => false)
-}
-
-function createCerts () {
- return certsExist().then(exist => {
- if (exist === true) {
- const errorMessage = 'Certs already exist.'
- logger.warning(errorMessage)
- throw new Error(errorMessage)
- }
-
- logger.info('Generating a RSA key...')
-
- const privateCertPath = join(CONFIG.STORAGE.CERT_DIR, PRIVATE_CERT_NAME)
- const genRsaOptions = {
- 'out': privateCertPath,
- '2048': false
- }
- return opensslExecPromise('genrsa', genRsaOptions)
- .then(() => {
- logger.info('RSA key generated.')
- logger.info('Managing public key...')
-
- const publicCertPath = join(CONFIG.STORAGE.CERT_DIR, 'peertube.pub')
- const rsaOptions = {
- 'in': privateCertPath,
- 'pubout': true,
- 'out': publicCertPath
- }
- return opensslExecPromise('rsa', rsaOptions)
- .then(() => logger.info('Public key managed.'))
- .catch(err => {
- logger.error('Cannot create public key on this pod.')
- throw err
- })
- })
- .catch(err => {
- logger.error('Cannot create private key on this pod.')
- throw err
- })
- })