Search in sources :

Example 21 with CodeSigner

use of java.security.CodeSigner in project ignite by apache.

the class GridUriDeploymentJarVerifier method getCertificates.

/**
 * Gets all JAR file entry certificates.
 * Method scans entry for signers and than collects all their certificates.
 *
 * @param entry JAR file entry.
 * @return Array of certificates which corresponds to the entry.
 */
private static Certificate[] getCertificates(JarEntry entry) {
    Certificate[] certs = null;
    CodeSigner[] signers = entry.getCodeSigners();
    // Extract the certificates in each code signer's cert chain.
    if (signers != null) {
        List<Certificate> certChains = new ArrayList<>();
        for (CodeSigner signer : signers) certChains.addAll(signer.getSignerCertPath().getCertificates());
        // Convert into a Certificate[]
        return certChains.toArray(new Certificate[certChains.size()]);
    }
    return certs;
}
Also used : ArrayList(java.util.ArrayList) CodeSigner(java.security.CodeSigner) Certificate(java.security.cert.Certificate)

Example 22 with CodeSigner

use of java.security.CodeSigner in project robovm by robovm.

the class CodeSignerTest method testEqualsObject.

/**
     * Test various assertions about equals()
     */
public final void testEqualsObject() {
    CodeSigner one = new CodeSigner(cpath, ts);
    CodeSigner two = new CodeSigner(cpath, ts);
    CodeSigner three = new CodeSigner(cpath, null);
    CertPath cpath2 = TestCertUtils.genCertPath(5, 3);
    CodeSigner four = new CodeSigner(cpath2, null);
    assertTrue(one.equals(one));
    assertTrue(one.equals(two));
    assertTrue(two.equals(one));
    assertFalse(one.equals(three));
    assertFalse(three.equals(one));
    assertTrue(three.equals(three));
    // different CertPaths
    assertFalse(three.equals(four));
    // special cases
    assertFalse(one.equals(null));
    assertFalse(one.equals(new Object()));
}
Also used : CertPath(java.security.cert.CertPath) CodeSigner(java.security.CodeSigner)

Example 23 with CodeSigner

use of java.security.CodeSigner in project robovm by robovm.

the class CodeSignerTest method testCodeSigner_01.

/**
     * timestamp can be null
     */
public final void testCodeSigner_01() {
    try {
        CodeSigner cs = new CodeSigner(cpath, null);
        assertNotNull(cs);
    } catch (Exception e) {
        fail("Unexpected exception");
    }
}
Also used : CodeSigner(java.security.CodeSigner)

Example 24 with CodeSigner

use of java.security.CodeSigner in project quasar by puniverse.

the class QuasarURLClassLoader method instrument.

private Resource instrument(final String className, final Resource res) {
    final ClassLoader parent = this;
    return new Resource() {

        private byte[] instrumented;

        @Override
        public synchronized byte[] getBytes() throws IOException {
            if (instrumented == null) {
                final byte[] bytes;
                ByteBuffer bb = res.getByteBuffer();
                if (bb != null) {
                    final int size = bb.remaining();
                    bytes = new byte[size];
                    bb.get(bytes);
                } else
                    bytes = res.getBytes();
                try {
                    this.instrumented = instrumentor.instrumentClass(parent, className, bytes);
                } catch (Exception ex) {
                    if (MethodDatabase.isProblematicClass(className))
                        instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
                    else
                        instrumentor.error("Unable to instrument " + className, ex);
                    instrumented = bytes;
                }
            }
            return instrumented;
        }

        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            return null;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            throw new AssertionError();
        }

        @Override
        public String getName() {
            return res.getName();
        }

        @Override
        public URL getURL() {
            return res.getURL();
        }

        @Override
        public URL getCodeSourceURL() {
            return res.getCodeSourceURL();
        }

        @Override
        public int getContentLength() throws IOException {
            return res.getContentLength();
        }

        @Override
        public Manifest getManifest() throws IOException {
            return res.getManifest();
        }

        @Override
        public Certificate[] getCertificates() {
            return res.getCertificates();
        }

        @Override
        public CodeSigner[] getCodeSigners() {
            return res.getCodeSigners();
        }
    };
}
Also used : Resource(sun.misc.Resource) URLClassLoader(java.net.URLClassLoader) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CodeSigner(java.security.CodeSigner) Certificate(java.security.cert.Certificate)

Example 25 with CodeSigner

use of java.security.CodeSigner in project quasar by puniverse.

the class QuasarURLClassLoaderHelper method instrument.

private Resource instrument(final String className, final Resource res) {
    return new Resource() {

        private byte[] instrumented;

        @Override
        public synchronized byte[] getBytes() throws IOException {
            if (instrumented == null) {
                final byte[] bytes;
                ByteBuffer bb = res.getByteBuffer();
                if (bb != null) {
                    final int size = bb.remaining();
                    bytes = new byte[size];
                    bb.get(bytes);
                } else
                    bytes = res.getBytes();
                try {
                    this.instrumented = instrumentor.instrumentClass(cl, className, bytes);
                } catch (Exception ex) {
                    if (MethodDatabase.isProblematicClass(className))
                        instrumentor.log(LogLevel.INFO, "Skipping problematic class instrumentation %s - %s %s", className, ex, Arrays.toString(ex.getStackTrace()));
                    else
                        instrumentor.error("Unable to instrument " + className, ex);
                    instrumented = bytes;
                }
            }
            return instrumented;
        }

        @Override
        public ByteBuffer getByteBuffer() throws IOException {
            return null;
        }

        @Override
        public InputStream getInputStream() throws IOException {
            throw new AssertionError();
        }

        @Override
        public String getName() {
            return res.getName();
        }

        @Override
        public URL getURL() {
            return res.getURL();
        }

        @Override
        public URL getCodeSourceURL() {
            return res.getCodeSourceURL();
        }

        @Override
        public int getContentLength() throws IOException {
            return res.getContentLength();
        }

        @Override
        public Manifest getManifest() throws IOException {
            return res.getManifest();
        }

        @Override
        public Certificate[] getCertificates() {
            return res.getCertificates();
        }

        @Override
        public CodeSigner[] getCodeSigners() {
            return res.getCodeSigners();
        }
    };
}
Also used : Resource(sun.misc.Resource) ByteBuffer(java.nio.ByteBuffer) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) CodeSigner(java.security.CodeSigner) Certificate(java.security.cert.Certificate)

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