use of java.security.KeyStore in project robovm by robovm.
the class TestKeyStore method createKeyStore.
/**
* Create an empty KeyStore
*/
public static KeyStore createKeyStore() {
try {
KeyStore keyStore = KeyStore.getInstance(StandardNames.KEY_STORE_ALGORITHM);
keyStore.load(null, null);
return keyStore;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of java.security.KeyStore in project robovm by robovm.
the class TestKeyStore method createClient.
/**
* Create a client key store that only contains self-signed certificates but no private keys
*/
public static KeyStore createClient(KeyStore caKeyStore) {
KeyStore clientKeyStore = createKeyStore();
copySelfSignedCertificates(clientKeyStore, caKeyStore);
return clientKeyStore;
}
use of java.security.KeyStore in project robovm by robovm.
the class CertPathBuilderTestPKIX method getCertPathParameters.
@Override
public CertPathParameters getCertPathParameters() throws Exception {
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
X509Certificate selfSignedcertificate = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCert.getBytes()));
keyStore.setCertificateEntry("selfSignedCert", selfSignedcertificate);
X509CertSelector targetConstraints = new X509CertSelector();
targetConstraints.setCertificate(selfSignedcertificate);
List<Certificate> certList = new ArrayList<Certificate>();
certList.add(selfSignedcertificate);
CertStoreParameters storeParams = new CollectionCertStoreParameters(certList);
CertStore certStore = CertStore.getInstance("Collection", storeParams);
PKIXBuilderParameters parameters = new PKIXBuilderParameters(keyStore, targetConstraints);
parameters.addCertStore(certStore);
parameters.setRevocationEnabled(false);
return parameters;
}
use of java.security.KeyStore in project robovm by robovm.
the class CertPathValidatorTestPKIX method setUp.
@Override
protected void setUp() throws Exception {
super.setUp();
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(null, null);
CertificateFactory certificateFactory = CertificateFactory.getInstance("X509");
X509Certificate selfSignedcertificate = (X509Certificate) certificateFactory.generateCertificate(new ByteArrayInputStream(selfSignedCert.getBytes()));
keyStore.setCertificateEntry("selfSignedCert", selfSignedcertificate);
X509CertSelector targetConstraints = new X509CertSelector();
targetConstraints.setCertificate(selfSignedcertificate);
List<Certificate> certList = new ArrayList<Certificate>();
certList.add(selfSignedcertificate);
CertStoreParameters storeParams = new CollectionCertStoreParameters(certList);
CertStore certStore = CertStore.getInstance("Collection", storeParams);
PKIXBuilderParameters parameters = new PKIXBuilderParameters(keyStore, targetConstraints);
parameters.addCertStore(certStore);
parameters.setRevocationEnabled(false);
CertPathBuilder pathBuilder = CertPathBuilder.getInstance("PKIX");
CertPathBuilderResult builderResult = pathBuilder.build(parameters);
certPath = builderResult.getCertPath();
params = new PKIXParameters(keyStore);
params.setRevocationEnabled(false);
}
use of java.security.KeyStore in project robovm by robovm.
the class TestUtils method getKeyStore.
/**
* Creates test <code>KeyStore</code> instance
*
* @param initialize
* Do not initialize returned <code>KeyStore</code> if false
*
* @param testKeyStoreType
* this parameter ignored if <code>initialize</code> is false;
* The following types supported:<br>
* 1 - <code>KeyStore</code> with untrusted certificates only<br>
* 2 - <code>KeyStore</code> with trusted certificates only<br>
* 3 - <code>KeyStore</code> with both trusted and untrusted certificates
*
* @return Returns test <code>KeyStore</code> instance
*/
public static KeyStore getKeyStore(boolean initialize, int testKeyStoreType) {
BufferedInputStream bis = null;
try {
KeyStore ks = KeyStore.getInstance(keyStoreType);
if (initialize) {
String fileName = keyStoreFileName + testKeyStoreType;
ks.load(Support_Resources.getResourceStream(fileName), storepass);
}
return ks;
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
if (initialize && bis != null) {
try {
bis.close();
} catch (IOException ign) {
}
}
}
}
Aggregations