Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE-172] - using JKS keystore format #176

Merged
merged 2 commits into from
Nov 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
<bouncycastle.version>1.56</bouncycastle.version>
</properties>

<description>
Expand Down Expand Up @@ -64,12 +65,12 @@
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk15on</artifactId>
<version>1.56</version>
<version>${bouncycastle.version}</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.56</version>
<version>${bouncycastle.version}</version>
</dependency>
</dependencies>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.security.KeyStore.Builder;
import java.security.KeyStore.ProtectionParameter;
import java.security.KeyStoreException;
import java.security.Provider;
import java.security.cert.X509Certificate;

/**
Expand Down Expand Up @@ -48,19 +49,42 @@ public FileSystemKeyStoreKeyingDataProvider(
KeyStorePasswordProvider keyStorePasswordProvider,
KeyEntryPasswordProvider entryPasswordProvider,
boolean returnFullChain) throws KeyStoreException
{
this(keyStoreType,keyStorePath,certificateSelector,keyStorePasswordProvider,entryPasswordProvider,returnFullChain,null);
}

/**
*
* @param keyStoreType the type of the keystore (jks, pkcs12, etc)
* @param keyStorePath the file-system path of the keystore
* @param certificateSelector the selector of signing certificate
* @param keyStorePasswordProvider the provider of the keystore loading password
* @param entryPasswordProvider the provider of entry passwords
* @param returnFullChain indicates of the full certificate chain should be returned, if available
* @param provider provider for parsing this store type, if it is passed <i>null</i> will be used default provider
* @throws KeyStoreException
*/
public FileSystemKeyStoreKeyingDataProvider(
final String keyStoreType,
final String keyStorePath,
SigningCertSelector certificateSelector,
KeyStorePasswordProvider keyStorePasswordProvider,
KeyEntryPasswordProvider entryPasswordProvider,
boolean returnFullChain,
final Provider provider) throws KeyStoreException
{
super(new KeyStoreBuilderCreator()
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
return KeyStore.Builder.newInstance(
keyStoreType,
null,
new File(keyStorePath),
loadProtection);
}
},
{
@Override
public Builder getBuilder(ProtectionParameter loadProtection)
{
return KeyStore.Builder.newInstance(
keyStoreType,
provider,
new File(keyStorePath),
loadProtection);
}
},
certificateSelector,
keyStorePasswordProvider,
entryPasswordProvider,
Expand Down
Binary file added src/test/cert/csrc.nist/test4.jks
Binary file not shown.
Binary file added src/test/cert/gva/raizaccv1_der_5.crl
Binary file not shown.
Binary file added src/test/cert/my/LG.jks
Binary file not shown.
5 changes: 2 additions & 3 deletions src/test/java/xades4j/production/SignerTestBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
import xades4j.providers.KeyingDataProvider;
import xades4j.providers.impl.PKCS11KeyStoreKeyingDataProvider;
import xades4j.utils.SignatureServicesTestBase;
import static xades4j.utils.SignatureServicesTestBase.onWindowsPlatform;

/**
*
Expand All @@ -44,8 +43,8 @@ public class SignerTestBase extends SignatureServicesTestBase
{
try
{
keyingProviderMy = createFileSystemKeyingDataProvider("pkcs12", "my/LG.pfx", "mykeypass", true);
keyingProviderNist = createFileSystemKeyingDataProvider("pkcs12", "csrc.nist/test4.p12", "password", false);
keyingProviderMy = createFileSystemKeyingDataProvider("JKS", "my/LG.jks", "mykeypass", true);
keyingProviderNist = createFileSystemKeyingDataProvider("JKS", "csrc.nist/test4.jks", "password", false);
} catch (KeyStoreException e)
{
throw new NullPointerException("SignerTestBase init failed: " + e.getMessage());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,36 +17,64 @@
package xades4j.providers.impl;

import java.io.FileInputStream;
import java.security.Security;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import org.junit.Before;

import org.bouncycastle.jce.provider.BouncyCastleProvider;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import xades4j.utils.SignatureServicesTestBase;
import static org.junit.Assert.*;

/**
*
* @author Luís
*/
@RunWith(Parameterized.class)
public class FileSystemKeyStoreKeyingDataProviderTest
{
FileSystemKeyStoreKeyingDataProvider keyingProvider;
X509Certificate signCert;
@Parameterized.Parameter(0)
public FileSystemKeyStoreKeyingDataProvider keyingProvider;
@Parameterized.Parameter(1)
public X509Certificate signCert;

@Before
public void setUp() throws Exception
{
keyingProvider = new FileSystemKeyStoreKeyingDataProvider(
@Parameterized.Parameters
public static Collection<Object[]> data() throws Exception {
Security.addProvider(new BouncyCastleProvider());
FileSystemKeyStoreKeyingDataProvider keyingProviderPksc12 = new FileSystemKeyStoreKeyingDataProvider(
"pkcs12",
SignatureServicesTestBase.toPlatformSpecificCertDirFilePath("my/LG.pfx"),
new FirstCertificateSelector(),
new DirectPasswordProvider("mykeypass"),
new DirectPasswordProvider("mykeypass"), true);

FileSystemKeyStoreKeyingDataProvider keyingProviderJks = new FileSystemKeyStoreKeyingDataProvider(
"JKS",
SignatureServicesTestBase.toPlatformSpecificCertDirFilePath("my/LG.jks"),
new FirstCertificateSelector(),
new DirectPasswordProvider("mykeypass"),
new DirectPasswordProvider("mykeypass"), true);
FileSystemKeyStoreKeyingDataProvider keyingProviderPksc12BC = new FileSystemKeyStoreKeyingDataProvider(
"pkcs12",
SignatureServicesTestBase.toPlatformSpecificCertDirFilePath("my/LG.pfx"),
new FirstCertificateSelector(),
new DirectPasswordProvider("mykeypass"),
new DirectPasswordProvider("mykeypass"), true,new BouncyCastleProvider());
CertificateFactory cf = CertificateFactory.getInstance("X.509");
signCert = (X509Certificate)cf.generateCertificate(

X509Certificate signCert = (X509Certificate)cf.generateCertificate(
new FileInputStream(SignatureServicesTestBase.toPlatformSpecificCertDirFilePath("my/LG.cer")));
ArrayList<Object[]> result = new ArrayList<Object[]>();
result.add(new Object[]{keyingProviderPksc12,signCert});

//TODO test will break, need find out why
//result.add(new Object[]{keyingProviderPksc12BC,signCert});
result.add(new Object[]{keyingProviderJks,signCert});
return result;
}

@Test
Expand Down