Search in sources :

Example 26 with CodeSigner

use of java.security.CodeSigner in project jdk8u_jdk by JetBrains.

the class SignatureFileVerifier method getSigners.

/**
     * Given the PKCS7 block and SignerInfo[], create an array of
     * CodeSigner objects. We do this only *once* for a given
     * signature block file.
     */
private CodeSigner[] getSigners(SignerInfo[] infos, PKCS7 block) throws IOException, NoSuchAlgorithmException, SignatureException, CertificateException {
    ArrayList<CodeSigner> signers = null;
    for (int i = 0; i < infos.length; i++) {
        SignerInfo info = infos[i];
        ArrayList<X509Certificate> chain = info.getCertificateChain(block);
        CertPath certChain = certificateFactory.generateCertPath(chain);
        if (signers == null) {
            signers = new ArrayList<>();
        }
        // Append the new code signer
        signers.add(new CodeSigner(certChain, info.getTimestamp()));
        if (debug != null) {
            debug.println("Signature Block Certificate: " + chain.get(0));
        }
    }
    if (signers != null) {
        return signers.toArray(new CodeSigner[signers.size()]);
    } else {
        return null;
    }
}
Also used : SignerInfo(sun.security.pkcs.SignerInfo) CertPath(java.security.cert.CertPath) CodeSigner(java.security.CodeSigner) X509Certificate(java.security.cert.X509Certificate)

Example 27 with CodeSigner

use of java.security.CodeSigner in project jboss-modules by jboss-modules.

the class JarFileResourceLoader method createCodeSource.

// this MUST only be called after the input stream is fully read (see MODULES-201)
private CodeSource createCodeSource(final JarEntry entry) {
    final CodeSigner[] entryCodeSigners = entry.getCodeSigners();
    final CodeSigners codeSigners = entryCodeSigners == null || entryCodeSigners.length == 0 ? EMPTY_CODE_SIGNERS : new CodeSigners(entryCodeSigners);
    CodeSource codeSource = codeSources.get(codeSigners);
    if (codeSource == null) {
        codeSources.put(codeSigners, codeSource = new CodeSource(rootUrl, entryCodeSigners));
    }
    return codeSource;
}
Also used : CodeSource(java.security.CodeSource) CodeSigner(java.security.CodeSigner)

Example 28 with CodeSigner

use of java.security.CodeSigner in project btrace by btraceio.

the class FileClient method loadWithSecurity.

private byte[] loadWithSecurity(String path) throws IOException {
    URL scriptUrl = URLClassLoader.getSystemResource(path);
    if (scriptUrl.getProtocol().equals("jar")) {
        String jarPath = scriptUrl.getPath().substring(5, scriptUrl.getPath().indexOf("!"));
        JarFile jar = new JarFile(URLDecoder.decode(jarPath, "UTF-8"));
        Enumeration<JarEntry> ens = jar.entries();
        while (ens.hasMoreElements()) {
            JarEntry en = ens.nextElement();
            if (!en.isDirectory()) {
                if (en.toString().equals(path)) {
                    byte[] data = readAll(jar.getInputStream(en), en.getSize());
                    CodeSigner[] signers = en.getCodeSigners();
                    canLoadPack = signers != null && signers.length != 0;
                    return data;
                }
            }
        }
    }
    return null;
}
Also used : JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) CodeSigner(java.security.CodeSigner)

Example 29 with CodeSigner

use of java.security.CodeSigner in project j2objc by google.

the class CodeSignerTest method testHashCode.

/**
 * Tests CodeSigner.hashCode()
 */
public void testHashCode() {
    CodeSigner cs1 = new CodeSigner(cpath, ts);
    CodeSigner cs2 = new CodeSigner(cpath, ts);
    CodeSigner cs3 = new CodeSigner(cpath, null);
    assertTrue(cs1.hashCode() == cs2.hashCode());
    assertTrue(cs2.hashCode() != cs3.hashCode());
}
Also used : CodeSigner(java.security.CodeSigner)

Example 30 with CodeSigner

use of java.security.CodeSigner in project j2objc by google.

the class CodeSignerTest method testToString.

/**
 * Tests CodeSigner.toString()
 */
public void testToString() {
    assertTrue(new CodeSigner(cpath, null).toString().contains(""));
    assertTrue(new CodeSigner(cpath, ts).toString().contains(""));
    assertTrue(new CodeSigner(cpath, null).toString().contains("Signer"));
    assertTrue(new CodeSigner(cpath, ts).toString().contains(ts.toString()));
}
Also used : CodeSigner(java.security.CodeSigner)

Aggregations

CodeSigner (java.security.CodeSigner)31 Certificate (java.security.cert.Certificate)8 CodeSource (java.security.CodeSource)7 X509Certificate (java.security.cert.X509Certificate)6 Manifest (java.util.jar.Manifest)5 IOException (java.io.IOException)4 URL (java.net.URL)4 ByteBuffer (java.nio.ByteBuffer)4 CertPath (java.security.cert.CertPath)4 JarEntry (java.util.jar.JarEntry)4 JarFile (java.util.jar.JarFile)4 SignerInfo (sun.security.pkcs.SignerInfo)4 Timestamp (java.security.Timestamp)3 ArrayList (java.util.ArrayList)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 URI (java.net.URI)2 GeneralSecurityException (java.security.GeneralSecurityException)2 KeyStoreException (java.security.KeyStoreException)2