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;
}
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;
}
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;
}
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;
}
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;
}
Aggregations