@simplewebauthn/server 3.0.0 → 4.3.0

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 (118) hide show
  1. package/dist/{assertion/generateAssertionOptions.d.ts → authentication/generateAuthenticationOptions.d.ts} +5 -5
  2. package/dist/{assertion/generateAssertionOptions.js → authentication/generateAuthenticationOptions.js} +6 -6
  3. package/dist/authentication/generateAuthenticationOptions.js.map +1 -0
  4. package/dist/{assertion/verifyAssertionResponse.d.ts → authentication/verifyAuthenticationResponse.d.ts} +12 -12
  5. package/dist/{assertion/verifyAssertionResponse.js → authentication/verifyAuthenticationResponse.js} +13 -12
  6. package/dist/authentication/verifyAuthenticationResponse.js.map +1 -0
  7. package/dist/helpers/convertAAGUIDToString.js +1 -1
  8. package/dist/helpers/convertAAGUIDToString.js.map +1 -1
  9. package/dist/helpers/convertCertBufferToPEM.d.ts +6 -0
  10. package/dist/helpers/{convertX509CertToPEM.js → convertCertBufferToPEM.js} +4 -4
  11. package/dist/helpers/convertCertBufferToPEM.js.map +1 -0
  12. package/dist/helpers/decodeAttestationObject.d.ts +2 -10
  13. package/dist/helpers/decodeAttestationObject.js +0 -11
  14. package/dist/helpers/decodeAttestationObject.js.map +1 -1
  15. package/dist/helpers/decodeClientDataJSON.d.ts +1 -2
  16. package/dist/helpers/index.d.ts +23 -0
  17. package/dist/helpers/index.js +39 -0
  18. package/dist/helpers/index.js.map +1 -0
  19. package/dist/helpers/isCertRevoked.js +4 -2
  20. package/dist/helpers/isCertRevoked.js.map +1 -1
  21. package/dist/helpers/logging.d.ts +16 -0
  22. package/dist/helpers/logging.js +27 -0
  23. package/dist/helpers/logging.js.map +1 -0
  24. package/dist/helpers/parseAuthenticatorData.js +13 -18
  25. package/dist/helpers/parseAuthenticatorData.js.map +1 -1
  26. package/dist/helpers/validateCertificatePath.d.ts +2 -1
  27. package/dist/helpers/validateCertificatePath.js +43 -4
  28. package/dist/helpers/validateCertificatePath.js.map +1 -1
  29. package/dist/index.d.ts +13 -11
  30. package/dist/index.js +12 -10
  31. package/dist/index.js.map +1 -1
  32. package/dist/metadata/mdsTypes.d.ts +207 -0
  33. package/dist/metadata/mdsTypes.js +3 -0
  34. package/dist/metadata/mdsTypes.js.map +1 -0
  35. package/dist/metadata/verifyAttestationWithMetadata.d.ts +5 -1
  36. package/dist/metadata/verifyAttestationWithMetadata.js +61 -27
  37. package/dist/metadata/verifyAttestationWithMetadata.js.map +1 -1
  38. package/dist/{attestation/generateAttestationOptions.d.ts → registration/generateRegistrationOptions.d.ts} +2 -2
  39. package/dist/{attestation/generateAttestationOptions.js → registration/generateRegistrationOptions.js} +3 -3
  40. package/dist/registration/generateRegistrationOptions.js.map +1 -0
  41. package/dist/{attestation → registration}/verifications/tpm/constants.d.ts +0 -0
  42. package/dist/{attestation → registration}/verifications/tpm/constants.js +0 -0
  43. package/dist/registration/verifications/tpm/constants.js.map +1 -0
  44. package/dist/{attestation → registration}/verifications/tpm/parseCertInfo.d.ts +0 -0
  45. package/dist/registration/verifications/tpm/parseCertInfo.js +53 -0
  46. package/dist/registration/verifications/tpm/parseCertInfo.js.map +1 -0
  47. package/dist/{attestation → registration}/verifications/tpm/parsePubArea.d.ts +0 -0
  48. package/dist/{attestation → registration}/verifications/tpm/parsePubArea.js +10 -19
  49. package/dist/registration/verifications/tpm/parsePubArea.js.map +1 -0
  50. package/dist/registration/verifications/tpm/verifyTPM.d.ts +2 -0
  51. package/dist/{attestation → registration}/verifications/tpm/verifyTPM.js +14 -4
  52. package/dist/registration/verifications/tpm/verifyTPM.js.map +1 -0
  53. package/dist/registration/verifications/verifyAndroidKey.d.ts +5 -0
  54. package/dist/{attestation → registration}/verifications/verifyAndroidKey.js +17 -12
  55. package/dist/registration/verifications/verifyAndroidKey.js.map +1 -0
  56. package/dist/registration/verifications/verifyAndroidSafetyNet.d.ts +5 -0
  57. package/dist/{attestation → registration}/verifications/verifyAndroidSafetyNet.js +6 -27
  58. package/dist/registration/verifications/verifyAndroidSafetyNet.js.map +1 -0
  59. package/dist/registration/verifications/verifyApple.d.ts +2 -0
  60. package/dist/{attestation → registration}/verifications/verifyApple.js +3 -26
  61. package/dist/registration/verifications/verifyApple.js.map +1 -0
  62. package/dist/registration/verifications/verifyFIDOU2F.d.ts +5 -0
  63. package/dist/{attestation → registration}/verifications/verifyFIDOU2F.js +12 -4
  64. package/dist/registration/verifications/verifyFIDOU2F.js.map +1 -0
  65. package/dist/registration/verifications/verifyPacked.d.ts +5 -0
  66. package/dist/{attestation → registration}/verifications/verifyPacked.js +15 -7
  67. package/dist/registration/verifications/verifyPacked.js.map +1 -0
  68. package/dist/registration/verifyRegistrationResponse.d.ts +71 -0
  69. package/dist/{attestation/verifyAttestationResponse.js → registration/verifyRegistrationResponse.js} +56 -92
  70. package/dist/registration/verifyRegistrationResponse.js.map +1 -0
  71. package/dist/services/defaultRootCerts/android-key.d.ts +24 -0
  72. package/dist/services/defaultRootCerts/android-key.js +89 -0
  73. package/dist/services/defaultRootCerts/android-key.js.map +1 -0
  74. package/dist/services/defaultRootCerts/android-safetynet.d.ts +22 -0
  75. package/dist/services/defaultRootCerts/android-safetynet.js +69 -0
  76. package/dist/services/defaultRootCerts/android-safetynet.js.map +1 -0
  77. package/dist/services/defaultRootCerts/apple.d.ts +11 -0
  78. package/dist/services/defaultRootCerts/apple.js +29 -0
  79. package/dist/services/defaultRootCerts/apple.js.map +1 -0
  80. package/dist/services/defaultRootCerts/mds.d.ts +11 -0
  81. package/dist/services/defaultRootCerts/mds.js +36 -0
  82. package/dist/services/defaultRootCerts/mds.js.map +1 -0
  83. package/dist/services/metadataService.d.ts +54 -0
  84. package/dist/{metadata → services}/metadataService.js +90 -109
  85. package/dist/services/metadataService.js.map +1 -0
  86. package/dist/services/settingsService.d.ts +26 -0
  87. package/dist/services/settingsService.js +63 -0
  88. package/dist/services/settingsService.js.map +1 -0
  89. package/package.json +28 -12
  90. package/.env +0 -2
  91. package/dist/assertion/generateAssertionOptions.js.map +0 -1
  92. package/dist/assertion/verifyAssertionResponse.js.map +0 -1
  93. package/dist/attestation/generateAttestationOptions.js.map +0 -1
  94. package/dist/attestation/verifications/tpm/constants.js.map +0 -1
  95. package/dist/attestation/verifications/tpm/parseCertInfo.js +0 -65
  96. package/dist/attestation/verifications/tpm/parseCertInfo.js.map +0 -1
  97. package/dist/attestation/verifications/tpm/parsePubArea.js.map +0 -1
  98. package/dist/attestation/verifications/tpm/verifyTPM.d.ts +0 -11
  99. package/dist/attestation/verifications/tpm/verifyTPM.js.map +0 -1
  100. package/dist/attestation/verifications/verifyAndroidKey.d.ts +0 -11
  101. package/dist/attestation/verifications/verifyAndroidKey.js.map +0 -1
  102. package/dist/attestation/verifications/verifyAndroidSafetyNet.d.ts +0 -14
  103. package/dist/attestation/verifications/verifyAndroidSafetyNet.js.map +0 -1
  104. package/dist/attestation/verifications/verifyApple.d.ts +0 -10
  105. package/dist/attestation/verifications/verifyApple.js.map +0 -1
  106. package/dist/attestation/verifications/verifyFIDOU2F.d.ts +0 -15
  107. package/dist/attestation/verifications/verifyFIDOU2F.js.map +0 -1
  108. package/dist/attestation/verifications/verifyPacked.d.ts +0 -14
  109. package/dist/attestation/verifications/verifyPacked.js.map +0 -1
  110. package/dist/attestation/verifyAttestationResponse.d.ts +0 -56
  111. package/dist/attestation/verifyAttestationResponse.js.map +0 -1
  112. package/dist/helpers/constants.d.ts +0 -30
  113. package/dist/helpers/constants.js +0 -52
  114. package/dist/helpers/constants.js.map +0 -1
  115. package/dist/helpers/convertX509CertToPEM.d.ts +0 -6
  116. package/dist/helpers/convertX509CertToPEM.js.map +0 -1
  117. package/dist/metadata/metadataService.d.ts +0 -75
  118. package/dist/metadata/metadataService.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  /// <reference types="node" />
2
2
  import type { AuthenticationExtensionsClientInputs, PublicKeyCredentialRequestOptionsJSON, PublicKeyCredentialDescriptor, UserVerificationRequirement } from '@simplewebauthn/typescript-types';
3
- export declare type GenerateAssertionOptionsOpts = {
3
+ export declare type GenerateAuthenticationOptionsOpts = {
4
4
  allowCredentials?: PublicKeyCredentialDescriptor[];
5
5
  challenge?: string | Buffer;
6
6
  timeout?: number;
@@ -14,11 +14,11 @@ export declare type GenerateAssertionOptionsOpts = {
14
14
  * @param allowCredentials Authenticators previously registered by the user, if any. If undefined
15
15
  * the client will ask the user which credential they want to use
16
16
  * @param challenge Random value the authenticator needs to sign and pass back
17
- * user for assertion
18
- * @param timeout How long (in ms) the user can take to complete assertion
17
+ * user for authentication
18
+ * @param timeout How long (in ms) the user can take to complete authentication
19
19
  * @param userVerification Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise
20
20
  * set to `'preferred'` or `'required'` as desired.
21
- * @param extensions Additional plugins the authenticator or browser should use during assertion
21
+ * @param extensions Additional plugins the authenticator or browser should use during authentication
22
22
  * @param rpID Valid domain name (after `https://`)
23
23
  */
24
- export default function generateAssertionOptions(options?: GenerateAssertionOptionsOpts): PublicKeyCredentialRequestOptionsJSON;
24
+ export default function generateAuthenticationOptions(options?: GenerateAuthenticationOptionsOpts): PublicKeyCredentialRequestOptionsJSON;
@@ -11,14 +11,14 @@ const generateChallenge_1 = __importDefault(require("../helpers/generateChalleng
11
11
  * @param allowCredentials Authenticators previously registered by the user, if any. If undefined
12
12
  * the client will ask the user which credential they want to use
13
13
  * @param challenge Random value the authenticator needs to sign and pass back
14
- * user for assertion
15
- * @param timeout How long (in ms) the user can take to complete assertion
14
+ * user for authentication
15
+ * @param timeout How long (in ms) the user can take to complete authentication
16
16
  * @param userVerification Set to `'discouraged'` when asserting as part of a 2FA flow, otherwise
17
17
  * set to `'preferred'` or `'required'` as desired.
18
- * @param extensions Additional plugins the authenticator or browser should use during assertion
18
+ * @param extensions Additional plugins the authenticator or browser should use during authentication
19
19
  * @param rpID Valid domain name (after `https://`)
20
20
  */
21
- function generateAssertionOptions(options = {}) {
21
+ function generateAuthenticationOptions(options = {}) {
22
22
  const { allowCredentials, challenge = generateChallenge_1.default(), timeout = 60000, userVerification, extensions, rpID, } = options;
23
23
  return {
24
24
  challenge: base64url_1.default.encode(challenge),
@@ -32,5 +32,5 @@ function generateAssertionOptions(options = {}) {
32
32
  rpId: rpID,
33
33
  };
34
34
  }
35
- exports.default = generateAssertionOptions;
36
- //# sourceMappingURL=generateAssertionOptions.js.map
35
+ exports.default = generateAuthenticationOptions;
36
+ //# sourceMappingURL=generateAuthenticationOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateAuthenticationOptions.js","sourceRoot":"","sources":["../../src/authentication/generateAuthenticationOptions.ts"],"names":[],"mappings":";;;;;AAMA,0DAAkC;AAElC,qFAA6D;AAW7D;;;;;;;;;;;;GAYG;AACH,SAAwB,6BAA6B,CACnD,UAA6C,EAAE;IAE/C,MAAM,EACJ,gBAAgB,EAChB,SAAS,GAAG,2BAAiB,EAAE,EAC/B,OAAO,GAAG,KAAK,EACf,gBAAgB,EAChB,UAAU,EACV,IAAI,GACL,GAAG,OAAO,CAAC;IAEZ,OAAO;QACL,SAAS,EAAE,mBAAS,CAAC,MAAM,CAAC,SAAS,CAAC;QACtC,gBAAgB,EAAE,gBAAgB,aAAhB,gBAAgB,uBAAhB,gBAAgB,CAAE,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;YAC/C,GAAG,IAAI;YACP,EAAE,EAAE,mBAAS,CAAC,MAAM,CAAC,IAAI,CAAC,EAAY,CAAC;SACxC,CAAC,CAAC;QACH,OAAO;QACP,gBAAgB;QAChB,UAAU;QACV,IAAI,EAAE,IAAI;KACX,CAAC;AACJ,CAAC;AAvBD,gDAuBC"}
@@ -1,7 +1,7 @@
1
1
  /// <reference types="node" />
2
- import { AssertionCredentialJSON, AuthenticatorDevice, UserVerificationRequirement } from '@simplewebauthn/typescript-types';
3
- export declare type VerifyAssertionResponseOpts = {
4
- credential: AssertionCredentialJSON;
2
+ import { AuthenticationCredentialJSON, AuthenticatorDevice, UserVerificationRequirement } from '@simplewebauthn/typescript-types';
3
+ export declare type VerifyAuthenticationResponseOpts = {
4
+ credential: AuthenticationCredentialJSON;
5
5
  expectedChallenge: string;
6
6
  expectedOrigin: string | string[];
7
7
  expectedRPID: string | string[];
@@ -16,28 +16,28 @@ export declare type VerifyAssertionResponseOpts = {
16
16
  * @param credential Authenticator credential returned by browser's `startAssertion()`
17
17
  * @param expectedChallenge The base64url-encoded `options.challenge` returned by
18
18
  * `generateAssertionOptions()`
19
- * @param expectedOrigin Website URL (or array of URLs) that the attestation should have occurred on
20
- * @param expectedRPID RP ID (or array of IDs) that was specified in the attestation options
19
+ * @param expectedOrigin Website URL (or array of URLs) that the registration should have occurred on
20
+ * @param expectedRPID RP ID (or array of IDs) that was specified in the registration options
21
21
  * @param authenticator An internal {@link AuthenticatorDevice} matching the credential's ID
22
22
  * @param fidoUserVerification (Optional) The value specified for `userVerification` when calling
23
23
  * `generateAssertionOptions()`. Activates FIDO-specific user presence and verification checks.
24
24
  * Omitting this value defaults verification to a WebAuthn-specific user presence requirement.
25
25
  */
26
- export default function verifyAssertionResponse(options: VerifyAssertionResponseOpts): VerifiedAssertion;
26
+ export default function verifyAuthenticationResponse(options: VerifyAuthenticationResponseOpts): VerifiedAuthenticationResponse;
27
27
  /**
28
- * Result of assertion verification
28
+ * Result of authentication verification
29
29
  *
30
- * @param verified If the assertion response could be verified
31
- * @param assertionInfo.credentialID The ID of the authenticator used during assertion.
30
+ * @param verified If the authentication response could be verified
31
+ * @param authenticationInfo.credentialID The ID of the authenticator used during authentication.
32
32
  * Should be used to identify which DB authenticator entry needs its `counter` updated to the value
33
33
  * below
34
- * @param assertionInfo.newCounter The number of times the authenticator identified above
34
+ * @param authenticationInfo.newCounter The number of times the authenticator identified above
35
35
  * reported it has been used. **Should be kept in a DB for later reference to help prevent replay
36
36
  * attacks!**
37
37
  */
38
- export declare type VerifiedAssertion = {
38
+ export declare type VerifiedAuthenticationResponse = {
39
39
  verified: boolean;
40
- assertionInfo: {
40
+ authenticationInfo: {
41
41
  credentialID: Buffer;
42
42
  newCounter: number;
43
43
  };
@@ -18,14 +18,14 @@ const isBase64URLString_1 = __importDefault(require("../helpers/isBase64URLStrin
18
18
  * @param credential Authenticator credential returned by browser's `startAssertion()`
19
19
  * @param expectedChallenge The base64url-encoded `options.challenge` returned by
20
20
  * `generateAssertionOptions()`
21
- * @param expectedOrigin Website URL (or array of URLs) that the attestation should have occurred on
22
- * @param expectedRPID RP ID (or array of IDs) that was specified in the attestation options
21
+ * @param expectedOrigin Website URL (or array of URLs) that the registration should have occurred on
22
+ * @param expectedRPID RP ID (or array of IDs) that was specified in the registration options
23
23
  * @param authenticator An internal {@link AuthenticatorDevice} matching the credential's ID
24
24
  * @param fidoUserVerification (Optional) The value specified for `userVerification` when calling
25
25
  * `generateAssertionOptions()`. Activates FIDO-specific user presence and verification checks.
26
26
  * Omitting this value defaults verification to a WebAuthn-specific user presence requirement.
27
27
  */
28
- function verifyAssertionResponse(options) {
28
+ function verifyAuthenticationResponse(options) {
29
29
  const { credential, expectedChallenge, expectedOrigin, expectedRPID, authenticator, fidoUserVerification, } = options;
30
30
  const { id, rawId, type: credentialType, response } = credential;
31
31
  // Ensure credential specified an ID
@@ -48,23 +48,24 @@ function verifyAssertionResponse(options) {
48
48
  }
49
49
  const clientDataJSON = decodeClientDataJSON_1.default(response.clientDataJSON);
50
50
  const { type, origin, challenge, tokenBinding } = clientDataJSON;
51
- // Make sure we're handling an assertion
51
+ // Make sure we're handling an authentication
52
52
  if (type !== 'webauthn.get') {
53
- throw new Error(`Unexpected assertion type: ${type}`);
53
+ throw new Error(`Unexpected authentication response type: ${type}`);
54
54
  }
55
55
  // Ensure the device provided the challenge we gave it
56
56
  if (challenge !== expectedChallenge) {
57
- throw new Error(`Unexpected assertion challenge "${challenge}", expected "${expectedChallenge}"`);
57
+ throw new Error(`Unexpected authentication response challenge "${challenge}", expected "${expectedChallenge}"`);
58
58
  }
59
59
  // Check that the origin is our site
60
60
  if (Array.isArray(expectedOrigin)) {
61
61
  if (!expectedOrigin.includes(origin)) {
62
- throw new Error(`Unexpected assertion origin "${origin}", expected one of: ${expectedOrigin.join(', ')}`);
62
+ const joinedExpectedOrigin = expectedOrigin.join(', ');
63
+ throw new Error(`Unexpected authentication response origin "${origin}", expected one of: ${joinedExpectedOrigin}`);
63
64
  }
64
65
  }
65
66
  else {
66
67
  if (origin !== expectedOrigin) {
67
- throw new Error(`Unexpected assertion origin "${origin}", expected "${expectedOrigin}"`);
68
+ throw new Error(`Unexpected authentication response origin "${origin}", expected "${expectedOrigin}"`);
68
69
  }
69
70
  }
70
71
  if (!isBase64URLString_1.default(response.authenticatorData)) {
@@ -119,7 +120,7 @@ function verifyAssertionResponse(options) {
119
120
  else {
120
121
  // WebAuthn only requires the user presence flag be true
121
122
  if (!flags.up) {
122
- throw new Error('User not present during assertion');
123
+ throw new Error('User not present during authentication');
123
124
  }
124
125
  }
125
126
  const clientDataHash = toHash_1.default(base64url_1.default.toBuffer(response.clientDataJSON));
@@ -135,12 +136,12 @@ function verifyAssertionResponse(options) {
135
136
  }
136
137
  const toReturn = {
137
138
  verified: verifySignature_1.default(signature, signatureBase, publicKey),
138
- assertionInfo: {
139
+ authenticationInfo: {
139
140
  newCounter: counter,
140
141
  credentialID: authenticator.credentialID,
141
142
  },
142
143
  };
143
144
  return toReturn;
144
145
  }
145
- exports.default = verifyAssertionResponse;
146
- //# sourceMappingURL=verifyAssertionResponse.js.map
146
+ exports.default = verifyAuthenticationResponse;
147
+ //# sourceMappingURL=verifyAuthenticationResponse.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"verifyAuthenticationResponse.js","sourceRoot":"","sources":["../../src/authentication/verifyAuthenticationResponse.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAOlC,2FAAmE;AACnE,+DAAuC;AACvC,6FAAqE;AACrE,iFAAyD;AACzD,+FAAuE;AACvE,qFAA6D;AAW7D;;;;;;;;;;;;;;GAcG;AACH,SAAwB,4BAA4B,CAClD,OAAyC;IAEzC,MAA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M,CAAC,MAAM,CAAC,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC,CAAC;IAEtE,MAAM,SAAS,GAAG,+BAAqB,CAAC,aAAa,CAAC,mBAAmB,CAAC,CAAC;IAC3E,MAAM,SAAS,GAAG,mBAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,SAAS,CAAC,CAAC;IAEzD,IAAI,CAAC,OAAO,GAAG,CAAC,IAAI,aAAa,CAAC,OAAO,GAAG,CAAC,CAAC,IAAI,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE;QAClF,sFAAsF;QACtF,2FAA2F;QAC3F,sFAAsF;QACtF,gDAAgD;QAChD,MAAM,IAAI,KAAK,CACb,0BAA0B,OAAO,4BAA4B,aAAa,CAAC,OAAO,EAAE,CACrF,CAAC;KACH;IAED,MAAM,QAAQ,GAAG;QACf,QAAQ,EAAE,yBAAe,CAAC,SAAS,EAAE,aAAa,EAAE,SAAS,CAAC;QAC9D,kBAAkB,EAAE;YAClB,UAAU,EAAE,OAAO;YACnB,YAAY,EAAE,aAAa,CAAC,YAAY;SACzC;KACF,CAAC;IAEF,OAAO,QAAQ,CAAC;AAClB,CAAC;AA1JD,+CA0JC"}
@@ -11,7 +11,7 @@ function convertAAGUIDToString(aaguid) {
11
11
  hex.slice(8, 12),
12
12
  hex.slice(12, 16),
13
13
  hex.slice(16, 20),
14
- hex.slice(20, 32),
14
+ hex.slice(20, 32), // 8
15
15
  ];
16
16
  // Formatted: adce0002-35bc-c60a-648b-0b25f1f05503
17
17
  return segments.join('-');
@@ -1 +1 @@
1
- {"version":3,"file":"convertAAGUIDToString.js","sourceRoot":"","sources":["../../src/helpers/convertAAGUIDToString.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,SAAwB,qBAAqB,CAAC,MAAc;IAC1D,4CAA4C;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAa;QACzB,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAChB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;KAClB,CAAC;IAEF,kDAAkD;IAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAdD,wCAcC"}
1
+ {"version":3,"file":"convertAAGUIDToString.js","sourceRoot":"","sources":["../../src/helpers/convertAAGUIDToString.ts"],"names":[],"mappings":";;AAAA;;GAEG;AACH,SAAwB,qBAAqB,CAAC,MAAc;IAC1D,4CAA4C;IAC5C,MAAM,GAAG,GAAG,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEnC,MAAM,QAAQ,GAAa;QACzB,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC;QACf,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAChB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC;QACjB,GAAG,CAAC,KAAK,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,IAAI;KACxB,CAAC;IAEF,kDAAkD;IAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAC5B,CAAC;AAdD,wCAcC"}
@@ -0,0 +1,6 @@
1
+ /// <reference types="node" />
2
+ import type { Base64URLString } from '@simplewebauthn/typescript-types';
3
+ /**
4
+ * Convert buffer to an OpenSSL-compatible PEM text format.
5
+ */
6
+ export default function convertCertBufferToPEM(certBuffer: Buffer | Base64URLString): string;
@@ -5,9 +5,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  const base64url_1 = __importDefault(require("base64url"));
7
7
  /**
8
- * Convert X.509 certificate to an OpenSSL-compatible PEM text format.
8
+ * Convert buffer to an OpenSSL-compatible PEM text format.
9
9
  */
10
- function convertX509CertToPEM(certBuffer) {
10
+ function convertCertBufferToPEM(certBuffer) {
11
11
  let buffer;
12
12
  if (typeof certBuffer === 'string') {
13
13
  buffer = base64url_1.default.toBuffer(certBuffer);
@@ -24,5 +24,5 @@ function convertX509CertToPEM(certBuffer) {
24
24
  PEMKey = `-----BEGIN CERTIFICATE-----\n${PEMKey}-----END CERTIFICATE-----\n`;
25
25
  return PEMKey;
26
26
  }
27
- exports.default = convertX509CertToPEM;
28
- //# sourceMappingURL=convertX509CertToPEM.js.map
27
+ exports.default = convertCertBufferToPEM;
28
+ //# sourceMappingURL=convertCertBufferToPEM.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertCertBufferToPEM.js","sourceRoot":"","sources":["../../src/helpers/convertCertBufferToPEM.ts"],"names":[],"mappings":";;;;;AAAA,0DAAkC;AAGlC;;GAEG;AACH,SAAwB,sBAAsB,CAAC,UAAoC;IACjF,IAAI,MAAc,CAAC;IACnB,IAAI,OAAO,UAAU,KAAK,QAAQ,EAAE;QAClC,MAAM,GAAG,mBAAS,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAC;KACzC;SAAM;QACL,MAAM,GAAG,UAAU,CAAC;KACrB;IAED,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,QAAQ,CAAC,CAAC;IAE1C,IAAI,MAAM,GAAG,EAAE,CAAC;IAChB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,EAAE,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE;QAC1D,MAAM,KAAK,GAAG,EAAE,GAAG,CAAC,CAAC;QAErB,MAAM,IAAI,GAAG,OAAO,CAAC,MAAM,CAAC,KAAK,EAAE,EAAE,CAAC,IAAI,CAAC;KAC5C;IAED,MAAM,GAAG,gCAAgC,MAAM,6BAA6B,CAAC;IAE7E,OAAO,MAAM,CAAC;AAChB,CAAC;AApBD,yCAoBC"}
@@ -5,17 +5,9 @@
5
5
  * @param base64AttestationObject Attestation Object buffer
6
6
  */
7
7
  export default function decodeAttestationObject(attestationObject: Buffer): AttestationObject;
8
- export declare enum ATTESTATION_FORMAT {
9
- FIDO_U2F = "fido-u2f",
10
- PACKED = "packed",
11
- ANDROID_SAFETYNET = "android-safetynet",
12
- ANDROID_KEY = "android-key",
13
- TPM = "tpm",
14
- APPLE = "apple",
15
- NONE = "none"
16
- }
8
+ export declare type AttestationFormat = 'fido-u2f' | 'packed' | 'android-safetynet' | 'android-key' | 'tpm' | 'apple' | 'none';
17
9
  export declare type AttestationObject = {
18
- fmt: ATTESTATION_FORMAT;
10
+ fmt: AttestationFormat;
19
11
  attStmt: AttestationStatement;
20
12
  authData: Buffer;
21
13
  };
@@ -3,7 +3,6 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.ATTESTATION_FORMAT = void 0;
7
6
  const cbor_1 = __importDefault(require("cbor"));
8
7
  /**
9
8
  * Convert an AttestationObject buffer to a proper object
@@ -15,14 +14,4 @@ function decodeAttestationObject(attestationObject) {
15
14
  return toCBOR;
16
15
  }
17
16
  exports.default = decodeAttestationObject;
18
- var ATTESTATION_FORMAT;
19
- (function (ATTESTATION_FORMAT) {
20
- ATTESTATION_FORMAT["FIDO_U2F"] = "fido-u2f";
21
- ATTESTATION_FORMAT["PACKED"] = "packed";
22
- ATTESTATION_FORMAT["ANDROID_SAFETYNET"] = "android-safetynet";
23
- ATTESTATION_FORMAT["ANDROID_KEY"] = "android-key";
24
- ATTESTATION_FORMAT["TPM"] = "tpm";
25
- ATTESTATION_FORMAT["APPLE"] = "apple";
26
- ATTESTATION_FORMAT["NONE"] = "none";
27
- })(ATTESTATION_FORMAT = exports.ATTESTATION_FORMAT || (exports.ATTESTATION_FORMAT = {}));
28
17
  //# sourceMappingURL=decodeAttestationObject.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"decodeAttestationObject.js","sourceRoot":"","sources":["../../src/helpers/decodeAttestationObject.ts"],"names":[],"mappings":";;;;;;AAAA,gDAAwB;AAExB;;;;GAIG;AACH,SAAwB,uBAAuB,CAAC,iBAAyB;IACvE,MAAM,MAAM,GAAsB,cAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAHD,0CAGC;AAED,IAAY,kBAQX;AARD,WAAY,kBAAkB;IAC5B,2CAAqB,CAAA;IACrB,uCAAiB,CAAA;IACjB,6DAAuC,CAAA;IACvC,iDAA2B,CAAA;IAC3B,iCAAW,CAAA;IACX,qCAAe,CAAA;IACf,mCAAa,CAAA;AACf,CAAC,EARW,kBAAkB,GAAlB,0BAAkB,KAAlB,0BAAkB,QAQ7B"}
1
+ {"version":3,"file":"decodeAttestationObject.js","sourceRoot":"","sources":["../../src/helpers/decodeAttestationObject.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AAExB;;;;GAIG;AACH,SAAwB,uBAAuB,CAAC,iBAAyB;IACvE,MAAM,MAAM,GAAsB,cAAI,CAAC,aAAa,CAAC,iBAAiB,CAAC,CAAC,CAAC,CAAC,CAAC;IAC3E,OAAO,MAAM,CAAC;AAChB,CAAC;AAHD,0CAGC"}
@@ -2,7 +2,7 @@
2
2
  * Decode an authenticator's base64url-encoded clientDataJSON to JSON
3
3
  */
4
4
  export default function decodeClientDataJSON(data: string): ClientDataJSON;
5
- declare type ClientDataJSON = {
5
+ export declare type ClientDataJSON = {
6
6
  type: string;
7
7
  challenge: string;
8
8
  origin: string;
@@ -12,4 +12,3 @@ declare type ClientDataJSON = {
12
12
  status: 'present' | 'supported' | 'not-supported';
13
13
  };
14
14
  };
15
- export {};
@@ -0,0 +1,23 @@
1
+ import convertAAGUIDToString from './convertAAGUIDToString';
2
+ import convertCertBufferToPEM from './convertCertBufferToPEM';
3
+ import convertCOSEtoPKCS from './convertCOSEtoPKCS';
4
+ import convertPublicKeyToPEM from './convertPublicKeyToPEM';
5
+ import decodeAttestationObject from './decodeAttestationObject';
6
+ import { decodeCborFirst } from './decodeCbor';
7
+ import decodeClientDataJSON from './decodeClientDataJSON';
8
+ import decodeCredentialPublicKey from './decodeCredentialPublicKey';
9
+ import generateChallenge from './generateChallenge';
10
+ import getCertificateInfo from './getCertificateInfo';
11
+ import isBase64URLString from './isBase64URLString';
12
+ import isCertRevoked from './isCertRevoked';
13
+ import parseAuthenticatorData from './parseAuthenticatorData';
14
+ import toHash from './toHash';
15
+ import validateCertificatePath from './validateCertificatePath';
16
+ import verifySignature from './verifySignature';
17
+ export { convertAAGUIDToString, convertCertBufferToPEM, convertCOSEtoPKCS, convertPublicKeyToPEM, decodeAttestationObject, decodeCborFirst, decodeClientDataJSON, decodeCredentialPublicKey, generateChallenge, getCertificateInfo, isBase64URLString, isCertRevoked, parseAuthenticatorData, toHash, validateCertificatePath, verifySignature, };
18
+ import type { AttestationFormat, AttestationObject, AttestationStatement } from './decodeAttestationObject';
19
+ import type { CertificateInfo } from './getCertificateInfo';
20
+ import type { ClientDataJSON } from './decodeClientDataJSON';
21
+ import type { COSEPublicKey } from './convertCOSEtoPKCS';
22
+ import type { ParsedAuthenticatorData } from './parseAuthenticatorData';
23
+ export type { AttestationFormat, AttestationObject, AttestationStatement, CertificateInfo, ClientDataJSON, COSEPublicKey, ParsedAuthenticatorData, };
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.verifySignature = exports.validateCertificatePath = exports.toHash = exports.parseAuthenticatorData = exports.isCertRevoked = exports.isBase64URLString = exports.getCertificateInfo = exports.generateChallenge = exports.decodeCredentialPublicKey = exports.decodeClientDataJSON = exports.decodeCborFirst = exports.decodeAttestationObject = exports.convertPublicKeyToPEM = exports.convertCOSEtoPKCS = exports.convertCertBufferToPEM = exports.convertAAGUIDToString = void 0;
7
+ const convertAAGUIDToString_1 = __importDefault(require("./convertAAGUIDToString"));
8
+ exports.convertAAGUIDToString = convertAAGUIDToString_1.default;
9
+ const convertCertBufferToPEM_1 = __importDefault(require("./convertCertBufferToPEM"));
10
+ exports.convertCertBufferToPEM = convertCertBufferToPEM_1.default;
11
+ const convertCOSEtoPKCS_1 = __importDefault(require("./convertCOSEtoPKCS"));
12
+ exports.convertCOSEtoPKCS = convertCOSEtoPKCS_1.default;
13
+ const convertPublicKeyToPEM_1 = __importDefault(require("./convertPublicKeyToPEM"));
14
+ exports.convertPublicKeyToPEM = convertPublicKeyToPEM_1.default;
15
+ const decodeAttestationObject_1 = __importDefault(require("./decodeAttestationObject"));
16
+ exports.decodeAttestationObject = decodeAttestationObject_1.default;
17
+ const decodeCbor_1 = require("./decodeCbor");
18
+ Object.defineProperty(exports, "decodeCborFirst", { enumerable: true, get: function () { return decodeCbor_1.decodeCborFirst; } });
19
+ const decodeClientDataJSON_1 = __importDefault(require("./decodeClientDataJSON"));
20
+ exports.decodeClientDataJSON = decodeClientDataJSON_1.default;
21
+ const decodeCredentialPublicKey_1 = __importDefault(require("./decodeCredentialPublicKey"));
22
+ exports.decodeCredentialPublicKey = decodeCredentialPublicKey_1.default;
23
+ const generateChallenge_1 = __importDefault(require("./generateChallenge"));
24
+ exports.generateChallenge = generateChallenge_1.default;
25
+ const getCertificateInfo_1 = __importDefault(require("./getCertificateInfo"));
26
+ exports.getCertificateInfo = getCertificateInfo_1.default;
27
+ const isBase64URLString_1 = __importDefault(require("./isBase64URLString"));
28
+ exports.isBase64URLString = isBase64URLString_1.default;
29
+ const isCertRevoked_1 = __importDefault(require("./isCertRevoked"));
30
+ exports.isCertRevoked = isCertRevoked_1.default;
31
+ const parseAuthenticatorData_1 = __importDefault(require("./parseAuthenticatorData"));
32
+ exports.parseAuthenticatorData = parseAuthenticatorData_1.default;
33
+ const toHash_1 = __importDefault(require("./toHash"));
34
+ exports.toHash = toHash_1.default;
35
+ const validateCertificatePath_1 = __importDefault(require("./validateCertificatePath"));
36
+ exports.validateCertificatePath = validateCertificatePath_1.default;
37
+ const verifySignature_1 = __importDefault(require("./verifySignature"));
38
+ exports.verifySignature = verifySignature_1.default;
39
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":";;;;;;AAAA,oFAA4D;AAkB1D,gCAlBK,+BAAqB,CAkBL;AAjBvB,sFAA8D;AAkB5D,iCAlBK,gCAAsB,CAkBL;AAjBxB,4EAAoD;AAkBlD,4BAlBK,2BAAiB,CAkBL;AAjBnB,oFAA4D;AAkB1D,gCAlBK,+BAAqB,CAkBL;AAjBvB,wFAAgE;AAkB9D,kCAlBK,iCAAuB,CAkBL;AAjBzB,6CAA+C;AAkB7C,gGAlBO,4BAAe,OAkBP;AAjBjB,kFAA0D;AAkBxD,+BAlBK,8BAAoB,CAkBL;AAjBtB,4FAAoE;AAkBlE,oCAlBK,mCAAyB,CAkBL;AAjB3B,4EAAoD;AAkBlD,4BAlBK,2BAAiB,CAkBL;AAjBnB,8EAAsD;AAkBpD,6BAlBK,4BAAkB,CAkBL;AAjBpB,4EAAoD;AAkBlD,4BAlBK,2BAAiB,CAkBL;AAjBnB,oEAA4C;AAkB1C,wBAlBK,uBAAa,CAkBL;AAjBf,sFAA8D;AAkB5D,iCAlBK,gCAAsB,CAkBL;AAjBxB,sDAA8B;AAkB5B,iBAlBK,gBAAM,CAkBL;AAjBR,wFAAgE;AAkB9D,kCAlBK,iCAAuB,CAkBL;AAjBzB,wEAAgD;AAkB9C,0BAlBK,yBAAe,CAkBL"}
@@ -7,6 +7,7 @@ const jsrsasign_1 = require("jsrsasign");
7
7
  const node_fetch_1 = __importDefault(require("node-fetch"));
8
8
  const asn1_schema_1 = require("@peculiar/asn1-schema");
9
9
  const asn1_x509_1 = require("@peculiar/asn1-x509");
10
+ const convertCertBufferToPEM_1 = __importDefault(require("./convertCertBufferToPEM"));
10
11
  const cacheRevokedCerts = {};
11
12
  /**
12
13
  * A method to pull a CRL from a certificate and compare its serial number to the list of revoked
@@ -50,8 +51,9 @@ async function isCertRevoked(cert) {
50
51
  const crlCert = new jsrsasign_1.X509();
51
52
  try {
52
53
  const respCRL = await node_fetch_1.default(crlURL[0]);
53
- const dataCRL = await respCRL.text();
54
- crlCert.readCertPEM(dataCRL);
54
+ const dataCRL = await respCRL.buffer();
55
+ const dataPEM = convertCertBufferToPEM_1.default(dataCRL);
56
+ crlCert.readCertPEM(dataPEM);
55
57
  }
56
58
  catch (err) {
57
59
  return false;
@@ -1 +1 @@
1
- {"version":3,"file":"isCertRevoked.js","sourceRoot":"","sources":["../../src/helpers/isCertRevoked.ts"],"names":[],"mappings":";;;;;AAAA,yCAAiC;AACjC,4DAA+B;AAC/B,uDAAkD;AAClD,mDAAsD;AAWtD,MAAM,iBAAiB,GAAsD,EAAE,CAAC;AAEhF;;;;;GAKG;AACY,KAAK,UAAU,aAAa,CAAC,IAAU;IACpD,MAAM,aAAa,GAAG,IAAI,CAAC,kBAAkB,EAAE,CAAC;IAEhD,0DAA0D;IAC1D,IAAI,aAAa,GAAoC,IAAI,CAAC;IAC1D,IAAI;QACF,aAAa,GAAG,IAAI,CAAC,4BAA4B,EAAqC,CAAC;KACxF;IAAC,OAAO,GAAG,EAAE;QACZ,OAAO,KAAK,CAAC;KACd;IAED,IAAI,aAAa,EAAE;QACjB,MAAM,MAAM,GAAG,iBAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACxD,IAAI,MAAM,EAAE;YACV,MAAM,GAAG,GAAG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AI,YAAY,EAAE;YAC/B,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YACrE,SAAS,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;SACzC;QAED,oBAAoB;QACpB,IAAI,aAAa,EAAE;YACjB,iBAAiB,CAAC,aAAa,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,SAAS,CAAC;SACtD;QAED,OAAO,SAAS,CAAC,YAAY,CAAC,OAAO,CAAC,aAAa,CAAC,IAAI,CAAC,CAAC;KAC3D;IAED,OAAO,KAAK,CAAC;AACf,CAAC;AA5ED,gCA4EC"}
@@ -0,0 +1,16 @@
1
+ import { Debugger } from 'debug';
2
+ /**
3
+ * Generate an instance of a `debug` logger that extends off of the "simplewebauthn" namespace for
4
+ * consistent naming.
5
+ *
6
+ * See https://www.npmjs.com/package/debug for information on how to control logging output when
7
+ * using @simplewebauthn/server
8
+ *
9
+ * Example:
10
+ *
11
+ * ```
12
+ * const log = getLogger('mds');
13
+ * log('hello'); // simplewebauthn:mds hello +0ms
14
+ * ```
15
+ */
16
+ export declare function getLogger(name: string): Debugger;
@@ -0,0 +1,27 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLogger = void 0;
7
+ const debug_1 = __importDefault(require("debug"));
8
+ const defaultLogger = debug_1.default('SimpleWebAuthn');
9
+ /**
10
+ * Generate an instance of a `debug` logger that extends off of the "simplewebauthn" namespace for
11
+ * consistent naming.
12
+ *
13
+ * See https://www.npmjs.com/package/debug for information on how to control logging output when
14
+ * using @simplewebauthn/server
15
+ *
16
+ * Example:
17
+ *
18
+ * ```
19
+ * const log = getLogger('mds');
20
+ * log('hello'); // simplewebauthn:mds hello +0ms
21
+ * ```
22
+ */
23
+ function getLogger(name) {
24
+ return defaultLogger.extend(name);
25
+ }
26
+ exports.getLogger = getLogger;
27
+ //# sourceMappingURL=logging.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logging.js","sourceRoot":"","sources":["../../src/helpers/logging.ts"],"names":[],"mappings":";;;;;;AAAA,kDAAwC;AAExC,MAAM,aAAa,GAAG,eAAK,CAAC,gBAAgB,CAAC,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,SAAgB,SAAS,CAAC,IAAY;IACpC,OAAO,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;AACpC,CAAC;AAFD,8BAEC"}
@@ -12,11 +12,9 @@ function parseAuthenticatorData(authData) {
12
12
  if (authData.byteLength < 37) {
13
13
  throw new Error(`Authenticator data was ${authData.byteLength} bytes, expected at least 37 bytes`);
14
14
  }
15
- let intBuffer = authData;
16
- const rpIdHash = intBuffer.slice(0, 32);
17
- intBuffer = intBuffer.slice(32);
18
- const flagsBuf = intBuffer.slice(0, 1);
19
- intBuffer = intBuffer.slice(1);
15
+ let pointer = 0;
16
+ const rpIdHash = authData.slice(pointer, (pointer += 32));
17
+ const flagsBuf = authData.slice(pointer, (pointer += 1));
20
18
  const flagsInt = flagsBuf[0];
21
19
  const flags = {
22
20
  up: !!(flagsInt & 0x01),
@@ -25,34 +23,31 @@ function parseAuthenticatorData(authData) {
25
23
  ed: !!(flagsInt & 0x80),
26
24
  flagsInt,
27
25
  };
28
- const counterBuf = intBuffer.slice(0, 4);
29
- intBuffer = intBuffer.slice(4);
26
+ const counterBuf = authData.slice(pointer, (pointer += 4));
30
27
  const counter = counterBuf.readUInt32BE(0);
31
28
  let aaguid = undefined;
32
29
  let credentialID = undefined;
33
30
  let credentialPublicKey = undefined;
34
31
  if (flags.at) {
35
- aaguid = intBuffer.slice(0, 16);
36
- intBuffer = intBuffer.slice(16);
37
- const credIDLenBuf = intBuffer.slice(0, 2);
38
- intBuffer = intBuffer.slice(2);
32
+ aaguid = authData.slice(pointer, (pointer += 16));
33
+ const credIDLenBuf = authData.slice(pointer, (pointer += 2));
39
34
  const credIDLen = credIDLenBuf.readUInt16BE(0);
40
- credentialID = intBuffer.slice(0, credIDLen);
41
- intBuffer = intBuffer.slice(credIDLen);
35
+ credentialID = authData.slice(pointer, (pointer += credIDLen));
42
36
  // Decode the next CBOR item in the buffer, then re-encode it back to a Buffer
43
- const firstDecoded = decodeCbor_1.decodeCborFirst(intBuffer);
37
+ const firstDecoded = decodeCbor_1.decodeCborFirst(authData.slice(pointer));
44
38
  const firstEncoded = Buffer.from(cbor_1.default.encode(firstDecoded));
45
39
  credentialPublicKey = firstEncoded;
46
- intBuffer = intBuffer.slice(firstEncoded.byteLength);
40
+ pointer += firstEncoded.byteLength;
47
41
  }
48
42
  let extensionsDataBuffer = undefined;
49
43
  if (flags.ed) {
50
- const firstDecoded = decodeCbor_1.decodeCborFirst(intBuffer);
44
+ const firstDecoded = decodeCbor_1.decodeCborFirst(authData.slice(pointer));
51
45
  const firstEncoded = Buffer.from(cbor_1.default.encode(firstDecoded));
52
46
  extensionsDataBuffer = firstEncoded;
53
- intBuffer = intBuffer.slice(firstEncoded.byteLength);
47
+ pointer += firstEncoded.byteLength;
54
48
  }
55
- if (intBuffer.byteLength > 0) {
49
+ // Pointer should be at the end of the authenticator data, otherwise too much data was sent
50
+ if (authData.byteLength > pointer) {
56
51
  throw new Error('Leftover bytes detected while parsing authenticator data');
57
52
  }
58
53
  return {
@@ -1 +1 @@
1
- {"version":3,"file":"parseAuthenticatorData.js","sourceRoot":"","sources":["../../src/helpers/parseAuthenticatorData.ts"],"names":[],"mappings":";;;;;AAAA,gDAAwB;AACxB,6CAA+C;AAE/C;;GAEG;AACH,SAAwB,sBAAsB,CAAC,QAAgB;IAC7D,IAAI,QAAQ,CAAC,UAAU,GAAG,EAAE,EAAE;QAC5B,MAAM,IAAI,KAAK,CACb,0BAA0B,QAAQ,CAAC,UAAU,oCAAoC,CAClF,CAAC;KACH;IAED,IAAI,S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and ensure they form a proper chain
3
3
  * @param certificates Typically the result of `x5c.map(convertASN1toPEM)`
4
+ * @param rootCertificates Possible root certificates to complete the path
4
5
  */
5
- export default function validateCertificatePath(certificates: string[]): Promise<boolean>;
6
+ export default function validateCertificatePath(certificates: string[], rootCertificates?: string[]): Promise<boolean>;
@@ -12,8 +12,40 @@ const { crypto } = jsrsasign_1.KJUR;
12
12
  /**
13
13
  * Traverse an array of PEM certificates and ensure they form a proper chain
14
14
  * @param certificates Typically the result of `x5c.map(convertASN1toPEM)`
15
+ * @param rootCertificates Possible root certificates to complete the path
15
16
  */
16
- async function validateCertificatePath(certificates) {
17
+ async function validateCertificatePath(certificates, rootCertificates = []) {
18
+ if (rootCertificates.length === 0) {
19
+ // We have no root certs with which to create a full path, so skip path validation
20
+ // TODO: Is this going to be acceptable default behavior??
21
+ return true;
22
+ }
23
+ let invalidSubjectAndIssuerError = false;
24
+ for (const rootCert of rootCertificates) {
25
+ try {
26
+ const certsWithRoot = certificates.concat([rootCert]);
27
+ await _validatePath(certsWithRoot);
28
+ // If we successfully validated a path then there's no need to continue
29
+ invalidSubjectAndIssuerError = false;
30
+ break;
31
+ }
32
+ catch (err) {
33
+ if (err instanceof InvalidSubjectAndIssuer) {
34
+ invalidSubjectAndIssuerError = true;
35
+ }
36
+ else {
37
+ throw err;
38
+ }
39
+ }
40
+ }
41
+ // We tried multiple root certs and none of them worked
42
+ if (invalidSubjectAndIssuerError) {
43
+ throw new InvalidSubjectAndIssuer();
44
+ }
45
+ return true;
46
+ }
47
+ exports.default = validateCertificatePath;
48
+ async function _validatePath(certificates) {
17
49
  if (new Set(certificates).size !== certificates.length) {
18
50
  throw new Error('Invalid certificate path: found duplicate certificates');
19
51
  }
@@ -39,12 +71,12 @@ async function validateCertificatePath(certificates) {
39
71
  // Check that intermediate certificate is within its valid time window
40
72
  const notBefore = jsrsasign_1.zulutodate(issuerCert.getNotBefore());
41
73
  const notAfter = jsrsasign_1.zulutodate(issuerCert.getNotAfter());
42
- const now = new Date();
74
+ const now = new Date(Date.now());
43
75
  if (notBefore > now || notAfter < now) {
44
76
  throw new Error('Intermediate certificate is not yet valid or expired');
45
77
  }
46
78
  if (subjectCert.getIssuerString() !== issuerCert.getSubjectString()) {
47
- throw new Error('Invalid certificate path: subject issuer did not match issuer subject');
79
+ throw new InvalidSubjectAndIssuer();
48
80
  }
49
81
  const subjectCertStruct = jsrsasign_1.ASN1HEX.getTLVbyList(subjectCert.hex, 0, [0]);
50
82
  const alg = subjectCert.getSignatureAlgorithmField();
@@ -58,5 +90,12 @@ async function validateCertificatePath(certificates) {
58
90
  }
59
91
  return true;
60
92
  }
61
- exports.default = validateCertificatePath;
93
+ // Custom errors to help pass on certain errors
94
+ class InvalidSubjectAndIssuer extends Error {
95
+ constructor() {
96
+ const message = 'Subject issuer did not match issuer subject';
97
+ super(message);
98
+ this.name = 'InvalidSubjectAndIssuer';
99
+ }
100
+ }
62
101
  //# sourceMappingURL=validateCertificatePath.js.map