Skip to content

Commit bee5bab

Browse files
authored
Merge pull request #123 from mahendya1002/future
fixing failed to sign issue, which was due to wrong pwd used while si…
2 parents 4cf59ab + be2c567 commit bee5bab

File tree

7 files changed

+30
-23
lines changed

7 files changed

+30
-23
lines changed

java/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,12 +210,12 @@
210210
<groupId>org.apache.ws.security</groupId>
211211
<artifactId>wss4j</artifactId>
212212
<version>1.6.19</version>
213-
<exclusions>
213+
<exclusions>
214214
<exclusion>
215215
<groupId>org.opensaml</groupId>
216216
<artifactId>opensaml</artifactId>
217217
</exclusion>
218-
</exclusions>
218+
</exclusions>
219219
</dependency>
220220
<dependency>
221221
<groupId>org.apache.commons</groupId>

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,9 @@ public class Identity {
4040
private long lastModifiedDate;
4141

4242
private static final String SERVER_ALIAS = "CyberSource_SJC_US";
43-
43+
44+
private char[] pswd;
45+
4446
private Logger logger = null;
4547

4648
/**
@@ -122,11 +124,8 @@ public Identity(MerchantConfig merchantConfig,X509Certificate x509Certificate, P
122124
*/
123125

124126
public boolean isValid(File keyFile) {
125-
126127
boolean changeKeyFileStatus=(this.lastModifiedDate == keyFile.lastModified());
127-
128128
if (!changeKeyFileStatus) {
129-
130129
logger.log(Logger.LT_INFO, "Key file changed");
131130
logger.log(Logger.LT_INFO, "Timestamp of current key file:"+keyFile.lastModified());
132131
}
@@ -142,6 +141,7 @@ private void setUpMerchant() throws SignException {
142141
throw new SignException("Exception while obtaining private key from KeyStore with alias, '" + merchantConfig.getKeyAlias() + "'");
143142
}
144143
name = merchantConfig.getMerchantID();
144+
pswd = merchantConfig.getKeyPassword().toCharArray();
145145
serialNumber = subjectDNrray[1];
146146
keyAlias = "serialNumber=" + serialNumber + ",CN=" + name;
147147
} else {
@@ -197,8 +197,11 @@ public String getSerialNumber() {
197197

198198
return serialNumber;
199199
}
200-
201-
200+
201+
public char[] getPswd() {
202+
return pswd;
203+
}
204+
202205
public void setSerialNumber(String serialNumber) {
203206
this.serialNumber = serialNumber;
204207
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public void addIdentityToKeyStore(Identity id, Logger logger) throws SignEncrypt
2626
try {
2727
if (privateKey != null) {
2828
X509Certificate[] certChain = {certificate};
29-
getKeyStore().setKeyEntry(id.getKeyAlias(), privateKey, id.getName().toCharArray(), certChain);
29+
getKeyStore().setKeyEntry(id.getKeyAlias(), privateKey, id.getPswd(), certChain);
3030
} else {
3131
getKeyStore().setCertificateEntry(id.getKeyAlias(), certificate);
3232
}

java/src/test/java/com/cybersource/ws/client/IdentityTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ public void setUp() throws Exception {
3030
}
3131

3232
@Test
33-
public void testSetUpMerchant() throws InstantiationException, IllegalAccessException, SignException, ConfigException{
33+
public void testSetUpMerchant() throws SignException, ConfigException{
3434
File p12file = Mockito.mock(File.class);
3535
MerchantConfig mc = Mockito.mock(MerchantConfig.class);
3636

@@ -43,9 +43,11 @@ public void testSetUpMerchant() throws InstantiationException, IllegalAccessExce
4343
Mockito.when(principal.getName()).thenReturn(keyAlias);
4444

4545
Mockito.when(mc.getKeyFile()).thenReturn(p12file);
46+
Mockito.when(mc.getKeyPassword()).thenReturn("testPwd");
4647
Identity identity = new Identity(mc,x509Cert,pkey,logger);
4748
assertEquals(identity.getName(), mc.getMerchantID());
4849
assertEquals(identity.getSerialNumber(), "400000009910179089277");
50+
assertEquals(String.valueOf(identity.getPswd()), "testPwd");
4951
assertNotNull(identity.getPrivateKey());
5052
}
5153

java/src/test/java/com/cybersource/ws/client/SecurityUtilIT.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,13 +163,20 @@ public void testMerchantIdentityToKeyStore() throws Exception{
163163

164164
Mockito.when(identity.getPrivateKey()).thenReturn(newPkay);
165165
Mockito.when(identity.getX509Cert()).thenReturn(x509Cert);
166-
Mockito.when(identity.getName()).thenReturn("MahenCertTest");
167166
Mockito.when(identity.getKeyAlias()).thenReturn("MahenCertTest");
167+
Mockito.when(identity.getPswd()).thenReturn("testPwd".toCharArray());
168168

169169
MessageHandlerKeyStore mhKeyStore= new MessageHandlerKeyStore();
170+
170171
MessageHandlerKeyStore spyMhKeyStore = Mockito.spy(mhKeyStore);
171172
Mockito.when(spyMhKeyStore.getKeyStore()).thenReturn(myKeystore);
172173
spyMhKeyStore.addIdentityToKeyStore(identity,logger);
174+
175+
Mockito.verify(identity,times(1)).getKeyAlias();
176+
Mockito.verify(identity,times(1)).getPrivateKey();
177+
Mockito.verify(identity,times(1)).getPswd();
178+
Mockito.verify(identity,times(1)).getX509Cert();
179+
173180
}
174181

175182
@Test

pom.xml

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,6 @@
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55

66
<modelVersion>4.0.0</modelVersion>
7-
8-
<name>cybersource-sdk-java-master</name>
9-
10-
<modules>
11-
<module>zip</module>
12-
<module>java</module>
13-
</modules>
14-
15-
<packaging>pom</packaging>
16-
177
<parent>
188
<groupId>org.sonatype.oss</groupId>
199
<artifactId>oss-parent</artifactId>
@@ -23,6 +13,11 @@
2313
<groupId>com.cybersource</groupId>
2414
<artifactId>cybersource-sdk-master</artifactId>
2515
<version>6.2.7-SNAPSHOT</version>
16+
<name>cybersource-sdk-java-master</name>
17+
<packaging>pom</packaging>
2618

27-
19+
<modules>
20+
<module>zip</module>
21+
<module>java</module>
22+
</modules>
2823
</project>

zip/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<modelVersion>4.0.0</modelVersion>
1111

1212
<artifactId>cybersource-sdk-zip</artifactId>
13-
<name>${artifactId}</name>
13+
<name>${project.artifactId}</name>
1414
<packaging>pom</packaging>
1515

1616
<build>

0 commit comments

Comments
 (0)