Search in sources :

Example 1 with DPSigner

use of org.apache.felix.deploymentadmin.itest.util.DPSigner 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)

Aggregations

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