use of java.security.CodeSigner in project Bytecoder by mirkosertic.
the class BuiltinClassLoader method defineClass.
/**
* Defines the given binary class name to the VM, loading the class
* bytes from the given module.
*
* @return the resulting Class or {@code null} if an I/O error occurs
*/
private Class<?> defineClass(String cn, LoadedModule loadedModule) {
ModuleReference mref = loadedModule.mref();
ModuleReader reader = moduleReaderFor(mref);
try {
ByteBuffer bb = null;
URL csURL = null;
// locate class file, special handling for patched modules to
// avoid locating the resource twice
String rn = cn.replace('.', '/').concat(".class");
if (reader instanceof PatchedModuleReader) {
Resource r = ((PatchedModuleReader) reader).findResource(rn);
if (r != null) {
bb = r.getByteBuffer();
csURL = r.getCodeSourceURL();
}
} else {
bb = reader.read(rn).orElse(null);
csURL = loadedModule.codeSourceURL();
}
if (bb == null) {
// class not found
return null;
}
CodeSource cs = new CodeSource(csURL, (CodeSigner[]) null);
try {
// define class to VM
return defineClass(cn, bb, cs);
} finally {
reader.release(bb);
}
} catch (IOException ioe) {
// TBD on how I/O errors should be propagated
return null;
}
}
use of java.security.CodeSigner in project LanternServer by LanternPowered.
the class LanternClassLoader method getCodeSource.
private CodeSource getCodeSource(String name, URL url) {
// Classes without a jar protocol, nope
if (!url.getProtocol().equalsIgnoreCase("jar")) {
return null;
}
final String u = url.toString();
final String s = "jar:";
if (!u.startsWith(s)) {
return null;
}
// The url should end with the following string, this
// is pointing to a class inside a jar
final String e = "!/" + name.replace('.', '/') + ".class";
if (!u.endsWith(e)) {
return null;
}
try {
url = new URL(u.substring(s.length(), u.length() - e.length()));
} catch (MalformedURLException ex) {
// Malformed, just fail
return null;
}
// Create the code source, no code signers since it's not required
return new CodeSource(url, (CodeSigner[]) null);
}
use of java.security.CodeSigner in project airavata by apache.
the class JythonClassLoader method findClassFromURL.
private Class findClassFromURL(String name, URL url, JarFile jarFile) throws ClassNotFoundException {
// logger.entering(new Object[] { name, url, jarFile });
String classPath = name.replace('.', '/').concat(".class");
try {
byte[] classBytes;
CodeSource codeSource = null;
if (jarFile == null) {
// It's a local directory
String dirPath = URLDecoder.decode(url.getPath(), "UTF-8");
File classFile = new File(dirPath, classPath);
classBytes = IOUtil.readToByteArray(classFile);
} else {
// A Jar file
JarEntry jarEntry = jarFile.getJarEntry(classPath);
CodeSigner[] codeSigners = jarEntry.getCodeSigners();
// logger.info("codeSigners: " + codeSigners);
if (codeSigners != null) {
// Somehow it's null.
for (CodeSigner signer : codeSigners) {
logger.debug("signer: " + signer);
}
}
codeSource = new CodeSource(this.xbayaURL, codeSigners);
InputStream classInputStream = jarFile.getInputStream(jarEntry);
classBytes = IOUtil.readToByteArray(classInputStream);
}
Class<?> klass = defineClass(name, classBytes, 0, classBytes.length, codeSource);
this.classes.put(name, klass);
return klass;
} catch (IOException e) {
logger.error(e.getMessage(), e);
throw new ClassNotFoundException();
}
}
use of java.security.CodeSigner in project j2objc by google.
the class CodeSignerTest method testCodeSigner_02.
/**
* Not null parameters
*/
public final void testCodeSigner_02() {
try {
CodeSigner cs = new CodeSigner(cpath, ts);
assertNotNull(cs);
} catch (Exception e) {
fail("Unexpected exception");
}
}
use of java.security.CodeSigner in project j2objc by google.
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()));
}
Aggregations