Skip to content

Commit a9d1ad4

Browse files
committed
Refactor JWT signing algorithm creation
Motivation: JWT requires the creation of signing algorithm to use for the creation and validation of tokens. This could be used to implement Quic token validation process and thus we could reuse the implementation engine to implement a Quic token validator. This refactor also ease the creation usage of thread local to replace synchronised blocks around java cryptographic objet non thread safe usage. Changes: Extract the sign/verify part into a small package independent of JWT that can be reused in this module.
1 parent 9e72313 commit a9d1ad4

File tree

19 files changed

+929
-417
lines changed

19 files changed

+929
-417
lines changed

pom.xml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
<type>pom</type>
6060
<scope>import</scope>
6161
</dependency>
62+
<dependency>
63+
<groupId>org.testcontainers</groupId>
64+
<artifactId>testcontainers</artifactId>
65+
<version>1.21.3</version>
66+
<scope>test</scope>
67+
</dependency>
6268
</dependencies>
6369
</dependencyManagement>
6470

@@ -134,4 +140,4 @@
134140
</plugins>
135141
</build>
136142

137-
</project>
143+
</project>
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package io.vertx.ext.auth.impl.jose;
2+
3+
import java.security.Signature;
4+
import java.security.spec.MGF1ParameterSpec;
5+
import java.security.spec.PSSParameterSpec;
6+
import java.util.concurrent.Callable;
7+
8+
/**
9+
* JWT alg.
10+
*/
11+
public enum Alg {
12+
13+
HS256("HmacSHA256", "1.2.840.113549.2.9", null),
14+
HS384("HmacSHA384", "1.2.840.113549.2.10", null),
15+
HS512("HmacSHA512", "1.2.840.113549.2.11", null),
16+
RS1(null, null, null), // ????
17+
RS256("SHA256withRSA", "1.2.840.113549.1.1.11", () -> Signature.getInstance("SHA256withRSA")),
18+
RS384("SHA384withRSA", "1.2.840.113549.1.1.12", () -> Signature.getInstance("SHA384withRSA")),
19+
RS512("SHA512withRSA", "1.2.840.113549.1.1.13", () -> Signature.getInstance("SHA512withRSA")),
20+
ES256K("SHA256withECDSA", null, () -> Signature.getInstance("SHA256withECDSA")),
21+
ES256("SHA256withECDSA", "1.2.840.10045.4.3.2", () -> Signature.getInstance("SHA256withECDSA")),
22+
ES384("SHA384withECDSA", "1.2.840.10045.4.3.3", () -> Signature.getInstance("SHA384withECDSA")),
23+
ES512("SHA512withECDSA", "1.2.840.10045.4.3.4", () -> Signature.getInstance("SHA512withECDSA")),
24+
25+
PS256("SHA256withRSAandMGF1", "1.2.840.113549.1.1.10", () -> {
26+
Signature sig = Signature.getInstance("RSASSA-PSS");
27+
sig.setParameter(new PSSParameterSpec("SHA-256", "MGF1", MGF1ParameterSpec.SHA256, 256 / 8, 1));
28+
return sig;
29+
}),
30+
PS384("SHA384withRSAandMGF1", "1.2.840.113549.1.1.10", () -> {
31+
Signature sig = Signature.getInstance("RSASSA-PSS");
32+
sig.setParameter(new PSSParameterSpec("SHA-384", "MGF1", MGF1ParameterSpec.SHA384, 384 / 8, 1));
33+
return sig;
34+
}),
35+
PS512("SHA512withRSAandMGF1", "1.2.840.113549.1.1.10 ", () -> {
36+
Signature sig = Signature.getInstance("RSASSA-PSS");
37+
sig.setParameter(new PSSParameterSpec("SHA-512", "MGF1", MGF1ParameterSpec.SHA512, 512 / 8, 1));
38+
return sig;
39+
}),
40+
EdDSA(null, null, () -> Signature.getInstance("EdDSA")),
41+
42+
;
43+
44+
public final String jce;
45+
public final String oid;
46+
public final Callable<Signature> signatureProvider;
47+
48+
Alg(String jce, String oid, Callable<Signature> signatureProvider) {
49+
this.jce = jce;
50+
this.oid = oid;
51+
this.signatureProvider = signatureProvider;
52+
}
53+
}

0 commit comments

Comments
 (0)