@@ -28,38 +28,52 @@ import com.yubico.internal.util.BinaryUtil
28
28
import com .yubico .internal .util .CertificateParser
29
29
import com .yubico .webauthn .TestAuthenticator
30
30
import com .yubico .webauthn .data .ByteArray
31
+ import com .yubico .webauthn .data .Generators .arbitraryByteArray
32
+ import com .yubico .webauthn .data .Generators .shrinkByteArray
31
33
import org .bouncycastle .asn1 .DEROctetString
32
34
import org .junit .runner .RunWith
33
35
import org .scalatest .funspec .AnyFunSpec
34
36
import org .scalatest .matchers .should .Matchers
35
37
import org .scalatestplus .junit .JUnitRunner
38
+ import org .scalatestplus .scalacheck .ScalaCheckDrivenPropertyChecks
36
39
37
40
import java .security .cert .X509Certificate
38
41
import scala .jdk .OptionConverters .RichOptional
39
42
40
43
@ RunWith (classOf [JUnitRunner ])
41
- class CertificateUtilSpec extends AnyFunSpec with Matchers {
44
+ class CertificateUtilSpec
45
+ extends AnyFunSpec
46
+ with Matchers
47
+ with ScalaCheckDrivenPropertyChecks {
42
48
describe(" parseFidoSerNumExtension" ) {
43
49
val idFidoGenCeSernum = " 1.3.6.1.4.1.45724.1.1.2"
44
50
45
51
it(" correctly parses the id-fido-gen-ce-sernum extension." ) {
46
- val (cert, _): (X509Certificate , _) = TestAuthenticator
47
- .generateAttestationCertificate(
48
- extensions = List (
49
- (
50
- idFidoGenCeSernum,
51
- false ,
52
- new DEROctetString (Array [Byte ](0 , 1 , 2 , 3 )),
52
+ forAll(
53
+ // 500-byte long serial numbers are not realistic, but would be valid DER data.
54
+ sizeRange(500 )
55
+ ) {
56
+ // Using Array[Byte] here causes an (almost) infinite loop in the shrinker in case of failure.
57
+ // See: https://github.com/typelevel/scalacheck/issues/968#issuecomment-2594018791
58
+ sernum : ByteArray =>
59
+ val (cert, _): (X509Certificate , _) = TestAuthenticator
60
+ .generateAttestationCertificate(
61
+ extensions = List (
62
+ (
63
+ idFidoGenCeSernum,
64
+ false ,
65
+ new DEROctetString (sernum.getBytes),
66
+ )
67
+ )
53
68
)
54
- )
55
- )
56
69
57
- val result =
58
- CertificateUtil
59
- .parseFidoSerNumExtension(cert)
60
- .toScala
61
- .map(new ByteArray (_))
62
- result should equal(Some (ByteArray .fromHex(" 00010203" )))
70
+ val result =
71
+ CertificateUtil
72
+ .parseFidoSerNumExtension(cert)
73
+ .toScala
74
+ .map(new ByteArray (_))
75
+ result should equal(Some (sernum))
76
+ }
63
77
}
64
78
65
79
it(" returns empty when cert has no id-fido-gen-ce-sernum extension." ) {
0 commit comments