Skip to content

Commit 9b2234e

Browse files
author
Shangamesh T
committed
Amazon Pay Java SDK 3.7.0
1 parent f5f1838 commit 9b2234e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+115
-64
lines changed

CHANGES.txt

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,9 @@
1+
Version 3.7.0 - March 2021
2+
- Fixed following two security risks :
3+
1. Deprecated setSecretKey(String) method & enabled setSecretKey(char[]) in Config & PayConfig
4+
2. Buyer Access token is passed as HTTP header instead of query parameter in URL for GetUserInfo API
5+
- Note: Consumers of previous SDK versions strongly recommended to update data type of secret key from string to char[] as of this SDK Version 3.7.0. Please check the link : https://www.techiedelight.com/why-character-array-preferred-over-string-storing-passwords/ to know why char array is preferred over string for string.
6+
17
Version 3.6.5 - January 2021
28
- Added additional attribute (expectImmediateAuthorization) to ConfirmOrderReference. This value can be set to true or false (Boolean). See Amazon Pay Strong Customer Authentication (SCA) Upgrade Integration Guide for more information.
39

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import com.amazon.pay.impl.PayConfig;
2525
```java
2626
String merchantId = "YOUR_MERCHANT_ID";
2727
String accessKey = "YOUR_ACCESS_KEY";
28-
String secretKey = "YOUR_SECRET_Key";
28+
char[] secretKey = getSecretKey() // Replace with your implementation
2929

3030
Config config = new PayConfig()
3131
.withSellerId(merchantId)
Binary file not shown.

pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<groupId>com.amazon.pay</groupId>
55
<artifactId>amazon-pay-java-sdk</artifactId>
66
<packaging>jar</packaging>
7-
<version>3.6.5</version>
7+
<version>3.7.0</version>
88
<dependencies>
99
<dependency>
1010
<groupId>commons-codec</groupId>

src/com/amazon/pay/Config.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public interface Config {
7474
/**
7575
* @return Returns SecretKey from PayConfig
7676
*/
77-
String getSecretKey();
77+
char[] getSecretKey();
7878

7979
/**
8080
* @return Returns the MerchantId/SellerId from PayConfig
@@ -138,9 +138,16 @@ public interface Config {
138138
void setRegion(Region region);
139139

140140
/**
141+
* @deprecated(since = "3.7.0") This method is deprecated, instead use setSecretKey(char[] secretAccessKey)
141142
* @param secretAccessKey Sets SecretKey in PayConfig
142143
*/
144+
@Deprecated
143145
void setSecretKey(String secretAccessKey);
146+
147+
/**
148+
* @param secretAccessKey Sets SecretKey in PayConfig
149+
*/
150+
void setSecretKey(char[] secretAccessKey);
144151

145152
/**
146153
* @param sellerId Sets MerchantId/SellerId in PayConfig

src/com/amazon/pay/exceptions/AmazonClientException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/exceptions/AmazonServiceException.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/impl/PayClient.java

+8-8
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ public ReverseProviderCreditResponseData reverseProviderCredit(ReverseProviderC
916916
@Override
917917
public User getUserInfo(String accessToken , String clientId) throws AmazonServiceException, IOException {
918918

919-
final String decodedAccessToken = URLDecoder.decode(accessToken, "UTF-8");
919+
final String decodedAccessToken = URLDecoder.decode(accessToken, ServiceConstants.UTF_8);
920920
String profileEndpoint;
921921

922922
if (payConfig.getOverrideProfileURL() != null) {
@@ -930,23 +930,23 @@ public User getUserInfo(String accessToken , String clientId) throws AmazonServi
930930
}
931931

932932
Map<String,String> headerValues = new HashMap<String, String>();
933-
ResponseData response = Util.httpSendRequest("GET" , profileEndpoint + "/auth/o2/tokeninfo?access_token=" + decodedAccessToken, null, headerValues, null);
933+
headerValues.put(ServiceConstants.X_AMZ_ACCESS_TOKEN, decodedAccessToken);
934+
ResponseData response = Util.httpSendRequest(ServiceConstants.GET, profileEndpoint + ServiceConstants.AUTH_O2_TOKENINFO_URI, null, headerValues, null);
934935

935936
Map m = Util.convertJsonToObject(response.toXML(), Map.class);
936-
if (m.containsKey("error")) {
937-
throw new AmazonServiceException("Retrieving User Info Failed. "+(String)m.get("error_description"));
937+
if (m.containsKey(ServiceConstants.ERROR)) {
938+
throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get(ServiceConstants.ERROR_DESCRIPTION));
938939
}
939940

940941
if (clientId == null || !clientId.equals(m.get("aud"))) {
941942
//the access token does not belong to us
942943
throw new AmazonClientException("Access token does not belong to clientId: " + clientId);
943944
}
944945

945-
headerValues.put("Authorization", "bearer " + decodedAccessToken);
946-
response = Util.httpSendRequest("GET" , profileEndpoint + "/user/profile", null, headerValues);
946+
response = Util.httpSendRequest(ServiceConstants.GET , profileEndpoint + ServiceConstants.USER_PROFILE_URI, null, headerValues);
947947
m = Util.convertJsonToObject(response.toXML() , Map.class);
948-
if (m.containsKey("error")) {
949-
throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get("error_description"));
948+
if (m.containsKey(ServiceConstants.ERROR)) {
949+
throw new AmazonServiceException("Retrieving User Info Failed. " + (String)m.get(ServiceConstants.ERROR_DESCRIPTION));
950950
}
951951

952952
final User user = Util.convertJsonToObject(response.toXML() , User.class);

src/com/amazon/pay/impl/PayConfig.java

+26-8
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class PayConfig implements Config {
2727

2828
private String accessKey;
29-
private String secretKey;
29+
private char[] secretKey;
3030
private String merchantId;
3131
private Region region;
3232
private Environment environment;
@@ -143,27 +143,46 @@ public PayConfig withAccessKey(String accessKey) {
143143
*
144144
*/
145145
@Override
146-
public String getSecretKey() {
146+
public char[] getSecretKey() {
147147
return secretKey;
148148
}
149149

150150

151151
/**
152-
*
152+
* @deprecated(since = "3.7.0") This method is deprecated, instead use setSecretKey(char[] secretKey)
153153
* @param secretKey - Sets SecretKey in PayConfig
154154
*/
155155
@Override
156+
@Deprecated
156157
public void setSecretKey(String secretKey) {
157-
this.secretKey = secretKey;
158+
this.secretKey = secretKey.toCharArray();
158159
}
160+
161+
/**
162+
* @param secretKey - Sets SecretKey in PayConfig
163+
*/
164+
@Override
165+
public void setSecretKey(char[] secretKey) {
166+
this.secretKey = secretKey;
167+
}
159168

160169

161170
/**
162-
*
171+
* @deprecated(since = "3.7.0") This method is deprecated, instead use withSecretKey(char[] privateKey)
163172
* @param secretKey - Sets SecretKey in PayConfig
164173
* @return Returns updated PayConfig object
165174
*/
175+
@Deprecated
166176
public PayConfig withSecretKey(String secretKey) {
177+
this.secretKey = secretKey.toCharArray();
178+
return this;
179+
}
180+
181+
/**
182+
* @param secretKey - Sets SecretKey in PayConfig
183+
* @return Returns updated PayConfig object
184+
*/
185+
public PayConfig withSecretKey(char[] secretKey) {
167186
this.secretKey = secretKey;
168187
return this;
169188
}
@@ -605,7 +624,7 @@ private PayConfig loadConfigurationFromProperties(Properties prop) {
605624
this.setAccessKey(prop.getProperty(property));
606625
break;
607626
case SECRET_KEY:
608-
this.setSecretKey(prop.getProperty(property));
627+
this.setSecretKey(prop.getProperty(property).toCharArray());
609628
break;
610629
case MERCHANT_ID:
611630
this.setSellerId(prop.getProperty(property));
@@ -681,7 +700,7 @@ private PayConfig loadConfigurationFromProperties(Properties prop) {
681700
private boolean checkIfRequriedPropertiesExist() {
682701
if (this.accessKey == null)
683702
generateException(Key.ACCESS_KEY);
684-
else if (this.secretKey == null)
703+
else if (this.secretKey == null || this.secretKey.length == 0)
685704
generateException(Key.SECRET_KEY);
686705
else if (this.merchantId == null)
687706
generateException(Key.MERCHANT_ID);
@@ -711,7 +730,6 @@ private void generateException(Key propertyKey) {
711730
public String toString() {
712731
return "PayConfig{" +
713732
"accessKeyId=" + accessKey +
714-
", secretAccessKey=" + secretKey +
715733
", sellerId=" + merchantId +
716734
", region=" + region +
717735
", environment=" + environment +

src/com/amazon/pay/impl/Util.java

+13-5
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@
3030
import java.net.HttpURLConnection;
3131
import java.net.URL;
3232
import java.net.URLEncoder;
33+
import java.nio.ByteBuffer;
34+
import java.nio.CharBuffer;
35+
import java.nio.charset.Charset;
3336
import java.security.InvalidKeyException;
3437
import java.security.NoSuchAlgorithmException;
3538
import java.text.SimpleDateFormat;
39+
import java.util.Arrays;
3640
import java.util.Date;
3741
import java.util.HashMap;
3842
import java.util.Iterator;
@@ -70,11 +74,12 @@ public class Util {
7074
*
7175
* @return signatureBase64 base64 encoded signature using specified secret key
7276
*/
73-
public static String getSignature(String stringToSign, String secretKey) throws IllegalStateException, InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
74-
Mac mac = Mac.getInstance("HmacSHA256");
75-
mac.init(new SecretKeySpec(secretKey.getBytes("UTF-8"), "HmacSHA256"));
76-
byte[] signature = mac.doFinal(stringToSign.getBytes("UTF-8"));
77-
String signatureBase64 = new String(Base64.encodeBase64(signature), "UTF-8");
77+
public static String getSignature(String stringToSign, char[] secretKey) throws IllegalStateException, InvalidKeyException, NoSuchAlgorithmException, UnsupportedEncodingException {
78+
final ByteBuffer byteBuffer = Charset.forName(ServiceConstants.UTF_8).encode(CharBuffer.wrap(secretKey));
79+
final Mac mac = Mac.getInstance(ServiceConstants.HMAC_SHA256);
80+
mac.init(new SecretKeySpec(Arrays.copyOf(byteBuffer.array(), byteBuffer.limit()), ServiceConstants.HMAC_SHA256));
81+
final byte[] signature = mac.doFinal(stringToSign.getBytes(ServiceConstants.UTF_8));
82+
final String signatureBase64 = new String(Base64.encodeBase64(signature), ServiceConstants.UTF_8);
7883
return signatureBase64;
7984
}
8085

@@ -159,6 +164,9 @@ public static ResponseData httpSendRequest(String method, String url, String url
159164
public static ResponseData httpSendRequest(String method, String url, String urlParameters, Map<String,String> headers, PayConfig config) throws IOException {
160165

161166
Map<String,String> headerMap = new HashMap<String,String>();
167+
if (headers != null) {
168+
headerMap.putAll(headers);
169+
}
162170

163171
if (config != null) {
164172

src/com/amazon/pay/impl/ipn/NotificationFactory.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/impl/ipn/NotificationVerification.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2017 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/AuthorizeRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CancelOrderReferenceRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CaptureRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/ChargeRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CloseAuthorizationRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CloseBillingAgreementRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CloseOrderReferenceRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/CreateOrderReferenceForIdRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetAuthorizationDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetBillingAgreementDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetCaptureDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetOrderReferenceDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetProviderCreditDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetProviderCreditReversalDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/GetRefundDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/ListOrderReferenceRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/RefundRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/ReverseProviderCreditRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/SetOrderReferenceDetailsRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/request/ValidateBillingAgreementRequest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

src/com/amazon/pay/response/model/AccountStatus.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2016-2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License").
55
* You may not use this file except in compliance with the License.

0 commit comments

Comments
 (0)