1515
1616package software .amazon .awssdk .services .signin .internal ;
1717
18- import java .io .IOException ;
1918import java .nio .charset .StandardCharsets ;
2019import java .security .InvalidKeyException ;
2120import java .security .NoSuchAlgorithmException ;
@@ -61,14 +60,17 @@ private DpopHeaderGenerator() {
6160 * @param pemContent - EC1 / RFC 5915 ASN.1 formated PEM contents
6261 * @param endpoint - The HTTP target URI (Section 7.1 of [RFC9110]) of the request to which the JWT is attached,
6362 * without query and fragment parts
63+ * @param httpMethod - the HTTP method of the request (eg: POST).
6464 * @param epochSeconds - creation time of the JWT in epoch seconds.
6565 * @param uuid - Unique identifier for the DPoP proof JWT - should be a UUID4 string.
6666 * @return DPoP header value
6767 */
68- public static String generateDPoPProofHeader (String pemContent , String endpoint , long epochSeconds , String uuid ) {
69- Validate .notBlank (pemContent , "pemContent must be set." );
70- Validate .notBlank (endpoint , "endpoint must be set." );
71- Validate .notBlank (uuid , "uuid must be set." );
68+ public static String generateDPoPProofHeader (String pemContent , String endpoint , String httpMethod ,
69+ long epochSeconds , String uuid ) {
70+ Validate .paramNotBlank (pemContent , "pemContent" );
71+ Validate .paramNotBlank (endpoint , "endpoint" );
72+ Validate .paramNotBlank (httpMethod , "httpMethod" );
73+ Validate .paramNotBlank (uuid , "uuid" );
7274
7375 try {
7476 // Load EC public and private key from PEM
@@ -78,7 +80,7 @@ public static String generateDPoPProofHeader(String pemContent, String endpoint,
7880
7981 // Build JSON strings (header, payload) with JsonGenerator
8082 byte [] headerJson = buildHeaderJson (publicKey );
81- byte [] payloadJson = buildPayloadJson (uuid , endpoint , epochSeconds );
83+ byte [] payloadJson = buildPayloadJson (uuid , endpoint , httpMethod , epochSeconds );
8284
8385 // Base64URL encode header + payload
8486 String encodedHeader = base64UrlEncode (headerJson );
@@ -94,14 +96,14 @@ public static String generateDPoPProofHeader(String pemContent, String endpoint,
9496 // Combine into JWT
9597 String encodedSignature = base64UrlEncode (signatureBytes );
9698 return message + "." + encodedSignature ;
97- } catch (IOException | NoSuchAlgorithmException | InvalidKeyException | SignatureException e ) {
99+ } catch (NoSuchAlgorithmException | InvalidKeyException | SignatureException e ) {
98100 throw new RuntimeException (e );
99101 }
100102 }
101103
102104 // build the JWT header which includes the public key
103105 // see: https://datatracker.ietf.org/doc/html/rfc9449#name-dpop-proof-jwt-syntax
104- private static byte [] buildHeaderJson (ECPublicKey publicKey ) throws IOException {
106+ private static byte [] buildHeaderJson (ECPublicKey publicKey ) {
105107 ECPoint pubPoint = publicKey .getW ();
106108 String x = base64UrlEncode (stripLeadingZero (pubPoint .getAffineX ().toByteArray ()));
107109 String y = base64UrlEncode (stripLeadingZero (pubPoint .getAffineY ().toByteArray ()));
@@ -142,7 +144,7 @@ private static byte[] buildHeaderJson(ECPublicKey publicKey) throws IOException
142144
143145 // build claims payload
144146 // see: https://datatracker.ietf.org/doc/html/rfc9449#name-dpop-proof-jwt-syntax
145- private static byte [] buildPayloadJson (String uuid , String endpoint , long epochSeconds ) throws IOException {
147+ private static byte [] buildPayloadJson (String uuid , String endpoint , String httpMethod , long epochSeconds ) {
146148 JsonWriter jsonWriter = null ;
147149 try {
148150 jsonWriter = JsonWriter .create ();
@@ -152,7 +154,7 @@ private static byte[] buildPayloadJson(String uuid, String endpoint, long epochS
152154 jsonWriter .writeValue (uuid );
153155
154156 jsonWriter .writeFieldName ("htm" );
155- jsonWriter .writeValue ("POST" );
157+ jsonWriter .writeValue (httpMethod );
156158
157159 jsonWriter .writeFieldName ("htu" );
158160 jsonWriter .writeValue (endpoint );
0 commit comments