From 8550f486b4116a9bf96eb547314fd0ac1c0c763c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Tue, 10 Oct 2017 23:25:17 +0200 Subject: [PATCH] reset file digest algo to MD5, add private key hash algo paramater --- .../org/xbib/gradle/plugin/rpm/Rpm.groovy | 21 +++++++------ .../gradle/plugin/rpm/RpmCopyAction.groovy | 1 + .../xbib/gradle/plugin/rpm/RpmPlugin.groovy | 2 +- .../rpm/SystemPackagingExtension.groovy | 3 ++ gradle.properties | 2 +- .../main/java/org/xbib/rpm/RpmBuilder.java | 31 +++++++++++++------ 6 files changed, 39 insertions(+), 21 deletions(-) diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/Rpm.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/Rpm.groovy index 7c710bc..1635b4a 100755 --- a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/Rpm.groovy +++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/Rpm.groovy @@ -113,55 +113,55 @@ class Rpm extends AbstractArchiveTask { @Input @Optional List getAllConfigurationPaths() { - return getConfigurationPaths() + (projectPackagingExtension?.getConfigurationPaths()?: []) + getConfigurationPaths() + (projectPackagingExtension?.getConfigurationPaths()?: []) } @Input @Optional List getAllPreInstallCommands() { - return getPreInstallCommands() + (projectPackagingExtension?.getPreInstallCommands() ?: []) + getPreInstallCommands() + (projectPackagingExtension?.getPreInstallCommands() ?: []) } @Input @Optional List getAllPostInstallCommands() { - return getPostInstallCommands() + (projectPackagingExtension?.getPostInstallCommands() ?: []) + getPostInstallCommands() + (projectPackagingExtension?.getPostInstallCommands() ?: []) } @Input @Optional List getAllPreUninstallCommands() { - return getPreUninstallCommands() + (projectPackagingExtension?.getPreUninstallCommands() ?: []) + getPreUninstallCommands() + (projectPackagingExtension?.getPreUninstallCommands() ?: []) } @Input @Optional List getAllPostUninstallCommands() { - return getPostUninstallCommands() + (projectPackagingExtension?.getPostUninstallCommands() ?: []) + getPostUninstallCommands() + (projectPackagingExtension?.getPostUninstallCommands() ?: []) } @Input @Optional List getAllPreTransCommands() { - return getPreTransCommands() + projectPackagingExtension?.getPreTransCommands() + getPreTransCommands() + projectPackagingExtension?.getPreTransCommands() } @Input @Optional List getAllPostTransCommands() { - return getPostTransCommands() + projectPackagingExtension?.getPostTransCommands() + getPostTransCommands() + projectPackagingExtension?.getPostTransCommands() } @Input @Optional List getAllCommonCommands() { - return getCommonCommands() + projectPackagingExtension?.getCommonCommands() + getCommonCommands() + projectPackagingExtension?.getCommonCommands() } @Input @Optional List getAllSupplementaryControlFiles() { - return getSupplementaryControlFiles() + (projectPackagingExtension?.getSupplementaryControlFiles() ?: []) + getSupplementaryControlFiles() + (projectPackagingExtension?.getSupplementaryControlFiles() ?: []) } @Input @@ -263,6 +263,9 @@ class Rpm extends AbstractArchiveTask { mapping.map('signingKeyRing', { projectPackagingExtension?.getSigningKeyRing() }) + mapping.map('signingKeyHashAlgo', { + projectPackagingExtension?.getSigningKeyHashAlgo() + }) mapping.map('user', { projectPackagingExtension?.getUser()?:getPackager() }) diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmCopyAction.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmCopyAction.groovy index c319230..2982b29 100755 --- a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmCopyAction.groovy +++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmCopyAction.groovy @@ -181,6 +181,7 @@ class RpmCopyAction implements CopyAction { builder.setPrivateKeyId task.getSigningKeyId() builder.setPrivateKeyPassphrase task.getSigningKeyPassphrase() builder.setPrivateKeyRing task.getSigningKeyRing() + builder.setPrivateKeyHashAlgo task.getSigningKeyHashAlgo() } String sourcePackage = task.sourcePackage if (!sourcePackage) { diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmPlugin.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmPlugin.groovy index e3d11f3..3e5ba41 100644 --- a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmPlugin.groovy +++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/RpmPlugin.groovy @@ -24,7 +24,7 @@ class RpmPlugin implements Plugin { project.ext.Rpm = Rpm.class RpmBuilder.metaClass.getDefaultSourcePackage() { - format.getLead().getName() + "-src.rpm" + format.getLead().getName() + ".src.rpm" } project.tasks.withType(Rpm) { Rpm task -> diff --git a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/SystemPackagingExtension.groovy b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/SystemPackagingExtension.groovy index 0d5faf5..15031ab 100755 --- a/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/SystemPackagingExtension.groovy +++ b/gradle-plugin-rpm/src/main/groovy/org/xbib/gradle/plugin/rpm/SystemPackagingExtension.groovy @@ -36,6 +36,9 @@ class SystemPackagingExtension { @Input @Optional String signingKeyId + @Input @Optional + String signingKeyHashAlgo + @Input @Optional String user diff --git a/gradle.properties b/gradle.properties index 51dad86..702cc1a 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ group = org.xbib name = rpm -version = 1.0.0 +version = 1.0.1 bouncycastle.version = 1.57 xbib-archive.version = 0.0.1 diff --git a/rpm-core/src/main/java/org/xbib/rpm/RpmBuilder.java b/rpm-core/src/main/java/org/xbib/rpm/RpmBuilder.java index e05ed7b..a113fc6 100644 --- a/rpm-core/src/main/java/org/xbib/rpm/RpmBuilder.java +++ b/rpm-core/src/main/java/org/xbib/rpm/RpmBuilder.java @@ -95,25 +95,25 @@ public class RpmBuilder { private String privateKeyPassphrase; - private int triggerCounter = 0; + private HashAlgo privateKeyHashAlgo; - private HashAlgo hashAlgo; + private int triggerCounter = 0; private CompressionType compressionType; private String packageName; public RpmBuilder() { - this(HashAlgo.SHA256, CompressionType.GZIP); + this(HashAlgo.SHA1, CompressionType.GZIP); } /** * 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 */ - public RpmBuilder(HashAlgo hashAlgo, CompressionType compressionType) { - this.hashAlgo = hashAlgo; + public RpmBuilder(HashAlgo privateKeyHashAlgo, CompressionType compressionType) { + this.privateKeyHashAlgo = privateKeyHashAlgo; this.compressionType = compressionType; format.getHeader().createEntry(HeaderTag.HEADERI18NTABLE, "C"); format.getHeader().createEntry(HeaderTag.BUILDTIME, (int) (System.currentTimeMillis() / 1000)); @@ -1452,6 +1452,17 @@ public class RpmBuilder { 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. * @@ -1538,8 +1549,8 @@ public class RpmBuilder { triggerscriptprogs.toArray(new String[triggerscriptprogs.size()])); } if (contents.size() > 0) { - format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, hashAlgo.num()); - format.getHeader().createEntry(HeaderTag.FILEDIGESTS, contents.getDigests(hashAlgo)); + format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, HashAlgo.MD5.num()); + format.getHeader().createEntry(HeaderTag.FILEDIGESTS, contents.getDigests(HashAlgo.MD5)); format.getHeader().createEntry(HeaderTag.FILESIZES, contents.getSizes()); format.getHeader().createEntry(HeaderTag.FILEMODES, contents.getModes()); format.getHeader().createEntry(HeaderTag.FILERDEVS, contents.getRdevs()); @@ -1566,7 +1577,7 @@ public class RpmBuilder { shaEntry.setSize(SHASIZE); SignatureGenerator signatureGenerator = new SignatureGenerator(privateKeyRing, privateKeyId, privateKeyPassphrase); - signatureGenerator.prepare(format.getSignatureHeader(), hashAlgo); + signatureGenerator.prepare(format.getSignatureHeader(), privateKeyHashAlgo); format.getLead().write(channel); SpecEntry signatureEntry = (SpecEntry) format.getSignatureHeader().addEntry(SignatureTag.SIGNATURES, 16); @@ -1576,7 +1587,7 @@ public class RpmBuilder { ChannelWrapper.Key sigsizekey = output.start(); ChannelWrapper.Key shakey = signatureGenerator.startDigest(output, "SHA"); ChannelWrapper.Key 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 // which was used for the calculation of a signature. This data shall be preserved or any header-only signature // will be invalidated.