Fixed Intel AMT ACM cert auto-ordering.
Ylian Saint-Hilaire committed
Aug 19, 2020 at 11:22 UTC
1c973771941afe29c91e2f29361668c4cefc2dbf
1 file changed
+16
-14
certoperations.js
+16
-14
@@ -97,6 +97,22 @@ module.exports.CertificateOperations = function (parent) {
97
if ((r.certs.length < 2) || (r.keys.length != 1)) continue;
98
}
99
100
+ // Reorder the certificates from leaf to root.
101
+ var orderedCerts = [], or = [], currenthash = null, orderingError = false;;
102
+ while ((orderingError == false) && (orderedCerts.length < r.certs.length)) {
103
+ orderingError = true;
104
+ for (var k in r.certs) {
105
+ if (((currenthash == null) && (r.certs[k].subject.hash == r.certs[k].issuer.hash)) || ((r.certs[k].issuer.hash == currenthash) && (r.certs[k].subject.hash != r.certs[k].issuer.hash))) {
106
+ currenthash = r.certs[k].subject.hash;
107
+ orderedCerts.unshift(Buffer.from(obj.forge.asn1.toDer(obj.pki.certificateToAsn1(r.certs[k])).data, 'binary').toString('base64'));
108
+ or.unshift(r.certs[k]);
109
+ orderingError = false;
110
+ }
111
+ }
112
+ }
113
+ if (orderingError == true) continue;
114
+ r.certs = or;
115
+
116
/*
117
// Debug: Display all certs & key as PEM
118
for (var k in r.certs) {
@@ -139,20 +155,6 @@ module.exports.CertificateOperations = function (parent) {
155
acmconfig.cn = certCommonName.value;
156
}
157
142
- // Reorder the certificates from leaf to root.
143
- var orderedCerts = [], currenthash = null, orderingError = false;;
144
- while ((orderingError == false) && (orderedCerts.length < r.certs.length)) {
145
- orderingError = true;
146
- for (var k in r.certs) {
147
- if (((currenthash == null) && (r.certs[k].subject.hash == r.certs[k].issuer.hash)) || ((r.certs[k].issuer.hash == currenthash) && (r.certs[k].subject.hash != r.certs[k].issuer.hash))) {
148
- currenthash = r.certs[k].subject.hash;
149
- orderedCerts.unshift(Buffer.from(obj.forge.asn1.toDer(obj.pki.certificateToAsn1(r.certs[k])).data, 'binary').toString('base64'));
150
- orderingError = false;
151
- }
152
- }
153
- }
154
- if (orderingError == true) continue;
155
-
158
delete acmconfig.cert;
159
delete acmconfig.certpass;
160
acmconfig.certs = orderedCerts;