From 9a2ca0847428596ef24799c6333b73e7e50ebd5c Mon Sep 17 00:00:00 2001 From: Kasra Bigdeli Date: Thu, 7 Mar 2019 23:17:30 -0800 Subject: [PATCH] Added encryption to SSH key --- src/datastore/AppsDataStore.ts | 48 +++++++++++++++++++++------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/datastore/AppsDataStore.ts b/src/datastore/AppsDataStore.ts index 6131395..1111e28 100644 --- a/src/datastore/AppsDataStore.ts +++ b/src/datastore/AppsDataStore.ts @@ -38,7 +38,7 @@ class AppsDataStore { private saveApp(appName: String, app: IAppDef) { const self = this - let passwordToBeEncrypted = '' + return Promise.resolve() .then(function() { if (!appName) { @@ -48,22 +48,6 @@ class AppsDataStore { ) } - let pushWebhook = app.appPushWebhook - if ( - pushWebhook && - pushWebhook.pushWebhookToken && - pushWebhook.tokenVersion && - pushWebhook.repoInfo && - pushWebhook.repoInfo.repo - ) { - // we have required info - passwordToBeEncrypted = pushWebhook.repoInfo.password - pushWebhook.repoInfo.password = '' - } else { - // some required data is missing. We drop the push data - pushWebhook = undefined - } - if (app.forceSsl) { let hasAtLeastOneSslDomain = app.hasDefaultSubDomainSsl const customDomainArray = app.customDomain @@ -173,13 +157,40 @@ class AppsDataStore { } }) .then(function() { + let passwordToBeEncrypted = '' + let sshKeyToBeEncrypted = '' + let pushWebhook = app.appPushWebhook + if ( + pushWebhook && + pushWebhook.pushWebhookToken && + pushWebhook.tokenVersion && + pushWebhook.repoInfo && + pushWebhook.repoInfo.repo + ) { + // we have required info + passwordToBeEncrypted = pushWebhook.repoInfo.password + sshKeyToBeEncrypted = pushWebhook.repoInfo.sshKey + pushWebhook.repoInfo.password = '' + pushWebhook.repoInfo.sshKey = '' + } else { + // some required data is missing. We drop the push data + pushWebhook = undefined + } + const appToSave: IAppDefSaved = app + if (passwordToBeEncrypted) { appToSave.appPushWebhook!.repoInfo!.passwordEncrypted = self.encryptor.encrypt( passwordToBeEncrypted ) } + if (sshKeyToBeEncrypted) { + appToSave.appPushWebhook!.repoInfo!.sshKeyEncrypted = self.encryptor.encrypt( + sshKeyToBeEncrypted + ) + } + return appToSave }) .then(function(appToSave: IAppDefSaved) { @@ -211,7 +222,8 @@ class AppsDataStore { if ( appSave.appPushWebhook && appSave.appPushWebhook.repoInfo && - appSave.appPushWebhook.repoInfo.passwordEncrypted + (appSave.appPushWebhook.repoInfo.passwordEncrypted || + appSave.appPushWebhook.repoInfo.sshKeyEncrypted) ) { const repo = appSave.appPushWebhook!.repoInfo appUnencrypted.appPushWebhook = {