Skip to content

Commit

Permalink
Add tests for parseFidoSerNumExtenstion
Browse files Browse the repository at this point in the history
  • Loading branch information
fdennis committed Jan 15, 2025
1 parent 81ac116 commit 07c9b32
Showing 1 changed file with 44 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.yubico.webauthn.attestation

import com.yubico.webauthn.TestAuthenticator
import com.yubico.webauthn.data.ByteArray
import org.bouncycastle.asn1.DEROctetString
import org.bouncycastle.asn1.x500.X500Name
import org.junit.runner.RunWith
import org.scalatest.funspec.AnyFunSpec
import org.scalatest.matchers.should.Matchers.convertToAnyShouldWrapper
import org.scalatestplus.junit.JUnitRunner

import java.security.cert.X509Certificate

@RunWith(classOf[JUnitRunner])
class CertificateUtilSpec extends AnyFunSpec {
describe("parseFidoSerNumExtension") {
val idFidoGenCeSernum = "1.3.6.1.4.1.45724.1.1.2"
it("should correctly parse the serial number from a valid certificate with the id-fido-gen-ce-sernum extension.") {
val goodCert: X509Certificate = TestAuthenticator
.generateAttestationCertificate(
name = new X500Name(
"O=Yubico, C=SE, OU=Authenticator Attestation"
),
extensions = List(
(
idFidoGenCeSernum,
false,
new DEROctetString(Array[Byte](0, 1, 2, 3)),
)
),
)
._1

val result = new ByteArray(
CertificateUtil
.parseFidoSerNumExtension(goodCert)
.get
)
result.shouldEqual(ByteArray.fromHex("00010203"));
}

}

}

0 comments on commit 07c9b32

Please sign in to comment.