Skip to content

Commit 0f91a40

Browse files
authored
Merge pull request #134 from CyberSource/future
6.2.8 release changes
2 parents f5e49e3 + 04b3a5b commit 0f91a40

21 files changed

+154
-125
lines changed

README.md

+10-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ To install the `cybersource-sdk-java` from central repository, add dependency to
1010
<dependency>
1111
<groupId>com.cybersource</groupId>
1212
<artifactId>cybersource-sdk-java</artifactId>
13-
<version>6.2.7</version>
13+
<version>6.2.8</version>
1414
</dependency>
1515
```
1616
Run `mvn install` to install dependency
@@ -19,7 +19,7 @@ Run `mvn install` to install dependency
1919
Add the dependency to your build.gradle
2020
```java
2121
dependencies {
22-
compile 'com.cybersource:cybersource-sdk-java:6.2.6'
22+
compile 'com.cybersource:cybersource-sdk-java:6.2.8'
2323
}
2424
```
2525
## Requirements
@@ -124,7 +124,7 @@ openssl pkcs12 -export -certfile CyberSourceCertAuth.crt -in <Merchant_ID>.crt -
124124

125125
- Create JKS from p12 using keytool
126126
```
127-
keytool -importkeystore -destkeystore <Your_keystore_name> -deststorepass <your_password> -srckeystore identity.p12 -srcstoretype PKCS12 -srcstorepass <Merchant_ID>
127+
keytool -importkeystore -destkeystore <Your_keystore_name>.jks -deststorepass <your_password> -srckeystore identity.p12 -srcstoretype PKCS12 -srcstorepass <Merchant_ID>
128128
```
129129
- Now import the CyberSource_SJC_US.crt to your keystore
130130
```
@@ -183,6 +183,13 @@ Retry Pattern allows to retry sending a failed request and it will only work wit
183183

184184
## Changes
185185

186+
Version Cybersource-sdk-java 6.2.8 (OCT,2019)
187+
_______________________________
188+
189+
1)Added request header and logged request and response headers
190+
191+
2)Caching of certificate is done using keyAlias earlier it was done using merchant_id
192+
186193
Version Cybersource-sdk-java 6.2.7 (MAR,2019)
187194
_______________________________
188195
1) Fixed security vulnerabilities found in the jar dependencies.

java/src/main/java/com/cybersource/ws/client/Client.java

+4-17
Original file line numberDiff line numberDiff line change
@@ -19,28 +19,19 @@
1919
package com.cybersource.ws.client;
2020

2121

22-
import org.apache.ws.security.util.XMLUtils;
2322
import org.w3c.dom.Document;
2423
import org.w3c.dom.Node;
2524
import org.w3c.dom.Text;
2625
import org.xml.sax.InputSource;
2726
import org.xml.sax.SAXException;
2827

29-
import javax.security.cert.X509Certificate;
3028
import javax.xml.parsers.DocumentBuilder;
3129
import javax.xml.parsers.ParserConfigurationException;
32-
33-
import java.io.File;
34-
import java.io.FileInputStream;
3530
import java.io.IOException;
3631
import java.io.StringReader;
3732
import java.lang.reflect.InvocationTargetException;
38-
import java.security.KeyStore;
39-
import java.security.cert.PKIXParameters;
40-
import java.security.cert.TrustAnchor;
4133
import java.text.MessageFormat;
4234
import java.util.HashMap;
43-
import java.util.Iterator;
4435
import java.util.Map;
4536
import java.util.Properties;
4637

@@ -49,8 +40,6 @@
4940
* form of a Map object.
5041
*/
5142
public class Client {
52-
private static final String HEADER_FORMAT = "{0}={1}";
53-
5443
private static final String SOAP_ENVELOPE1 = "<soap:Envelope xmlns:soap=\"" +
5544
"http://schemas.xmlsoap.org/soap/envelope/\">\n<soap:Body id=\"body1\">\n" +
5645
"<nvpRequest xmlns=\"{0}\">\n{1}</nvpRequest>" +
@@ -99,8 +88,6 @@ public static Map runTransaction(
9988
MerchantConfig mc;
10089
LoggerWrapper logger = null;
10190
Connection con = null;
102-
103-
10491
try {
10592
setVersionInformation(request);
10693

@@ -229,16 +216,16 @@ private static Document soapWrapAndSign(
229216
+ mapToString(request, true, PCI.REQUEST));
230217
}
231218

232-
Document wrappedDoc = soapWrap(request, mc, builder,logger);
219+
Document wrappedDoc = soapWrap(request, mc, builder);
233220
logger.log(Logger.LT_INFO, "Client, End of soapWrap ",true);
234221

235-
Document resultDocument = null;
222+
Document resultDocument;
236223

237224
SecurityUtil.loadMerchantP12File(mc,logger);
238225
logger.log(Logger.LT_INFO, "Client, End of loading Merchant Certificates ", true);
239226

240227
// sign Document object
241-
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getMerchantID(), mc.getKeyPassword(), logger);
228+
resultDocument = SecurityUtil.createSignedDoc(wrappedDoc, mc.getKeyAlias(), mc.getKeyPassword(), logger);
242229
logger.log(Logger.LT_INFO, "Client, End of createSignedDoc ", true);
243230

244231
if ( mc.getUseSignAndEncrypted() ) {
@@ -254,7 +241,7 @@ private static Document soapWrapAndSign(
254241
return resultDocument ;
255242
}
256243

257-
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder, LoggerWrapper logger) throws SAXException, IOException{
244+
private static Document soapWrap(Map request, MerchantConfig mc, DocumentBuilder builder) throws SAXException, IOException{
258245
// wrap in SOAP envelope
259246
Object[] arguments
260247
= {mc.getEffectiveNamespaceURI(),

java/src/main/java/com/cybersource/ws/client/Connection.java

+15-4
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.net.HttpURLConnection;
3636
import java.net.MalformedURLException;
3737
import java.net.ProtocolException;
38+
import java.util.concurrent.TimeUnit;
3839

3940

4041
/**
@@ -123,10 +124,9 @@ public Document post(Document request)
123124
private void checkForFault()
124125
throws FaultException, ClientException {
125126
try {
126-
logger.log(Logger.LT_INFO, "Reading response...");
127-
127+
logger.log(Logger.LT_INFO, "waiting for response...");
128128
int responseCode = getHttpResponseCode();
129-
129+
logResponseHeaders();
130130
// if successful, there's nothing left to do here.
131131
// we'll process the response in a later method.
132132
if (responseCode == HttpURLConnection.HTTP_OK) return;
@@ -193,7 +193,10 @@ private void checkForFault()
193193
private Document parseReceivedDocument()
194194
throws IOException, SAXException {
195195
logger.log(Logger.LT_INFO, "Parsing response...");
196-
return builder.parse(getResponseStream());
196+
//long startTime = System.nanoTime();
197+
Document document = builder.parse(getResponseStream());
198+
//System.out.println("Connection.parseReceivedDocument time taken to parse the response is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
199+
return document;
197200
}
198201

199202
/**
@@ -214,7 +217,15 @@ static ByteArrayOutputStream makeStream(Document doc)
214217

215218
return baos;
216219
}
220+
/*
221+
* Log Request and Response Headers
222+
*
223+
*/
224+
225+
abstract public void logRequestHeaders();
226+
abstract public void logResponseHeaders();
217227
}
218228

229+
219230
/* Copyright 2006 CyberSource Corporation */
220231

java/src/main/java/com/cybersource/ws/client/HttpClientConnection.java

+18-10
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,9 @@
3333
import java.io.ByteArrayOutputStream;
3434
import java.io.IOException;
3535
import java.io.InputStream;
36-
import java.net.MalformedURLException;
37-
import java.net.ProtocolException;
3836
import java.util.ArrayList;
37+
import java.util.Arrays;
3938
import java.util.List;
40-
4139
/**
4240
* Class helps in posting the Request document for the Transaction using HttpClient.
4341
* Converts the document to String format and also helps in setting up the Proxy connections.
@@ -57,9 +55,7 @@ class HttpClientConnection extends Connection {
5755
* @see com.cybersource.ws.client.Connection#postDocument(org.w3c.dom.Document)
5856
*/
5957
void postDocument(Document request)
60-
throws IOException, TransformerConfigurationException,
61-
TransformerException, MalformedURLException,
62-
ProtocolException {
58+
throws IOException, TransformerException {
6359

6460
/*
6561
* SimpleHttpConnectionManager(boolean alwaysClose) :
@@ -81,7 +77,8 @@ void postDocument(Document request)
8177

8278
postMethod.setRequestEntity(
8379
new StringRequestEntity(requestString, null, "UTF-8"));
84-
80+
postMethod.setRequestHeader(Utility.ORIGIN_TIMESTAMP, String.valueOf(System.currentTimeMillis()));
81+
logRequestHeaders();
8582
httpClient.executeMethod(postMethod);
8683
}
8784

@@ -105,8 +102,7 @@ public void release() {
105102
/* (non-Javadoc)
106103
* @see com.cybersource.ws.client.Connection#getHttpResponseCode()
107104
*/
108-
int getHttpResponseCode()
109-
throws IOException {
105+
int getHttpResponseCode(){
110106
return postMethod != null ? postMethod.getStatusCode() : -1;
111107
}
112108

@@ -222,7 +218,6 @@ public boolean retryMethod(
222218
Thread.sleep(retryWaitInterval);
223219
logger.log( Logger.LT_INFO+" Retrying Request -- ",mc.getUniqueKey().toString()+ " Retry Count -- "+executionCount);
224220
} catch (InterruptedException e) {
225-
// TODO Auto-generated catch block
226221
e.printStackTrace();
227222
}
228223
return true;
@@ -231,6 +226,19 @@ public boolean retryMethod(
231226
return false;
232227
}
233228
}
229+
230+
@Override
231+
public void logRequestHeaders() {
232+
List<Header> reqheaders=Arrays.asList(postMethod.getRequestHeaders());
233+
logger.log(Logger.LT_INFO, "Request Headers: " +reqheaders);
234+
}
235+
236+
@Override
237+
public void logResponseHeaders() {
238+
List<Header> respheaders=Arrays.asList(postMethod.getResponseHeaders());
239+
logger.log(Logger.LT_INFO, "Response Headers"+ respheaders);
240+
}
241+
234242
}
235243

236244
/* Copyright 2006 CyberSource Corporation */

java/src/main/java/com/cybersource/ws/client/Identity.java

+6-16
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,6 @@ public class Identity {
4343

4444
private char[] pswd;
4545

46-
private Logger logger = null;
47-
4846
/**
4947
* Creates an Identity instance.this type of the instance can
5048
* only be used to store server certificate identity.
@@ -56,18 +54,15 @@ public class Identity {
5654
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate,Logger logger) throws SignException {
5755
this.merchantConfig = merchantConfig;
5856
this.x509Cert=x509Certificate;
59-
if(this.logger == null){
60-
this.logger=logger;
61-
}
6257
if(merchantConfig.isJdkCertEnabled() || merchantConfig.isCacertEnabled()){
6358
setupJdkServerCerts();
6459
}
6560
else{
6661
setUpServer();
6762
}
6863
}
64+
6965
private void setupJdkServerCerts() throws SignException {
70-
7166
if (x509Cert != null) {
7267
String subjectDN = x509Cert.getSubjectDN().getName();
7368
if (subjectDN != null) {
@@ -82,7 +77,6 @@ else if (subjectDNrray.length == 2 && subjectDNrray[1].contains(SERVER_ALIAS)) {
8277
}else{
8378
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
8479
}
85-
8680
} else {
8781
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
8882
}
@@ -99,17 +93,13 @@ else if (subjectDNrray.length == 2 && subjectDNrray[1].contains(SERVER_ALIAS)) {
9993
* @param privateKey
10094
* @throws SignException
10195
*/
102-
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey,Logger logger) throws SignException {
96+
public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, PrivateKey privateKey, Logger logger) throws SignException {
10397
this.merchantConfig = merchantConfig;
10498
this.x509Cert = x509Certificate;
10599
this.privateKey = privateKey;
106-
if(this.logger == null){
107-
this.logger=logger;
108-
}
109100
try {
110101
this.lastModifiedDate=merchantConfig.getKeyFile().lastModified();
111102
} catch (ConfigException e) {
112-
113103
logger.log(Logger.LT_EXCEPTION,
114104
"Identity object ,cannot instantiate with key file lastModifiedDate. "
115105
+ e.getMessage());
@@ -123,7 +113,7 @@ public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, P
123113
* else isValid method will return true and certificate reload will not occur.
124114
*/
125115

126-
public boolean isValid(File keyFile) {
116+
public boolean isValid(File keyFile, Logger logger) {
127117
boolean changeKeyFileStatus=(this.lastModifiedDate == keyFile.lastModified());
128118
if (!changeKeyFileStatus) {
129119
logger.log(Logger.LT_INFO, "Key file changed");
@@ -136,14 +126,14 @@ private void setUpMerchant() throws SignException {
136126
if (serialNumber == null && x509Cert != null) {
137127
String subjectDN = x509Cert.getSubjectDN().getName();
138128
if (subjectDN != null) {
139-
String subjectDNrray[] = subjectDN.split("SERIALNUMBER=");
129+
String[] subjectDNrray = subjectDN.split("SERIALNUMBER=");
140130
if (subjectDNrray.length != 2) {
141131
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
142132
}
143133
name = merchantConfig.getMerchantID();
144134
pswd = merchantConfig.getKeyPassword().toCharArray();
145135
serialNumber = subjectDNrray[1];
146-
keyAlias = "serialNumber=" + serialNumber + ",CN=" + name;
136+
keyAlias = merchantConfig.getKeyAlias();
147137
} else {
148138
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
149139
}
@@ -155,7 +145,7 @@ private void setUpServer() throws SignException {
155145
if (serialNumber == null && x509Cert != null) {
156146
String subjectDN = x509Cert.getSubjectDN().getName();
157147
if (subjectDN != null) {
158-
String subjectDNrray[] = subjectDN.split("SERIALNUMBER=");
148+
String[] subjectDNrray = subjectDN.split("SERIALNUMBER=");
159149
if (subjectDNrray.length == 1 && subjectDNrray[0].contains("CyberSourceCertAuth")){
160150
name = keyAlias = "CyberSourceCertAuth";
161151
}

0 commit comments

Comments
 (0)