Skip to content
This repository was archived by the owner on Mar 5, 2021. It is now read-only.

Commit 48388de

Browse files
author
Walker Funk
committed
RPM signing feature w/ added license info
Signed-off-by: Walker Funk <[email protected]>
1 parent 3869c16 commit 48388de

File tree

20 files changed

+1139
-13
lines changed

20 files changed

+1139
-13
lines changed

bundles/org.eclipse.packagedrone.repo.adapter.rpm/META-INF/MANIFEST.MF

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@ Bundle-RequiredExecutionEnvironment: JavaSE-1.8
88
Web-ContextPath: /yum
99
Import-Package: com.google.common.escape;version="18.0.0",
1010
com.google.common.net;version="18.0.0",
11+
com.google.common.io;version="18.0.0",
12+
com.google.common.hash;version="18.0.0",
1113
com.google.gson;version="2.3.1",
1214
javax.servlet;version="3.1.0",
1315
javax.servlet.http;version="3.1.0",
1416
org.apache.commons.compress.archivers.cpio;version="1.9.0",
17+
org.bouncycastle.openpgp;version="1.52.0",
1518
org.eclipse.packagedrone;version="1.0.0",
1619
org.eclipse.packagedrone.repo;version="1.0.0",
1720
org.eclipse.packagedrone.repo.aspect;version="1.0.0",
1821
org.eclipse.packagedrone.repo.aspect.aggregate;version="1.0.0",
1922
org.eclipse.packagedrone.repo.aspect.common.spool;version="1.0.0",
2023
org.eclipse.packagedrone.repo.aspect.extract;version="1.0.0",
24+
org.eclipse.packagedrone.repo.aspect.virtual;version="1.0.0",
2125
org.eclipse.packagedrone.repo.aspect.group;version="1.0.0",
2226
org.eclipse.packagedrone.repo.aspect.recipe;version="1.0.0",
2327
org.eclipse.packagedrone.repo.channel;version="1.0.0",
@@ -28,6 +32,7 @@ Import-Package: com.google.common.escape;version="18.0.0",
2832
org.eclipse.packagedrone.repo.utils;version="1.0.0",
2933
org.eclipse.packagedrone.repo.web.utils;version="1.0.0",
3034
org.eclipse.packagedrone.repo.xml;version="1.0.0",
35+
org.eclipse.packagedrone.utils;version="1.0.0",
3136
org.eclipse.packagedrone.utils.io;version="1.0.0",
3237
org.eclipse.packagedrone.utils.rpm;version="0.13.0",
3338
org.eclipse.packagedrone.utils.rpm.deps;version="0.13.0",
@@ -43,7 +48,7 @@ Import-Package: com.google.common.escape;version="18.0.0",
4348
org.osgi.framework;version="1.8.0",
4449
org.osgi.util.tracker;version="1.5.1",
4550
org.slf4j;version="1.7.2"
46-
Service-Component: OSGI-INF/rpm.xml,OSGI-INF/yum.xml,OSGI-INF/groupRpm.xml,OSGI-INF/recipeYum.xml,
51+
Service-Component: OSGI-INF/rpm.xml,OSGI-INF/rpmSign.xml,OSGI-INF/yum.xml,OSGI-INF/groupRpm.xml,OSGI-INF/recipeYum.xml,
4752
OSGI-INF/servlet.xml
4853
Require-Bundle: org.jboss.spec.javax.servlet.jstl.jboss-jstl-api_1.2_spec;bundle-version="1.1.2"
4954
Export-Package: org.eclipse.packagedrone.repo.adapter.rpm;version="1.0.0"
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
drone.aspect.id=rpm.signer
2+
drone.aspect.name=RPM Signer
3+
drone.aspect.description=Sign RPM files
4+
drone.aspect.version=1.0.0
5+
drone.aspect.group.id=rpm
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" name="org.eclipse.packagedrone.repo.adapter.rpm.signer">
3+
<implementation class="org.eclipse.packagedrone.repo.adapter.rpm.internal.RpmSignerAspectFactory"/>
4+
<properties entry="OSGI-INF/rpmSign.properties"/>
5+
<service>
6+
<provide interface="org.eclipse.packagedrone.repo.aspect.ChannelAspectFactory"/>
7+
</service>
8+
</scr:component>

bundles/org.eclipse.packagedrone.repo.adapter.rpm/src/org/eclipse/packagedrone/repo/adapter/rpm/Constants.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* IBH SYSTEMS GmbH - initial API and implementation
10+
* Walker Funk - Trident Systems Inc. - rpm signing components
1011
*******************************************************************************/
1112
package org.eclipse.packagedrone.repo.adapter.rpm;
1213

@@ -18,8 +19,12 @@ public final class Constants
1819

1920
public static final String RPM_ASPECT_ID = "rpm";
2021

22+
public static final String RPM_SIGN_ASPECT_ID = "rpm.signer";
23+
2124
public static final String YUM_ASPECT_ID = "yum";
2225

26+
public static final MetaKey KEY_RSA = new MetaKey ( GROUP_ID, "rsa" );
27+
2328
public static final MetaKey KEY_INFO = new MetaKey ( RPM_ASPECT_ID, "info" );
2429

2530
private Constants ()

bundles/org.eclipse.packagedrone.repo.adapter.rpm/src/org/eclipse/packagedrone/repo/adapter/rpm/internal/RpmExtractor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Contributors:
99
* IBH SYSTEMS GmbH - initial API and implementation
1010
* Bachmann electronic GmbH - #86 Adding 'release' rpm metadata tag
11+
* Walker Funk - Trident Systems Inc. rpm rsa signature extraction
1112
*******************************************************************************/
1213
package org.eclipse.packagedrone.repo.adapter.rpm.internal;
1314

@@ -21,6 +22,7 @@
2122
import org.eclipse.packagedrone.repo.adapter.rpm.RpmInformationsJson;
2223
import org.eclipse.packagedrone.repo.aspect.extract.Extractor;
2324
import org.eclipse.packagedrone.utils.rpm.RpmTag;
25+
import org.eclipse.packagedrone.utils.rpm.RpmSignatureTag;
2426
import org.eclipse.packagedrone.utils.rpm.info.RpmInformation;
2527
import org.eclipse.packagedrone.utils.rpm.info.RpmInformations;
2628
import org.eclipse.packagedrone.utils.rpm.parse.RpmInputStream;
@@ -54,6 +56,12 @@ public void extractMetaData ( final Context context, final Map<String, String> m
5456
metadata.put ( "release", RpmInformations.asString ( in.getPayloadHeader ().getTag ( RpmTag.RELEASE ) ) );
5557

5658
metadata.put ( Constants.KEY_INFO.getKey (), RpmInformationsJson.toJson ( info ) );
59+
60+
String signature = RpmInformations.asArmored ( in.getSignatureHeader ().getTag ( RpmSignatureTag.RSAHEADER ) );
61+
if ( signature != null && signature != "" )
62+
{
63+
metadata.put ( Constants.KEY_RSA.getKey (), signature );
64+
}
5765
}
5866
catch ( final Exception e )
5967
{
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 Trident Systems, Inc.
3+
* This software was developed with U.S government funding in support of the above
4+
* contract. Trident grants unlimited rights to modify, distribute and incorporate
5+
* our contributions to Eclipse Package Drone bound by the overall restrictions from
6+
* the parent Eclipse Public License v1.0 available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Walker Funk - Trident Systems Inc. - initial implementation
11+
*******************************************************************************/
12+
package org.eclipse.packagedrone.repo.adapter.rpm.internal;
13+
14+
import org.eclipse.packagedrone.repo.aspect.ChannelAspect;
15+
import org.eclipse.packagedrone.repo.aspect.ChannelAspectFactory;
16+
import org.eclipse.packagedrone.repo.aspect.virtual.Virtualizer;
17+
import org.eclipse.packagedrone.repo.adapter.rpm.Constants;
18+
import org.eclipse.packagedrone.repo.adapter.rpm.internal.RpmSignerVirtualizer;
19+
20+
public class RpmSignerAspectFactory implements ChannelAspectFactory
21+
{
22+
23+
@Override
24+
public ChannelAspect createAspect ()
25+
{
26+
return new ChannelAspect () {
27+
28+
@Override
29+
public String getId ()
30+
{
31+
return Constants.RPM_SIGN_ASPECT_ID;
32+
}
33+
34+
@Override
35+
public Virtualizer getArtifactVirtualizer ()
36+
{
37+
return new RpmSignerVirtualizer ();
38+
}
39+
};
40+
}
41+
42+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2019 Trident Systems, Inc.
3+
* This software was developed with U.S government funding in support of the above
4+
* contract. Trident grants unlimited rights to modify, distribute and incorporate
5+
* our contributions to Eclipse Package Drone bound by the overall restrictions from
6+
* the parent Eclipse Public License v1.0 available at
7+
* http://www.eclipse.org/legal/epl-v10.html
8+
*
9+
* Contributors:
10+
* Walker Funk - Trident Systems Inc. - initial implementation
11+
*******************************************************************************/
12+
package org.eclipse.packagedrone.repo.adapter.rpm.internal;
13+
14+
import java.io.DataInputStream;
15+
import java.io.BufferedInputStream;
16+
import java.nio.file.Files;
17+
import java.nio.file.Path;
18+
import java.nio.file.StandardOpenOption;
19+
import java.util.Map;
20+
import java.util.HashMap;
21+
import java.util.Collection;
22+
23+
import org.eclipse.packagedrone.repo.MetaKey;
24+
import org.eclipse.packagedrone.repo.utils.HashHelper;
25+
import org.eclipse.packagedrone.repo.signing.SigningService;
26+
import org.eclipse.packagedrone.repo.aspect.virtual.Virtualizer;
27+
import org.eclipse.packagedrone.repo.channel.ArtifactInformation;
28+
import org.eclipse.packagedrone.repo.adapter.rpm.Constants;
29+
import org.eclipse.packagedrone.repo.adapter.rpm.yum.internal.YumChannelAggregator;
30+
import org.eclipse.packagedrone.utils.Exceptions;
31+
import org.eclipse.packagedrone.utils.rpm.parse.RpmParserStream;
32+
33+
import org.osgi.framework.FrameworkUtil;
34+
import org.osgi.framework.BundleContext;
35+
import org.osgi.framework.ServiceReference;
36+
37+
import com.google.common.io.ByteStreams;
38+
import com.google.common.hash.Hashing;
39+
import com.google.common.hash.HashCode;
40+
import com.google.common.hash.HashFunction;
41+
42+
import org.slf4j.Logger;
43+
import org.slf4j.LoggerFactory;
44+
45+
public class RpmSignerVirtualizer implements Virtualizer
46+
{
47+
private final static Logger logger = LoggerFactory.getLogger ( RpmSignerVirtualizer.class );
48+
49+
private static final MetaKey KEY_SIGNING_ID = new MetaKey ( "yum", "signingServiceId" );
50+
51+
private final BundleContext bundleContext = FrameworkUtil.getBundle ( YumChannelAggregator.class ).getBundleContext ();
52+
53+
@Override
54+
public void virtualize ( final Context context )
55+
{
56+
Exceptions.wrapException ( () -> processVirtualize ( context ) );
57+
}
58+
59+
private void processVirtualize ( final Context context ) throws Exception
60+
{
61+
final Path path = context.getFile ();
62+
final ArtifactInformation art = context.getArtifactInformation ();
63+
final String name = art.getName ();
64+
Map<MetaKey, String> metaData = new HashMap<> ( art.getMetaData () );
65+
66+
if ( metaData.containsKey ( Constants.KEY_RSA ) )
67+
{
68+
return;
69+
}
70+
71+
final String signingServiceId = context.getProvidedChannelMetaData ().get ( KEY_SIGNING_ID );
72+
ServiceReference<SigningService> ssref = null;
73+
SigningService signingService = null;
74+
75+
if ( signingServiceId != null && !signingServiceId.isEmpty () )
76+
{
77+
final Collection<ServiceReference<SigningService>> services = bundleContext.getServiceReferences ( SigningService.class, String.format( "(%s=%s)", org.osgi.framework.Constants.SERVICE_PID, signingServiceId ) );
78+
79+
if ( services == null || services.isEmpty () )
80+
{
81+
throw new IllegalStateException ( String.format ( "Unable to find configured signing service: %s", signingServiceId ) );
82+
}
83+
84+
ssref = services.iterator ().next ();
85+
signingService = bundleContext.getService ( ssref );
86+
87+
try ( RpmParserStream preIn = new RpmParserStream ( new BufferedInputStream ( Files.newInputStream ( path, StandardOpenOption.READ ) ) ); )
88+
{
89+
signingService.signRpm ( path, preIn );
90+
91+
Map<String, HashFunction> functions = new HashMap<> ();
92+
93+
functions.put ( "md5", Hashing.md5 () );
94+
functions.put ( "sha1", Hashing.sha1 () );
95+
functions.put ( "sha256", Hashing.sha256 () );
96+
functions.put ( "sha512", Hashing.sha512 () );
97+
98+
final Map<String, HashCode> result = HashHelper.createChecksums ( path, functions );
99+
for ( final Map.Entry<String, HashCode> entry : result.entrySet () )
100+
{
101+
metaData.replace ( new MetaKey ("hasher", entry.getKey () ), entry.getValue ().toString () );
102+
}
103+
104+
DataInputStream postIn = new DataInputStream ( Files.newInputStream( path, StandardOpenOption.READ ) );
105+
context.createVirtualArtifact ( name, out -> ByteStreams.copy ( postIn, out ), metaData );
106+
}
107+
catch ( final Exception e )
108+
{
109+
logger.debug ( "Failed to sign RPM", e );
110+
}
111+
}
112+
}
113+
}

bundles/org.eclipse.packagedrone.repo.adapter.rpm/src/org/eclipse/packagedrone/repo/adapter/rpm/yum/internal/YumChannelAggregator.java

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* IBH SYSTEMS GmbH - initial API and implementation
10+
* Walker Funk - Trident Systems Inc. - limit repo to only signed rpms when signing enabled
1011
*******************************************************************************/
1112
package org.eclipse.packagedrone.repo.adapter.rpm.yum.internal;
1213

@@ -46,6 +47,8 @@ public class YumChannelAggregator implements ChannelAggregator
4647

4748
private final XmlToolsFactory xml;
4849

50+
private boolean isSigning = false;
51+
4952
public YumChannelAggregator ( final XmlToolsFactory xml )
5053
{
5154
this.xml = xml;
@@ -69,6 +72,7 @@ public Map<String, String> aggregateMetaData ( final AggregationContext context
6972

7073
ssref = services.iterator ().next ();
7174
signingService = this.context.getService ( ssref );
75+
this.isSigning = true;
7276
}
7377

7478
try
@@ -88,20 +92,22 @@ public Map<String, String> aggregateMetaData ( final AggregationContext context
8892
creator.process ( repoContext -> {
8993
for ( final ArtifactInformation art : context.getArtifacts () )
9094
{
91-
final RpmInformation info = RpmInformationsJson.fromJson ( art.getMetaData ().get ( Constants.KEY_INFO ) );
92-
93-
if ( info == null )
95+
if ( ( this.isSigning && art.getMetaData ().containsKey ( Constants.KEY_RSA ) ) || !this.isSigning )
9496
{
95-
continue;
96-
}
97+
final RpmInformation info = RpmInformationsJson.fromJson(art.getMetaData().get(Constants.KEY_INFO));
9798

98-
final String sha1 = art.getMetaData ().get ( KEY_SHA1 );
99-
final Map<HashAlgorithm, String> checksums = Collections.singletonMap ( HashAlgorithm.SHA1, sha1 );
99+
if (info == null) {
100+
continue;
101+
}
100102

101-
final String location = String.format ( "pool/%s/%s", art.getId (), art.getName () );
102-
final RepositoryCreator.FileInformation file = new RepositoryCreator.FileInformation ( art.getCreationInstant (), art.getSize (), location );
103+
final String sha1 = art.getMetaData().get(KEY_SHA1);
104+
final Map<HashAlgorithm, String> checksums = Collections.singletonMap(HashAlgorithm.SHA1, sha1);
103105

104-
repoContext.addPackage ( file, info, checksums, HashAlgorithm.SHA1 );
106+
final String location = String.format("pool/%s/%s", art.getId(), art.getName());
107+
final RepositoryCreator.FileInformation file = new RepositoryCreator.FileInformation(art.getCreationInstant(), art.getSize(), location);
108+
109+
repoContext.addPackage(file, info, checksums, HashAlgorithm.SHA1);
110+
}
105111
}
106112
} );
107113

@@ -134,4 +140,4 @@ private DefaultXmlContext makeXmlContext ()
134140
final DefaultXmlContext xmlCtx = new DefaultXmlContext ( dbf, this.xml.newTransformerFactory () );
135141
return xmlCtx;
136142
}
137-
}
143+
}

bundles/org.eclipse.packagedrone.repo.adapter.rpm/src/org/eclipse/packagedrone/repo/adapter/rpm/yum/internal/YumRecipe.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class YumRecipe implements Recipe
1919
@Override
2020
public LinkTarget setup ( final String channelId, final AspectableChannel channel )
2121
{
22-
channel.addAspects ( true, "rpm", "yum" );
22+
channel.addAspects ( true, "rpm", "yum", "rpm.signer" );
2323
return null;
2424
}
2525
}

bundles/org.eclipse.packagedrone.repo.channel.apm/src/org/eclipse/packagedrone/repo/channel/apm/ModifyContextImpl.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* Contributors:
99
* IBH SYSTEMS GmbH - initial API and implementation
10+
* Walker Funk - Trident Systems Inc. - added system call to clear function to delete empty directories
1011
*******************************************************************************/
1112
package org.eclipse.packagedrone.repo.channel.apm;
1213

@@ -30,6 +31,7 @@
3031
import java.util.UUID;
3132
import java.util.function.Consumer;
3233
import java.util.stream.Collectors;
34+
import java.lang.Runtime;
3335

3436
import org.eclipse.packagedrone.repo.MetaKey;
3537
import org.eclipse.packagedrone.repo.channel.ArtifactInformation;
@@ -822,6 +824,16 @@ public void clear ()
822824

823825
this.state.setNumberOfArtifacts ( 0L );
824826
this.state.setNumberOfBytes ( 0L );
827+
828+
final String cmd = "rm -rf " + System.getProperty ( "drone.storage.base" ) + "/channels/" + this.channelId + "/blobs/data/*";
829+
try
830+
{
831+
Process p = Runtime.getRuntime().exec( new String[] {"sh", "-c", cmd} );
832+
}
833+
catch ( Exception e )
834+
{
835+
throw new RuntimeException ( "Could not remove channel " + this.channelId + " data directories" );
836+
}
825837
}
826838

827839
@Override

0 commit comments

Comments
 (0)