-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving to SNI certs instead of pinned certs for LabClient token acquisition
- Loading branch information
Showing
5 changed files
with
773 additions
and
822 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright (c) Microsoft Corporation. All rights reserved. | ||
* Licensed under the MIT License. | ||
*/ | ||
|
||
const path = require("path"); | ||
const fs = require("fs"); | ||
|
||
const pemPath = process.argv[2]; | ||
const pemCert = fs.readFileSync(pemPath, "utf8"); | ||
|
||
const END_PRIVATE_KEY = "-----END PRIVATE KEY-----"; | ||
const END_CERTIFICATE = "-----END CERTIFICATE-----"; | ||
|
||
// Separate the private key from the x5c certificate chain | ||
const [privateKey, certs] = pemCert.split(END_PRIVATE_KEY); | ||
const x5cCerts = reorderCerts(certs); | ||
const processedPem = `${privateKey}${END_PRIVATE_KEY}${x5cCerts}${END_CERTIFICATE}`; | ||
|
||
fs.writeFileSync(pemPath, processedPem, "utf8"); | ||
|
||
/** | ||
* Moves the leaf certificate to the front of the chain | ||
* @param {*} certs Serialized x5c certificate chain | ||
*/ | ||
function reorderCerts(certs) { | ||
// Split the certs into an array | ||
const x5cCerts = certs.split(END_CERTIFICATE); | ||
// Remove the last element which is an empty string | ||
x5cCerts.pop(); | ||
// Move the leaf certificate to the front of the chain | ||
x5cCerts.unshift(x5cCerts.pop()); | ||
// Rejoin into a serialized cert chain | ||
return x5cCerts.join(END_CERTIFICATE); | ||
} |
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.