use of java.security.cert.CertificateFactory in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory15.
/**
* Test for <code>generateCertPath(List certificates)</code> method
* Assertion: returns empty CertPath if certificates is empty
*/
public void testCertificateFactory15() throws CertificateException {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
CertificateFactory[] certFs = initCertFs();
assertNotNull("CertificateFactory objects were not created", certFs);
List<Certificate> list = new Vector<Certificate>();
for (int i = 0; i < certFs.length; i++) {
CertPath cp = certFs[i].generateCertPath(list);
List<? extends Certificate> list1 = cp.getCertificates();
assertTrue("List should be empty", list1.isEmpty());
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory08.
/**
* Test for <code>getInstance(String type, Provider provider)</code>
* method
* Assertion: returns CertificateFactorythrows when type and provider
* have valid values
*/
public void testCertificateFactory08() throws CertificateException {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
CertificateFactory certF;
for (int i = 0; i < validValues.length; i++) {
certF = CertificateFactory.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect provider", certF.getProvider(), defaultProvider);
assertEquals("Incorrect type", certF.getType(), validValues[i]);
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class myCertificateFactory method testCertificateFactory18.
/**
* Test for <code>getType()</code> method
*/
public void testCertificateFactory18() throws CertificateException {
if (!X509Support) {
fail(NotSupportMsg);
return;
}
for (int i = 0; i < validValues.length; i++) {
try {
CertificateFactory certF = CertificateFactory.getInstance(validValues[i]);
assertEquals("Incorrect type: ", validValues[i], certF.getType());
certF = CertificateFactory.getInstance(validValues[i], defaultProviderName);
assertEquals("Incorrect type", certF.getType(), validValues[i]);
certF = CertificateFactory.getInstance(validValues[i], defaultProvider);
assertEquals("Incorrect provider", certF.getProvider(), defaultProvider);
assertEquals("Incorrect type", certF.getType(), validValues[i]);
} catch (NoSuchProviderException e) {
fail("Unexpected NoSuchProviderException " + e.getMessage());
}
}
}
use of java.security.cert.CertificateFactory in project robovm by robovm.
the class CertificateTest method setUp.
public void setUp() throws Exception {
super.setUp();
TestUtils.initCertPathSSCertChain();
cert = TestUtils.rootCertificateSS;
CertificateFactory cf = CertificateFactory.getInstance("X.509");
wrongProvider = cf.getProvider();
usefulProvider = Signature.getInstance("SHA1WithRSA").getProvider();
}
use of java.security.cert.CertificateFactory in project dbeaver by serge-rider.
the class DefaultCertificateStorage method addCertificate.
@Override
public void addCertificate(DBPDataSourceContainer dataSource, String certType, byte[] caCertData, byte[] clientCertData, byte[] keyData) throws DBException {
final KeyStore keyStore = getKeyStore(dataSource, certType);
try {
CertificateFactory cf = CertificateFactory.getInstance("X.509");
List<Certificate> certChain = new ArrayList<>();
if (caCertData != null) {
Certificate caCert = cf.generateCertificate(new ByteArrayInputStream(caCertData));
keyStore.setCertificateEntry("ca-cert", caCert);
//certChain.add(caCert);
}
if (clientCertData != null) {
Certificate clientCert = cf.generateCertificate(new ByteArrayInputStream(clientCertData));
keyStore.setCertificateEntry("client-cert", clientCert);
certChain.add(clientCert);
}
if (keyData != null) {
PrivateKey privateKey = loadPrivateKeyFromPEM(keyData);
keyStore.setKeyEntry("key-cert", privateKey, DEFAULT_PASSWORD, certChain.toArray(new Certificate[certChain.size()]));
}
saveKeyStore(dataSource, certType, keyStore);
} catch (Throwable e) {
throw new DBException("Error adding certificate to keystore", e);
}
}
Aggregations