@vizamodo/aws-sts-core 0.4.11 → 0.4.13

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.
Files changed (2) hide show
  1. package/dist/sts/issue.js +25 -27
  2. package/package.json +1 -1
package/dist/sts/issue.js CHANGED
@@ -44,24 +44,30 @@ async function getSigningMaterial(certBase64, privateKeyPkcs8Base64) {
44
44
  cachedPrivateKeyBase64 === privateKeyPkcs8Base64) {
45
45
  return cachedSigningKey;
46
46
  }
47
- // FIX 2: cache vars updated inside .then() no race condition.
48
- signingKeyPromise = null;
49
- cachedSigningKey = null;
50
- cachedCertBase64 = null;
51
- cachedPrivateKeyBase64 = null;
52
- signingKeyPromise = crypto.subtle
53
- .importKey("pkcs8", base64ToBytes(privateKeyPkcs8Base64), { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"])
54
- .then((key) => {
55
- cachedSigningKey = key;
47
+ // Material rotated discard the stale resolved key so we re-import.
48
+ if (cachedSigningKey) {
49
+ signingKeyPromise = null;
50
+ cachedSigningKey = null;
51
+ }
52
+ if (!signingKeyPromise) {
53
+ try {
54
+ const keyBuffer = base64ToBytes(privateKeyPkcs8Base64);
55
+ signingKeyPromise = crypto.subtle.importKey("pkcs8", keyBuffer, { name: "ECDSA", namedCurve: "P-256" }, false, ["sign"]);
56
+ }
57
+ catch {
58
+ throw new InternalError("invalid_signing_material");
59
+ }
60
+ }
61
+ try {
62
+ cachedSigningKey = await signingKeyPromise;
56
63
  cachedCertBase64 = certBase64;
57
64
  cachedPrivateKeyBase64 = privateKeyPkcs8Base64;
58
- return key;
59
- })
60
- .catch(() => {
65
+ return cachedSigningKey;
66
+ }
67
+ catch {
61
68
  signingKeyPromise = null;
62
69
  throw new InternalError("invalid_signing_material");
63
- });
64
- return signingKeyPromise;
70
+ }
65
71
  }
66
72
  // ── Session TTL ────────────────────────────────────────────────────────────
67
73
  function resolveSessionTtl(profile) {
@@ -125,19 +131,11 @@ async function fetchCredentials(input) {
125
131
  "X-Amz-X509": normalizedCert,
126
132
  "Authorization": `${ALGORITHM} Credential=${certSerialDec}/${credentialScope}, SignedHeaders=${signedHeaders}, Signature=${signatureHex}`,
127
133
  });
128
- // FIX 4: catch network errors as aws_unreachable.
129
- let res;
130
- try {
131
- res = await fetch(`https://${host}${PATH}`, {
132
- method: "POST",
133
- headers: finalHeaders,
134
- body,
135
- });
136
- }
137
- catch (err) {
138
- console.warn("[aws-unreachable]", { region, err });
139
- throw new InternalError("aws_unreachable");
140
- }
134
+ const res = await fetch(`https://${host}${PATH}`, {
135
+ method: "POST",
136
+ headers: finalHeaders,
137
+ body,
138
+ });
141
139
  if (!res.ok) {
142
140
  console.warn("[aws-rejected]", { status: res.status, region });
143
141
  throw new InternalError("aws_rejected");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vizamodo/aws-sts-core",
3
- "version": "0.4.11",
3
+ "version": "0.4.13",
4
4
  "description": "Pure AWS STS + SigV4 (X509 Roles Anywhere) core logic",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",