-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
405 additions
and
147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
packages/dashmate/src/listr/prompts/validators/validateSslCertificateFiles.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import crypto from 'node:crypto'; | ||
import fs from 'node:fs'; | ||
|
||
/** | ||
* @param {string} chainFilePath | ||
* @param {string} privateFilePath | ||
* @return {boolean} | ||
*/ | ||
export default function validateSslCertificateFiles(chainFilePath, privateFilePath) { | ||
const bundlePem = fs.readFileSync(chainFilePath, 'utf8'); | ||
const privateKeyPem = fs.readFileSync(privateFilePath, 'utf8'); | ||
|
||
// Step 2: Create a signature using the private key | ||
const data = 'This is a test message'; | ||
const sign = crypto.createSign('SHA256'); | ||
sign.update(data); | ||
sign.end(); | ||
|
||
const signature = sign.sign(privateKeyPem, 'hex'); | ||
|
||
// Verify the signature using the public key from the certificate | ||
const verify = crypto.createVerify('SHA256'); | ||
verify.update(data); | ||
verify.end(); | ||
|
||
// Extract the public key from the first certificate in the bundle | ||
const certificate = crypto.createPublicKey({ | ||
key: bundlePem, | ||
format: 'pem', | ||
}); | ||
|
||
return verify.verify(certificate, signature, 'hex'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.