Skip to content

Commit 6efa205

Browse files
committed
Added the flag to check the merchant certificate validity in Identity and security util file also changes reflected to client and xmlclient file
1 parent efb1aa8 commit 6efa205

4 files changed

Lines changed: 33 additions & 5 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,12 +212,13 @@ private static void setVersionInformation(Map<String, String> request) {
212212
* @throws SignException if signing fails.
213213
* @throws SAXException
214214
* @throws SignEncryptException
215+
* @throws ConfigException
215216
*/
216217
private static Document soapWrapAndSign(
217218
Map request, MerchantConfig mc, DocumentBuilder builder,
218219
LoggerWrapper logger)
219220
throws
220-
IOException, SignException, SAXException, SignEncryptException {
221+
IOException, SignException, SAXException, SignEncryptException, ConfigException {
221222
boolean logSignedData = mc.getLogSignedData();
222223
if (!logSignedData) {
223224
logger.log(

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

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
*/
1010
package com.cybersource.ws.client;
1111

12+
import java.io.File;
1213
import java.security.PrivateKey;
1314
import java.security.cert.CertificateEncodingException;
1415
import java.security.cert.X509Certificate;
@@ -35,9 +36,15 @@ public class Identity {
3536
private PrivateKey privateKey;
3637

3738
private MerchantConfig merchantConfig;
39+
40+
private long lastModifiedDate;
3841

3942
private static final String SERVER_ALIAS = "CyberSource_SJC_US";
4043

44+
Logger logger;
45+
46+
47+
4148
/**
4249
* Creates an Identity instance.this type of the instance can
4350
* only be used to store server certificate identity.
@@ -93,9 +100,23 @@ public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, P
93100
this.merchantConfig = merchantConfig;
94101
this.x509Cert = x509Certificate;
95102
this.privateKey = privateKey;
103+
try {
104+
this.lastModifiedDate=merchantConfig.getKeyFile().lastModified();
105+
} catch (ConfigException e) {
106+
logger.log(Logger.LT_EXCEPTION,
107+
"Identity object ,cannot instantiate with key file lastModifiedDate. "
108+
+ e.getMessage());
109+
throw new SignException(e.getMessage());
110+
}
96111
setUpMerchant();
97112
}
98113

114+
public boolean isValid(File keyFile)
115+
{
116+
117+
return this.lastModifiedDate == keyFile.lastModified();
118+
}
119+
99120
private void setUpMerchant() throws SignException {
100121
if (serialNumber == null && x509Cert != null) {
101122
String subjectDN = x509Cert.getSubjectDN().getName();

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public class SecurityUtil {
4848

4949
private static BouncyCastleProvider bcProvider = new BouncyCastleProvider();
5050

51+
52+
5153

5254
// This is loaded by WSS4J but since we use it lets make sure its here
5355
static {
@@ -77,12 +79,15 @@ private static void initKeystore() throws KeyStoreException, CredentialException
7779
* @throws IOException
7880
* @throws CredentialException
7981
*/
80-
public static void loadMerchantP12File(MerchantConfig merchantConfig, Logger logger) throws SignException, SignEncryptException {
82+
public static void loadMerchantP12File(MerchantConfig merchantConfig, Logger logger) throws SignException, SignEncryptException, ConfigException {
8183

8284
// Load the KeyStore and get the signing key and certificate do this once only
8385
// This change is made based on the assumptions that at point of time , a merchant will have only one P12 Key
84-
85-
if(identities.get(merchantConfig.getMerchantID()) == null){
86+
87+
88+
89+
Identity identitys=identities.get(merchantConfig.getMerchantID());
90+
if(identities.get(merchantConfig.getMerchantID()) == null || !(identitys.isValid(merchantConfig.getKeyFile()))){
8691
try {
8792
if (localKeyStoreHandler == null)
8893
initKeystore();

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,12 @@ private static void setVersionInformation(Document request, String nsURI) {
355355
* @return signed document.
356356
* @throws SignException if signing fails.
357357
* @throws SignEncryptException
358+
* @throws ConfigException
358359
*/
359360
private static Document soapWrapAndSign(
360361
Document doc, MerchantConfig mc, DocumentBuilder builder,
361362
LoggerWrapper logger)
362-
throws SignException, SignEncryptException {
363+
throws SignException, SignEncryptException, ConfigException {
363364
boolean logSignedData = mc.getLogSignedData();
364365

365366
if (!logSignedData) {

0 commit comments

Comments
 (0)