@vizamodo/aws-sts-core 0.4.1 → 0.4.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/sts/issue.js +62 -18
- package/package.json +1 -1
package/dist/sts/issue.js
CHANGED
|
@@ -135,6 +135,35 @@ async function fetchCredentials(input) {
|
|
|
135
135
|
});
|
|
136
136
|
const signatureHex = await signStringToSign(stringToSign, signingKey);
|
|
137
137
|
const certSerialDec = getCertSerialDec(normalizedCert);
|
|
138
|
+
// 🔍 Deep debug helper (compare with working version)
|
|
139
|
+
function debugAwsSigning() {
|
|
140
|
+
try {
|
|
141
|
+
console.debug("[aws-debug][input]", {
|
|
142
|
+
roleArn,
|
|
143
|
+
profileArn,
|
|
144
|
+
trustAnchorArn,
|
|
145
|
+
region,
|
|
146
|
+
sessionTtl,
|
|
147
|
+
});
|
|
148
|
+
console.debug("[aws-debug][cert]", {
|
|
149
|
+
length: normalizedCert.length,
|
|
150
|
+
preview: normalizedCert.slice(0, 30),
|
|
151
|
+
});
|
|
152
|
+
console.debug("[aws-debug][serial]", {
|
|
153
|
+
serialDec: certSerialDec,
|
|
154
|
+
serialHex: BigInt(certSerialDec).toString(16),
|
|
155
|
+
});
|
|
156
|
+
console.debug("[aws-debug][headers]", baseHeaders);
|
|
157
|
+
console.debug("[aws-debug][signedHeaders]", signedHeaders);
|
|
158
|
+
console.debug("[aws-debug][canonicalRequest]", canonicalRequest);
|
|
159
|
+
console.debug("[aws-debug][stringToSign]", stringToSign);
|
|
160
|
+
console.debug("[aws-debug][signatureHex]", signatureHex);
|
|
161
|
+
}
|
|
162
|
+
catch (e) {
|
|
163
|
+
console.warn("[aws-debug][error]", e);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
debugAwsSigning();
|
|
138
167
|
const finalHeaders = new Headers({
|
|
139
168
|
"Content-Type": "application/json",
|
|
140
169
|
"X-Amz-Date": amzDate,
|
|
@@ -154,7 +183,12 @@ async function fetchCredentials(input) {
|
|
|
154
183
|
throw new InternalError("aws_unreachable");
|
|
155
184
|
}
|
|
156
185
|
if (!res.ok) {
|
|
157
|
-
|
|
186
|
+
const text = await res.text().catch(() => "<no-body>");
|
|
187
|
+
console.error("[aws-rejected]", {
|
|
188
|
+
status: res.status,
|
|
189
|
+
body: text,
|
|
190
|
+
region,
|
|
191
|
+
});
|
|
158
192
|
throw new InternalError("aws_rejected");
|
|
159
193
|
}
|
|
160
194
|
const json = await res.json();
|
|
@@ -221,32 +255,42 @@ function parseCertSerialDec(normalizedCertBase64) {
|
|
|
221
255
|
len = (len << 8) | der[offset++];
|
|
222
256
|
return len;
|
|
223
257
|
}
|
|
258
|
+
// Certificate ::= SEQUENCE
|
|
224
259
|
if (der[offset++] !== 0x30)
|
|
225
260
|
throw new Error("bad cert");
|
|
226
261
|
readLen();
|
|
262
|
+
// tbsCertificate ::= SEQUENCE
|
|
227
263
|
if (der[offset++] !== 0x30)
|
|
228
264
|
throw new Error("bad tbs");
|
|
229
265
|
readLen();
|
|
230
|
-
//
|
|
266
|
+
// Optional version [0] EXPLICIT
|
|
231
267
|
if (der[offset] === 0xa0) {
|
|
232
|
-
offset++;
|
|
233
|
-
offset += readLen();
|
|
234
|
-
}
|
|
235
|
-
if (der[offset++] !== 0x02)
|
|
236
|
-
throw new Error("bad serial tag");
|
|
237
|
-
const serialLen = readLen();
|
|
238
|
-
if (offset + serialLen > der.length)
|
|
239
|
-
throw new Error("DER overflow");
|
|
240
|
-
let serial = der.slice(offset, offset + serialLen);
|
|
241
|
-
// Strip ASN.1 sign-extension padding byte.
|
|
242
|
-
if (serial.length > 1 && serial[0] === 0x00) {
|
|
243
|
-
serial = serial.slice(1);
|
|
268
|
+
offset++; // tag
|
|
269
|
+
offset += readLen(); // skip content
|
|
244
270
|
}
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
271
|
+
// Now scan for first INTEGER with "real" length (>2 bytes)
|
|
272
|
+
while (offset < der.length) {
|
|
273
|
+
if (der[offset++] !== 0x02)
|
|
274
|
+
continue;
|
|
275
|
+
const len = readLen();
|
|
276
|
+
if (len <= 2) {
|
|
277
|
+
offset += len; // skip small integers (likely version)
|
|
278
|
+
continue;
|
|
279
|
+
}
|
|
280
|
+
if (offset + len > der.length)
|
|
281
|
+
throw new Error("DER overflow");
|
|
282
|
+
let serial = der.slice(offset, offset + len);
|
|
283
|
+
// Strip leading 0x00 ONLY if it's padding
|
|
284
|
+
if (serial.length > 1 && serial[0] === 0x00 && (serial[1] & 0x80) === 0) {
|
|
285
|
+
serial = serial.slice(1);
|
|
286
|
+
}
|
|
287
|
+
let serialBig = 0n;
|
|
288
|
+
for (let i = 0; i < serial.length; i++) {
|
|
289
|
+
serialBig = (serialBig << 8n) | BigInt(serial[i]);
|
|
290
|
+
}
|
|
291
|
+
return serialBig.toString();
|
|
248
292
|
}
|
|
249
|
-
|
|
293
|
+
throw new Error("serial not found");
|
|
250
294
|
}
|
|
251
295
|
catch (e) {
|
|
252
296
|
console.error("[parseCertSerialDec] failed", e);
|