@openeudi/openid4vp 0.8.0 → 0.8.1

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/index.js CHANGED
@@ -6361,6 +6361,33 @@ var init_es20152 = __esm({
6361
6361
  init_validity();
6362
6362
  }
6363
6363
  });
6364
+ function getSkiHex(cert) {
6365
+ const ext = cert.getExtension(SubjectKeyIdentifierExtension);
6366
+ return ext ? ext.keyId.toLowerCase() : null;
6367
+ }
6368
+ function certificatesEqual(a, b) {
6369
+ const ab = new Uint8Array(a.rawData);
6370
+ const bb = new Uint8Array(b.rawData);
6371
+ if (ab.length !== bb.length) return false;
6372
+ for (let i = 0; i < ab.length; i++) {
6373
+ if (ab[i] !== bb[i]) return false;
6374
+ }
6375
+ return true;
6376
+ }
6377
+ function getSkiBytes(cert) {
6378
+ const ext = cert.getExtension(SubjectKeyIdentifierExtension);
6379
+ if (!ext) return null;
6380
+ const hex = ext.keyId;
6381
+ const out = new Uint8Array(hex.length / 2);
6382
+ for (let i = 0; i < out.length; i++) {
6383
+ out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
6384
+ }
6385
+ return out;
6386
+ }
6387
+ var init_x509_utils = __esm({
6388
+ "src/trust/x509-utils.ts"() {
6389
+ }
6390
+ });
6364
6391
  function mapX509AlgoToJwaName(cert) {
6365
6392
  const alg = cert.signatureAlgorithm;
6366
6393
  const name = alg?.name ?? "";
@@ -6370,8 +6397,11 @@ function mapX509AlgoToJwaName(cert) {
6370
6397
  if (name === "ECDSA" && hash === "SHA-512") return "ES512";
6371
6398
  if (name === "Ed25519" || name === "EdDSA") return "EdDSA";
6372
6399
  if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-256") return "RS256";
6400
+ if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-384") return "RS384";
6401
+ if (name === "RSASSA-PKCS1-v1_5" && hash === "SHA-512") return "RS512";
6373
6402
  if (name === "RSA-PSS" && hash === "SHA-256") return "PS256";
6374
6403
  if (name === "RSA-PSS" && hash === "SHA-384") return "PS384";
6404
+ if (name === "RSA-PSS" && hash === "SHA-512") return "PS512";
6375
6405
  return `${name}-${hash}`;
6376
6406
  }
6377
6407
  function collectLeafNames(leaf) {
@@ -6464,8 +6494,20 @@ var init_ChainBuilder = __esm({
6464
6494
  init_es2015();
6465
6495
  init_es20152();
6466
6496
  init_errors();
6497
+ init_x509_utils();
6467
6498
  NAME_CONSTRAINTS_OID = "2.5.29.30";
6468
- DEFAULT_ALGORITHMS = ["ES256", "ES384", "EdDSA", "RS256", "PS256"];
6499
+ DEFAULT_ALGORITHMS = [
6500
+ "ES256",
6501
+ "ES384",
6502
+ "ES512",
6503
+ "EdDSA",
6504
+ "RS256",
6505
+ "RS384",
6506
+ "RS512",
6507
+ "PS256",
6508
+ "PS384",
6509
+ "PS512"
6510
+ ];
6469
6511
  ChainBuilder = class {
6470
6512
  constructor(opts = {}) {
6471
6513
  this.opts = opts;
@@ -6524,6 +6566,12 @@ var init_ChainBuilder = __esm({
6524
6566
  current = issuer;
6525
6567
  nonLeafDepth += 1;
6526
6568
  }
6569
+ if (!certificatesEqual(current, anchor)) {
6570
+ throw new CertificateChainError(
6571
+ `certificate ${current.subject} shares the trust anchor's Subject DN but is not the anchor (no signature closure)`,
6572
+ { reason: "signature" }
6573
+ );
6574
+ }
6527
6575
  this.checkNameConstraints(leaf, chain.slice(1));
6528
6576
  return chain;
6529
6577
  }
@@ -7764,7 +7812,10 @@ var init_RevocationChecker = __esm({
7764
7812
  if (hints.ocspUrl) {
7765
7813
  try {
7766
7814
  return await this.ocsp.checkCached(subjectCert, issuerCert, hints.ocspUrl, now);
7767
- } catch {
7815
+ } catch (err) {
7816
+ console.warn(
7817
+ `[openid4vp] OCSP check failed for ${subjectCert.subject} via ${hints.ocspUrl}, falling back to CRL: ${err.message}`
7818
+ );
7768
7819
  }
7769
7820
  }
7770
7821
  for (const url of hints.crlUrls) {
@@ -7792,6 +7843,9 @@ var init_RevocationChecker = __esm({
7792
7843
  return { status: "good", source: "crl", checkedAt: now };
7793
7844
  } catch (err) {
7794
7845
  if (err instanceof RevocationCheckFailedError) throw err;
7846
+ console.warn(
7847
+ `[openid4vp] CRL check failed for ${subjectCert.subject} via ${url}: ${err.message}`
7848
+ );
7795
7849
  continue;
7796
7850
  }
7797
7851
  }
@@ -7810,24 +7864,6 @@ var init_RevocationChecker = __esm({
7810
7864
  };
7811
7865
  }
7812
7866
  });
7813
- function getSkiHex(cert) {
7814
- const ext = cert.getExtension(SubjectKeyIdentifierExtension);
7815
- return ext ? ext.keyId.toLowerCase() : null;
7816
- }
7817
- function getSkiBytes(cert) {
7818
- const ext = cert.getExtension(SubjectKeyIdentifierExtension);
7819
- if (!ext) return null;
7820
- const hex = ext.keyId;
7821
- const out = new Uint8Array(hex.length / 2);
7822
- for (let i = 0; i < out.length; i++) {
7823
- out[i] = parseInt(hex.slice(i * 2, i * 2 + 2), 16);
7824
- }
7825
- return out;
7826
- }
7827
- var init_x509_utils = __esm({
7828
- "src/trust/x509-utils.ts"() {
7829
- }
7830
- });
7831
7867
 
7832
7868
  // src/trust/lotl-loa-mapping.ts
7833
7869
  function mapLoA(uris) {
@@ -8009,8 +8045,13 @@ var init_TrustEvaluator = __esm({
8009
8045
  );
8010
8046
  const terminusCert = chain[chain.length - 1];
8011
8047
  const anchor = anchors.find(
8012
- (a) => a.certificate.serialNumber === terminusCert.serialNumber
8013
- ) ?? anchors[0];
8048
+ (a) => certificatesEqual(a.certificate, terminusCert)
8049
+ );
8050
+ if (!anchor) {
8051
+ throw new TrustAnchorNotFoundError(
8052
+ `chain terminus ${terminusCert.subject} does not match any trust anchor certificate`
8053
+ );
8054
+ }
8014
8055
  const issuerForRevocation = chain.length > 1 ? chain[1] : terminusCert;
8015
8056
  const revocation = await this.revocationChecker.check(
8016
8057
  leaf,
@@ -8314,7 +8355,7 @@ function isHaipQuery(query) {
8314
8355
 
8315
8356
  // src/crypto/cose-sign1.ts
8316
8357
  init_errors();
8317
- var decoder = new Encoder({ mapsAsObjects: false, useRecords: false });
8358
+ var decoder = new Encoder({ mapsAsObjects: false, useRecords: false, tagUint8Array: false });
8318
8359
  var HEADER_ALG = 1;
8319
8360
  var HEADER_X5CHAIN = 33;
8320
8361
  var COSE_ALG_TO_NAME = {