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;
}
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();
}
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;
}
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);
}
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;
}
Aggregations