24
24
25
25
package com .yubico .webauthn .attestation
26
26
27
- import java .util .Collections
28
-
29
27
import com .yubico .internal .util .CertificateParser
30
28
import com .yubico .internal .util .JacksonCodecs
31
- import com .yubico .webauthn .attestation .resolver .SimpleAttestationResolver
32
- import com .yubico .webauthn .attestation .resolver .SimpleTrustResolver
33
- import com .yubico .webauthn .test .RealExamples
34
29
import com .yubico .webauthn .FinishRegistrationOptions
35
30
import com .yubico .webauthn .RelyingParty
36
31
import com .yubico .webauthn .attestation .Transport .LIGHTNING
37
32
import com .yubico .webauthn .attestation .Transport .NFC
38
33
import com .yubico .webauthn .attestation .Transport .USB
34
+ import com .yubico .webauthn .attestation .resolver .SimpleAttestationResolver
35
+ import com .yubico .webauthn .attestation .resolver .SimpleTrustResolver
39
36
import com .yubico .webauthn .data .PublicKeyCredentialCreationOptions
40
37
import com .yubico .webauthn .data .PublicKeyCredentialParameters
41
38
import com .yubico .webauthn .test .Helpers
39
+ import com .yubico .webauthn .test .RealExamples
42
40
import org .junit .runner .RunWith
43
41
import org .scalatest .FunSpec
44
42
import org .scalatest .Matchers
45
43
import org .scalatestplus .junit .JUnitRunner
46
44
45
+ import java .util .Collections
47
46
import scala .jdk .CollectionConverters ._
48
47
49
-
50
48
@ RunWith (classOf [JUnitRunner ])
51
49
class DeviceIdentificationSpec extends FunSpec with Matchers {
52
50
53
51
def metadataService (metadataJson : String ): StandardMetadataService = {
54
- val metadata = Collections .singleton(JacksonCodecs .json().readValue(metadataJson, classOf [MetadataObject ]))
52
+ val metadata = Collections .singleton(
53
+ JacksonCodecs .json().readValue(metadataJson, classOf [MetadataObject ])
54
+ )
55
55
new StandardMetadataService (
56
- new SimpleAttestationResolver (metadata, SimpleTrustResolver .fromMetadata(metadata))
56
+ new SimpleAttestationResolver (
57
+ metadata,
58
+ SimpleTrustResolver .fromMetadata(metadata),
59
+ )
57
60
)
58
61
}
59
62
60
63
describe(" A RelyingParty with the default StandardMetadataService" ) {
61
64
62
65
describe(" correctly identifies" ) {
63
- def check (expectedName : String , testData : RealExamples .Example , transports : Set [Transport ]): Unit = {
64
- val rp = RelyingParty .builder()
66
+ def check (
67
+ expectedName : String ,
68
+ testData : RealExamples .Example ,
69
+ transports : Set [Transport ],
70
+ ): Unit = {
71
+ val rp = RelyingParty
72
+ .builder()
65
73
.identity(testData.rp)
66
74
.credentialRepository(Helpers .CredentialRepository .empty)
67
75
.metadataService(new StandardMetadataService ())
68
76
.build()
69
77
70
- val result = rp.finishRegistration(FinishRegistrationOptions .builder()
71
- .request(PublicKeyCredentialCreationOptions .builder()
72
- .rp(testData.rp)
73
- .user(testData.user)
74
- .challenge(testData.attestation.challenge)
75
- .pubKeyCredParams(List (PublicKeyCredentialParameters .ES256 ).asJava)
76
- .build())
77
- .response(testData.attestation.credential)
78
- .build());
78
+ val result = rp.finishRegistration(
79
+ FinishRegistrationOptions
80
+ .builder()
81
+ .request(
82
+ PublicKeyCredentialCreationOptions
83
+ .builder()
84
+ .rp(testData.rp)
85
+ .user(testData.user)
86
+ .challenge(testData.attestation.challenge)
87
+ .pubKeyCredParams(
88
+ List (PublicKeyCredentialParameters .ES256 ).asJava
89
+ )
90
+ .build()
91
+ )
92
+ .response(testData.attestation.credential)
93
+ .build()
94
+ );
79
95
80
- result.isAttestationTrusted should be (true )
81
- result.getAttestationMetadata.isPresent should be (true )
82
- result.getAttestationMetadata.get.getDeviceProperties.isPresent should be (true )
83
- result.getAttestationMetadata.get.getDeviceProperties.get().get(" displayName" ) should equal (expectedName)
84
- result.getAttestationMetadata.get.getTransports.isPresent should be (true )
85
- result.getAttestationMetadata.get.getTransports.get.asScala should equal (transports)
96
+ result.isAttestationTrusted should be(true )
97
+ result.getAttestationMetadata.isPresent should be(true )
98
+ result.getAttestationMetadata.get.getDeviceProperties.isPresent should be(
99
+ true
100
+ )
101
+ result.getAttestationMetadata.get.getDeviceProperties
102
+ .get()
103
+ .get(" displayName" ) should equal(expectedName)
104
+ result.getAttestationMetadata.get.getTransports.isPresent should be(
105
+ true
106
+ )
107
+ result.getAttestationMetadata.get.getTransports.get.asScala should equal(
108
+ transports
109
+ )
86
110
}
87
111
88
112
it(" a YubiKey NEO." ) {
@@ -98,7 +122,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
98
122
check(" YubiKey 5 NFC" , RealExamples .YubiKey5Nfc , Set (USB , NFC ))
99
123
}
100
124
it(" a newer YubiKey 5 NFC." ) {
101
- check(" YubiKey 5/5C NFC" , RealExamples .YubiKey5NfcPost5cNfc , Set (USB , NFC ))
125
+ check(
126
+ " YubiKey 5/5C NFC" ,
127
+ RealExamples .YubiKey5NfcPost5cNfc ,
128
+ Set (USB , NFC ),
129
+ )
102
130
}
103
131
it(" a YubiKey 5C NFC." ) {
104
132
check(" YubiKey 5/5C NFC" , RealExamples .YubiKey5cNfc , Set (USB , NFC ))
@@ -116,21 +144,33 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
116
144
check(" Security Key by Yubico" , RealExamples .SecurityKey2 , Set (USB ))
117
145
}
118
146
it(" a Security Key NFC by Yubico." ) {
119
- check(" Security Key NFC by Yubico" , RealExamples .SecurityKeyNfc , Set (USB , NFC ))
147
+ check(
148
+ " Security Key NFC by Yubico" ,
149
+ RealExamples .SecurityKeyNfc ,
150
+ Set (USB , NFC ),
151
+ )
120
152
}
121
153
}
122
154
}
123
155
124
156
describe(" The default AttestationResolver" ) {
125
157
describe(" successfully identifies" ) {
126
- def check (expectedName : String , testData : RealExamples .Example , transports : Set [Transport ]): Unit = {
158
+ def check (
159
+ expectedName : String ,
160
+ testData : RealExamples .Example ,
161
+ transports : Set [Transport ],
162
+ ): Unit = {
127
163
val cert = CertificateParser .parseDer(testData.attestationCert.getBytes)
128
- val resolved = StandardMetadataService .createDefaultAttestationResolver().resolve(cert)
129
- resolved.isPresent should be (true )
130
- resolved.get.getDeviceProperties.isPresent should be (true )
131
- resolved.get.getDeviceProperties.get.get(" displayName" ) should equal (expectedName)
132
- resolved.get.getTransports.isPresent should be (true )
133
- resolved.get.getTransports.get.asScala should equal (transports)
164
+ val resolved = StandardMetadataService
165
+ .createDefaultAttestationResolver()
166
+ .resolve(cert)
167
+ resolved.isPresent should be(true )
168
+ resolved.get.getDeviceProperties.isPresent should be(true )
169
+ resolved.get.getDeviceProperties.get.get(" displayName" ) should equal(
170
+ expectedName
171
+ )
172
+ resolved.get.getTransports.isPresent should be(true )
173
+ resolved.get.getTransports.get.asScala should equal(transports)
134
174
}
135
175
136
176
it(" a YubiKey NEO." ) {
@@ -146,7 +186,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
146
186
check(" YubiKey 5 NFC" , RealExamples .YubiKey5Nfc , Set (USB , NFC ))
147
187
}
148
188
it(" a newer YubiKey 5 NFC." ) {
149
- check(" YubiKey 5/5C NFC" , RealExamples .YubiKey5NfcPost5cNfc , Set (USB , NFC ))
189
+ check(
190
+ " YubiKey 5/5C NFC" ,
191
+ RealExamples .YubiKey5NfcPost5cNfc ,
192
+ Set (USB , NFC ),
193
+ )
150
194
}
151
195
it(" a YubiKey 5C NFC." ) {
152
196
check(" YubiKey 5/5C NFC" , RealExamples .YubiKey5cNfc , Set (USB , NFC ))
@@ -164,7 +208,11 @@ class DeviceIdentificationSpec extends FunSpec with Matchers {
164
208
check(" Security Key by Yubico" , RealExamples .SecurityKey2 , Set (USB ))
165
209
}
166
210
it(" a Security Key NFC by Yubico." ) {
167
- check(" Security Key NFC by Yubico" , RealExamples .SecurityKeyNfc , Set (USB , NFC ))
211
+ check(
212
+ " Security Key NFC by Yubico" ,
213
+ RealExamples .SecurityKeyNfc ,
214
+ Set (USB , NFC ),
215
+ )
168
216
}
169
217
}
170
218
}
0 commit comments