Skip to content

Commit 7c8fd3b

Browse files
authored
Merge pull request #299 from iaik-jheher/feature/expose-public-key
Expose credential public key as a PublicKey object
2 parents 1c8a8ad + a5d88f7 commit 7c8fd3b

File tree

4 files changed

+48
-0
lines changed

4 files changed

+48
-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

NEWS

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
== Version 2.6.0 (unreleased) ==
2+
3+
* Added method `getParsedPublicKey(): java.security.PublicKey` to
4+
`RegistrationResult` and `RegisteredCredential`.
5+
** Thanks to Jakob Heher (A-SIT) for the contribution, see
6+
https://github.com/Yubico/java-webauthn-server/pull/299
7+
8+
19
== Version 2.5.0 (unreleased) ==
210

311
`webauthn-server-core`:

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424

2525
package com.yubico.webauthn;
2626

27+
import COSE.CoseException;
2728
import com.fasterxml.jackson.annotation.JsonAlias;
2829
import com.fasterxml.jackson.annotation.JsonCreator;
30+
import com.fasterxml.jackson.annotation.JsonIgnore;
2931
import com.fasterxml.jackson.annotation.JsonProperty;
3032
import com.yubico.webauthn.data.AttestedCredentialData;
3133
import com.yubico.webauthn.data.AuthenticatorAssertionResponse;
@@ -34,6 +36,10 @@
3436
import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
3537
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
3638
import com.yubico.webauthn.data.UserIdentity;
39+
import java.io.IOException;
40+
import java.security.NoSuchAlgorithmException;
41+
import java.security.PublicKey;
42+
import java.security.spec.InvalidKeySpecException;
3743
import java.util.Optional;
3844
import lombok.AccessLevel;
3945
import lombok.Builder;
@@ -84,6 +90,19 @@ public final class RegisteredCredential {
8490
*/
8591
@NonNull private final ByteArray publicKeyCose;
8692

93+
/**
94+
* The public key of the credential, parsed as a {@link PublicKey} object.
95+
*
96+
* @see #getPublicKeyCose()
97+
* @see RegistrationResult#getParsedPublicKey()
98+
*/
99+
@NonNull
100+
@JsonIgnore
101+
public PublicKey getParsedPublicKey()
102+
throws InvalidKeySpecException, NoSuchAlgorithmException, CoseException, IOException {
103+
return WebAuthnCodecs.importCosePublicKey(getPublicKeyCose());
104+
}
105+
87106
/**
88107
* The stored <a href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#signcount">signature
89108
* count</a> of the credential.

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

Lines changed: 18 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;
@@ -41,9 +42,13 @@
4142
import com.yubico.webauthn.data.ClientRegistrationExtensionOutputs;
4243
import com.yubico.webauthn.data.PublicKeyCredential;
4344
import com.yubico.webauthn.data.PublicKeyCredentialDescriptor;
45+
import java.io.IOException;
46+
import java.security.NoSuchAlgorithmException;
47+
import java.security.PublicKey;
4448
import java.security.cert.CertificateEncodingException;
4549
import java.security.cert.CertificateException;
4650
import java.security.cert.X509Certificate;
51+
import java.security.spec.InvalidKeySpecException;
4752
import java.util.List;
4853
import java.util.Optional;
4954
import java.util.stream.Collectors;
@@ -285,6 +290,19 @@ public ByteArray getPublicKeyCose() {
285290
.getCredentialPublicKey();
286291
}
287292

293+
/**
294+
* The public key of the created credential, parsed as a {@link PublicKey} object.
295+
*
296+
* @see #getPublicKeyCose()
297+
* @see RegisteredCredential#getParsedPublicKey()
298+
*/
299+
@NonNull
300+
@JsonIgnore
301+
public PublicKey getParsedPublicKey()
302+
throws InvalidKeySpecException, NoSuchAlgorithmException, CoseException, IOException {
303+
return WebAuthnCodecs.importCosePublicKey(getPublicKeyCose());
304+
}
305+
288306
/**
289307
* The <a
290308
* href="https://www.w3.org/TR/2021/REC-webauthn-2-20210408/#client-extension-output">client

0 commit comments

Comments
 (0)