77import com .fasterxml .jackson .core .JsonProcessingException ;
88import com .fasterxml .jackson .core .type .TypeReference ;
99import com .fasterxml .jackson .databind .ObjectMapper ;
10- import com .nimbusds .jose .JOSEException ;
1110import com .nimbusds .jose .JOSEObjectType ;
1211import com .nimbusds .jose .JWSAlgorithm ;
1312import com .nimbusds .jose .JWSHeader ;
1413import com .nimbusds .jose .JWSSigner ;
1514import com .nimbusds .jose .crypto .ECDSASigner ;
1615import com .nimbusds .jose .jwk .ECKey ;
16+ import com .nimbusds .jose .util .Base64 ;
1717import com .nimbusds .jwt .JWTClaimsSet ;
1818import com .nimbusds .jwt .SignedJWT ;
19+ import java .security .cert .CertificateEncodingException ;
20+ import java .security .cert .X509Certificate ;
1921import java .security .interfaces .ECPrivateKey ;
2022import java .time .Duration ;
2123import java .time .Instant ;
@@ -33,8 +35,7 @@ public class WalletUnitAttestationService {
3335 private final ObjectMapper objectMapper ;
3436
3537 public WalletUnitAttestationService (
36- WuaKeystoreProperties keystoreProperties ,
37- ObjectMapper objectMapper ) {
38+ WuaKeystoreProperties keystoreProperties , ObjectMapper objectMapper ) {
3839 this .keystoreProperties = keystoreProperties ;
3940 this .objectMapper = objectMapper ;
4041 }
@@ -48,30 +49,12 @@ public SignedJWT createWalletUnitAttestation(String walletPublicKeyJwk) throws E
4849 claims .put ("status" , getStatus ());
4950 claims .put ("attested_keys" , attestedKeys );
5051
51- return createSignedJwt (
52- keystoreProperties .getSigningKey (),
53- keystoreProperties .alias (),
54- keystoreProperties .issuer (),
55- Duration .ofHours (keystoreProperties .validityHours ()),
56- claims );
57- }
58-
59- private Map <String , Object > getStatus () throws JsonProcessingException {
60- return objectMapper .readValue (keystoreProperties .status (), new TypeReference <>() {});
61- }
62-
63- private Map <String , Object > getEudiWalletInfo () throws JsonProcessingException {
64- return objectMapper .readValue (
65- keystoreProperties .eudiWalletInfo (), new TypeReference <>() {});
66- }
52+ ECPrivateKey signingKey = keystoreProperties .getSigningKey ();
53+ String keyId = keystoreProperties .alias ();
54+ List <X509Certificate > certificateChain = keystoreProperties .getCertificateChain ();
55+ String issuer = keystoreProperties .issuer ();
56+ Duration validity = Duration .ofHours (keystoreProperties .validityHours ());
6757
68- private SignedJWT createSignedJwt (
69- ECPrivateKey signingKey ,
70- String keyId ,
71- String issuer ,
72- Duration validity ,
73- Map <String , Object > claims )
74- throws JOSEException {
7558 Instant now = Instant .now ();
7659
7760 JWTClaimsSet .Builder claimsBuilder =
@@ -86,10 +69,23 @@ private SignedJWT createSignedJwt(
8669
8770 JWTClaimsSet claimsSet = claimsBuilder .build ();
8871
72+ List <Base64 > x5c =
73+ certificateChain .stream ()
74+ .map (
75+ c -> {
76+ try {
77+ return Base64 .encode (c .getEncoded ());
78+ } catch (CertificateEncodingException e ) {
79+ throw new RuntimeException (e );
80+ }
81+ })
82+ .toList ();
83+
8984 JWSHeader header =
9085 new JWSHeader .Builder (JWSAlgorithm .ES256 )
9186 .keyID (keyId )
9287 .type (new JOSEObjectType ("keyattestation+jwt" ))
88+ .x509CertChain (x5c )
9389 .build ();
9490
9591 SignedJWT signedJwt = new SignedJWT (header , claimsSet );
@@ -99,4 +95,12 @@ private SignedJWT createSignedJwt(
9995
10096 return signedJwt ;
10197 }
98+
99+ private Map <String , Object > getStatus () throws JsonProcessingException {
100+ return objectMapper .readValue (keystoreProperties .status (), new TypeReference <>() {});
101+ }
102+
103+ private Map <String , Object > getEudiWalletInfo () throws JsonProcessingException {
104+ return objectMapper .readValue (keystoreProperties .eudiWalletInfo (), new TypeReference <>() {});
105+ }
102106}
0 commit comments