|
|
@@ -1,8 +1,9 @@
|
|
|
'use strict';
|
|
|
|
|
|
-const { unescape } = require('querystring');
|
|
|
const { pki, md, asn1 } = require('node-forge');
|
|
|
|
|
|
+const NUMBER_OF_CHARACTERS_IN_10_COLON_DELIMITED_BYTES = 29;
|
|
|
+
|
|
|
/*
|
|
|
escapedPemCertificate comes from nginx, it's the client cert in PEM format.
|
|
|
This function calculates the 10-byte fingerprint required by OpenADR.
|
|
|
@@ -11,7 +12,7 @@ const { pki, md, asn1 } = require('node-forge');
|
|
|
function calculatePartialFingerprintOfEscapedPemCertificate(
|
|
|
escapedPemCertificate,
|
|
|
) {
|
|
|
- const pemCertificate = unescape(escapedPemCertificate);
|
|
|
+ const pemCertificate = decodeURIComponent(escapedPemCertificate);
|
|
|
const parsedCertificate = pki.certificateFromPem(pemCertificate);
|
|
|
const asn1Encoded = pki.certificateToAsn1(parsedCertificate);
|
|
|
const derEncoded = asn1.toDer(asn1Encoded).getBytes();
|
|
|
@@ -22,7 +23,9 @@ function calculatePartialFingerprintOfEscapedPemCertificate(
|
|
|
.toHex()
|
|
|
.match(/.{2}/g)
|
|
|
.join(':');
|
|
|
- return fullFingerprintDelimited.slice(-29).toUpperCase();
|
|
|
+ return fullFingerprintDelimited
|
|
|
+ .slice(-NUMBER_OF_CHARACTERS_IN_10_COLON_DELIMITED_BYTES)
|
|
|
+ .toUpperCase();
|
|
|
}
|
|
|
|
|
|
module.exports = {
|