@@ -302,28 +302,50 @@ object TestAuthenticator {
302
302
}
303
303
}
304
304
305
- private def createCredential (
305
+ private def createAuthenticatorData (
306
306
aaguid : ByteArray = Defaults .aaguid,
307
- attestationMaker : AttestationMaker ,
308
307
authenticatorExtensions : Option [JsonNode ] = None ,
309
- challenge : ByteArray = Defaults .challenge,
310
- clientData : Option [JsonNode ] = None ,
311
- clientExtensions : ClientRegistrationExtensionOutputs =
312
- ClientRegistrationExtensionOutputs .builder().build(),
313
308
credentialKeypair : Option [KeyPair ] = None ,
314
309
keyAlgorithm : COSEAlgorithmIdentifier = Defaults .keyAlgorithm,
315
- origin : String = Defaults .origin,
316
- tokenBindingStatus : String = Defaults .TokenBinding .status,
317
- tokenBindingId : Option [String ] = Defaults .TokenBinding .id,
318
310
): (
319
- data.PublicKeyCredential [
320
- data.AuthenticatorAttestationResponse ,
321
- ClientRegistrationExtensionOutputs ,
322
- ],
311
+ ByteArray ,
323
312
KeyPair ,
324
- List [(X509Certificate , PrivateKey )],
325
313
) = {
314
+ val keypair =
315
+ credentialKeypair.getOrElse(generateKeypair(algorithm = keyAlgorithm))
316
+ val publicKeyCose = keypair.getPublic match {
317
+ case pub : ECPublicKey => WebAuthnTestCodecs .ecPublicKeyToCose(pub)
318
+ case pub : BCEdDSAPublicKey => WebAuthnTestCodecs .eddsaPublicKeyToCose(pub)
319
+ case pub : RSAPublicKey =>
320
+ WebAuthnTestCodecs .rsaPublicKeyToCose(pub, keyAlgorithm)
321
+ }
326
322
323
+ val authDataBytes : ByteArray = makeAuthDataBytes(
324
+ rpId = Defaults .rpId,
325
+ attestedCredentialDataBytes = Some (
326
+ makeAttestedCredentialDataBytes(
327
+ aaguid = aaguid,
328
+ publicKeyCose = publicKeyCose,
329
+ )
330
+ ),
331
+ extensionsCborBytes = authenticatorExtensions map (ext =>
332
+ new ByteArray (JacksonCodecs .cbor().writeValueAsBytes(ext))
333
+ ),
334
+ )
335
+
336
+ (
337
+ authDataBytes,
338
+ keypair,
339
+ )
340
+ }
341
+
342
+ private def createClientData (
343
+ challenge : ByteArray = Defaults .challenge,
344
+ clientData : Option [JsonNode ] = None ,
345
+ origin : String = Defaults .origin,
346
+ tokenBindingStatus : String = Defaults .TokenBinding .status,
347
+ tokenBindingId : Option [String ] = Defaults .TokenBinding .id,
348
+ ): String = {
327
349
val clientDataJson : String =
328
350
JacksonCodecs .json.writeValueAsString(clientData getOrElse {
329
351
val json : ObjectNode = jsonFactory.objectNode()
@@ -349,29 +371,27 @@ object TestAuthenticator {
349
371
350
372
json
351
373
})
352
- val clientDataJsonBytes = toBytes(clientDataJson)
353
374
354
- val keypair =
355
- credentialKeypair.getOrElse(generateKeypair(algorithm = keyAlgorithm))
356
- val publicKeyCose = keypair.getPublic match {
357
- case pub : ECPublicKey => WebAuthnTestCodecs .ecPublicKeyToCose(pub)
358
- case pub : BCEdDSAPublicKey => WebAuthnTestCodecs .eddsaPublicKeyToCose(pub)
359
- case pub : RSAPublicKey =>
360
- WebAuthnTestCodecs .rsaPublicKeyToCose(pub, keyAlgorithm)
361
- }
375
+ clientDataJson
376
+ }
362
377
363
- val authDataBytes : ByteArray = makeAuthDataBytes(
364
- rpId = Defaults .rpId,
365
- attestedCredentialDataBytes = Some (
366
- makeAttestedCredentialDataBytes(
367
- aaguid = aaguid,
368
- publicKeyCose = publicKeyCose,
369
- )
370
- ),
371
- extensionsCborBytes = authenticatorExtensions map (ext =>
372
- new ByteArray (JacksonCodecs .cbor().writeValueAsBytes(ext))
373
- ),
374
- )
378
+ private def createCredential (
379
+ authDataBytes : ByteArray ,
380
+ clientDataJson : String ,
381
+ credentialKeypair : KeyPair ,
382
+ attestationMaker : AttestationMaker ,
383
+ clientExtensions : ClientRegistrationExtensionOutputs =
384
+ ClientRegistrationExtensionOutputs .builder().build(),
385
+ ): (
386
+ data.PublicKeyCredential [
387
+ data.AuthenticatorAttestationResponse ,
388
+ ClientRegistrationExtensionOutputs ,
389
+ ],
390
+ KeyPair ,
391
+ List [(X509Certificate , PrivateKey )],
392
+ ) = {
393
+
394
+ val clientDataJsonBytes = toBytes(clientDataJson)
375
395
376
396
val attestationObjectBytes =
377
397
attestationMaker.makeAttestationObjectBytes(authDataBytes, clientDataJson)
@@ -391,7 +411,7 @@ object TestAuthenticator {
391
411
.response(response)
392
412
.clientExtensionResults(clientExtensions)
393
413
.build(),
394
- keypair ,
414
+ credentialKeypair ,
395
415
attestationMaker.certChain,
396
416
)
397
417
}
@@ -407,13 +427,20 @@ object TestAuthenticator {
407
427
],
408
428
KeyPair ,
409
429
List [(X509Certificate , PrivateKey )],
410
- ) =
411
- createCredential (
430
+ ) = {
431
+ val (authData, credentialKeypair) = createAuthenticatorData (
412
432
aaguid = aaguid,
413
- attestationMaker = attestationMaker,
414
433
keyAlgorithm = keyAlgorithm,
415
434
)
416
435
436
+ createCredential(
437
+ authDataBytes = authData,
438
+ credentialKeypair = credentialKeypair,
439
+ clientDataJson = createClientData(),
440
+ attestationMaker = attestationMaker,
441
+ )
442
+ }
443
+
417
444
def createSelfAttestedCredential (
418
445
attestationMaker : SelfAttestation => AttestationMaker ,
419
446
keyAlgorithm : COSEAlgorithmIdentifier = Defaults .keyAlgorithm,
@@ -425,12 +452,15 @@ object TestAuthenticator {
425
452
KeyPair ,
426
453
List [(X509Certificate , PrivateKey )],
427
454
) = {
428
- val keypair = generateKeypair(keyAlgorithm)
455
+ val (authData, keypair) = createAuthenticatorData(credentialKeypair =
456
+ Some (generateKeypair(keyAlgorithm))
457
+ )
429
458
val signer = SelfAttestation (keypair, keyAlgorithm)
430
459
createCredential(
460
+ authDataBytes = authData,
461
+ clientDataJson = createClientData(),
462
+ credentialKeypair = keypair,
431
463
attestationMaker = attestationMaker(signer),
432
- credentialKeypair = Some (keypair),
433
- keyAlgorithm = keyAlgorithm,
434
464
)
435
465
}
436
466
@@ -444,12 +474,17 @@ object TestAuthenticator {
444
474
],
445
475
KeyPair ,
446
476
List [(X509Certificate , PrivateKey )],
447
- ) =
477
+ ) = {
478
+ val (authData, keypair) = createAuthenticatorData(
479
+ authenticatorExtensions = authenticatorExtensions
480
+ )
448
481
createCredential(
482
+ authDataBytes = authData,
483
+ clientDataJson = createClientData(challenge = challenge),
484
+ credentialKeypair = keypair,
449
485
attestationMaker = AttestationMaker .none(),
450
- authenticatorExtensions = authenticatorExtensions,
451
- challenge = challenge,
452
486
)
487
+ }
453
488
454
489
def createAssertionFromTestData (
455
490
testData : RegistrationTestData ,
0 commit comments