Search in sources :

Example 1 with SignedContentFactory

use of org.eclipse.osgi.signedcontent.SignedContentFactory in project rt.equinox.framework by eclipse.

the class EquinoxBundle method getSignerCertificates.

@Override
public Map<X509Certificate, List<X509Certificate>> getSignerCertificates(int signersType) {
    SignedContentFactory factory = equinoxContainer.getSignedContentFactory();
    if (factory == null) {
        return Collections.emptyMap();
    }
    try {
        SignerInfo[] infos = signerInfos;
        if (infos == null) {
            SignedContent signedContent = factory.getSignedContent(this);
            infos = signedContent.getSignerInfos();
            signerInfos = infos;
        }
        if (infos.length == 0)
            return Collections.emptyMap();
        Map<X509Certificate, List<X509Certificate>> results = new HashMap<>(infos.length);
        for (int i = 0; i < infos.length; i++) {
            if (signersType == SIGNERS_TRUSTED && !infos[i].isTrusted())
                continue;
            Certificate[] certs = infos[i].getCertificateChain();
            if (certs == null || certs.length == 0)
                continue;
            List<X509Certificate> certChain = new ArrayList<>();
            for (int j = 0; j < certs.length; j++) certChain.add((X509Certificate) certs[j]);
            results.put((X509Certificate) certs[0], certChain);
        }
        return results;
    } catch (Exception e) {
        return Collections.emptyMap();
    }
}
Also used : HashMap(java.util.HashMap) SignedContentFactory(org.eclipse.osgi.signedcontent.SignedContentFactory) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) BundleException(org.osgi.framework.BundleException) IOException(java.io.IOException) SignerInfo(org.eclipse.osgi.signedcontent.SignerInfo) SignedContent(org.eclipse.osgi.signedcontent.SignedContent) List(java.util.List) ArrayList(java.util.ArrayList) X509Certificate(java.security.cert.X509Certificate) Certificate(java.security.cert.Certificate)

Example 2 with SignedContentFactory

use of org.eclipse.osgi.signedcontent.SignedContentFactory in project rt.equinox.framework by eclipse.

the class BaseSecurityTest method getSignedContentFactory.

protected SignedContentFactory getSignedContentFactory() {
    ServiceReference ref = OSGiTestsActivator.getContext().getServiceReference(SignedContentFactory.class.getName());
    assertNotNull("No SignedContentFactory service", ref);
    SignedContentFactory factory = (SignedContentFactory) OSGiTestsActivator.getContext().getService(ref);
    OSGiTestsActivator.getContext().ungetService(ref);
    return factory;
}
Also used : SignedContentFactory(org.eclipse.osgi.signedcontent.SignedContentFactory)

Aggregations

SignedContentFactory (org.eclipse.osgi.signedcontent.SignedContentFactory)2 IOException (java.io.IOException)1 Certificate (java.security.cert.Certificate)1 X509Certificate (java.security.cert.X509Certificate)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 List (java.util.List)1 SignedContent (org.eclipse.osgi.signedcontent.SignedContent)1 SignerInfo (org.eclipse.osgi.signedcontent.SignerInfo)1 BundleException (org.osgi.framework.BundleException)1