Skip to content

Commit

Permalink
fix: Add creds decryption .env (#475)
Browse files Browse the repository at this point in the history
* feat: Add creds encryption .env

* Remove encrypted key import in swagger
  • Loading branch information
DaevMithran authored Jan 19, 2024
1 parent 0dd521e commit d332764
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 20 deletions.
1 change: 1 addition & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ jobs:
TESTNET_RPC_URL: ${{ vars.TESTNET_RPC_URL }}
VERIDA_NETWORK: ${{ vars.VERIDA_NETWORK }}
VERIDA_PRIVATE_KEY: ${{ secrets.VERIDA_PRIVATE_KEY }}
CREDS_DECRYPTION_SECRET: ${{ secrets.CREDS_DECRYPTION_SECRET }}

- uses: actions/upload-artifact@v4
if: always()
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class KeyController {
*/
public async importKey(request: Request, response: Response) {
// Get parameters requeired for key importing
const { type, encrypted, ivHex, salt, alias, privateKeyHex } = request.body as ImportKeyRequestBody;
const { type, encrypted = false, ivHex, salt, alias, privateKeyHex } = request.body as ImportKeyRequestBody;
// Get strategy e.g. postgres or local
const identityServiceStrategySetup = new IdentityServiceStrategySetup(response.locals.customer.customerId);
let decryptedPrivateKeyHex = privateKeyHex;
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,11 +213,11 @@ export async function deriveSymmetricKeyFromSecret(
}

export async function decryptPrivateKey(encryptedPrivateKeyHex: string, ivHex: string, salt: string) {
if (!process.env.ENCRYPTION_SECRET) {
if (!process.env.CREDS_DECRYPTION_SECRET) {
throw new Error('Missing encryption secret');
}
// derive key from passphrase
const derivedKey = await deriveSymmetricKeyFromSecret(process.env.ENCRYPTION_SECRET, salt);
const derivedKey = await deriveSymmetricKeyFromSecret(process.env.CREDS_DECRYPTION_SECRET, salt);

// unwrap encrypted key with iv
const encryptedKey = Buffer.from(encryptedPrivateKeyHex, 'hex');
Expand Down
10 changes: 0 additions & 10 deletions src/static/swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -2650,16 +2650,6 @@
},
"privateKeyHex": {
"type": "string"
},
"ivHex": {
"type": "string",
"required": false
},
"salt": {
"type": "string"
},
"encrypted": {
"type": "boolean"
}
}
},
Expand Down
3 changes: 3 additions & 0 deletions src/types/environment.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ declare global {
ENABLE_ACCOUNT_TOPUP: string | 'false';
FAUCET_URI: string;
TESTNET_MINIMUM_BALANCE: number;

// Creds
CREDS_DECRYPTION_SECRET: string;
}
}

Expand Down
7 changes: 0 additions & 7 deletions src/types/swagger-types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -702,13 +702,6 @@
* enum: [ Ed25519, Secp256k1 ]
* privateKeyHex:
* type: string
* ivHex:
* type: string
* required: false
* salt:
* type: string
* encrypted:
* type: boolean
* KeyResult:
* type: object
* properties:
Expand Down

0 comments on commit d332764

Please sign in to comment.