Search in sources :

Example 1 with BundleEntry

use of org.eclipse.osgi.storage.bundlefile.BundleEntry in project rt.equinox.framework by eclipse.

the class SignatureBlockProcessor method process.

public SignedContentImpl process() throws IOException, InvalidKeyException, SignatureException, CertificateException, NoSuchAlgorithmException, NoSuchProviderException {
    BundleFile wrappedBundleFile = signedBundle.getBundleFile();
    BundleEntry be = wrappedBundleFile.getEntry(META_INF_MANIFEST_MF);
    if (be == null)
        return createUnsignedContent();
    // read all the signature block file names into a list
    Enumeration<String> en = wrappedBundleFile.getEntryPaths(META_INF);
    List<String> signers = new ArrayList<>(2);
    while (en.hasMoreElements()) {
        String name = en.nextElement();
        if ((name.endsWith(DOT_DSA) || name.endsWith(DOT_RSA)) && name.indexOf('/') == name.lastIndexOf('/'))
            signers.add(name);
    }
    // this means the jar is not signed
    if (signers.size() == 0)
        return createUnsignedContent();
    byte[] manifestBytes = readIntoArray(be);
    for (Iterator<String> iSigners = signers.iterator(); iSigners.hasNext(); ) processSigner(wrappedBundleFile, manifestBytes, iSigners.next());
    // done processing now create a SingedContent to return
    SignerInfo[] allSigners = signerInfos.toArray(new SignerInfo[signerInfos.size()]);
    for (Iterator<Map.Entry<String, Object>> iResults = contentMDResults.entrySet().iterator(); iResults.hasNext(); ) {
        Map.Entry<String, Object> entry = iResults.next();
        @SuppressWarnings("unchecked") List<Object>[] value = (List<Object>[]) entry.getValue();
        SignerInfo[] entrySigners = value[0].toArray(new SignerInfo[value[0].size()]);
        byte[][] entryResults = value[1].toArray(new byte[value[1].size()][]);
        entry.setValue(new Object[] { entrySigners, entryResults });
    }
    SignedContentImpl result = new SignedContentImpl(allSigners, (supportFlags & SignedBundleHook.VERIFY_RUNTIME) != 0 ? contentMDResults : null);
    result.setContent(signedBundle);
    result.setTSASignerInfos(tsaSignerInfos);
    return result;
}
Also used : BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry) SignerInfo(org.eclipse.osgi.signedcontent.SignerInfo) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry) FrameworkLogEntry(org.eclipse.osgi.framework.log.FrameworkLogEntry) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile)

Example 2 with BundleEntry

use of org.eclipse.osgi.storage.bundlefile.BundleEntry in project rt.equinox.framework by eclipse.

the class BundleInfo method hasPackageInfo.

// Used to check the bundle manifest file for any package information.
// This is used when '.' is on the Bundle-ClassPath to prevent reading
// the bundle manifest for package information when loading classes.
static boolean hasPackageInfo(BundleFile bundleFile) {
    if (bundleFile == null) {
        return false;
    }
    BundleEntry manifest = bundleFile.getEntry(OSGI_BUNDLE_MANIFEST);
    if (manifest == null) {
        return false;
    }
    BufferedReader br = null;
    try {
        br = new BufferedReader(new InputStreamReader(manifest.getInputStream()));
        String line;
        while ((line = br.readLine()) != null) {
            if (line.length() < 20)
                continue;
            switch(line.charAt(0)) {
                case 'S':
                    if (line.charAt(1) == 'p')
                        if (// $NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
                        line.startsWith("Specification-Title: ") || line.startsWith("Specification-Version: ") || line.startsWith("Specification-Vendor: "))
                            return true;
                    break;
                case 'I':
                    if (// $NON-NLS-1$ //$NON-NLS-2$//$NON-NLS-3$
                    line.startsWith("Implementation-Title: ") || line.startsWith("Implementation-Version: ") || line.startsWith("Implementation-Vendor: "))
                        return true;
                    break;
            }
        }
    } catch (IOException ioe) {
    // do nothing
    } finally {
        if (br != null)
            try {
                br.close();
            } catch (IOException e) {
            // do nothing
            }
    }
    return false;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry)

Example 3 with BundleEntry

use of org.eclipse.osgi.storage.bundlefile.BundleEntry in project rt.equinox.framework by eclipse.

the class Handler method findBundleEntry.

protected BundleEntry findBundleEntry(URL url, Module module) throws IOException {
    ModuleRevision revision = module.getCurrentRevision();
    BundleInfo.Generation revisionInfo = (BundleInfo.Generation) revision.getRevisionInfo();
    BundleEntry entry = revisionInfo == null ? null : revisionInfo.getBundleFile().getEntry(url.getPath());
    if (entry == null) {
        String path = url.getPath();
        if (revisionInfo != null && (path.indexOf('%') >= 0 || path.indexOf('+') >= 0)) {
            entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, true));
            if (entry != null) {
                return entry;
            }
            entry = revisionInfo.getBundleFile().getEntry(LocationHelper.decode(path, false));
            if (entry != null) {
                return entry;
            }
        }
        throw new FileNotFoundException(url.getPath());
    }
    return entry;
}
Also used : BundleInfo(org.eclipse.osgi.storage.BundleInfo) FileNotFoundException(java.io.FileNotFoundException) ModuleRevision(org.eclipse.osgi.container.ModuleRevision) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry)

Example 4 with BundleEntry

use of org.eclipse.osgi.storage.bundlefile.BundleEntry in project rt.equinox.framework by eclipse.

the class ClasspathManager method findLocalEntry.

/**
 * Finds a local entry by searching the ClasspathEntry with the specified
 * class path index.
 * @param path the requested entry path.
 * @param classPathIndex the index of the ClasspathEntry to search
 * @return the requested entry or null if the entry does not exist
 */
public BundleEntry findLocalEntry(String path, int classPathIndex) {
    BundleEntry result = null;
    int curIndex = 0;
    for (int i = 0; i < entries.length; i++) {
        if (entries[i] != null) {
            result = entries[i].findEntry(path);
            if (result != null && (classPathIndex == -1 || classPathIndex == curIndex))
                return result;
        }
        curIndex++;
    }
    // look in fragments
    FragmentClasspath[] currentFragments = getFragmentClasspaths();
    for (int i = 0; i < currentFragments.length; i++) {
        ClasspathEntry[] fragEntries = currentFragments[i].getEntries();
        for (int j = 0; j < fragEntries.length; j++) {
            result = fragEntries[j].findEntry(path);
            if (result != null && (classPathIndex == -1 || classPathIndex == curIndex))
                return result;
            curIndex++;
        }
    }
    return null;
}
Also used : BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry)

Example 5 with BundleEntry

use of org.eclipse.osgi.storage.bundlefile.BundleEntry in project rt.equinox.framework by eclipse.

the class ClasspathManager method getClasspath.

/**
 * Creates a new ClasspathEntry object for the requested classpath if the source exists.
 * @param cp the requested classpath.
 * @param cpGeneration the source generation to search for the classpath
 * @return a new ClasspathEntry for the requested classpath or null if the source does not exist.
 */
public ClasspathEntry getClasspath(String cp, Generation cpGeneration) {
    BundleFile bundlefile = null;
    File file;
    BundleEntry cpEntry = cpGeneration.getBundleFile().getEntry(cp);
    // check for internal library directories in a bundle jar file
    if (// $NON-NLS-1$
    cpEntry != null && cpEntry.getName().endsWith("/"))
        bundlefile = createBundleFile(cp, cpGeneration);
    else // check for internal library jars
    if ((file = cpGeneration.getBundleFile().getFile(cp, false)) != null)
        bundlefile = createBundleFile(file, cpGeneration);
    if (bundlefile != null)
        return createClassPathEntry(bundlefile, cpGeneration);
    return null;
}
Also used : BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) BundleFile(org.eclipse.osgi.storage.bundlefile.BundleFile) File(java.io.File) BundleEntry(org.eclipse.osgi.storage.bundlefile.BundleEntry)

Aggregations

BundleEntry (org.eclipse.osgi.storage.bundlefile.BundleEntry)11 BundleFile (org.eclipse.osgi.storage.bundlefile.BundleFile)5 IOException (java.io.IOException)3 File (java.io.File)2 FileNotFoundException (java.io.FileNotFoundException)2 ModuleRevision (org.eclipse.osgi.container.ModuleRevision)2 BufferedInputStream (java.io.BufferedInputStream)1 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DataInputStream (java.io.DataInputStream)1 FileInputStream (java.io.FileInputStream)1 InputStream (java.io.InputStream)1 InputStreamReader (java.io.InputStreamReader)1 Certificate (java.security.cert.Certificate)1 ArrayList (java.util.ArrayList)1 ModuleWiring (org.eclipse.osgi.container.ModuleWiring)1 FrameworkLogEntry (org.eclipse.osgi.framework.log.FrameworkLogEntry)1 ModuleClassLoader (org.eclipse.osgi.internal.loader.ModuleClassLoader)1 SignerInfo (org.eclipse.osgi.signedcontent.SignerInfo)1 BundleInfo (org.eclipse.osgi.storage.BundleInfo)1