-
Notifications
You must be signed in to change notification settings - Fork 6
Fix: encryptProjectConfig now supports AES-GCM #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -153,27 +153,45 @@ export function encryptProjectConfig(config: string): { | |||||||||||||||||||||||
| key: string; | ||||||||||||||||||||||||
| } { | ||||||||||||||||||||||||
| const key = crypto.randomBytes(32); | ||||||||||||||||||||||||
| const iv = Buffer.alloc(16).fill(0); | ||||||||||||||||||||||||
| const cipher = crypto.createCipheriv('aes256', key, iv); | ||||||||||||||||||||||||
| const encrypted = cipher.update(config, 'utf8', 'hex') + cipher.final('hex'); | ||||||||||||||||||||||||
| return { | ||||||||||||||||||||||||
| config: encrypted, | ||||||||||||||||||||||||
| key: key.toString('hex') | ||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||
| const iv = crypto.randomBytes(12); | ||||||||||||||||||||||||
| const cipher = crypto.createCipheriv('aes-256-gcm', key, iv); | ||||||||||||||||||||||||
| const encrypted = Buffer.concat([ | ||||||||||||||||||||||||
| cipher.update(config, 'utf8'), | ||||||||||||||||||||||||
| cipher.final() | ||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||
| const authTag = cipher.getAuthTag(); | ||||||||||||||||||||||||
| const final = `v2:${iv.toString('hex')}:${authTag.toString( | ||||||||||||||||||||||||
| 'hex' | ||||||||||||||||||||||||
| )}:${encrypted.toString('hex')}`; | ||||||||||||||||||||||||
| return { config: final, key: key.toString('hex') }; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| export function decryptProjectConfig(config: string, key: string): string { | ||||||||||||||||||||||||
| const iv = Buffer.alloc(16).fill(0); | ||||||||||||||||||||||||
| const decipher = crypto.createDecipheriv( | ||||||||||||||||||||||||
| 'aes256', | ||||||||||||||||||||||||
| Buffer.from(key, 'hex'), | ||||||||||||||||||||||||
| iv | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
| const decryptedMessage = Buffer.concat([ | ||||||||||||||||||||||||
| decipher.update(config, 'hex'), | ||||||||||||||||||||||||
| export function decryptProjectConfig( | ||||||||||||||||||||||||
| encrypted: string, | ||||||||||||||||||||||||
| keyHex: string | ||||||||||||||||||||||||
| ): string { | ||||||||||||||||||||||||
| const key = Buffer.from(keyHex, 'hex'); | ||||||||||||||||||||||||
| if (encrypted.startsWith('v2:')) { | ||||||||||||||||||||||||
| const [_v, ivHex, tagHex, encryptedHex] = encrypted.split(':'); | ||||||||||||||||||||||||
| const decipher = crypto.createDecipheriv( | ||||||||||||||||||||||||
| 'aes-256-gcm', | ||||||||||||||||||||||||
| key, | ||||||||||||||||||||||||
| Buffer.from(ivHex, 'hex') | ||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||
|
Comment on lines
+176
to
+180
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Semgrep identified an issue in your code: To resolve this comment: ✨ Commit Assistant fix suggestion
Suggested change
View step-by-step instructions
💬 Ignore this findingReply with Semgrep commands to ignore this finding.
Alternatively, triage in Semgrep AppSec Platform to ignore the finding created by gcm-no-tag-length. Questions about this issue? Reach out to Product Security in #prodsec-tools. You can view more details about this finding in the Semgrep AppSec Platform. |
||||||||||||||||||||||||
| decipher.setAuthTag(Buffer.from(tagHex, 'hex')); | ||||||||||||||||||||||||
| const decrypted = Buffer.concat([ | ||||||||||||||||||||||||
| decipher.update(Buffer.from(encryptedHex, 'hex')), | ||||||||||||||||||||||||
| decipher.final() | ||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||
| return decrypted.toString('utf8'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| const iv = Buffer.alloc(16, 0); | ||||||||||||||||||||||||
| const decipher = crypto.createDecipheriv('aes-256-cbc', key, iv); | ||||||||||||||||||||||||
| const decrypted = Buffer.concat([ | ||||||||||||||||||||||||
| decipher.update(Buffer.from(encrypted, 'hex')), | ||||||||||||||||||||||||
sanpj2292 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
| decipher.final() | ||||||||||||||||||||||||
| ]); | ||||||||||||||||||||||||
| return decryptedMessage.toString('utf8'); | ||||||||||||||||||||||||
| return decrypted.toString('utf8'); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| // Rename any 'functions' members of the contained PackageSpecs of a config to 'actions'. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
Uh oh!
There was an error while loading. Please reload this page.