Skip to content

Commit b47438c

Browse files
ynojimavietj
authored andcommitted
Rename from PublicKeyCredential to COSEAlgorithm
since WebAuthn specification uses the name "PublicKeyCredential" for other type.
1 parent 60f3fa9 commit b47438c

File tree

8 files changed

+33
-55
lines changed

8 files changed

+33
-55
lines changed

vertx-auth-webauthn4j/src/main/generated/io/vertx/ext/auth/webauthn4j/AttestationCertificatesConverter.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
5-
import java.time.Instant;
6-
import java.time.format.DateTimeFormatter;
75

86
/**
97
* Converter and mapper for {@link io.vertx.ext.auth.webauthn4j.AttestationCertificates}.
@@ -16,7 +14,7 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, Attesta
1614
switch (member.getKey()) {
1715
case "alg":
1816
if (member.getValue() instanceof String) {
19-
obj.setAlg(io.vertx.ext.auth.webauthn4j.PublicKeyCredential.valueOf((String)member.getValue()));
17+
obj.setAlg(COSEAlgorithm.valueOf((String)member.getValue()));
2018
}
2119
break;
2220
case "x5c":

vertx-auth-webauthn4j/src/main/generated/io/vertx/ext/auth/webauthn4j/WebAuthn4JOptionsConverter.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import io.vertx.core.json.JsonObject;
44
import io.vertx.core.json.JsonArray;
5-
import java.time.Instant;
6-
import java.time.format.DateTimeFormatter;
75

86
/**
97
* Converter and mapper for {@link io.vertx.ext.auth.webauthn4j.WebAuthn4JOptions}.
@@ -41,10 +39,10 @@ static void fromJson(Iterable<java.util.Map.Entry<String, Object>> json, WebAuth
4139
break;
4240
case "pubKeyCredParams":
4341
if (member.getValue() instanceof JsonArray) {
44-
java.util.ArrayList<io.vertx.ext.auth.webauthn4j.PublicKeyCredential> list = new java.util.ArrayList<>();
42+
java.util.ArrayList<COSEAlgorithm> list = new java.util.ArrayList<>();
4543
((Iterable<Object>)member.getValue()).forEach( item -> {
4644
if (item instanceof String)
47-
list.add(io.vertx.ext.auth.webauthn4j.PublicKeyCredential.valueOf((String)item));
45+
list.add(COSEAlgorithm.valueOf((String)item));
4846
});
4947
obj.setPubKeyCredParams(list);
5048
}

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/AttestationCertificates.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public class AttestationCertificates {
3333
/**
3434
* The algorithm used for the public credential
3535
*/
36-
private PublicKeyCredential alg;
36+
private COSEAlgorithm alg;
3737

3838
/**
3939
* The list of X509 certificates encoded as base64url.
@@ -47,11 +47,11 @@ public AttestationCertificates(JsonObject json) {
4747
AttestationCertificatesConverter.fromJson(json, this);
4848
}
4949

50-
public PublicKeyCredential getAlg() {
50+
public COSEAlgorithm getAlg() {
5151
return alg;
5252
}
5353

54-
public AttestationCertificates setAlg(PublicKeyCredential alg) {
54+
public AttestationCertificates setAlg(COSEAlgorithm alg) {
5555
this.alg = alg;
5656
return this;
5757
}

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/PublicKeyCredential.java renamed to vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/COSEAlgorithm.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
* https://www.iana.org/assignments/cose/cose.xhtml#algorithms
2323
*/
2424
@VertxGen
25-
public enum PublicKeyCredential {
25+
public enum COSEAlgorithm {
2626
ES256(-7),
2727
ES384(-35),
2828
ES512(-36),
@@ -38,11 +38,11 @@ public enum PublicKeyCredential {
3838

3939
private final int coseId;
4040

41-
PublicKeyCredential(int coseId) {
41+
COSEAlgorithm(int coseId) {
4242
this.coseId = coseId;
4343
}
4444

45-
public static PublicKeyCredential valueOf(int coseId) {
45+
public static COSEAlgorithm valueOf(int coseId) {
4646
switch (coseId) {
4747
case -7:
4848
return ES256;

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/WebAuthn4JOptions.java

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,11 @@
2828

2929
import static io.vertx.ext.auth.webauthn4j.Attestation.NONE;
3030
import static io.vertx.ext.auth.webauthn4j.AuthenticatorTransport.*;
31-
import static io.vertx.ext.auth.webauthn4j.PublicKeyCredential.ES256;
32-
import static io.vertx.ext.auth.webauthn4j.PublicKeyCredential.RS256;
31+
import static io.vertx.ext.auth.webauthn4j.COSEAlgorithm.ES256;
32+
import static io.vertx.ext.auth.webauthn4j.COSEAlgorithm.RS256;
3333
import static io.vertx.ext.auth.webauthn4j.UserVerification.DISCOURAGED;
3434

35-
import java.security.cert.CRLException;
3635
import java.security.cert.CertificateException;
37-
import java.security.cert.X509CRL;
3836
import java.security.cert.X509Certificate;
3937
import java.util.*;
4038

@@ -200,7 +198,7 @@ public class WebAuthn4JOptions {
200198
private Attestation attestation;
201199

202200
// Needs to be a list, order is important
203-
private List<PublicKeyCredential> pubKeyCredParams;
201+
private List<COSEAlgorithm> pubKeyCredParams;
204202

205203
private int challengeLength;
206204
private JsonObject extensions;
@@ -210,7 +208,7 @@ public class WebAuthn4JOptions {
210208
// private List<X509CRL> rootCrls;
211209

212210
private boolean relaxedSafetyNetIntegrityVeridict;
213-
211+
214212
private boolean useMetadata;
215213

216214
private boolean userPresenceRequired;
@@ -327,11 +325,11 @@ public WebAuthn4JOptions setResidentKey(ResidentKey residentKey) {
327325
return this;
328326
}
329327

330-
public List<PublicKeyCredential> getPubKeyCredParams() {
328+
public List<COSEAlgorithm> getPubKeyCredParams() {
331329
return pubKeyCredParams;
332330
}
333331

334-
public WebAuthn4JOptions addPubKeyCredParam(PublicKeyCredential pubKeyCredParam) {
332+
public WebAuthn4JOptions addPubKeyCredParam(COSEAlgorithm pubKeyCredParam) {
335333
if (pubKeyCredParam == null) {
336334
throw new IllegalArgumentException("pubKeyCredParam cannot be null");
337335
}
@@ -345,7 +343,7 @@ public WebAuthn4JOptions addPubKeyCredParam(PublicKeyCredential pubKeyCredParam)
345343
return this;
346344
}
347345

348-
public WebAuthn4JOptions setPubKeyCredParams(List<PublicKeyCredential> pubKeyCredParams) {
346+
public WebAuthn4JOptions setPubKeyCredParams(List<COSEAlgorithm> pubKeyCredParams) {
349347
if (pubKeyCredParams.size() == 0) {
350348
throw new IllegalArgumentException("PubKeyCredParams must have at least 1 element");
351349
}
@@ -540,11 +538,11 @@ public WebAuthn4JOptions setUseMetadata(boolean useMetadata) {
540538
this.useMetadata = useMetadata;
541539
return this;
542540
}
543-
541+
544542
public boolean isUseMetadata() {
545543
return useMetadata;
546544
}
547-
545+
548546
public JsonObject toJson() {
549547
final JsonObject json = new JsonObject();
550548
WebAuthn4JOptionsConverter.toJson(this, json);
@@ -559,7 +557,7 @@ public String toString() {
559557
public boolean isUserPresenceRequired() {
560558
return userPresenceRequired;
561559
}
562-
560+
563561
public WebAuthn4JOptions setUserPresenceRequired(boolean userPresenceRequired) {
564562
this.userPresenceRequired = userPresenceRequired;
565563
return this;

vertx-auth-webauthn4j/src/main/java/io/vertx/ext/auth/webauthn4j/impl/WebAuthn4JImpl.java

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,8 @@
9898
import io.vertx.ext.auth.impl.CertificateHelper;
9999
import io.vertx.ext.auth.impl.CertificateHelper.CertInfo;
100100
import io.vertx.ext.auth.prng.VertxContextPRNG;
101-
import io.vertx.ext.auth.webauthn4j.Attestation;
102-
import io.vertx.ext.auth.webauthn4j.AttestationCertificates;
103-
import io.vertx.ext.auth.webauthn4j.Authenticator;
104-
import io.vertx.ext.auth.webauthn4j.AuthenticatorTransport;
105-
import io.vertx.ext.auth.webauthn4j.CredentialStorage;
106-
import io.vertx.ext.auth.webauthn4j.PublicKeyCredential;
107-
import io.vertx.ext.auth.webauthn4j.ResidentKey;
108-
import io.vertx.ext.auth.webauthn4j.UserVerification;
109-
import io.vertx.ext.auth.webauthn4j.WebAuthn4J;
110-
import io.vertx.ext.auth.webauthn4j.WebAuthn4JOptions;
111-
import io.vertx.ext.auth.webauthn4j.WebAuthn4JCredentials;
112-
import io.vertx.ext.auth.webauthn4j.WebAuthn4JException;
101+
import io.vertx.ext.auth.webauthn4j.*;
102+
import io.vertx.ext.auth.webauthn4j.COSEAlgorithm;
113103

114104
public class WebAuthn4JImpl implements WebAuthn4J {
115105

@@ -268,7 +258,7 @@ public Future<JsonObject> createCredentialsOptions(JsonObject user) {
268258
putOpt(json.getJsonObject("user"), "displayName", user.getString("displayName"));
269259
putOpt(json.getJsonObject("user"), "icon", user.getString("icon"));
270260
// put the public key credentials parameters
271-
for (PublicKeyCredential pubKeyCredParam : options.getPubKeyCredParams()) {
261+
for (COSEAlgorithm pubKeyCredParam : options.getPubKeyCredParams()) {
272262
addOpt(
273263
json.getJsonArray("pubKeyCredParams"),
274264
new JsonObject()
@@ -551,8 +541,8 @@ private Future<Authenticator> verifyWebAuthNCreate(JsonObject response, WebAuthn
551541
boolean userPresenceRequired = options.isUserPresenceRequired();
552542

553543
List<PublicKeyCredentialParameters> pubKeyCredParams = new ArrayList<>(options.getPubKeyCredParams().size());
554-
for (PublicKeyCredential publicKeyCredential : options.getPubKeyCredParams()) {
555-
pubKeyCredParams.add(new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, COSEAlgorithmIdentifier.create(publicKeyCredential.coseId())));
544+
for (COSEAlgorithm COSEAlgorithm : options.getPubKeyCredParams()) {
545+
pubKeyCredParams.add(new PublicKeyCredentialParameters(PublicKeyCredentialType.PUBLIC_KEY, COSEAlgorithmIdentifier.create(COSEAlgorithm.coseId())));
556546
}
557547
RegistrationParameters registrationParameters = new RegistrationParameters(serverProperty, pubKeyCredParams, userVerificationRequired, userPresenceRequired);
558548

@@ -587,20 +577,20 @@ private AttestationCertificates convertAttestationCertificates(AttestationStatem
587577
}
588578
// algo
589579
if(attestationStatement instanceof AndroidKeyAttestationStatement){
590-
attestationCertificates.setAlg(PublicKeyCredential.valueOf((int) ((AndroidKeyAttestationStatement)attestationStatement).getAlg().getValue()));
580+
attestationCertificates.setAlg(COSEAlgorithm.valueOf((int) ((AndroidKeyAttestationStatement)attestationStatement).getAlg().getValue()));
591581
} else if(attestationStatement instanceof AndroidSafetyNetAttestationStatement){
592582
// hoping the names match
593-
attestationCertificates.setAlg(PublicKeyCredential.valueOf(((AndroidSafetyNetAttestationStatement)attestationStatement).getResponse().getHeader().getAlg().getName()));
583+
attestationCertificates.setAlg(COSEAlgorithm.valueOf(((AndroidSafetyNetAttestationStatement)attestationStatement).getResponse().getHeader().getAlg().getName()));
594584
} else if(attestationStatement instanceof AppleAnonymousAttestationStatement){
595585
// FIXME: optional, but not read in webauthn4j?
596586
attestationCertificates.setAlg(null);
597587
} else if(attestationStatement instanceof FIDOU2FAttestationStatement){
598588
// seems to be fixed?
599-
attestationCertificates.setAlg(PublicKeyCredential.valueOf((int) COSEAlgorithmIdentifier.ES256.getValue()));
589+
attestationCertificates.setAlg(COSEAlgorithm.valueOf((int) COSEAlgorithmIdentifier.ES256.getValue()));
600590
} else if(attestationStatement instanceof PackedAttestationStatement){
601-
attestationCertificates.setAlg(PublicKeyCredential.valueOf((int) ((PackedAttestationStatement)attestationStatement).getAlg().getValue()));
591+
attestationCertificates.setAlg(COSEAlgorithm.valueOf((int) ((PackedAttestationStatement)attestationStatement).getAlg().getValue()));
602592
} else if(attestationStatement instanceof TPMAttestationStatement){
603-
attestationCertificates.setAlg(PublicKeyCredential.valueOf((int) ((TPMAttestationStatement)attestationStatement).getAlg().getValue()));
593+
attestationCertificates.setAlg(COSEAlgorithm.valueOf((int) ((TPMAttestationStatement)attestationStatement).getAlg().getValue()));
604594
} else {
605595
throw new WebAuthn4JException("Unsupported attestation statement format: "+attestationStatement.getFormat());
606596
}

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/WebAuth4JNTest.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import java.security.cert.CertificateException;
44
import java.util.Base64;
55

6+
import io.vertx.ext.auth.webauthn4j.*;
67
import org.junit.Before;
78
import org.junit.Ignore;
89
import org.junit.Rule;
@@ -11,12 +12,7 @@
1112

1213
import io.vertx.core.json.JsonObject;
1314
import io.vertx.ext.auth.impl.jose.JWS;
14-
import io.vertx.ext.auth.webauthn4j.Authenticator;
15-
import io.vertx.ext.auth.webauthn4j.PublicKeyCredential;
16-
import io.vertx.ext.auth.webauthn4j.RelyingParty;
17-
import io.vertx.ext.auth.webauthn4j.WebAuthn4J;
18-
import io.vertx.ext.auth.webauthn4j.WebAuthn4JOptions;
19-
import io.vertx.ext.auth.webauthn4j.WebAuthn4JCredentials;
15+
import io.vertx.ext.auth.webauthn4j.COSEAlgorithm;
2016
import io.vertx.ext.unit.Async;
2117
import io.vertx.ext.unit.TestContext;
2218
import io.vertx.ext.unit.junit.RunTestOnContext;
@@ -120,7 +116,7 @@ public void testPAckedSurrogate(TestContext should) {
120116
WebAuthn4J webAuthN = WebAuthn4J.create(
121117
rule.vertx(),
122118
new WebAuthn4JOptions().setRelyingParty(new RelyingParty().setName("FIDO Examples Corporation"))
123-
.addPubKeyCredParam(PublicKeyCredential.RS1)
119+
.addPubKeyCredParam(COSEAlgorithm.RS1)
124120
)
125121
.credentialStorage(database);
126122

vertx-auth-webauthn4j/src/test/java/io/vertx/tests/attestation/AttestationTest.java

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import io.vertx.ext.unit.junit.VertxUnitRunner;
1010
import io.vertx.tests.DummyStore;
1111

12-
import static io.vertx.ext.auth.webauthn4j.PublicKeyCredential.RS256;
13-
1412
import java.security.cert.CertificateException;
1513

1614
import org.junit.Before;
@@ -619,7 +617,7 @@ public void testPackedSurrogateAttestationSample(TestContext should) {
619617
rule.vertx(),
620618
new WebAuthn4JOptions()
621619
.setRelyingParty(new RelyingParty().setName("FIDO Examples Corporation"))
622-
.addPubKeyCredParam(PublicKeyCredential.RS1)
620+
.addPubKeyCredParam(COSEAlgorithm.RS1)
623621
)
624622
.credentialStorage(database);
625623

0 commit comments

Comments
 (0)