6161import java .util .Objects ;
6262import java .util .regex .Pattern ;
6363
64- import com .fasterxml .jackson .core .JsonProcessingException ;
6564import com .google .auto .service .AutoService ;
6665import com .nimbusds .jose .JOSEException ;
6766import com .nimbusds .jose .JWEObjectJSON ;
@@ -134,24 +133,6 @@ public AbstractVault create(final Session<?> session, final String region, final
134133 return this ;
135134 }
136135
137- public static String decryptWithJWK (final String jwe , final JWK jwk ) throws ParseException , JOSEException , JsonProcessingException , VaultException {
138- final JWEObjectJSON jweObject = JWEObjectJSON .parse (jwe );
139- jweObject .decrypt (new MultiDecrypter (jwk , Collections .singleton (UVF_SPEC_VERSION_KEY_PARAM )));
140-
141- // https://datatracker.ietf.org/doc/html/rfc7515#section-4.1.11
142- // Recipients MAY consider the JWS to be invalid if the critical
143- // list contains any Header Parameter names defined by this
144- // specification or [JWA] for use with JWS or if any other constraints on its use are violated.
145- final Object uvfSpecVersion = jweObject .getHeader ().getCustomParams ().get (UVF_SPEC_VERSION_KEY_PARAM );
146- if (uvfSpecVersion .equals (1 )) {
147- throw new VaultException (String .format ("Unexpected value for critical header %s: found %s, expected \" 1\" " , UVF_SPEC_VERSION_KEY_PARAM , uvfSpecVersion ));
148- }
149-
150- final Payload payload = jweObject .getPayload ();
151- return payload .toString ();
152- }
153-
154-
155136 // load -> unlock -> open
156137 @ Override
157138 public CryptoVault load (final Session <?> session , final PasswordCallback callback , final VaultMetadataProvider metadata ) throws BackgroundException {
@@ -161,9 +142,12 @@ public CryptoVault load(final Session<?> session, final PasswordCallback callbac
161142 try {
162143 final String jwe = new String (metadataProvider .getMetadata (), StandardCharsets .US_ASCII );
163144 final JWK jwk = jwkCallback .prompt (session .getHost (), StringUtils .EMPTY , StringUtils .EMPTY , new LoginOptions ()).getKey ();
164- uvfMetadata = decryptWithJWK (jwe , jwk );
145+ final JWEObjectJSON jweObject = JWEObjectJSON .parse (jwe );
146+ jweObject .decrypt (new MultiDecrypter (jwk , Collections .singleton (UVF_SPEC_VERSION_KEY_PARAM )));
147+ final Payload payload = jweObject .getPayload ();
148+ uvfMetadata = payload .toString ();
165149 }
166- catch (ParseException | JOSEException | JsonProcessingException e ) {
150+ catch (ParseException | JOSEException e ) {
167151 throw new VaultException ("Failure retrieving key material" , e );
168152 }
169153
0 commit comments