use of java.security.cert.Certificate in project robovm by robovm.
the class CipherTest method test_initWithCertificate.
public void test_initWithCertificate() throws Exception {
/* Certificate creation notes: certificate should be valid 37273 starting
* from 13 Nov 2008
* If it brcomes invalidated regenerate it using following commands:
* 1. openssl genrsa -des3 -out test.key 1024
* 2. openssl req -new -key test.key -out test.csr
* 3. cp test.key test.key.org
* 4. openssl rsa -in test.key.org -out test.key
* 5. openssl x509 -req -days 37273 -in test.csr -signkey test.key -out test.cert
* */
String certName = Support_Resources.getURL("test.cert");
InputStream is = new URL(certName).openConnection().getInputStream();
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate cert = cf.generateCertificate(is);
is.close();
Cipher c = Cipher.getInstance("RSA");
c.init(Cipher.ENCRYPT_MODE, cert);
c = Cipher.getInstance("DES/CBC/PKCS5Padding");
try {
c.init(Cipher.ENCRYPT_MODE, cert);
fail();
} catch (InvalidKeyException expected) {
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class SecureClassLoaderTest method testGetPermissions.
public void testGetPermissions() throws Exception {
URL url = new URL("http://localhost");
CodeSource cs = new CodeSource(url, (Certificate[]) null);
MyClassLoader ldr = new MyClassLoader();
ldr.getPerms(null);
ldr.getPerms(cs);
}
use of java.security.cert.Certificate in project robovm by robovm.
the class JarEntry method getCodeSigners.
private CodeSigner[] getCodeSigners(Certificate[] certs) {
if (certs == null) {
return null;
}
X500Principal prevIssuer = null;
ArrayList<Certificate> list = new ArrayList<Certificate>(certs.length);
ArrayList<CodeSigner> asigners = new ArrayList<CodeSigner>();
for (Certificate element : certs) {
if (!(element instanceof X509Certificate)) {
// Only X509Certificate-s are taken into account - see API spec.
continue;
}
X509Certificate x509 = (X509Certificate) element;
if (prevIssuer != null) {
X500Principal subj = x509.getSubjectX500Principal();
if (!prevIssuer.equals(subj)) {
// Ok, this ends the previous chain,
// so transform this one into CertPath ...
addCodeSigner(asigners, list);
// ... and start a new one
list.clear();
}
// else { it's still the same chain }
}
prevIssuer = x509.getIssuerX500Principal();
list.add(x509);
}
if (!list.isEmpty()) {
addCodeSigner(asigners, list);
}
if (asigners.isEmpty()) {
// 'signers' is 'null' already
return null;
}
CodeSigner[] tmp = new CodeSigner[asigners.size()];
asigners.toArray(tmp);
return tmp;
}
use of java.security.cert.Certificate in project robovm by robovm.
the class OldJarURLConnectionTest method test_getCertificates.
public void test_getCertificates() throws Exception {
URL u = createContent("TestCodeSigners.jar", "Test.class");
juc = (JarURLConnection) u.openConnection();
assertNull(juc.getCertificates());
JarEntry je = juc.getJarEntry();
JarFile jf = juc.getJarFile();
InputStream is = jf.getInputStream(je);
is.skip(je.getSize());
Certificate[] certs = juc.getCertificates();
assertEquals(3, certs.length);
URL invURL = createContent("InvalidJar.jar", "Test.class");
JarURLConnection juConn = (JarURLConnection) invURL.openConnection();
try {
juConn.getCertificates();
fail("IOException was not thrown.");
} catch (java.io.IOException io) {
//expected
}
}
use of java.security.cert.Certificate in project robovm by robovm.
the class OldAndroidZipStressTest method checkJarCertificates.
/**
* JarEntry.getCertificates() is really slow. http://b/1046174
*/
public void checkJarCertificates(File file) throws Exception {
JarFile jarFile = new JarFile(file);
JarEntry je = jarFile.getJarEntry("AndroidManifest.xml");
byte[] readBuffer = new byte[1024];
long t0 = System.currentTimeMillis();
// We must read the stream for the JarEntry to retrieve its certificates.
InputStream is = jarFile.getInputStream(je);
while (is.read(readBuffer, 0, readBuffer.length) != -1) {
}
is.close();
Certificate[] certs = je != null ? je.getCertificates() : null;
long t1 = System.currentTimeMillis();
System.out.println("loadCertificates() took " + (t1 - t0) + " ms");
if (certs == null) {
System.out.println("We have no certificates");
} else {
System.out.println("We have " + certs.length + " certificates");
}
}
Aggregations