fall back to MD5 file digests as default because rpm on RHEL9/F37 is annoying us

This commit is contained in:
Jörg Prante 2023-06-15 16:26:47 +02:00
parent f4ec0b1acb
commit d0bbd3b1a9
15 changed files with 110 additions and 40 deletions

View file

@ -6,7 +6,7 @@ plugins {
id "io.github.gradle-nexus.publish-plugin" version "1.3.0"
id "org.cyclonedx.bom" version "1.7.2"
id "com.github.spotbugs" version "5.0.13"
id "org.xbib.gradle.plugin.asciidoctor" version "2.5.2.2"
id "org.xbib.gradle.plugin.asciidoctor" version "3.0.0"
}
wrapper {
@ -34,5 +34,7 @@ subprojects {
apply from: rootProject.file('gradle/repositories/maven.gradle')
apply from: rootProject.file('gradle/compile/java.gradle')
apply from: rootProject.file('gradle/test/junit5.gradle')
apply from: rootProject.file('gradle/publishing/maven.gradle')
apply from: rootProject.file('gradle/publish/maven.gradle')
}
apply from: rootProject.file('gradle/publish/sonatype.gradle')
apply from: rootProject.file('gradle/publish/forgejo.gradle')

View file

@ -1,5 +1,5 @@
group = org.xbib
name = rpm
version = 3.0.0
version = 3.0.1
org.gradle.warning.mode = ALL

View file

@ -0,0 +1,16 @@
if (project.hasProperty('forgeJoToken')) {
publishing {
repositories {
maven {
url 'https://xbib.org/api/packages/joerg/maven'
credentials(HttpHeaderCredentials) {
name = "Authorization"
value = "token ${project.property('forgeJoToken')}"
}
authentication {
header(HttpHeaderAuthentication)
}
}
}
}
}

27
gradle/publish/ivy.gradle Normal file
View file

@ -0,0 +1,27 @@
apply plugin: 'ivy-publish'
publishing {
repositories {
ivy {
url = "https://xbib.org/repo"
}
}
publications {
ivy(IvyPublication) {
from components.java
descriptor {
license {
name = 'The Apache License, Version 2.0'
url = 'http://www.apache.org/licenses/LICENSE-2.0.txt'
}
author {
name = 'Jörg Prante'
url = 'http://example.com/users/jane'
}
descriptor.description {
text = rootProject.ext.description
}
}
}
}
}

View file

@ -0,0 +1,11 @@
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
nexusPublishing {
repositories {
sonatype {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}
}
}

View file

@ -1,11 +0,0 @@
if (project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')) {
apply plugin: 'io.codearte.nexus-staging'
nexusStaging {
username = project.property('ossrhUsername')
password = project.property('ossrhPassword')
packageGroup = "org.xbib"
}
}

View file

@ -15,4 +15,5 @@ module org.xbib.rpm {
requires transitive org.bouncycastle.provider;
requires org.xbib.io.compress.bzip;
requires org.xbib.io.compress.xz;
requires java.logging;
}

View file

@ -100,6 +100,8 @@ public class RpmBuilder {
private HashAlgo privateKeyHashAlgo;
private HashAlgo fileDigestsAlgo;
private int triggerCounter = 0;
private final CompressionType compressionType;
@ -107,7 +109,7 @@ public class RpmBuilder {
private String packageName;
public RpmBuilder() {
this(HashAlgo.SHA1, CompressionType.GZIP);
this(HashAlgo.SHA1, HashAlgo.MD5, CompressionType.GZIP);
}
/**
@ -115,8 +117,9 @@ public class RpmBuilder {
* @param privateKeyHashAlgo the hash algo
* @param compressionType compression type
*/
public RpmBuilder(HashAlgo privateKeyHashAlgo, CompressionType compressionType) {
public RpmBuilder(HashAlgo privateKeyHashAlgo, HashAlgo fileDigestsAlgo, CompressionType compressionType) {
this.privateKeyHashAlgo = privateKeyHashAlgo;
this.fileDigestsAlgo = fileDigestsAlgo;
this.compressionType = compressionType;
format.getHeader().createEntry(HeaderTag.HEADERI18NTABLE, "C");
format.getHeader().createEntry(HeaderTag.BUILDTIME, (int) (System.currentTimeMillis() / 1000));
@ -1091,6 +1094,15 @@ public class RpmBuilder {
}
}
/**
* Hash algo for the file digests.
*
* @param fileDigestsAlgo the file digests hash algo, default is MD5.
*/
public void setFileDigestsAlgo(HashAlgo fileDigestsAlgo) {
this.fileDigestsAlgo = fileDigestsAlgo;
}
/**
* Set RPM package name.
*
@ -1170,8 +1182,9 @@ public class RpmBuilder {
format.getHeader().createEntry(HeaderTag.TRIGGERSCRIPTPROG, triggerscriptprogs.toArray(new String[0]));
}
if (contents.size() > 0) {
format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, HashAlgo.SHA256.num());
format.getHeader().createEntry(HeaderTag.FILEDIGESTS, contents.getDigests(HashAlgo.SHA256));
StringList digests = contents.getDigests(fileDigestsAlgo);
format.getHeader().createEntry(HeaderTag.FILEDIGESTALGOS, fileDigestsAlgo.num());
format.getHeader().createEntry(HeaderTag.FILEDIGESTS, digests);
format.getHeader().createEntry(HeaderTag.FILESIZES, contents.getSizes());
format.getHeader().createEntry(HeaderTag.FILEMODES, contents.getModes());
format.getHeader().createEntry(HeaderTag.FILERDEVS, contents.getRdevs());
@ -1255,18 +1268,22 @@ public class RpmBuilder {
private OutputStream createCompressedStream(OutputStream outputStream) throws IOException {
switch (compressionType) {
case NONE:
case NONE -> {
return outputStream;
case GZIP:
}
case GZIP -> {
return new GZIPOutputStream(outputStream, true);
case BZIP2:
}
case BZIP2 -> {
return new Bzip2OutputStream(outputStream);
case XZ:
}
case XZ -> {
X86Options x86 = new X86Options();
LZMA2Options lzma2 = new LZMA2Options();
FilterOptions[] options = { x86, lzma2 };
FilterOptions[] options = {x86, lzma2};
return new XZOutputStream(outputStream, options);
}
}
// not reached
return outputStream;
}
@ -1466,6 +1483,4 @@ public class RpmBuilder {
}
return sb.toString();
}
}

View file

@ -5,7 +5,6 @@ import java.nio.BufferUnderflowException;
import java.nio.ByteBuffer;
import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.security.MessageDigest;
import java.util.HashMap;
import java.util.Map;

View file

@ -135,6 +135,7 @@ public class Contents {
CpioHeader header = new CpioHeader(path);
header.setType(CpioHeader.SYMLINK);
header.setFileSize(target.length());
header.setChecksum(0);
header.setMtime(System.currentTimeMillis());
header.setUid(uid == -1 ? DEFAULT_UID : uid);
header.setGid(gid == -1 ? DEFAULT_GID : gid);
@ -229,6 +230,7 @@ public class Contents {
header.setGid(gid == -1 ? (int) Files.getAttribute(source, "unix:gid") : gid);
header.setPermissions(permissions == -1 ? DEFAULT_FILE_PERMISSION : permissions);
header.setVerifyFlags(verifyFlags);
header.setChecksum(0);
headers.add(header);
UserGroup userGroup = new UserGroup();
userGroup.user = getDefaultIfMissing(uname, DEFAULT_USERNAME);

View file

@ -69,7 +69,7 @@ public class CpioHeader {
private int rdevMajor;
private int checksum;
private int checksum; // ignored!
protected String name;
@ -87,8 +87,8 @@ public class CpioHeader {
public CpioHeader(String name, URL url) {
try {
URLConnection connection = url.openConnection();
mtime = connection.getLastModified();
filesize = connection.getContentLength();
this.mtime = connection.getLastModified();
this.filesize = connection.getContentLength();
this.name = normalizePath(name);
setType(FILE);
} catch (IOException e) {
@ -97,8 +97,8 @@ public class CpioHeader {
}
public CpioHeader(String name, Path path) throws IOException {
mtime = Files.getLastModifiedTime(path).toMillis();
filesize = (int) Files.size(path);
this.mtime = Files.getLastModifiedTime(path).toMillis();
this.filesize = (int) Files.size(path);
this.name = normalizePath(name);
setType(Files.isDirectory(path) ? DIR : FILE);
}
@ -226,6 +226,14 @@ public class CpioHeader {
this.filesize = filesize;
}
public int getChecksum() {
return checksum;
}
public void setChecksum(int checksum) {
this.checksum = checksum;
}
protected ByteBuffer writeSix(CharSequence data) {
return charset.encode(pad(data, 6));
}
@ -354,6 +362,7 @@ public class CpioHeader {
"RDevMinor: " + rdevMinor + "\n" +
"RDevMajor: " + rdevMajor + "\n" +
"NameSize: " + (name.length() + 1) + "\n" +
"Name: " + name + "\n";
"Name: " + name + "\n" +
"Checksum: " + checksum + "\n";
}
}

View file

@ -1,9 +1,7 @@
package org.xbib.rpm.security;
/**
* Enumeration of hash algorithms as of RFC 4880.
*
*/
public enum HashAlgo {
@ -19,9 +17,9 @@ public enum HashAlgo {
SHA512("SHA-512", 10),
SHA224("SHA-224", 11);
String algo;
final String algo;
int num;
final int num;
HashAlgo(String algo, int num) {
this.algo = algo;

View file

@ -207,7 +207,7 @@ public class RpmBuilderTest {
@Test
public void testBzip2Build() throws Exception {
RpmBuilder rpmBuilder = new RpmBuilder(HashAlgo.SHA256, CompressionType.GZIP);
RpmBuilder rpmBuilder = new RpmBuilder(HashAlgo.SHA256, HashAlgo.MD5, CompressionType.GZIP);
rpmBuilder.setPackage("test-compressed", "1.0", "1");
rpmBuilder.setBuildHost("localhost");
rpmBuilder.setLicense("GPL");

View file

@ -1,15 +1,14 @@
package org.xbib.rpm;
import java.util.EnumSet;
import org.junit.jupiter.api.Test;
import org.xbib.rpm.lead.Architecture;
import org.xbib.rpm.lead.Os;
import org.xbib.rpm.lead.PackageType;
import java.nio.file.Paths;
import org.xbib.rpm.payload.Directive;
/**
*
*/
public class SimpleRpmTest {
@Test
@ -28,6 +27,8 @@ public class SimpleRpmTest {
rpmBuilder.setPackager("Jane Doe");
rpmBuilder.setUrl("http://example.org");
rpmBuilder.setProvides("test");
rpmBuilder.addFile("/etc", Paths.get("build.gradle"), 0, 0,
EnumSet.of(Directive.NONE), "root", "root", false);
rpmBuilder.build(Paths.get("build"));
}
}