Search in sources :

Example 81 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DPSigner method createSignatureFile.

private Manifest createSignatureFile(Manifest manifest) throws IOException {
    byte[] mfRawBytes;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        manifest.write(baos);
        mfRawBytes = baos.toByteArray();
    }
    Manifest sf = new Manifest();
    Attributes sfMain = sf.getMainAttributes();
    Map<String, Attributes> sfEntries = sf.getEntries();
    sfMain.put(Attributes.Name.SIGNATURE_VERSION, "1.0");
    sfMain.putValue("Created-By", "Apache Felix DeploymentPackageBuilder");
    sfMain.putValue(m_digestAlg + "-Digest-Manifest", calculateDigest(mfRawBytes));
    sfMain.putValue(m_digestAlg + "-Digest-Manifest-Main-Attribute", calculateDigest(getRawBytesMainAttributes(manifest)));
    for (Entry<String, Attributes> entry : manifest.getEntries().entrySet()) {
        String name = entry.getKey();
        byte[] entryData = getRawBytesAttributes(entry.getValue());
        sfEntries.put(name, getDigestAttributes(entryData));
    }
    return sf;
}
Also used : Attributes(java.util.jar.Attributes) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Example 82 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DPSigner method writeSignedManifest.

public void writeSignedManifest(Manifest manifest, ZipOutputStream zos, PrivateKey privKey, X509Certificate cert) throws Exception {
    zos.putNextEntry(new ZipEntry(JarFile.MANIFEST_NAME));
    manifest.write(zos);
    zos.closeEntry();
    long now = System.currentTimeMillis();
    // Determine the signature-file manifest...
    Manifest sf = createSignatureFile(manifest);
    byte[] sfRawBytes;
    try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
        sf.write(baos);
        sfRawBytes = baos.toByteArray();
    }
    ZipEntry sigFileEntry = new ZipEntry(m_baseName.concat(".SF"));
    sigFileEntry.setTime(now);
    zos.putNextEntry(sigFileEntry);
    // Write the actual entry data...
    zos.write(sfRawBytes, 0, sfRawBytes.length);
    zos.closeEntry();
    // Create a PKCS#7 signature...
    byte[] encoded = calculateSignatureBlock(privKey, cert, sfRawBytes);
    ZipEntry blockFileEntry = new ZipEntry(m_baseName.concat(getBlockFileExtension(privKey)));
    blockFileEntry.setTime(now);
    zos.putNextEntry(blockFileEntry);
    zos.write(encoded);
    zos.closeEntry();
}
Also used : ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Manifest(java.util.jar.Manifest)

Example 83 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DeploymentPackageBuilder method createManifest.

private Manifest createManifest(List<ArtifactData> files) throws Exception {
    Manifest manifest = new Manifest();
    Attributes main = manifest.getMainAttributes();
    main.putValue("Manifest-Version", "1.0");
    main.putValue("DeploymentPackage-SymbolicName", m_symbolicName);
    main.putValue("DeploymentPackage-Version", m_version);
    if ((m_fixPackageVersion != null) && !"".equals(m_fixPackageVersion)) {
        main.putValue("DeploymentPackage-FixPack", m_fixPackageVersion);
    }
    Map<String, Attributes> entries = manifest.getEntries();
    for (ArtifactData file : files) {
        Attributes attrs = new Attributes();
        attrs.putValue("Name", file.getFilename());
        if (file.isBundle()) {
            attrs.putValue("Bundle-SymbolicName", file.getSymbolicName());
            attrs.putValue("Bundle-Version", file.getVersion());
            if (file.isCustomizer()) {
                attrs.putValue("DeploymentPackage-Customizer", "true");
                attrs.putValue("Deployment-ProvidesResourceProcessor", file.getProcessorPid());
            }
        } else if (file.isResourceProcessorNeeded()) {
            attrs.putValue("Resource-Processor", file.getProcessorPid());
        }
        if (file.isMissing()) {
            attrs.putValue("DeploymentPackage-Missing", "true");
        }
        if (isAddSignatures()) {
            m_signer.addDigestAttribute(attrs, file);
        }
        entries.put(file.getFilename(), attrs);
    }
    return manifest;
}
Also used : Attributes(java.util.jar.Attributes) Manifest(java.util.jar.Manifest)

Example 84 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class DeploymentPackageBuilder method generate.

/**
 * Generates a deployment package and streams it to the output stream you provide. Before
 * it starts generating, it will first validate that you have actually specified a
 * resource processor for each type of artifact you provided.
 *
 * @param output the output stream to write to
 * @throws Exception if something goes wrong while validating or generating
 */
public void generate(OutputStream output) throws Exception {
    Manifest m = createManifest();
    List<ArtifactData> artifacts = getArtifactList();
    writeStream(artifacts, m, output);
}
Also used : Manifest(java.util.jar.Manifest)

Example 85 with Manifest

use of java.util.jar.Manifest in project felix by apache.

the class Utils method readManifest.

public static Manifest readManifest(File manifestFile) throws IOException {
    InputStream is = null;
    Manifest mf = null;
    try {
        is = new GZIPInputStream(new FileInputStream(manifestFile));
        mf = new Manifest(is);
    } finally {
        closeSilently(is);
    }
    return mf;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) GZIPInputStream(java.util.zip.GZIPInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) Manifest(java.util.jar.Manifest) FileInputStream(java.io.FileInputStream)

Aggregations

Manifest (java.util.jar.Manifest)1226 Attributes (java.util.jar.Attributes)392 File (java.io.File)391 IOException (java.io.IOException)336 JarFile (java.util.jar.JarFile)231 InputStream (java.io.InputStream)184 URL (java.net.URL)177 JarOutputStream (java.util.jar.JarOutputStream)145 FileOutputStream (java.io.FileOutputStream)131 Test (org.junit.Test)129 FileInputStream (java.io.FileInputStream)119 Jar (aQute.bnd.osgi.Jar)105 JarInputStream (java.util.jar.JarInputStream)104 Builder (aQute.bnd.osgi.Builder)99 ZipEntry (java.util.zip.ZipEntry)99 ByteArrayOutputStream (java.io.ByteArrayOutputStream)96 JarEntry (java.util.jar.JarEntry)96 ByteArrayInputStream (java.io.ByteArrayInputStream)93 ArrayList (java.util.ArrayList)83 Map (java.util.Map)83