Search in sources :

Example 1 with StorageHookImpl

use of org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl in project rt.equinox.framework by eclipse.

the class SignedBundleHook method wrapBundleFile.

public BundleFileWrapper wrapBundleFile(BundleFile bundleFile, Generation generation, boolean base) {
    try {
        if (bundleFile != null) {
            StorageHookImpl hook = generation.getStorageHook(SignedStorageHook.class);
            SignedBundleFile signedBaseFile;
            if (base && hook != null) {
                signedBaseFile = new SignedBundleFile(bundleFile, hook.signedContent, supportSignedBundles, this);
                if (hook.signedContent == null) {
                    signedBaseFile.initializeSignedContent();
                    SignedContentImpl signedContent = signedBaseFile.getSignedContent();
                    hook.signedContent = signedContent != null && signedContent.isSigned() ? signedContent : null;
                }
            } else
                signedBaseFile = new SignedBundleFile(bundleFile, null, supportSignedBundles, this);
            signedBaseFile.initializeSignedContent();
            SignedContentImpl signedContent = signedBaseFile.getSignedContent();
            if (signedContent != null && signedContent.isSigned()) {
                // only use the signed file if there are certs
                signedContent.setContent(signedBaseFile);
                return new BundleFileWrapper(signedBaseFile);
            }
        }
    } catch (IOException e) {
        // $NON-NLS-1$
        log("Bad bundle file: " + bundleFile.getBaseFile(), FrameworkLogEntry.WARNING, e);
    } catch (GeneralSecurityException e) {
        // $NON-NLS-1$
        log("Bad bundle file: " + bundleFile.getBaseFile(), FrameworkLogEntry.WARNING, e);
    }
    return null;
}
Also used : StorageHookImpl(org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl) IOException(java.io.IOException)

Example 2 with StorageHookImpl

use of org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl in project rt.equinox.framework by eclipse.

the class SignedBundleHook method getSignedContent.

public SignedContent getSignedContent(Bundle bundle) throws IOException, InvalidKeyException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException, IllegalArgumentException {
    final Generation generation = (Generation) ((EquinoxBundle) bundle).getModule().getCurrentRevision().getRevisionInfo();
    StorageHookImpl hook = generation.getStorageHook(SignedStorageHook.class);
    SignedContent result = hook != null ? hook.signedContent : null;
    if (result != null)
        // just reuse the signed content the storage hook
        return result;
    // must create a new signed content using the raw file
    if (System.getSecurityManager() == null)
        return getSignedContent(generation.getBundleFile().getBaseFile());
    try {
        return AccessController.doPrivileged(new PrivilegedExceptionAction<SignedContent>() {

            public SignedContent run() throws Exception {
                return getSignedContent(generation.getBundleFile().getBaseFile());
            }
        });
    } catch (PrivilegedActionException e) {
        if (e.getException() instanceof IOException)
            throw (IOException) e.getException();
        if (e.getException() instanceof InvalidKeyException)
            throw (InvalidKeyException) e.getException();
        if (e.getException() instanceof SignatureException)
            throw (SignatureException) e.getException();
        if (e.getException() instanceof CertificateException)
            throw (CertificateException) e.getException();
        if (e.getException() instanceof NoSuchAlgorithmException)
            throw (NoSuchAlgorithmException) e.getException();
        if (e.getException() instanceof NoSuchProviderException)
            throw (NoSuchProviderException) e.getException();
        // $NON-NLS-1$
        throw new RuntimeException("Unknown error.", e.getException());
    }
}
Also used : StorageHookImpl(org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl) CertificateException(java.security.cert.CertificateException) IOException(java.io.IOException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) CertificateException(java.security.cert.CertificateException) Generation(org.eclipse.osgi.storage.BundleInfo.Generation)

Example 3 with StorageHookImpl

use of org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl in project rt.equinox.framework by eclipse.

the class TrustEngineListener method getSignedContent.

private SignedContentImpl getSignedContent(Bundle bundle) {
    Generation generation = (Generation) ((EquinoxBundle) bundle).getModule().getCurrentRevision().getRevisionInfo();
    StorageHookImpl hook = generation.getStorageHook(SignedStorageHook.class);
    return hook != null ? hook.signedContent : null;
}
Also used : Generation(org.eclipse.osgi.storage.BundleInfo.Generation) StorageHookImpl(org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl)

Aggregations

StorageHookImpl (org.eclipse.osgi.internal.signedcontent.SignedStorageHook.StorageHookImpl)3 IOException (java.io.IOException)2 Generation (org.eclipse.osgi.storage.BundleInfo.Generation)2 MalformedURLException (java.net.MalformedURLException)1 CertificateException (java.security.cert.CertificateException)1