reset file digest algo to MD5, add private key hash algo paramater

This commit is contained in:
Jörg Prante 2017-10-10 23:25:17 +02:00
parent f79133d8f5
commit 8550f486b4
6 changed files with 39 additions and 21 deletions

View file

@ -113,55 +113,55 @@ class Rpm extends AbstractArchiveTask {
@Input @Input
@Optional @Optional
List<Object> getAllConfigurationPaths() { List<Object> getAllConfigurationPaths() {
return getConfigurationPaths() + (projectPackagingExtension?.getConfigurationPaths()?: []) getConfigurationPaths() + (projectPackagingExtension?.getConfigurationPaths()?: [])
} }
@Input @Input
@Optional @Optional
List<Object> getAllPreInstallCommands() { List<Object> getAllPreInstallCommands() {
return getPreInstallCommands() + (projectPackagingExtension?.getPreInstallCommands() ?: []) getPreInstallCommands() + (projectPackagingExtension?.getPreInstallCommands() ?: [])
} }
@Input @Input
@Optional @Optional
List<Object> getAllPostInstallCommands() { List<Object> getAllPostInstallCommands() {
return getPostInstallCommands() + (projectPackagingExtension?.getPostInstallCommands() ?: []) getPostInstallCommands() + (projectPackagingExtension?.getPostInstallCommands() ?: [])
} }
@Input @Input
@Optional @Optional
List<Object> getAllPreUninstallCommands() { List<Object> getAllPreUninstallCommands() {
return getPreUninstallCommands() + (projectPackagingExtension?.getPreUninstallCommands() ?: []) getPreUninstallCommands() + (projectPackagingExtension?.getPreUninstallCommands() ?: [])
} }
@Input @Input
@Optional @Optional
List<Object> getAllPostUninstallCommands() { List<Object> getAllPostUninstallCommands() {
return getPostUninstallCommands() + (projectPackagingExtension?.getPostUninstallCommands() ?: []) getPostUninstallCommands() + (projectPackagingExtension?.getPostUninstallCommands() ?: [])
} }
@Input @Input
@Optional @Optional
List<Object> getAllPreTransCommands() { List<Object> getAllPreTransCommands() {
return getPreTransCommands() + projectPackagingExtension?.getPreTransCommands() getPreTransCommands() + projectPackagingExtension?.getPreTransCommands()
} }
@Input @Input
@Optional @Optional
List<Object> getAllPostTransCommands() { List<Object> getAllPostTransCommands() {
return getPostTransCommands() + projectPackagingExtension?.getPostTransCommands() getPostTransCommands() + projectPackagingExtension?.getPostTransCommands()
} }
@Input @Input
@Optional @Optional
List<Object> getAllCommonCommands() { List<Object> getAllCommonCommands() {
return getCommonCommands() + projectPackagingExtension?.getCommonCommands() getCommonCommands() + projectPackagingExtension?.getCommonCommands()
} }
@Input @Input
@Optional @Optional
List<Object> getAllSupplementaryControlFiles() { List<Object> getAllSupplementaryControlFiles() {
return getSupplementaryControlFiles() + (projectPackagingExtension?.getSupplementaryControlFiles() ?: []) getSupplementaryControlFiles() + (projectPackagingExtension?.getSupplementaryControlFiles() ?: [])
} }
@Input @Input
@ -263,6 +263,9 @@ class Rpm extends AbstractArchiveTask {
mapping.map('signingKeyRing', { mapping.map('signingKeyRing', {
projectPackagingExtension?.getSigningKeyRing() projectPackagingExtension?.getSigningKeyRing()
}) })
mapping.map('signingKeyHashAlgo', {
projectPackagingExtension?.getSigningKeyHashAlgo()
})
mapping.map('user', { mapping.map('user', {
projectPackagingExtension?.getUser()?:getPackager() projectPackagingExtension?.getUser()?:getPackager()
}) })

View file

@ -181,6 +181,7 @@ class RpmCopyAction implements CopyAction {
builder.setPrivateKeyId task.getSigningKeyId() builder.setPrivateKeyId task.getSigningKeyId()
builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase() builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase()
builder.setPrivateKeyRing task.getSigningKeyRing() builder.setPrivateKeyRing task.getSigningKeyRing()
builder.setPrivateKeyHashAlgo task.getSigningKeyHashAlgo()
} }
String sourcePackage = task.sourcePackage String sourcePackage = task.sourcePackage
if (!sourcePackage) { if (!sourcePackage) {

View file

@ -24,7 +24,7 @@ class RpmPlugin implements Plugin<Project> {
project.ext.Rpm = Rpm.class project.ext.Rpm = Rpm.class
RpmBuilder.metaClass.getDefaultSourcePackage() { RpmBuilder.metaClass.getDefaultSourcePackage() {
format.getLead().getName() + "-src.rpm" format.getLead().getName() + ".src.rpm"
} }
project.tasks.withType(Rpm) { Rpm task -> project.tasks.withType(Rpm) { Rpm task ->

View file

@ -36,6 +36,9 @@ class SystemPackagingExtension {
@Input @Optional @Input @Optional
String signingKeyId String signingKeyId
@Input @Optional
String signingKeyHashAlgo
@Input @Optional @Input @Optional
String user String user

View file

@ -1,6 +1,6 @@
group = org.xbib group = org.xbib
name = rpm name = rpm
version = 1.0.0 version = 1.0.1
bouncycastle.version = 1.57 bouncycastle.version = 1.57
xbib-archive.version = 0.0.1 xbib-archive.version = 0.0.1

View file

@ -95,25 +95,25 @@ public class RpmBuilder {
private String privateKeyPassphrase; private String privateKeyPassphrase;
private int triggerCounter = 0; private HashAlgo privateKeyHashAlgo;
private HashAlgo hashAlgo; private int triggerCounter = 0;
private CompressionType compressionType; private CompressionType compressionType;
private String packageName; private String packageName;
public RpmBuilder() { public RpmBuilder() {
this(HashAlgo.SHA256, CompressionType.GZIP); this(HashAlgo.SHA1, CompressionType.GZIP);
} }
/** /**
* Initializes the builder and sets some required fields to known values. * Initializes the builder and sets some required fields to known values.
* @param hashAlgo the hash algo * @param privateKeyHashAlgo the hash algo
* @param compressionType compression type * @param compressionType compression type
*/ */
public RpmBuilder(HashAlgo hashAlgo, CompressionType compressionType) { public RpmBuilder(HashAlgo privateKeyHashAlgo, CompressionType compressionType) {
this.hashAlgo = hashAlgo; this.privateKeyHashAlgo = privateKeyHashAlgo;
this.compressionType = compressionType; this.compressionType = compressionType;
format.getHeader().createEntry(HeaderTag.HEADERI18NTABLE, "C"); format.getHeader().createEntry(HeaderTag.HEADERI18NTABLE, "C");
format.getHeader().createEntry(HeaderTag.BUILDTIME, (int) (System.currentTimeMillis() / 1000)); format.getHeader().createEntry(HeaderTag.BUILDTIME, (int) (System.currentTimeMillis() / 1000));
@ -1452,6 +1452,17 @@ public class RpmBuilder {
this.privateKeyPassphrase = privateKeyPassphrase; this.privateKeyPassphrase = privateKeyPassphrase;
} }
/**
* Hash algo for the private key.
*
* @param privateKeyHashAlgo the private key hash algo
*/
public void setPrivateKeyHashAlgo(String privateKeyHashAlgo) {
if (privateKeyHashAlgo != null) {
this.privateKeyHashAlgo = HashAlgo.valueOf(privateKeyHashAlgo);
}
}
/** /**
* Set RPM package name. * Set RPM package name.
* *
@ -1538,8 +1549,8 @@ public class RpmBuilder {
triggerscriptprogs.toArray(new String[triggerscriptprogs.size()])); triggerscriptprogs.toArray(new String[triggerscriptprogs.size()]));
} }
if (contents.size() > 0) { if (contents.size() > 0) {
format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, hashAlgo.num()); format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, HashAlgo.MD5.num());
format.getHeader().createEntry(HeaderTag.FILEDIGESTS, contents.getDigests(hashAlgo)); format.getHeader().createEntry(HeaderTag.FILEDIGESTS, contents.getDigests(HashAlgo.MD5));
format.getHeader().createEntry(HeaderTag.FILESIZES, contents.getSizes()); format.getHeader().createEntry(HeaderTag.FILESIZES, contents.getSizes());
format.getHeader().createEntry(HeaderTag.FILEMODES, contents.getModes()); format.getHeader().createEntry(HeaderTag.FILEMODES, contents.getModes());
format.getHeader().createEntry(HeaderTag.FILERDEVS, contents.getRdevs()); format.getHeader().createEntry(HeaderTag.FILERDEVS, contents.getRdevs());
@ -1566,7 +1577,7 @@ public class RpmBuilder {
shaEntry.setSize(SHASIZE); shaEntry.setSize(SHASIZE);
SignatureGenerator signatureGenerator = new SignatureGenerator(privateKeyRing, privateKeyId, privateKeyPassphrase); SignatureGenerator signatureGenerator = new SignatureGenerator(privateKeyRing, privateKeyId, privateKeyPassphrase);
signatureGenerator.prepare(format.getSignatureHeader(), hashAlgo); signatureGenerator.prepare(format.getSignatureHeader(), privateKeyHashAlgo);
format.getLead().write(channel); format.getLead().write(channel);
SpecEntry<byte[]> signatureEntry = SpecEntry<byte[]> signatureEntry =
(SpecEntry<byte[]>) format.getSignatureHeader().addEntry(SignatureTag.SIGNATURES, 16); (SpecEntry<byte[]>) format.getSignatureHeader().addEntry(SignatureTag.SIGNATURES, 16);
@ -1576,7 +1587,7 @@ public class RpmBuilder {
ChannelWrapper.Key<Integer> sigsizekey = output.start(); ChannelWrapper.Key<Integer> sigsizekey = output.start();
ChannelWrapper.Key<byte[]> shakey = signatureGenerator.startDigest(output, "SHA"); ChannelWrapper.Key<byte[]> shakey = signatureGenerator.startDigest(output, "SHA");
ChannelWrapper.Key<byte[]> md5key = signatureGenerator.startDigest(output, "MD5"); ChannelWrapper.Key<byte[]> md5key = signatureGenerator.startDigest(output, "MD5");
signatureGenerator.startBeforeHeader(output, hashAlgo); signatureGenerator.startBeforeHeader(output, privateKeyHashAlgo);
// Region concept. This tag contains an index record which specifies the portion of the Header Record // Region concept. This tag contains an index record which specifies the portion of the Header Record
// which was used for the calculation of a signature. This data shall be preserved or any header-only signature // which was used for the calculation of a signature. This data shall be preserved or any header-only signature
// will be invalidated. // will be invalidated.