Skip to content

Commit 0836704

Browse files
committed
expose credential public key as a PublicKey object
1 parent f207b27 commit 0836704

File tree

3 files changed

+36
-0
lines changed

3 files changed

+36
-0
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ out/
1111
*.iws
1212
.attach_pid*
1313

14+
# VS Code
15+
.vscode/
16+
1417
# Mac
1518
.DS_Store
1619

webauthn-server-core/src/main/java/com/yubico/webauthn/RegisteredCredential.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.yubico.webauthn;
2626

27+
import COSE.CoseException;
2728
import com.fasterxml.jackson.annotation.JsonCreator;
2829
import com.fasterxml.jackson.annotation.JsonProperty;
2930
import com.yubico.webauthn.data.AttestedCredentialData;
@@ -33,6 +34,10 @@
3334
import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
3435
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
3536
import com.yubico.webauthn.data.UserIdentity;
37+
import java.io.IOException;
38+
import java.security.NoSuchAlgorithmException;
39+
import java.security.PublicKey;
40+
import java.security.spec.InvalidKeySpecException;
3641
import java.util.Optional;
3742
import lombok.AccessLevel;
3843
import lombok.Builder;
@@ -83,6 +88,18 @@ public final class RegisteredCredential {
8388
*/
8489
@NonNull private final ByteArray publicKeyCose;
8590

91+
/**
92+
* The credential public key, as a {@link java.security.PublicKey} object.
93+
*
94+
* <p>Provided for convenience.
95+
*/
96+
@NonNull
97+
@JsonIgnore
98+
public PublicKey getPublicKeyAsPublicKey()
99+
throws InvalidKeySpecException, NoSuchAlgorithmException, CoseException, IOException {
100+
return WebAuthnCodecs.importCosePublicKey(getPublicKeyCose());
101+
}
102+
86103
/**
87104
* The stored <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#signcount">signature
88105
* count</a> of the credential.

webauthn-server-core/src/main/java/com/yubico/webauthn/RegistrationResult.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
package com.yubico.webauthn;
2626

27+
import COSE.CoseException;
2728
import com.fasterxml.jackson.annotation.JsonCreator;
2829
import com.fasterxml.jackson.annotation.JsonIgnore;
2930
import com.fasterxml.jackson.annotation.JsonProperty;
@@ -38,9 +39,13 @@
3839
import com.yubico.webauthn.data.ClientRegistrationExtensionOutputs;
3940
import com.yubico.webauthn.data.PublicKeyCredential;
4041
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
42+
import java.io.IOException;
43+
import java.security.NoSuchAlgorithmException;
44+
import java.security.PublicKey;
4145
import java.security.cert.CertificateEncodingException;
4246
import java.security.cert.CertificateException;
4347
import java.security.cert.X509Certificate;
48+
import java.security.spec.InvalidKeySpecException;
4449
import java.util.List;
4550
import java.util.Optional;
4651
import java.util.stream.Collectors;
@@ -263,6 +268,17 @@ public ByteArray getPublicKeyCose() {
263268
.getCredentialPublicKey();
264269
}
265270

271+
/**
272+
* The public key of the created credential, as a {@link java.security.PublicKey} object.
273+
* <p>Provided for convenience.
274+
*/
275+
@NonNull
276+
@JsonIgnore
277+
public PublicKey getPublicKeyAsPublicKey()
278+
throws InvalidKeySpecException, NoSuchAlgorithmException, CoseException, IOException {
279+
return WebAuthnCodecs.importCosePublicKey(getPublicKeyCose());
280+
}
281+
266282
/**
267283
* The <a
268284
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-extension-output">client

0 commit comments

Comments
 (0)