use of java.security.CodeSigner in project XobotOS by xamarin.
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.CodeSigner in project jdk8u_jdk by JetBrains.
the class Serialize method main.
public static void main(String[] args) throws Exception {
// Create a certpath consisting of one certificate
File f = new File(System.getProperty("test.src", "."), "cert_file");
FileInputStream fis = new FileInputStream(f);
CertificateFactory cf = CertificateFactory.getInstance("X.509");
Certificate c = cf.generateCertificate(fis);
fis.close();
CertPath cp = cf.generateCertPath(Collections.singletonList(c));
// Create a code signer
CodeSigner cs = new CodeSigner(cp, new Timestamp(new Date(), cp));
// Serialize the code signer
ByteArrayOutputStream byteOut = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(byteOut);
out.writeObject(cs);
out.close();
// Deserialize the code signer
byte[] data = byteOut.toByteArray();
CodeSigner cs2 = (CodeSigner) new ObjectInputStream(new ByteArrayInputStream(data)).readObject();
// Test for equality
if (!cs.equals(cs2) || cs.hashCode() != cs2.hashCode()) {
throw new Exception("CodeSigner serialization test FAILED");
}
}
use of java.security.CodeSigner in project jdk8u_jdk by JetBrains.
the class GetMethodsReturnClones method main.
public static void main(String[] args) throws Exception {
List<JarEntry> entries = new ArrayList<>();
try (JarFile jf = new JarFile(BASE + "test.jar", true)) {
byte[] buffer = new byte[8192];
Enumeration<JarEntry> e = jf.entries();
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
entries.add(je);
try (InputStream is = jf.getInputStream(je)) {
while (is.read(buffer, 0, buffer.length) != -1) {
// we just read. this will throw a SecurityException
// if a signature/digest check fails.
}
}
}
}
for (JarEntry je : entries) {
Certificate[] certs = je.getCertificates();
CodeSigner[] signers = je.getCodeSigners();
if (certs != null) {
certs[0] = null;
certs = je.getCertificates();
if (certs[0] == null) {
throw new Exception("Modified internal certs array");
}
}
if (signers != null) {
signers[0] = null;
signers = je.getCodeSigners();
if (signers[0] == null) {
throw new Exception("Modified internal codesigners array");
}
}
}
}
use of java.security.CodeSigner 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.CodeSigner in project robovm by robovm.
the class CodeSignerTest method testCodeSigner_02.
/**
* Not null parameters
*/
public final void testCodeSigner_02() {
try {
CodeSigner cs = new CodeSigner(cpath, ts);
assertNotNull(cs);
} catch (Exception e) {
fail("Unexpected exception");
}
}
Aggregations