use of org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider in project wildfly by wildfly.
the class ControllerServlet method init.
public void init(ServletConfig config) throws ServletException {
try {
final KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
try (InputStream in = Files.newInputStream(Paths.get("target/jcetest.keystore"))) {
keyStore.load(in, "password".toCharArray());
}
final X509Certificate testCertificate = (X509Certificate) keyStore.getCertificate("test");
assert testCertificate != null;
// the three musketeers who are guarding the crown are hardcoded in jse.jar (JarVerifier)
// sun.security.validator.SimpleValidator
final Object validator = get("javax.crypto.JarVerifier", "providerValidator", Object.class);
get(validator, "trustedX500Principals", Map.class).put(testCertificate.getIssuerX500Principal(), Arrays.asList(testCertificate));
} catch (ClassNotFoundException e) {
throw new ServletException("This requires being run on Oracle JDK 7.", e);
} catch (Exception e) {
throw new ServletException("Cannot install the certificate to the validator.", e);
}
java.security.Security.addProvider(new DummyProvider());
}
use of org.jboss.as.test.integration.deployment.jcedeployment.provider.DummyProvider in project wildfly by wildfly.
the class JCETestCase method deployment.
@Deployment
public static Archive<?> deployment() throws Exception {
final JavaArchive jce = ShrinkWrap.create(JavaArchive.class, "jcetest.jar").addPackage(DummyProvider.class.getPackage());
final File jceJar = new File("target/jcetest.jar");
jce.as(ZipExporter.class).exportTo(jceJar, true);
final File signedJceJar = new File("target/jcetestsigned.jar");
JavaArchive signedJce;
if (isJCETestable()) {
// see genkey-jcetest-keystore in pom.xml for the keystore creation
final JarSignerUtil signer = new JarSignerUtil(new File("target/jcetest.keystore"), "password", "password", /* alias */
"test");
signer.sign(jceJar, signedJceJar);
signer.verify(signedJceJar);
signedJce = ShrinkWrap.create(ZipImporter.class, "jcetestsigned.jar").importFrom(signedJceJar).as(JavaArchive.class);
} else {
log.trace("skipping the test since it can run on Oracle JDK only");
signedJce = jce;
}
final WebArchive war = ShrinkWrap.create(WebArchive.class, "test.war").addClasses(ControllerServlet.class);
final EnterpriseArchive ear = ShrinkWrap.create(EnterpriseArchive.class, "jcetest.ear").addAsLibrary(signedJce).addAsModule(war).addAsManifestResource(JCETestCase.class.getPackage(), "jboss-deployment-structure.xml", "jboss-deployment-structure.xml");
// ControllerServlet and DummyProvider need the following perms for their "dirty" game
ear.addAsManifestResource(createPermissionsXmlAsset(new FilePermission("target/jcetest.keystore", "read"), new RuntimePermission("accessDeclaredMembers"), new ReflectPermission("suppressAccessChecks"), new RuntimePermission("accessClassInPackage.sun.security.validator"), new SecurityPermission("putProviderProperty.DP"), new SecurityPermission("insertProvider"), new RuntimePermission("getProtectionDomain")), "permissions.xml");
return ear;
}
Aggregations