@simplewebauthn/server 7.4.0 → 8.0.0-alpha.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 (343) hide show
  1. package/LICENSE.md +11 -14
  2. package/README.md +6 -2
  3. package/{dist → esm}/authentication/generateAuthenticationOptions.d.ts +2 -2
  4. package/esm/authentication/generateAuthenticationOptions.js +36 -0
  5. package/{dist → esm}/authentication/verifyAuthenticationResponse.d.ts +2 -2
  6. package/esm/authentication/verifyAuthenticationResponse.js +164 -0
  7. package/esm/deps.d.ts +10 -0
  8. package/esm/deps.js +12 -0
  9. package/esm/helpers/convertAAGUIDToString.js +17 -0
  10. package/esm/helpers/convertCOSEtoPKCS.js +21 -0
  11. package/{dist → esm}/helpers/convertCertBufferToPEM.d.ts +1 -1
  12. package/esm/helpers/convertCertBufferToPEM.js +31 -0
  13. package/esm/helpers/convertPEMToBytes.js +11 -0
  14. package/{dist → esm}/helpers/convertX509PublicKeyToCOSE.d.ts +1 -1
  15. package/esm/helpers/convertX509PublicKeyToCOSE.js +70 -0
  16. package/{dist → esm}/helpers/cose.d.ts +2 -1
  17. package/esm/helpers/cose.js +81 -0
  18. package/{dist → esm}/helpers/decodeAttestationObject.d.ts +3 -0
  19. package/esm/helpers/decodeAttestationObject.js +13 -0
  20. package/esm/helpers/decodeAuthenticatorExtensions.js +34 -0
  21. package/{dist → esm}/helpers/decodeClientDataJSON.d.ts +3 -0
  22. package/esm/helpers/decodeClientDataJSON.js +13 -0
  23. package/esm/helpers/decodeCredentialPublicKey.d.ts +5 -0
  24. package/esm/helpers/decodeCredentialPublicKey.js +8 -0
  25. package/esm/helpers/fetch.d.ts +8 -0
  26. package/esm/helpers/fetch.js +12 -0
  27. package/esm/helpers/generateChallenge.d.ts +7 -0
  28. package/esm/helpers/generateChallenge.js +21 -0
  29. package/{dist → esm}/helpers/getCertificateInfo.d.ts +1 -1
  30. package/esm/helpers/getCertificateInfo.js +76 -0
  31. package/esm/helpers/index.d.ts +22 -0
  32. package/esm/helpers/index.js +16 -0
  33. package/{dist → esm}/helpers/isCertRevoked.d.ts +1 -1
  34. package/esm/helpers/isCertRevoked.js +98 -0
  35. package/{dist → esm}/helpers/iso/index.d.ts +4 -4
  36. package/esm/helpers/iso/index.js +11 -0
  37. package/esm/helpers/iso/isoBase64URL.js +57 -0
  38. package/{dist → esm}/helpers/iso/isoCBOR.d.ts +1 -1
  39. package/esm/helpers/iso/isoCBOR.js +44 -0
  40. package/{dist → esm}/helpers/iso/isoCrypto/digest.d.ts +1 -1
  41. package/esm/helpers/iso/isoCrypto/digest.js +14 -0
  42. package/{dist → esm}/helpers/iso/isoCrypto/getRandomValues.d.ts +1 -1
  43. package/esm/helpers/iso/isoCrypto/getRandomValues.js +11 -0
  44. package/esm/helpers/iso/isoCrypto/getWebCrypto.d.ts +6 -0
  45. package/esm/helpers/iso/isoCrypto/getWebCrypto.js +40 -0
  46. package/esm/helpers/iso/isoCrypto/importKey.js +8 -0
  47. package/esm/helpers/iso/isoCrypto/index.d.ts +3 -0
  48. package/esm/helpers/iso/isoCrypto/index.js +3 -0
  49. package/{dist → esm}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +2 -2
  50. package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js +20 -0
  51. package/{dist → esm}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +2 -2
  52. package/esm/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +19 -0
  53. package/esm/helpers/iso/isoCrypto/structs.js +1 -0
  54. package/esm/helpers/iso/isoCrypto/unwrapEC2Signature.js +30 -0
  55. package/{dist → esm}/helpers/iso/isoCrypto/verify.d.ts +1 -1
  56. package/esm/helpers/iso/isoCrypto/verify.js +28 -0
  57. package/{dist → esm}/helpers/iso/isoCrypto/verifyEC2.d.ts +1 -1
  58. package/esm/helpers/iso/isoCrypto/verifyEC2.js +73 -0
  59. package/{dist → esm}/helpers/iso/isoCrypto/verifyOKP.d.ts +1 -1
  60. package/esm/helpers/iso/isoCrypto/verifyOKP.js +51 -0
  61. package/{dist → esm}/helpers/iso/isoCrypto/verifyRSA.d.ts +1 -1
  62. package/esm/helpers/iso/isoCrypto/verifyRSA.js +91 -0
  63. package/esm/helpers/iso/isoUint8Array.js +75 -0
  64. package/{dist → esm}/helpers/logging.d.ts +1 -1
  65. package/esm/helpers/logging.js +19 -0
  66. package/{dist → esm}/helpers/mapX509SignatureAlgToCOSEAlg.d.ts +1 -1
  67. package/esm/helpers/mapX509SignatureAlgToCOSEAlg.js +35 -0
  68. package/esm/helpers/matchExpectedRPID.js +41 -0
  69. package/{dist → esm}/helpers/parseAuthenticatorData.d.ts +4 -1
  70. package/esm/helpers/parseAuthenticatorData.js +71 -0
  71. package/{dist → esm}/helpers/parseBackupFlags.d.ts +4 -1
  72. package/esm/helpers/parseBackupFlags.js +25 -0
  73. package/{dist → esm}/helpers/toHash.d.ts +1 -1
  74. package/esm/helpers/toHash.js +12 -0
  75. package/esm/helpers/validateCertificatePath.js +122 -0
  76. package/{dist → esm}/helpers/verifySignature.d.ts +4 -1
  77. package/esm/helpers/verifySignature.js +32 -0
  78. package/esm/index.d.ts +17 -0
  79. package/esm/index.js +11 -0
  80. package/{dist → esm}/metadata/mdsTypes.d.ts +1 -1
  81. package/esm/metadata/mdsTypes.js +17 -0
  82. package/esm/metadata/parseJWT.js +12 -0
  83. package/{dist → esm}/metadata/verifyAttestationWithMetadata.d.ts +3 -3
  84. package/esm/metadata/verifyAttestationWithMetadata.js +159 -0
  85. package/esm/metadata/verifyJWT.js +37 -0
  86. package/esm/package.json +3 -0
  87. package/{dist → esm}/registration/generateRegistrationOptions.d.ts +2 -2
  88. package/esm/registration/generateRegistrationOptions.js +142 -0
  89. package/esm/registration/verifications/tpm/constants.js +182 -0
  90. package/esm/registration/verifications/tpm/parseCertInfo.js +58 -0
  91. package/esm/registration/verifications/tpm/parsePubArea.js +94 -0
  92. package/{dist → esm}/registration/verifications/tpm/verifyAttestationTPM.d.ts +1 -1
  93. package/esm/registration/verifications/tpm/verifyAttestationTPM.js +323 -0
  94. package/{dist → esm}/registration/verifications/verifyAttestationAndroidKey.d.ts +1 -1
  95. package/esm/registration/verifications/verifyAttestationAndroidKey.js +90 -0
  96. package/{dist → esm}/registration/verifications/verifyAttestationAndroidSafetyNet.d.ts +1 -1
  97. package/esm/registration/verifications/verifyAttestationAndroidSafetyNet.js +112 -0
  98. package/{dist → esm}/registration/verifications/verifyAttestationApple.d.ts +1 -1
  99. package/esm/registration/verifications/verifyAttestationApple.js +57 -0
  100. package/{dist → esm}/registration/verifications/verifyAttestationFIDOU2F.d.ts +1 -1
  101. package/esm/registration/verifications/verifyAttestationFIDOU2F.js +48 -0
  102. package/{dist → esm}/registration/verifications/verifyAttestationPacked.d.ts +1 -1
  103. package/esm/registration/verifications/verifyAttestationPacked.js +105 -0
  104. package/{dist → esm}/registration/verifyRegistrationResponse.d.ts +3 -3
  105. package/esm/registration/verifyRegistrationResponse.js +198 -0
  106. package/esm/services/defaultRootCerts/android-key.js +85 -0
  107. package/esm/services/defaultRootCerts/android-safetynet.js +32 -0
  108. package/esm/services/defaultRootCerts/apple.js +25 -0
  109. package/esm/services/defaultRootCerts/mds.js +32 -0
  110. package/{dist → esm}/services/metadataService.d.ts +1 -1
  111. package/{dist → esm}/services/metadataService.js +52 -36
  112. package/{dist → esm}/services/settingsService.d.ts +1 -1
  113. package/esm/services/settingsService.js +65 -0
  114. package/package.json +40 -45
  115. package/script/authentication/generateAuthenticationOptions.d.ts +23 -0
  116. package/{dist → script}/authentication/generateAuthenticationOptions.js +8 -9
  117. package/script/authentication/verifyAuthenticationResponse.d.ts +66 -0
  118. package/{dist → script}/authentication/verifyAuthenticationResponse.js +25 -23
  119. package/script/deps.d.ts +10 -0
  120. package/script/deps.js +68 -0
  121. package/script/helpers/convertAAGUIDToString.d.ts +4 -0
  122. package/{dist → script}/helpers/convertAAGUIDToString.js +2 -3
  123. package/script/helpers/convertCOSEtoPKCS.d.ts +4 -0
  124. package/{dist → script}/helpers/convertCOSEtoPKCS.js +7 -8
  125. package/script/helpers/convertCertBufferToPEM.d.ts +5 -0
  126. package/{dist → script}/helpers/convertCertBufferToPEM.js +5 -6
  127. package/script/helpers/convertPEMToBytes.d.ts +4 -0
  128. package/{dist → script}/helpers/convertPEMToBytes.js +2 -3
  129. package/script/helpers/convertX509PublicKeyToCOSE.d.ts +2 -0
  130. package/{dist → script}/helpers/convertX509PublicKeyToCOSE.js +21 -25
  131. package/script/helpers/cose.d.ts +98 -0
  132. package/{dist → script}/helpers/cose.js +1 -1
  133. package/script/helpers/decodeAttestationObject.d.ts +29 -0
  134. package/script/helpers/decodeAttestationObject.js +17 -0
  135. package/script/helpers/decodeAuthenticatorExtensions.d.ts +20 -0
  136. package/{dist → script}/helpers/decodeAuthenticatorExtensions.js +2 -3
  137. package/script/helpers/decodeClientDataJSON.d.ts +17 -0
  138. package/script/helpers/decodeClientDataJSON.js +17 -0
  139. package/script/helpers/decodeCredentialPublicKey.d.ts +5 -0
  140. package/script/helpers/decodeCredentialPublicKey.js +12 -0
  141. package/script/helpers/fetch.d.ts +8 -0
  142. package/script/helpers/fetch.js +16 -0
  143. package/script/helpers/generateChallenge.d.ts +7 -0
  144. package/{dist → script}/helpers/generateChallenge.js +9 -6
  145. package/script/helpers/getCertificateInfo.d.ts +31 -0
  146. package/{dist → script}/helpers/getCertificateInfo.js +4 -6
  147. package/script/helpers/index.d.ts +22 -0
  148. package/script/helpers/index.js +59 -0
  149. package/script/helpers/isCertRevoked.d.ts +8 -0
  150. package/{dist → script}/helpers/isCertRevoked.js +20 -25
  151. package/script/helpers/iso/index.d.ts +11 -0
  152. package/{dist → script}/helpers/iso/index.js +4 -5
  153. package/script/helpers/iso/isoBase64URL.d.ts +37 -0
  154. package/{dist → script}/helpers/iso/isoBase64URL.js +0 -1
  155. package/script/helpers/iso/isoCBOR.d.ts +12 -0
  156. package/{dist → script}/helpers/iso/isoCBOR.js +8 -28
  157. package/script/helpers/iso/isoCrypto/digest.d.ts +8 -0
  158. package/script/helpers/iso/isoCrypto/digest.js +18 -0
  159. package/script/helpers/iso/isoCrypto/getRandomValues.d.ts +6 -0
  160. package/script/helpers/iso/isoCrypto/getRandomValues.js +15 -0
  161. package/script/helpers/iso/isoCrypto/getWebCrypto.d.ts +6 -0
  162. package/script/helpers/iso/isoCrypto/getWebCrypto.js +44 -0
  163. package/script/helpers/iso/isoCrypto/importKey.d.ts +4 -0
  164. package/script/helpers/iso/isoCrypto/importKey.js +12 -0
  165. package/script/helpers/iso/isoCrypto/index.d.ts +3 -0
  166. package/{dist → script}/helpers/iso/isoCrypto/index.js +6 -7
  167. package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.d.ts +6 -0
  168. package/{dist → script}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js +6 -6
  169. package/script/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.d.ts +6 -0
  170. package/{dist → script}/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js +5 -6
  171. package/script/helpers/iso/isoCrypto/structs.d.ts +3 -0
  172. package/{dist → script}/helpers/iso/isoCrypto/structs.js +0 -1
  173. package/script/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +6 -0
  174. package/{dist → script}/helpers/iso/isoCrypto/unwrapEC2Signature.js +4 -6
  175. package/script/helpers/iso/isoCrypto/verify.d.ts +10 -0
  176. package/script/helpers/iso/isoCrypto/verify.js +32 -0
  177. package/script/helpers/iso/isoCrypto/verifyEC2.d.ts +10 -0
  178. package/{dist → script}/helpers/iso/isoCrypto/verifyEC2.js +19 -22
  179. package/script/helpers/iso/isoCrypto/verifyOKP.d.ts +6 -0
  180. package/{dist → script}/helpers/iso/isoCrypto/verifyOKP.js +13 -16
  181. package/script/helpers/iso/isoCrypto/verifyRSA.d.ts +10 -0
  182. package/{dist → script}/helpers/iso/isoCrypto/verifyRSA.js +19 -22
  183. package/script/helpers/iso/isoUint8Array.d.ts +36 -0
  184. package/{dist → script}/helpers/iso/isoUint8Array.js +7 -8
  185. package/script/helpers/logging.d.ts +17 -0
  186. package/{dist → script}/helpers/logging.js +2 -6
  187. package/script/helpers/mapX509SignatureAlgToCOSEAlg.d.ts +8 -0
  188. package/{dist → script}/helpers/mapX509SignatureAlgToCOSEAlg.js +8 -9
  189. package/script/helpers/matchExpectedRPID.d.ts +7 -0
  190. package/{dist → script}/helpers/matchExpectedRPID.js +5 -6
  191. package/script/helpers/parseAuthenticatorData.d.ts +28 -0
  192. package/{dist → script}/helpers/parseAuthenticatorData.js +19 -16
  193. package/script/helpers/parseBackupFlags.d.ts +19 -0
  194. package/{dist → script}/helpers/parseBackupFlags.js +2 -2
  195. package/script/helpers/toHash.d.ts +6 -0
  196. package/{dist → script}/helpers/toHash.js +4 -5
  197. package/script/helpers/validateCertificatePath.d.ts +6 -0
  198. package/{dist → script}/helpers/validateCertificatePath.js +13 -15
  199. package/script/helpers/verifySignature.d.ts +14 -0
  200. package/script/helpers/verifySignature.js +36 -0
  201. package/script/index.d.ts +17 -0
  202. package/script/index.js +19 -0
  203. package/script/metadata/mdsTypes.d.ts +216 -0
  204. package/{dist → script}/metadata/mdsTypes.js +0 -1
  205. package/script/metadata/parseJWT.d.ts +4 -0
  206. package/{dist → script}/metadata/parseJWT.js +3 -4
  207. package/script/metadata/verifyAttestationWithMetadata.d.ts +29 -0
  208. package/{dist → script}/metadata/verifyAttestationWithMetadata.js +24 -22
  209. package/script/metadata/verifyJWT.d.ts +10 -0
  210. package/script/metadata/verifyJWT.js +41 -0
  211. package/script/package.json +3 -0
  212. package/script/registration/generateRegistrationOptions.d.ts +43 -0
  213. package/{dist → script}/registration/generateRegistrationOptions.js +9 -10
  214. package/script/registration/verifications/tpm/constants.d.ts +47 -0
  215. package/{dist → script}/registration/verifications/tpm/constants.js +1 -2
  216. package/script/registration/verifications/tpm/parseCertInfo.d.ts +24 -0
  217. package/{dist → script}/registration/verifications/tpm/parseCertInfo.js +13 -14
  218. package/script/registration/verifications/tpm/parsePubArea.d.ts +43 -0
  219. package/{dist → script}/registration/verifications/tpm/parsePubArea.js +16 -17
  220. package/script/registration/verifications/tpm/verifyAttestationTPM.d.ts +2 -0
  221. package/{dist → script}/registration/verifications/tpm/verifyAttestationTPM.js +58 -58
  222. package/script/registration/verifications/verifyAttestationAndroidKey.d.ts +5 -0
  223. package/{dist → script}/registration/verifications/verifyAttestationAndroidKey.js +22 -26
  224. package/script/registration/verifications/verifyAttestationAndroidSafetyNet.d.ts +5 -0
  225. package/{dist → script}/registration/verifications/verifyAttestationAndroidSafetyNet.js +22 -23
  226. package/script/registration/verifications/verifyAttestationApple.d.ts +2 -0
  227. package/{dist → script}/registration/verifications/verifyAttestationApple.js +15 -17
  228. package/script/registration/verifications/verifyAttestationFIDOU2F.d.ts +5 -0
  229. package/{dist → script}/registration/verifications/verifyAttestationFIDOU2F.js +12 -13
  230. package/script/registration/verifications/verifyAttestationPacked.d.ts +5 -0
  231. package/{dist → script}/registration/verifications/verifyAttestationPacked.js +17 -18
  232. package/script/registration/verifyRegistrationResponse.d.ts +85 -0
  233. package/{dist → script}/registration/verifyRegistrationResponse.js +39 -38
  234. package/script/services/defaultRootCerts/android-key.d.ts +24 -0
  235. package/{dist → script}/services/defaultRootCerts/android-key.js +0 -1
  236. package/script/services/defaultRootCerts/android-safetynet.d.ts +11 -0
  237. package/{dist → script}/services/defaultRootCerts/android-safetynet.js +0 -1
  238. package/script/services/defaultRootCerts/apple.d.ts +11 -0
  239. package/{dist → script}/services/defaultRootCerts/apple.js +0 -1
  240. package/script/services/defaultRootCerts/mds.d.ts +11 -0
  241. package/{dist → script}/services/defaultRootCerts/mds.js +0 -1
  242. package/script/services/metadataService.d.ts +53 -0
  243. package/script/services/metadataService.js +277 -0
  244. package/script/services/settingsService.d.ts +25 -0
  245. package/{dist → script}/services/settingsService.js +21 -13
  246. package/dist/authentication/generateAuthenticationOptions.js.map +0 -1
  247. package/dist/authentication/verifyAuthenticationResponse.js.map +0 -1
  248. package/dist/helpers/convertAAGUIDToString.js.map +0 -1
  249. package/dist/helpers/convertCOSEtoPKCS.js.map +0 -1
  250. package/dist/helpers/convertCertBufferToPEM.js.map +0 -1
  251. package/dist/helpers/convertPEMToBytes.js.map +0 -1
  252. package/dist/helpers/convertX509PublicKeyToCOSE.js.map +0 -1
  253. package/dist/helpers/cose.js.map +0 -1
  254. package/dist/helpers/decodeAttestationObject.js +0 -14
  255. package/dist/helpers/decodeAttestationObject.js.map +0 -1
  256. package/dist/helpers/decodeAuthenticatorExtensions.js.map +0 -1
  257. package/dist/helpers/decodeClientDataJSON.js +0 -14
  258. package/dist/helpers/decodeClientDataJSON.js.map +0 -1
  259. package/dist/helpers/decodeCredentialPublicKey.d.ts +0 -2
  260. package/dist/helpers/decodeCredentialPublicKey.js +0 -9
  261. package/dist/helpers/decodeCredentialPublicKey.js.map +0 -1
  262. package/dist/helpers/generateChallenge.d.ts +0 -4
  263. package/dist/helpers/generateChallenge.js.map +0 -1
  264. package/dist/helpers/getCertificateInfo.js.map +0 -1
  265. package/dist/helpers/index.d.ts +0 -22
  266. package/dist/helpers/index.js +0 -60
  267. package/dist/helpers/index.js.map +0 -1
  268. package/dist/helpers/isCertRevoked.js.map +0 -1
  269. package/dist/helpers/iso/index.js.map +0 -1
  270. package/dist/helpers/iso/isoBase64URL.js.map +0 -1
  271. package/dist/helpers/iso/isoCBOR.js.map +0 -1
  272. package/dist/helpers/iso/isoCrypto/digest.js +0 -21
  273. package/dist/helpers/iso/isoCrypto/digest.js.map +0 -1
  274. package/dist/helpers/iso/isoCrypto/getRandomValues.js +0 -18
  275. package/dist/helpers/iso/isoCrypto/getRandomValues.js.map +0 -1
  276. package/dist/helpers/iso/isoCrypto/importKey.js +0 -13
  277. package/dist/helpers/iso/isoCrypto/importKey.js.map +0 -1
  278. package/dist/helpers/iso/isoCrypto/index.d.ts +0 -3
  279. package/dist/helpers/iso/isoCrypto/index.js.map +0 -1
  280. package/dist/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoAlg.js.map +0 -1
  281. package/dist/helpers/iso/isoCrypto/mapCoseAlgToWebCryptoKeyAlgName.js.map +0 -1
  282. package/dist/helpers/iso/isoCrypto/structs.js.map +0 -1
  283. package/dist/helpers/iso/isoCrypto/unwrapEC2Signature.js.map +0 -1
  284. package/dist/helpers/iso/isoCrypto/verify.js +0 -28
  285. package/dist/helpers/iso/isoCrypto/verify.js.map +0 -1
  286. package/dist/helpers/iso/isoCrypto/verifyEC2.js.map +0 -1
  287. package/dist/helpers/iso/isoCrypto/verifyOKP.js.map +0 -1
  288. package/dist/helpers/iso/isoCrypto/verifyRSA.js.map +0 -1
  289. package/dist/helpers/iso/isoUint8Array.js.map +0 -1
  290. package/dist/helpers/logging.js.map +0 -1
  291. package/dist/helpers/mapX509SignatureAlgToCOSEAlg.js.map +0 -1
  292. package/dist/helpers/matchExpectedRPID.js.map +0 -1
  293. package/dist/helpers/parseAuthenticatorData.js.map +0 -1
  294. package/dist/helpers/parseBackupFlags.js.map +0 -1
  295. package/dist/helpers/toHash.js.map +0 -1
  296. package/dist/helpers/validateCertificatePath.js.map +0 -1
  297. package/dist/helpers/verifySignature.js +0 -33
  298. package/dist/helpers/verifySignature.js.map +0 -1
  299. package/dist/index.d.ts +0 -17
  300. package/dist/index.js +0 -20
  301. package/dist/index.js.map +0 -1
  302. package/dist/metadata/mdsTypes.js.map +0 -1
  303. package/dist/metadata/parseJWT.js.map +0 -1
  304. package/dist/metadata/verifyAttestationWithMetadata.js.map +0 -1
  305. package/dist/metadata/verifyJWT.js +0 -42
  306. package/dist/metadata/verifyJWT.js.map +0 -1
  307. package/dist/registration/generateRegistrationOptions.js.map +0 -1
  308. package/dist/registration/verifications/tpm/constants.js.map +0 -1
  309. package/dist/registration/verifications/tpm/parseCertInfo.js.map +0 -1
  310. package/dist/registration/verifications/tpm/parsePubArea.js.map +0 -1
  311. package/dist/registration/verifications/tpm/verifyAttestationTPM.js.map +0 -1
  312. package/dist/registration/verifications/verifyAttestationAndroidKey.js.map +0 -1
  313. package/dist/registration/verifications/verifyAttestationAndroidSafetyNet.js.map +0 -1
  314. package/dist/registration/verifications/verifyAttestationApple.js.map +0 -1
  315. package/dist/registration/verifications/verifyAttestationFIDOU2F.js.map +0 -1
  316. package/dist/registration/verifications/verifyAttestationPacked.js.map +0 -1
  317. package/dist/registration/verifyRegistrationResponse.js.map +0 -1
  318. package/dist/services/defaultRootCerts/android-key.js.map +0 -1
  319. package/dist/services/defaultRootCerts/android-safetynet.js.map +0 -1
  320. package/dist/services/defaultRootCerts/apple.js.map +0 -1
  321. package/dist/services/defaultRootCerts/mds.js.map +0 -1
  322. package/dist/services/metadataService.js.map +0 -1
  323. package/dist/services/settingsService.js.map +0 -1
  324. /package/{dist → esm}/helpers/convertAAGUIDToString.d.ts +0 -0
  325. /package/{dist → esm}/helpers/convertCOSEtoPKCS.d.ts +0 -0
  326. /package/{dist → esm}/helpers/convertPEMToBytes.d.ts +0 -0
  327. /package/{dist → esm}/helpers/decodeAuthenticatorExtensions.d.ts +0 -0
  328. /package/{dist → esm}/helpers/iso/isoBase64URL.d.ts +0 -0
  329. /package/{dist → esm}/helpers/iso/isoCrypto/importKey.d.ts +0 -0
  330. /package/{dist → esm}/helpers/iso/isoCrypto/structs.d.ts +0 -0
  331. /package/{dist → esm}/helpers/iso/isoCrypto/unwrapEC2Signature.d.ts +0 -0
  332. /package/{dist → esm}/helpers/iso/isoUint8Array.d.ts +0 -0
  333. /package/{dist → esm}/helpers/matchExpectedRPID.d.ts +0 -0
  334. /package/{dist → esm}/helpers/validateCertificatePath.d.ts +0 -0
  335. /package/{dist → esm}/metadata/parseJWT.d.ts +0 -0
  336. /package/{dist → esm}/metadata/verifyJWT.d.ts +0 -0
  337. /package/{dist → esm}/registration/verifications/tpm/constants.d.ts +0 -0
  338. /package/{dist → esm}/registration/verifications/tpm/parseCertInfo.d.ts +0 -0
  339. /package/{dist → esm}/registration/verifications/tpm/parsePubArea.d.ts +0 -0
  340. /package/{dist → esm}/services/defaultRootCerts/android-key.d.ts +0 -0
  341. /package/{dist → esm}/services/defaultRootCerts/android-safetynet.d.ts +0 -0
  342. /package/{dist → esm}/services/defaultRootCerts/apple.d.ts +0 -0
  343. /package/{dist → esm}/services/defaultRootCerts/mds.d.ts +0 -0
@@ -0,0 +1,182 @@
1
+ // deno-lint-ignore-file no-dupe-keys
2
+ /**
3
+ * A whole lotta domain knowledge is captured here, with hazy connections to source
4
+ * documents. Good places to start searching for more info on these values are the
5
+ * following Trusted Computing Group TPM Library docs linked in the WebAuthn API:
6
+ *
7
+ * - https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-1-Architecture-01.38.pdf
8
+ * - https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-01.38.pdf
9
+ * - https://www.trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-3-Commands-01.38.pdf
10
+ */
11
+ /**
12
+ * 6.9 TPM_ST (Structure Tags)
13
+ */
14
+ export const TPM_ST = {
15
+ 0x00c4: 'TPM_ST_RSP_COMMAND',
16
+ 0x8000: 'TPM_ST_NULL',
17
+ 0x8001: 'TPM_ST_NO_SESSIONS',
18
+ 0x8002: 'TPM_ST_SESSIONS',
19
+ 0x8014: 'TPM_ST_ATTEST_NV',
20
+ 0x8015: 'TPM_ST_ATTEST_COMMAND_AUDIT',
21
+ 0x8016: 'TPM_ST_ATTEST_SESSION_AUDIT',
22
+ 0x8017: 'TPM_ST_ATTEST_CERTIFY',
23
+ 0x8018: 'TPM_ST_ATTEST_QUOTE',
24
+ 0x8019: 'TPM_ST_ATTEST_TIME',
25
+ 0x801a: 'TPM_ST_ATTEST_CREATION',
26
+ 0x8021: 'TPM_ST_CREATION',
27
+ 0x8022: 'TPM_ST_VERIFIED',
28
+ 0x8023: 'TPM_ST_AUTH_SECRET',
29
+ 0x8024: 'TPM_ST_HASHCHECK',
30
+ 0x8025: 'TPM_ST_AUTH_SIGNED',
31
+ 0x8029: 'TPM_ST_FU_MANIFEST',
32
+ };
33
+ /**
34
+ * 6.3 TPM_ALG_ID
35
+ */
36
+ export const TPM_ALG = {
37
+ 0x0000: 'TPM_ALG_ERROR',
38
+ 0x0001: 'TPM_ALG_RSA',
39
+ 0x0004: 'TPM_ALG_SHA',
40
+ // @ts-ignore 2300
41
+ 0x0004: 'TPM_ALG_SHA1',
42
+ 0x0005: 'TPM_ALG_HMAC',
43
+ 0x0006: 'TPM_ALG_AES',
44
+ 0x0007: 'TPM_ALG_MGF1',
45
+ 0x0008: 'TPM_ALG_KEYEDHASH',
46
+ 0x000a: 'TPM_ALG_XOR',
47
+ 0x000b: 'TPM_ALG_SHA256',
48
+ 0x000c: 'TPM_ALG_SHA384',
49
+ 0x000d: 'TPM_ALG_SHA512',
50
+ 0x0010: 'TPM_ALG_NULL',
51
+ 0x0012: 'TPM_ALG_SM3_256',
52
+ 0x0013: 'TPM_ALG_SM4',
53
+ 0x0014: 'TPM_ALG_RSASSA',
54
+ 0x0015: 'TPM_ALG_RSAES',
55
+ 0x0016: 'TPM_ALG_RSAPSS',
56
+ 0x0017: 'TPM_ALG_OAEP',
57
+ 0x0018: 'TPM_ALG_ECDSA',
58
+ 0x0019: 'TPM_ALG_ECDH',
59
+ 0x001a: 'TPM_ALG_ECDAA',
60
+ 0x001b: 'TPM_ALG_SM2',
61
+ 0x001c: 'TPM_ALG_ECSCHNORR',
62
+ 0x001d: 'TPM_ALG_ECMQV',
63
+ 0x0020: 'TPM_ALG_KDF1_SP800_56A',
64
+ 0x0021: 'TPM_ALG_KDF2',
65
+ 0x0022: 'TPM_ALG_KDF1_SP800_108',
66
+ 0x0023: 'TPM_ALG_ECC',
67
+ 0x0025: 'TPM_ALG_SYMCIPHER',
68
+ 0x0026: 'TPM_ALG_CAMELLIA',
69
+ 0x0040: 'TPM_ALG_CTR',
70
+ 0x0041: 'TPM_ALG_OFB',
71
+ 0x0042: 'TPM_ALG_CBC',
72
+ 0x0043: 'TPM_ALG_CFB',
73
+ 0x0044: 'TPM_ALG_ECB',
74
+ };
75
+ /**
76
+ * 6.4 TPM_ECC_CURVE
77
+ */
78
+ export const TPM_ECC_CURVE = {
79
+ 0x0000: 'TPM_ECC_NONE',
80
+ 0x0001: 'TPM_ECC_NIST_P192',
81
+ 0x0002: 'TPM_ECC_NIST_P224',
82
+ 0x0003: 'TPM_ECC_NIST_P256',
83
+ 0x0004: 'TPM_ECC_NIST_P384',
84
+ 0x0005: 'TPM_ECC_NIST_P521',
85
+ 0x0010: 'TPM_ECC_BN_P256',
86
+ 0x0011: 'TPM_ECC_BN_P638',
87
+ 0x0020: 'TPM_ECC_SM2_P256',
88
+ };
89
+ /**
90
+ * Sourced from https://trustedcomputinggroup.org/resource/vendor-id-registry/
91
+ *
92
+ * Latest version:
93
+ * https://trustedcomputinggroup.org/wp-content/uploads/TCG-TPM-Vendor-ID-Registry-Version-1.02-Revision-1.00.pdf
94
+ */
95
+ export const TPM_MANUFACTURERS = {
96
+ 'id:414D4400': {
97
+ name: 'AMD',
98
+ id: 'AMD',
99
+ },
100
+ 'id:41544D4C': {
101
+ name: 'Atmel',
102
+ id: 'ATML',
103
+ },
104
+ 'id:4252434D': {
105
+ name: 'Broadcom',
106
+ id: 'BRCM',
107
+ },
108
+ 'id:49424d00': {
109
+ name: 'IBM',
110
+ id: 'IBM',
111
+ },
112
+ 'id:49465800': {
113
+ name: 'Infineon',
114
+ id: 'IFX',
115
+ },
116
+ 'id:494E5443': {
117
+ name: 'Intel',
118
+ id: 'INTC',
119
+ },
120
+ 'id:4C454E00': {
121
+ name: 'Lenovo',
122
+ id: 'LEN',
123
+ },
124
+ 'id:4E534D20': {
125
+ name: 'National Semiconductor',
126
+ id: 'NSM',
127
+ },
128
+ 'id:4E545A00': {
129
+ name: 'Nationz',
130
+ id: 'NTZ',
131
+ },
132
+ 'id:4E544300': {
133
+ name: 'Nuvoton Technology',
134
+ id: 'NTC',
135
+ },
136
+ 'id:51434F4D': {
137
+ name: 'Qualcomm',
138
+ id: 'QCOM',
139
+ },
140
+ 'id:534D5343': {
141
+ name: 'SMSC',
142
+ id: 'SMSC',
143
+ },
144
+ 'id:53544D20': {
145
+ name: 'ST Microelectronics',
146
+ id: 'STM',
147
+ },
148
+ 'id:534D534E': {
149
+ name: 'Samsung',
150
+ id: 'SMSN',
151
+ },
152
+ 'id:534E5300': {
153
+ name: 'Sinosun',
154
+ id: 'SNS',
155
+ },
156
+ 'id:54584E00': {
157
+ name: 'Texas Instruments',
158
+ id: 'TXN',
159
+ },
160
+ 'id:57454300': {
161
+ name: 'Winbond',
162
+ id: 'WEC',
163
+ },
164
+ 'id:524F4343': {
165
+ name: 'Fuzhouk Rockchip',
166
+ id: 'ROCC',
167
+ },
168
+ 'id:FFFFF1D0': {
169
+ name: 'FIDO Alliance',
170
+ id: 'FIDO',
171
+ },
172
+ };
173
+ /**
174
+ * Match TPM public area curve ID's to `crv` numbers used in COSE public keys
175
+ */
176
+ export const TPM_ECC_CURVE_COSE_CRV_MAP = {
177
+ TPM_ECC_NIST_P256: 1,
178
+ TPM_ECC_NIST_P384: 2,
179
+ TPM_ECC_NIST_P521: 3,
180
+ TPM_ECC_BN_P256: 1,
181
+ TPM_ECC_SM2_P256: 1, // p256
182
+ };
@@ -0,0 +1,58 @@
1
+ import { TPM_ALG, TPM_ST } from './constants.js';
2
+ import { isoUint8Array } from '../../../helpers/iso/index.js';
3
+ /**
4
+ * Cut up a TPM attestation's certInfo into intelligible chunks
5
+ */
6
+ export function parseCertInfo(certInfo) {
7
+ let pointer = 0;
8
+ const dataView = isoUint8Array.toDataView(certInfo);
9
+ // Get a magic constant
10
+ const magic = dataView.getUint32(pointer);
11
+ pointer += 4;
12
+ // Determine the algorithm used for attestation
13
+ const typeBuffer = dataView.getUint16(pointer);
14
+ pointer += 2;
15
+ const type = TPM_ST[typeBuffer];
16
+ // The name of a parent entity, can be ignored
17
+ const qualifiedSignerLength = dataView.getUint16(pointer);
18
+ pointer += 2;
19
+ const qualifiedSigner = certInfo.slice(pointer, pointer += qualifiedSignerLength);
20
+ // Get the expected hash of `attsToBeSigned`
21
+ const extraDataLength = dataView.getUint16(pointer);
22
+ pointer += 2;
23
+ const extraData = certInfo.slice(pointer, pointer += extraDataLength);
24
+ // Information about the TPM device's internal clock, can be ignored
25
+ const clock = certInfo.slice(pointer, pointer += 8);
26
+ const resetCount = dataView.getUint32(pointer);
27
+ pointer += 4;
28
+ const restartCount = dataView.getUint32(pointer);
29
+ pointer += 4;
30
+ const safe = !!certInfo.slice(pointer, pointer += 1);
31
+ const clockInfo = { clock, resetCount, restartCount, safe };
32
+ // TPM device firmware version
33
+ const firmwareVersion = certInfo.slice(pointer, pointer += 8);
34
+ // Attested Name
35
+ const attestedNameLength = dataView.getUint16(pointer);
36
+ pointer += 2;
37
+ const attestedName = certInfo.slice(pointer, pointer += attestedNameLength);
38
+ const attestedNameDataView = isoUint8Array.toDataView(attestedName);
39
+ // Attested qualified name, can be ignored
40
+ const qualifiedNameLength = dataView.getUint16(pointer);
41
+ pointer += 2;
42
+ const qualifiedName = certInfo.slice(pointer, pointer += qualifiedNameLength);
43
+ const attested = {
44
+ nameAlg: TPM_ALG[attestedNameDataView.getUint16(0)],
45
+ nameAlgBuffer: attestedName.slice(0, 2),
46
+ name: attestedName,
47
+ qualifiedName,
48
+ };
49
+ return {
50
+ magic,
51
+ type,
52
+ qualifiedSigner,
53
+ extraData,
54
+ clockInfo,
55
+ firmwareVersion,
56
+ attested,
57
+ };
58
+ }
@@ -0,0 +1,94 @@
1
+ import { TPM_ALG, TPM_ECC_CURVE } from './constants.js';
2
+ import { isoUint8Array } from '../../../helpers/iso/index.js';
3
+ /**
4
+ * Break apart a TPM attestation's pubArea buffer
5
+ *
6
+ * See 12.2.4 TPMT_PUBLIC here:
7
+ * https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-00.96-130315.pdf
8
+ */
9
+ export function parsePubArea(pubArea) {
10
+ let pointer = 0;
11
+ const dataView = isoUint8Array.toDataView(pubArea);
12
+ const type = TPM_ALG[dataView.getUint16(pointer)];
13
+ pointer += 2;
14
+ const nameAlg = TPM_ALG[dataView.getUint16(pointer)];
15
+ pointer += 2;
16
+ // Get some authenticator attributes(?)
17
+ // const objectAttributesInt = pubArea.slice(pointer, (pointer += 4)).readUInt32BE(0);
18
+ const objectAttributesInt = dataView.getUint32(pointer);
19
+ pointer += 4;
20
+ const objectAttributes = {
21
+ fixedTPM: !!(objectAttributesInt & 1),
22
+ stClear: !!(objectAttributesInt & 2),
23
+ fixedParent: !!(objectAttributesInt & 8),
24
+ sensitiveDataOrigin: !!(objectAttributesInt & 16),
25
+ userWithAuth: !!(objectAttributesInt & 32),
26
+ adminWithPolicy: !!(objectAttributesInt & 64),
27
+ noDA: !!(objectAttributesInt & 512),
28
+ encryptedDuplication: !!(objectAttributesInt & 1024),
29
+ restricted: !!(objectAttributesInt & 32768),
30
+ decrypt: !!(objectAttributesInt & 65536),
31
+ signOrEncrypt: !!(objectAttributesInt & 131072),
32
+ };
33
+ // Slice out the authPolicy of dynamic length
34
+ const authPolicyLength = dataView.getUint16(pointer);
35
+ pointer += 2;
36
+ const authPolicy = pubArea.slice(pointer, pointer += authPolicyLength);
37
+ // Extract additional curve params according to type
38
+ const parameters = {};
39
+ let unique = Uint8Array.from([]);
40
+ if (type === 'TPM_ALG_RSA') {
41
+ const symmetric = TPM_ALG[dataView.getUint16(pointer)];
42
+ pointer += 2;
43
+ const scheme = TPM_ALG[dataView.getUint16(pointer)];
44
+ pointer += 2;
45
+ const keyBits = dataView.getUint16(pointer);
46
+ pointer += 2;
47
+ const exponent = dataView.getUint32(pointer);
48
+ pointer += 4;
49
+ parameters.rsa = { symmetric, scheme, keyBits, exponent };
50
+ /**
51
+ * See 11.2.4.5 TPM2B_PUBLIC_KEY_RSA here:
52
+ * https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-00.96-130315.pdf
53
+ */
54
+ // const uniqueLength = pubArea.slice(pointer, (pointer += 2)).readUInt16BE(0);
55
+ const uniqueLength = dataView.getUint16(pointer);
56
+ pointer += 2;
57
+ unique = pubArea.slice(pointer, pointer += uniqueLength);
58
+ }
59
+ else if (type === 'TPM_ALG_ECC') {
60
+ const symmetric = TPM_ALG[dataView.getUint16(pointer)];
61
+ pointer += 2;
62
+ const scheme = TPM_ALG[dataView.getUint16(pointer)];
63
+ pointer += 2;
64
+ const curveID = TPM_ECC_CURVE[dataView.getUint16(pointer)];
65
+ pointer += 2;
66
+ const kdf = TPM_ALG[dataView.getUint16(pointer)];
67
+ pointer += 2;
68
+ parameters.ecc = { symmetric, scheme, curveID, kdf };
69
+ /**
70
+ * See 11.2.5.1 TPM2B_ECC_PARAMETER here:
71
+ * https://trustedcomputinggroup.org/wp-content/uploads/TPM-Rev-2.0-Part-2-Structures-00.96-130315.pdf
72
+ */
73
+ // Retrieve X
74
+ const uniqueXLength = dataView.getUint16(pointer);
75
+ pointer += 2;
76
+ const uniqueX = pubArea.slice(pointer, pointer += uniqueXLength);
77
+ // Retrieve Y
78
+ const uniqueYLength = dataView.getUint16(pointer);
79
+ pointer += 2;
80
+ const uniqueY = pubArea.slice(pointer, pointer += uniqueYLength);
81
+ unique = isoUint8Array.concat([uniqueX, uniqueY]);
82
+ }
83
+ else {
84
+ throw new Error(`Unexpected type "${type}" (TPM)`);
85
+ }
86
+ return {
87
+ type,
88
+ nameAlg,
89
+ objectAttributes,
90
+ authPolicy,
91
+ parameters,
92
+ unique,
93
+ };
94
+ }
@@ -1,2 +1,2 @@
1
- import type { AttestationFormatVerifierOpts } from '../../verifyRegistrationResponse';
1
+ import type { AttestationFormatVerifierOpts } from '../../verifyRegistrationResponse.js';
2
2
  export declare function verifyAttestationTPM(options: AttestationFormatVerifierOpts): Promise<boolean>;
@@ -0,0 +1,323 @@
1
+ import { AsnParser, Certificate, ExtendedKeyUsage, id_ce_extKeyUsage, id_ce_subjectAltName, SubjectAlternativeName, } from '../../../deps.js';
2
+ import { decodeCredentialPublicKey } from '../../../helpers/decodeCredentialPublicKey.js';
3
+ import { COSEALG, COSEKEYS, isCOSEAlg, isCOSEPublicKeyEC2, isCOSEPublicKeyRSA, } from '../../../helpers/cose.js';
4
+ import { toHash } from '../../../helpers/toHash.js';
5
+ import { convertCertBufferToPEM } from '../../../helpers/convertCertBufferToPEM.js';
6
+ import { validateCertificatePath } from '../../../helpers/validateCertificatePath.js';
7
+ import { getCertificateInfo } from '../../../helpers/getCertificateInfo.js';
8
+ import { verifySignature } from '../../../helpers/verifySignature.js';
9
+ import { isoUint8Array } from '../../../helpers/iso/index.js';
10
+ import { MetadataService } from '../../../services/metadataService.js';
11
+ import { verifyAttestationWithMetadata } from '../../../metadata/verifyAttestationWithMetadata.js';
12
+ import { TPM_ECC_CURVE_COSE_CRV_MAP, TPM_MANUFACTURERS } from './constants.js';
13
+ import { parseCertInfo } from './parseCertInfo.js';
14
+ import { parsePubArea } from './parsePubArea.js';
15
+ export async function verifyAttestationTPM(options) {
16
+ const { aaguid, attStmt, authData, credentialPublicKey, clientDataHash, rootCertificates, } = options;
17
+ const ver = attStmt.get('ver');
18
+ const sig = attStmt.get('sig');
19
+ const alg = attStmt.get('alg');
20
+ const x5c = attStmt.get('x5c');
21
+ const pubArea = attStmt.get('pubArea');
22
+ const certInfo = attStmt.get('certInfo');
23
+ /**
24
+ * Verify structures
25
+ */
26
+ if (ver !== '2.0') {
27
+ throw new Error(`Unexpected ver "${ver}", expected "2.0" (TPM)`);
28
+ }
29
+ if (!sig) {
30
+ throw new Error('No attestation signature provided in attestation statement (TPM)');
31
+ }
32
+ if (!alg) {
33
+ throw new Error(`Attestation statement did not contain alg (TPM)`);
34
+ }
35
+ if (!isCOSEAlg(alg)) {
36
+ throw new Error(`Attestation statement contained invalid alg ${alg} (TPM)`);
37
+ }
38
+ if (!x5c) {
39
+ throw new Error('No attestation certificate provided in attestation statement (TPM)');
40
+ }
41
+ if (!pubArea) {
42
+ throw new Error('Attestation statement did not contain pubArea (TPM)');
43
+ }
44
+ if (!certInfo) {
45
+ throw new Error('Attestation statement did not contain certInfo (TPM)');
46
+ }
47
+ const parsedPubArea = parsePubArea(pubArea);
48
+ const { unique, type: pubType, parameters } = parsedPubArea;
49
+ // Verify that the public key specified by the parameters and unique fields of pubArea is
50
+ // identical to the credentialPublicKey in the attestedCredentialData in authenticatorData.
51
+ const cosePublicKey = decodeCredentialPublicKey(credentialPublicKey);
52
+ if (pubType === 'TPM_ALG_RSA') {
53
+ if (!isCOSEPublicKeyRSA(cosePublicKey)) {
54
+ throw new Error(`Credential public key with kty ${cosePublicKey.get(COSEKEYS.kty)} did not match ${pubType}`);
55
+ }
56
+ const n = cosePublicKey.get(COSEKEYS.n);
57
+ const e = cosePublicKey.get(COSEKEYS.e);
58
+ if (!n) {
59
+ throw new Error('COSE public key missing n (TPM|RSA)');
60
+ }
61
+ if (!e) {
62
+ throw new Error('COSE public key missing e (TPM|RSA)');
63
+ }
64
+ if (!isoUint8Array.areEqual(unique, n)) {
65
+ throw new Error('PubArea unique is not same as credentialPublicKey (TPM|RSA)');
66
+ }
67
+ if (!parameters.rsa) {
68
+ throw new Error(`Parsed pubArea type is RSA, but missing parameters.rsa (TPM|RSA)`);
69
+ }
70
+ const eBuffer = e;
71
+ // If `exponent` is equal to 0x00, then exponent is the default RSA exponent of 2^16+1 (65537)
72
+ const pubAreaExponent = parameters.rsa.exponent || 65537;
73
+ // Do some bit shifting to get to an integer
74
+ const eSum = eBuffer[0] + (eBuffer[1] << 8) + (eBuffer[2] << 16);
75
+ if (pubAreaExponent !== eSum) {
76
+ throw new Error(`Unexpected public key exp ${eSum}, expected ${pubAreaExponent} (TPM|RSA)`);
77
+ }
78
+ }
79
+ else if (pubType === 'TPM_ALG_ECC') {
80
+ if (!isCOSEPublicKeyEC2(cosePublicKey)) {
81
+ throw new Error(`Credential public key with kty ${cosePublicKey.get(COSEKEYS.kty)} did not match ${pubType}`);
82
+ }
83
+ const crv = cosePublicKey.get(COSEKEYS.crv);
84
+ const x = cosePublicKey.get(COSEKEYS.x);
85
+ const y = cosePublicKey.get(COSEKEYS.y);
86
+ if (!crv) {
87
+ throw new Error('COSE public key missing crv (TPM|ECC)');
88
+ }
89
+ if (!x) {
90
+ throw new Error('COSE public key missing x (TPM|ECC)');
91
+ }
92
+ if (!y) {
93
+ throw new Error('COSE public key missing y (TPM|ECC)');
94
+ }
95
+ if (!isoUint8Array.areEqual(unique, isoUint8Array.concat([x, y]))) {
96
+ throw new Error('PubArea unique is not same as public key x and y (TPM|ECC)');
97
+ }
98
+ if (!parameters.ecc) {
99
+ throw new Error(`Parsed pubArea type is ECC, but missing parameters.ecc (TPM|ECC)`);
100
+ }
101
+ const pubAreaCurveID = parameters.ecc.curveID;
102
+ const pubAreaCurveIDMapToCOSECRV = TPM_ECC_CURVE_COSE_CRV_MAP[pubAreaCurveID];
103
+ if (pubAreaCurveIDMapToCOSECRV !== crv) {
104
+ throw new Error(`Public area key curve ID "${pubAreaCurveID}" mapped to "${pubAreaCurveIDMapToCOSECRV}" which did not match public key crv of "${crv}" (TPM|ECC)`);
105
+ }
106
+ }
107
+ else {
108
+ throw new Error(`Unsupported pubArea.type "${pubType}"`);
109
+ }
110
+ const parsedCertInfo = parseCertInfo(certInfo);
111
+ const { magic, type: certType, attested, extraData } = parsedCertInfo;
112
+ if (magic !== 0xff544347) {
113
+ throw new Error(`Unexpected magic value "${magic}", expected "0xff544347" (TPM)`);
114
+ }
115
+ if (certType !== 'TPM_ST_ATTEST_CERTIFY') {
116
+ throw new Error(`Unexpected type "${certType}", expected "TPM_ST_ATTEST_CERTIFY" (TPM)`);
117
+ }
118
+ // Hash pubArea to create pubAreaHash using the nameAlg in attested
119
+ const pubAreaHash = await toHash(pubArea, attestedNameAlgToCOSEAlg(attested.nameAlg));
120
+ // Concatenate attested.nameAlg and pubAreaHash to create attestedName.
121
+ const attestedName = isoUint8Array.concat([
122
+ attested.nameAlgBuffer,
123
+ pubAreaHash,
124
+ ]);
125
+ // Check that certInfo.attested.name is equals to attestedName.
126
+ if (!isoUint8Array.areEqual(attested.name, attestedName)) {
127
+ throw new Error(`Attested name comparison failed (TPM)`);
128
+ }
129
+ // Concatenate authData with clientDataHash to create attToBeSigned
130
+ const attToBeSigned = isoUint8Array.concat([authData, clientDataHash]);
131
+ // Hash attToBeSigned using the algorithm specified in attStmt.alg to create attToBeSignedHash
132
+ const attToBeSignedHash = await toHash(attToBeSigned, alg);
133
+ // Check that certInfo.extraData is equals to attToBeSignedHash.
134
+ if (!isoUint8Array.areEqual(extraData, attToBeSignedHash)) {
135
+ throw new Error('CertInfo extra data did not equal hashed attestation (TPM)');
136
+ }
137
+ /**
138
+ * Verify signature
139
+ */
140
+ if (x5c.length < 1) {
141
+ throw new Error('No certificates present in x5c array (TPM)');
142
+ }
143
+ // Pick a leaf AIK certificate of the x5c array and parse it.
144
+ const leafCertInfo = getCertificateInfo(x5c[0]);
145
+ const { basicConstraintsCA, version, subject, notAfter, notBefore } = leafCertInfo;
146
+ if (basicConstraintsCA) {
147
+ throw new Error('Certificate basic constraints CA was not `false` (TPM)');
148
+ }
149
+ // Check that certificate is of version 3 (value must be set to 2).
150
+ if (version !== 2) {
151
+ throw new Error('Certificate version was not `3` (ASN.1 value of 2) (TPM)');
152
+ }
153
+ // Check that Subject sequence is empty.
154
+ if (subject.combined.length > 0) {
155
+ throw new Error('Certificate subject was not empty (TPM)');
156
+ }
157
+ // Check that certificate is currently valid
158
+ let now = new Date();
159
+ if (notBefore > now) {
160
+ throw new Error(`Certificate not good before "${notBefore.toString()}" (TPM)`);
161
+ }
162
+ // Check that certificate has not expired
163
+ now = new Date();
164
+ if (notAfter < now) {
165
+ throw new Error(`Certificate not good after "${notAfter.toString()}" (TPM)`);
166
+ }
167
+ /**
168
+ * Plumb the depths of the certificate's ASN.1-formatted data for some values we need to verify
169
+ */
170
+ const parsedCert = AsnParser.parse(x5c[0], Certificate);
171
+ if (!parsedCert.tbsCertificate.extensions) {
172
+ throw new Error('Certificate was missing extensions (TPM)');
173
+ }
174
+ let subjectAltNamePresent;
175
+ let extKeyUsage;
176
+ parsedCert.tbsCertificate.extensions.forEach((ext) => {
177
+ if (ext.extnID === id_ce_subjectAltName) {
178
+ subjectAltNamePresent = AsnParser.parse(ext.extnValue, SubjectAlternativeName);
179
+ }
180
+ else if (ext.extnID === id_ce_extKeyUsage) {
181
+ extKeyUsage = AsnParser.parse(ext.extnValue, ExtendedKeyUsage);
182
+ }
183
+ });
184
+ // Check that certificate contains subjectAltName (2.5.29.17) extension,
185
+ if (!subjectAltNamePresent) {
186
+ throw new Error('Certificate did not contain subjectAltName extension (TPM)');
187
+ }
188
+ // TPM-specific values are buried within `directoryName`, so first make sure there are values
189
+ // there.
190
+ if (!subjectAltNamePresent[0].directoryName?.[0].length) {
191
+ throw new Error('Certificate subjectAltName extension directoryName was empty (TPM)');
192
+ }
193
+ const { tcgAtTpmManufacturer, tcgAtTpmModel, tcgAtTpmVersion } = getTcgAtTpmValues(subjectAltNamePresent[0].directoryName);
194
+ if (!tcgAtTpmManufacturer || !tcgAtTpmModel || !tcgAtTpmVersion) {
195
+ throw new Error('Certificate contained incomplete subjectAltName data (TPM)');
196
+ }
197
+ if (!extKeyUsage) {
198
+ throw new Error('Certificate did not contain ExtendedKeyUsage extension (TPM)');
199
+ }
200
+ // Check that tcpaTpmManufacturer (2.23.133.2.1) field is set to a valid manufacturer ID.
201
+ if (!TPM_MANUFACTURERS[tcgAtTpmManufacturer]) {
202
+ throw new Error(`Could not match TPM manufacturer "${tcgAtTpmManufacturer}" (TPM)`);
203
+ }
204
+ // Check that certificate contains extKeyUsage (2.5.29.37) extension and it must contain
205
+ // tcg-kp-AIKCertificate (2.23.133.8.3) OID.
206
+ if (extKeyUsage[0] !== '2.23.133.8.3') {
207
+ throw new Error(`Unexpected extKeyUsage "${extKeyUsage[0]}", expected "2.23.133.8.3" (TPM)`);
208
+ }
209
+ // TODO: If certificate contains id-fido-gen-ce-aaguid(1.3.6.1.4.1.45724.1.1.4) extension, check
210
+ // that it’s value is set to the same AAGUID as in authData.
211
+ // Run some metadata checks if a statement exists for this authenticator
212
+ const statement = await MetadataService.getStatement(aaguid);
213
+ if (statement) {
214
+ try {
215
+ await verifyAttestationWithMetadata({
216
+ statement,
217
+ credentialPublicKey,
218
+ x5c,
219
+ attestationStatementAlg: alg,
220
+ });
221
+ }
222
+ catch (err) {
223
+ const _err = err;
224
+ throw new Error(`${_err.message} (TPM)`);
225
+ }
226
+ }
227
+ else {
228
+ try {
229
+ // Try validating the certificate path using the root certificates set via SettingsService
230
+ await validateCertificatePath(x5c.map(convertCertBufferToPEM), rootCertificates);
231
+ }
232
+ catch (err) {
233
+ const _err = err;
234
+ throw new Error(`${_err.message} (TPM)`);
235
+ }
236
+ }
237
+ // Verify signature over certInfo with the public key extracted from AIK certificate.
238
+ // In the wise words of Yuriy Ackermann: "Get Martini friend, you are done!"
239
+ return verifySignature({
240
+ signature: sig,
241
+ data: certInfo,
242
+ x509Certificate: x5c[0],
243
+ hashAlgorithm: alg,
244
+ });
245
+ }
246
+ /**
247
+ * Contain logic for pulling TPM-specific values out of subjectAlternativeName extension
248
+ */
249
+ function getTcgAtTpmValues(root) {
250
+ const oidManufacturer = '2.23.133.2.1';
251
+ const oidModel = '2.23.133.2.2';
252
+ const oidVersion = '2.23.133.2.3';
253
+ let tcgAtTpmManufacturer;
254
+ let tcgAtTpmModel;
255
+ let tcgAtTpmVersion;
256
+ /**
257
+ * Iterate through the following potential structures:
258
+ *
259
+ * (Good, follows the spec)
260
+ * https://trustedcomputinggroup.org/wp-content/uploads/TCG_IWG_EKCredentialProfile_v2p3_r2_pub.pdf (page 33)
261
+ * Name [
262
+ * RelativeDistinguishedName [
263
+ * AttributeTypeAndValue { type, value }
264
+ * ]
265
+ * RelativeDistinguishedName [
266
+ * AttributeTypeAndValue { type, value }
267
+ * ]
268
+ * RelativeDistinguishedName [
269
+ * AttributeTypeAndValue { type, value }
270
+ * ]
271
+ * ]
272
+ *
273
+ * (Bad, does not follow the spec)
274
+ * Name [
275
+ * RelativeDistinguishedName [
276
+ * AttributeTypeAndValue { type, value }
277
+ * AttributeTypeAndValue { type, value }
278
+ * AttributeTypeAndValue { type, value }
279
+ * ]
280
+ * ]
281
+ *
282
+ * Both structures have been seen in the wild and need to be supported
283
+ */
284
+ root.forEach((relName) => {
285
+ relName.forEach((attr) => {
286
+ if (attr.type === oidManufacturer) {
287
+ tcgAtTpmManufacturer = attr.value.toString();
288
+ }
289
+ else if (attr.type === oidModel) {
290
+ tcgAtTpmModel = attr.value.toString();
291
+ }
292
+ else if (attr.type === oidVersion) {
293
+ tcgAtTpmVersion = attr.value.toString();
294
+ }
295
+ });
296
+ });
297
+ return {
298
+ tcgAtTpmManufacturer,
299
+ tcgAtTpmModel,
300
+ tcgAtTpmVersion,
301
+ };
302
+ }
303
+ /**
304
+ * Convert TPM-specific SHA algorithm ID's with COSE-specific equivalents. Note that the choice to
305
+ * use ECDSA SHA IDs is arbitrary; any such COSEALG that would map to SHA-256 in
306
+ * `mapCoseAlgToWebCryptoAlg()`
307
+ *
308
+ * SHA IDs referenced from here:
309
+ *
310
+ * https://trustedcomputinggroup.org/wp-content/uploads/TCG_TPM2_r1p59_Part2_Structures_pub.pdf
311
+ */
312
+ function attestedNameAlgToCOSEAlg(alg) {
313
+ if (alg === 'TPM_ALG_SHA256') {
314
+ return COSEALG.ES256;
315
+ }
316
+ else if (alg === 'TPM_ALG_SHA384') {
317
+ return COSEALG.ES384;
318
+ }
319
+ else if (alg === 'TPM_ALG_SHA512') {
320
+ return COSEALG.ES512;
321
+ }
322
+ throw new Error(`Unexpected TPM attested name alg ${alg}`);
323
+ }
@@ -1,4 +1,4 @@
1
- import type { AttestationFormatVerifierOpts } from '../verifyRegistrationResponse';
1
+ import type { AttestationFormatVerifierOpts } from '../verifyRegistrationResponse.js';
2
2
  /**
3
3
  * Verify an attestation response with fmt 'android-key'
4
4
  */