Search in sources :

Example 1 with SignerInfo

use of org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo in project felix by apache.

the class DPSignerTest method testSignArtifactsOk.

@Test
public void testSignArtifactsOk() throws Exception {
    URL dpProps = getClass().getResource("/dp.properties");
    assertNotNull(dpProps);
    DeploymentPackageBuilder builder = DeploymentPackageBuilder.create("dpSignerTest1", "1.0.0");
    builder.add(builder.createLocalizationResource().setUrl(dpProps).setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setFilename("dp.properties"));
    SignerInfo signerInfo = CertificateUtil.createSelfSignedCert("CN=testCert", KeyType.RSA);
    DPSigner signer = new DPSigner();
    byte[] rawData;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        signer.sign(builder, signerInfo.getPrivate(), signerInfo.getCert(), baos);
        rawData = baos.toByteArray();
    }
    try (ByteArrayInputStream bais = new ByteArrayInputStream(rawData);
        JarInputStream jis = new JarInputStream(bais, true)) {
        JarEntry entry;
        while ((entry = jis.getNextJarEntry()) != null) {
            assertNotNull(entry);
            jis.closeEntry();
        }
        assertNotNull(jis.getManifest());
    }
}
Also used : SignerInfo(org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo) ByteArrayInputStream(java.io.ByteArrayInputStream) JarInputStream(java.util.jar.JarInputStream) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) DPSigner(org.apache.felix.deploymentadmin.itest.util.DPSigner) ByteArrayOutputStream(java.io.ByteArrayOutputStream) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) Test(org.junit.Test)

Example 2 with SignerInfo

use of org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo in project felix by apache.

the class InstallDeploymentPackageTest method testInstallDeploymentPackageWithLocalizationAndSignatureFilesOk.

/**
 * FELIX-518 - Test that DP with localization and signature files are properly deployed.
 */
@Test
public void testInstallDeploymentPackageWithLocalizationAndSignatureFilesOk() throws Exception {
    URL dpProps = getClass().getResource("/dp.properties");
    assertNotNull(dpProps);
    SignerInfo signer = createSelfSignedCert("CN=dpTest", KeyType.EC);
    DeploymentPackageBuilder dpBuilder = createNewDeploymentPackageBuilder("1.0.0");
    dpBuilder.signOutput(signer.getPrivate(), signer.getCert()).add(dpBuilder.createLocalizationResource().setUrl(dpProps).setResourceProcessorPID(TEST_FAILING_BUNDLE_RP1).setFilename("dp.properties")).add(dpBuilder.createResourceProcessorResource().setUrl(getTestBundleURL("rp1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle1"))).add(dpBuilder.createBundleResource().setUrl(getTestBundleURL("bundle2")));
    // should succeed.
    installDeploymentPackage(dpBuilder);
    assertBundleExists("testbundles.bundle1", "1.0.0");
    assertBundleExists("testbundles.bundle2", "1.0.0");
    assertBundleExists("testbundles.rp1", "1.0.0");
}
Also used : SignerInfo(org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo) DeploymentPackageBuilder(org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder) URL(java.net.URL) Test(org.junit.Test)

Aggregations

URL (java.net.URL)2 SignerInfo (org.apache.felix.deploymentadmin.itest.util.CertificateUtil.SignerInfo)2 DeploymentPackageBuilder (org.apache.felix.deploymentadmin.itest.util.DeploymentPackageBuilder)2 Test (org.junit.Test)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 JarEntry (java.util.jar.JarEntry)1 JarInputStream (java.util.jar.JarInputStream)1 DPSigner (org.apache.felix.deploymentadmin.itest.util.DPSigner)1