Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Checking for weak signatures #18

Merged
merged 1 commit into from
Mar 31, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions src/main/java/com/github/s4u/plugins/PGPVerifyMojo.java
Original file line number Diff line number Diff line change
@@ -16,6 +16,7 @@

package com.github.s4u.plugins;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;
import org.apache.maven.ProjectDependenciesResolver;
import org.apache.maven.artifact.Artifact;
@@ -119,13 +120,21 @@ public class PGPVerifyMojo extends AbstractMojo {
private String pgpKeyServer;

/**
* Fail the build if some of dependency hasn't signature.
* Fail the build if any dependency doesn't have a signature.
*
* @since 1.1.0
*/
@Parameter(property = "pgpverify.failNoSignature", defaultValue = "false")
private boolean failNoSignature;

/**
* Fail the build if any dependency has a weak signature.
*
* @since 1.2.0
*/
@Parameter(property = "pgpgverify.failWeakSignature", defaultValue = "false")
private boolean failWeakSignature;

/**
* Verify pom files also.
*
@@ -230,7 +239,7 @@ private void prepareForKeys() throws MojoFailureException, MojoExecutionExceptio
* @return Artifacts for all the pom files
*/
private Set<Artifact> getPomArtifacts(Set<Artifact> resolve) throws MojoExecutionException {
Set<Artifact> poms = new HashSet<Artifact>();
Set<Artifact> poms = new HashSet<>();

for (Artifact a : resolve) {
if (a.isSnapshot()) {
@@ -312,6 +321,15 @@ private void initCache() throws MojoFailureException {

private boolean verifyPGPSignature(Artifact artifact, File artifactFile, File signatureFile) throws MojoFailureException {

final Map<Integer, String> weakSignatures = ImmutableMap.<Integer, String>builder()
.put(1, "MD5")
.put(4, "DOUBLE_SHA")
.put(5, "MD2")
.put(6, "TIGER_192")
.put(7, "HAVAL_5_160")
.put(11, "SHA224")

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it intended that SHA-224 is considered weak but not SHA-1?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, although I know it's weird. My reasoning is that SHA-1 is so commonly used that marking it as weak at this point would flood developers with warning/error messages, even though it's strictly weaker than SHA-224. Essentially the same reasoning used by the developer of OpenKeychain when they built their list of allowed signature algorithms.

I originally checked the security of the underlying public key as well, but the same problem occurred (so, so many RSA keys under 2048 bits...). One of the chief advantages of this plugin (IMO) is its SSH-like security model - as a rule, it won't spam warnings at you unless something is seriously wrong and it won't fail the build unless you're probably under attack (at least under default settings), so I'm hesitant to add a whole bunch of error messages for common cases that developers can't do anything about.

That being said, if we judge that SHA224 is still an improvement over SHA1 (which it is by bits of security, if not frequency of use) then I can remove it from this list.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, thanks. Just noticed it and thought it looked strange but now I know it is a reason behind it.

.build();

getLog().debug("Artifact file: " + artifactFile);
getLog().debug("Artifact sign: " + signatureFile);

@@ -347,6 +365,17 @@ private boolean verifyPGPSignature(Artifact artifact, File artifactFile, File si
if (pgpSignature.verify()) {
getLog().info(String.format(msgFormat, artifact.getId(),
"OK", publicKey.getKeyID(), Lists.newArrayList(publicKey.getUserIDs())));
if (weakSignatures.containsKey(pgpSignature.getHashAlgorithm())) {
if (failWeakSignature) {
getLog().error("Weak signature algorithm used: "
+ weakSignatures.get(pgpSignature.getHashAlgorithm()));
throw new MojoFailureException("Weak signature algorithm used: "
+ weakSignatures.get(pgpSignature.getHashAlgorithm()));
} else {
getLog().warn("Weak signature algorithm used: "
+ weakSignatures.get(pgpSignature.getHashAlgorithm()));
}
}
return true;
} else {
getLog().warn(String.format(msgFormat, artifact.getId(),