Skip to content

Commit 6b3ec91

Browse files
committed
CYBS-737: Review comments fix
1 parent af8d08d commit 6b3ec91

3 files changed

Lines changed: 34 additions & 40 deletions

File tree

README.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -227,25 +227,27 @@ Retry Pattern allows to retry sending a failed request and it will only work wit
227227
- Config parameter for this property is 'retryInterval' in `cybs.property` file. The default value for 'retryInterval' parameter is 1000 which means a delay of 1000 milliSeconds.
228228

229229
## Third Party jars
230-
1. org.apache.ws.security.wss4j:1.6.19
231-
The Apache WSS4J project provides a Java implementation of the primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications from the OASIS Web Services Security TC.
232-
2. org.bouncycastle:bcprov-jdk15on:1.61
230+
1. org.apache.wss4j:wss4j-ws-security-common:2.4.1
231+
The Apache WSS4J project provides a Java implementation of the common primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications from the OASIS Web Services Security TC.
232+
2. org.apache.wss4j:wss4j-ws-security-dom:2.4.1
233+
WSS4J 2.0.0 introduces a streaming (StAX-based) WS-Security implementation to complement the existing DOM-based implementation. The DOM-based implementation is quite performant and flexible, but suffers from having to read the entire XML tree into memory. For large SOAP requests this can have a detrimental impact on performance. In addition, for web services stacks such as Apache CXF which are streaming-based, it carries an additional performance penalty of having to explicitly convert the request stream to a DOM Element.
234+
3. org.bouncycastle:bcprov-jdk15on:1.67
233235
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
234-
3. org.apache.santuario:xmlsec:1.5.6
236+
4. org.apache.santuario:xmlsec:2.3.0
235237
The XML Security project is aimed at providing implementation of security standards for XML,supports XML-Signature Syntax and Processing,XML Encryption Syntax and Processing, and supports XML Digital Signature APIs.
236-
4. org.apache.commons:commons-lang3:3.4
238+
5. org.apache.commons:commons-lang3:3.4
237239
Apache Commons Lang, a package of Java utility classes for the classes that are in java.lang's hierarchy, or are considered to be so standard as to justify existence in java.lang.
238-
5. commons-logging:commons-logging:jar:1.1.1
240+
6. commons-logging:commons-logging:jar:1.1.1
239241
This is getting downloaded as compile time dependency of wss4j:1.6.19.Apache Commons Logging is a thin adapter allowing configurable bridging to other, well known logging systems.
240-
6. org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21
242+
7. org.slf4j:slf4j-api:1.7.32, org.slf4j:slf4j-jcl:1.7.32, org.slf4j:slf4j-simple:1.7.32
241243
slf4j-api is getting used as a dependency for wss4j. Modified to latest version.
242-
7. junit:junit:4.13.1
244+
8. junit:junit:4.13.1
243245
JUnit is a unit testing framework for Java.
244-
8. org.mockito:mockito-all:1.10.19
246+
9. org.mockito:mockito-all:1.10.19
245247
Mock objects library for java
246-
9. org.apache.httpcomponents:httpclient:4.5.13
248+
10. org.apache.httpcomponents:httpclient:4.5.13
247249
Provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. It is used for poolinghttpclientconnectionmanager feature.
248-
10. org.apache.httpcomponents:httpcore:4.4.13
250+
11. org.apache.httpcomponents:httpcore:4.4.13
249251
Provides low level HTTP transport components that can be used to build custom client and server side HTTP services with a minimal footprint.
250252

251253
## Changes

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

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import org.apache.wss4j.common.WSEncryptionPart;
44
import org.apache.wss4j.common.ext.WSSecurityException;
5+
import org.apache.wss4j.common.util.KeyUtils;
56
import org.apache.wss4j.dom.WSConstants;
67
import org.apache.wss4j.dom.WSDocInfo;
78
import org.apache.wss4j.dom.message.WSSecEncrypt;
@@ -12,7 +13,6 @@
1213
import org.w3c.dom.Document;
1314

1415
import javax.crypto.KeyGenerator;
15-
import javax.crypto.SecretKey;
1616
import java.io.FileInputStream;
1717
import java.io.FileNotFoundException;
1818
import java.io.IOException;
@@ -46,8 +46,6 @@ public class SecurityUtil {
4646
private static final String SIGNATURE_ALGORITHM = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
4747
// By default digest algorithm is set to "http://www.w3.org/2000/09/xmldsig#sha1"
4848
private static final String DIGEST_ALGORITHM = "http://www.w3.org/2001/04/xmlenc#sha256";
49-
// SymmetricKey Generator Algorithm to handle message encryption
50-
private static final String SYM_KEY_ALGO = "AES";
5149

5250
private static BouncyCastleProvider bcProvider = new BouncyCastleProvider();
5351

@@ -56,6 +54,8 @@ public class SecurityUtil {
5654
Security.addProvider(bcProvider);
5755
try {
5856
initKeystore();
57+
//Must initialize xml-security library correctly before use it
58+
Init.init();
5959
} catch (Exception e) {
6060
localKeyStoreHandler=null;
6161
}
@@ -205,9 +205,6 @@ public static Document handleMessageCreation(Document signedDoc, String merchant
205205
throw new SignException(e);
206206
}
207207

208-
//Must initialize xml-security library correctly before use it
209-
Init.init();
210-
211208
WSSecEncrypt encrBuilder = new WSSecEncrypt(secHeader);
212209
//Set the user name to get the encryption certificate.
213210
//The public key of this certificate is used, thus no password necessary. The user name is a keystore alias usually.
@@ -225,7 +222,6 @@ public static Document handleMessageCreation(Document signedDoc, String merchant
225222
//Sets the algorithm to encode the symmetric key. Default is the WSConstants.KEYTRANSPORT_RSAOEP algorithm.
226223
//encrBuilder.setKeyEnc(WSConstants.KEYTRANSPORT_RSAOEP);
227224

228-
229225
//Create signed document
230226
//Document signedDoc = createSignedDoc(workingDocument,senderAlias,password,secHeader);
231227

@@ -235,13 +231,8 @@ public static Document handleMessageCreation(Document signedDoc, String merchant
235231
// If no external key (symmetricalKey) was set ,generate an encryption
236232
// key (session key) for this Encrypt element. This key will be
237233
// encrypted using the public key of the receiver
238-
SecretKey symmetricKey;
239-
try {
240-
symmetricKey = KeyGenerator.getInstance(SYM_KEY_ALGO).generateKey();
241-
} catch (NoSuchAlgorithmException e) {
242-
throw new WSSecurityException(WSSecurityException.ErrorCode.UNSUPPORTED_ALGORITHM, e, "Failed to generate SecretKey");
243-
}
244-
signedEncryptedDoc = encrBuilder.build(localKeyStoreHandler, symmetricKey);
234+
KeyGenerator keyGen = KeyUtils.getKeyGenerator(WSConstants.AES_256);
235+
signedEncryptedDoc = encrBuilder.build(localKeyStoreHandler, keyGen.generateKey());
245236
} catch (WSSecurityException e) {
246237
logger.log(Logger.LT_EXCEPTION, "Failed while encrypting signed requeest for , '" + merchantId + "'" + " with " + SERVER_ALIAS);
247238
throw new SignEncryptException("Failed while encrypting signed requeest for , '" + merchantId + "'" + " with " + SERVER_ALIAS, e);
@@ -260,9 +251,8 @@ public static Document handleMessageCreation(Document signedDoc, String merchant
260251
* @throws SignException
261252
*/
262253
public static Document createSignedDoc(Document workingDocument,String keyAlias, String password,Logger logger) throws SignException {
263-
264254
logger.log(Logger.LT_INFO, "Signing request...");
265-
long startTime = System.nanoTime();
255+
// long startTime = System.nanoTime();
266256
WSSecHeader secHeader = new WSSecHeader(workingDocument);
267257
try {
268258
secHeader.insertSecurityHeader();
@@ -288,7 +278,7 @@ public static Document createSignedDoc(Document workingDocument,String keyAlias,
288278
try {
289279
sign.addReferencesToSign(Collections.singletonList(msgBodyPart));
290280
Document document = sign.build(localKeyStoreHandler);
291-
System.out.println("SecurityUtil.createSignedDoc time taken to sign the request is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
281+
// System.out.println("SecurityUtil.createSignedDoc time taken to sign the request is " + TimeUnit.NANOSECONDS.toMillis(System.nanoTime() - startTime) + " ms");
292282
return document;
293283
} catch (WSSecurityException e) {
294284
logger.log(Logger.LT_EXCEPTION, "Failed while signing request for , '" + keyAlias + "'");

zip/README

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -242,37 +242,39 @@ numberOfRetries parameter value should be set between 0 to 5. By default the val
242242
Config parameter for this property is 'retryInterval' in cybs.property file. The default value for 'retryInterval' parameter is 1000 which means a delay of 1000 milliSeconds.
243243

244244
##Third Party jars
245-
1.) org.apache.ws.security.wss4j:1.6.19
246-
The Apache WSS4J project provides a Java implementation of the primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications
247-
from the OASIS Web Services Security TC.
245+
1.) org.apache.wss4j:wss4j-ws-security-common:2.4.1
246+
The Apache WSS4J project provides a Java implementation of the common primary security standards for Web Services, namely the OASIS Web Services Security (WS-Security) specifications from the OASIS Web Services Security TC.
248247

249-
2.) org.bouncycastle:bcprov-jdk15on:1.61
248+
2.) org.apache.wss4j:wss4j-ws-security-dom:2.4.1
249+
WSS4J 2.0.0 introduces a streaming (StAX-based) WS-Security implementation to complement the existing DOM-based implementation. The DOM-based implementation is quite performant and flexible, but suffers from having to read the entire XML tree into memory. For large SOAP requests this can have a detrimental impact on performance. In addition, for web services stacks such as Apache CXF which are streaming-based, it carries an additional performance penalty of having to explicitly convert the request stream to a DOM Element.
250+
251+
3.) org.bouncycastle:bcprov-jdk15on:1.61
250252
This jar contains JCE provider and lightweight API for the Bouncy Castle Cryptography APIs for JDK 1.5 to JDK 1.8.
251253

252-
3.) org.apache.santuario:xmlsec:1.5.6
254+
4.) org.apache.santuario:xmlsec:1.5.6
253255
The XML Security project is aimed at providing implementation of security standards for XML,supports XML-Signature Syntax and Processing,XML Encryption Syntax and Processing,
254256
and supports XML Digital Signature APIs.
255257

256-
4.) org.apache.commons:commons-lang3:3.4
258+
5.) org.apache.commons:commons-lang3:3.4
257259
Apache Commons Lang, a package of Java utility classes for the classes that are in java.lang's hierarchy, or are considered to be so standard as to justify existence in
258260
java.lang.
259261

260-
5.) commons-logging:commons-logging:jar:1.1.1
262+
6.) commons-logging:commons-logging:jar:1.1.1
261263
This is getting downloaded as compile time dependency of wss4j:1.6.19.Apache Commons Logging is a thin adapter allowing configurable bridging to other, well known logging systems.
262264

263-
6.) org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21
265+
7.) org.slf4j:slf4j-api:1.7.21 and org.slf4j:slf4j-jcl:1.7.21
264266
slf4j-api is getting used as a dependency for wss4j. Modified to latest version.
265267

266-
7.) junit:junit:4.13.1
268+
8.) junit:junit:4.13.1
267269
JUnit is a unit testing framework for Java.
268270

269-
8.) org.mockito:mockito-all:1.10.19
271+
9.) org.mockito:mockito-all:1.10.19
270272
Mock objects library for java
271273

272-
9.) org.apache.httpcomponents:httpclient:4.5.13
274+
10.) org.apache.httpcomponents:httpclient:4.5.13
273275
provides reusable components for client-side authentication, HTTP state management, and HTTP connection management. It is used for poolinghttpclientconnectionmanager feature.
274276

275-
10.) org.apache.httpcomponents:httpcore:4.4.13
277+
11.) org.apache.httpcomponents:httpcore:4.4.13
276278
Provides low level HTTP transport components that can be used to build custom client and server side HTTP services with a minimal footprint.
277279

278280
##Changes

0 commit comments

Comments
 (0)