Repository: jreleaser/jreleaser
Issue: [signing] ECDH keys not being recognized

This is an upstream issue. This issue only exists for upgrading as soon as upstream is fixed.

Follow-up to https://github.com/jreleaser/jreleaser/issues/136.
Of course I created a new key using Curve25519.

```
[INFO]  Writing output properties to out/jreleaser/output.properties
[ERROR] JReleaser failed after 1.012 s
org.jreleaser.model.JReleaserException: Unexpected error when signing release.
        at org.jreleaser.workflow.SignWorkflowItem.invoke(SignWorkflowItem.java:35)
        at org.jreleaser.workflow.WorkflowImpl.execute(WorkflowImpl.java:51)
        at org.jreleaser.cli.Sign.doExecute(Sign.java:34)
        at org.jreleaser.cli.AbstractModelCommand.execute(AbstractModelCommand.java:64)
        at org.jreleaser.cli.AbstractCommand.call(AbstractCommand.java:72)
        at org.jreleaser.cli.AbstractModelCommand.call(AbstractModelCommand.java:38)
        at org.jreleaser.cli.AbstractCommand.call(AbstractCommand.java:37)
        at picocli.CommandLine.executeUserObject(CommandLine.java:1953)
        at picocli.CommandLine.access$1300(CommandLine.java:145)
        at picocli.CommandLine$RunLast.executeUserObjectOfLastSubcommandWithSameParent(CommandLine.java:2352)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2346)
        at picocli.CommandLine$RunLast.handle(CommandLine.java:2311)
        at picocli.CommandLine$AbstractParseResultHandler.execute(CommandLine.java:2179)
        at picocli.CommandLine.execute(CommandLine.java:2078)
        at org.jreleaser.cli.Main.execute(Main.java:73)
        at org.jreleaser.cli.Main.run(Main.java:59)
        at org.jreleaser.cli.Main.main(Main.java:51)
Caused by: org.jreleaser.util.signing.SigningException: Unexpected error when initializing signature generator
        at org.jreleaser.engine.sign.Signer.initSignatureGenerator(Signer.java:218)
        at org.jreleaser.engine.sign.Signer.sign(Signer.java:194)
        at org.jreleaser.engine.sign.Signer.sign(Signer.java:104)
        at org.jreleaser.workflow.SignWorkflowItem.invoke(SignWorkflowItem.java:33)
        ... 16 more
Caused by: org.bouncycastle.openpgp.PGPException: unknown algorithm tag in signature:18
        at org.bouncycastle.openpgp.operator.jcajce.OperatorHelper.createSignature(Unknown Source)
        at org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder.build(Unknown Source)
        at org.bouncycastle.openpgp.operator.jcajce.JcaPGPContentSignerBuilder.build(Unknown Source)
        at org.bouncycastle.openpgp.PGPSignatureGenerator.init(Unknown Source)
        at org.jreleaser.engine.sign.Signer.initSignatureGenerator(Signer.java:214)
        ... 19 more                                                                                                                                                                                              
```


### Task List

- [X] Steps to reproduce provided
- [X] Stacktrace (if present) provided
- [ ] Example that reproduces the problem (link to git repository is ideal)
- [X] Full description of the issue provided (see below)

### Steps to Reproduce

1. Create an ECDH key using GnuPG or similar
2. use in jreleaser


### Expected Behaviour

Key being used

### Actual Behaviour

Exception: https://github.com/bcgit/bc-java/blob/4a937ecd3ed3934fecb742063ea2fea6e7b9af8d/pg/src/main/java/org/bouncycastle/openpgp/operator/jcajce/OperatorHelper.java#L276
also
https://github.com/bcgit/bc-java/blob/4a937ecd3ed3934fecb742063ea2fea6e7b9af8d/pg/src/main/java/org/bouncycastle/bcpg/PublicKeyAlgorithmTags.java#L17

### Environment Information

- **Operating System**: Ubuntu 20.04
- **JReleaser Version:** 0.3.0 or 0.4.0-SNAPSHOT
- **JDK Version:** 11 OpenJ9




Changed files:
core/jreleaser-utils/src/main/java/org/jreleaser/util/signing/Keyring.java

diff --git a/core/jreleaser-utils/src/main/java/org/jreleaser/util/signing/Keyring.java b/core/jreleaser-utils/src/main/java/org/jreleaser/util/signing/Keyring.java
index adc5fa79..71e2a0be 100644
--- a/core/jreleaser-utils/src/main/java/org/jreleaser/util/signing/Keyring.java
+++ b/core/jreleaser-utils/src/main/java/org/jreleaser/util/signing/Keyring.java
@@ -17,6 +17,11 @@
  */
 package org.jreleaser.util.signing;
 
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Collections;
+import java.util.Iterator;
+import org.bouncycastle.bcpg.PublicKeyAlgorithmTags;
 import org.bouncycastle.openpgp.PGPException;
 import org.bouncycastle.openpgp.PGPPublicKey;
 import org.bouncycastle.openpgp.PGPPublicKeyRing;
@@ -27,11 +32,6 @@ import org.bouncycastle.openpgp.PGPSecretKeyRingCollection;
 import org.bouncycastle.openpgp.operator.KeyFingerPrintCalculator;
 import org.bouncycastle.openpgp.operator.bc.BcKeyFingerprintCalculator;
 
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.Iterator;
-
 /**
  * Adapted from {@code name.neuhalfen.projects.crypto.bouncycastle.openpgp.keys.keyrings.InMemoryKeyring}
  * Original author: Jens Neuhalfen
@@ -109,7 +109,7 @@ public abstract class Keyring {
             Iterator<PGPPublicKey> keyIter = keyRing.getPublicKeys();
             while (keyIter.hasNext()) {
                 PGPPublicKey key = keyIter.next();
-                if (key.isEncryptionKey()) {
+                if (isSigningKey(key)) {
                     return key;
                 }
             }
@@ -117,4 +117,25 @@ public abstract class Keyring {
 
         throw new SigningException("Did not find public key for signing.");
     }
+
+    /**
+     * Returns {@code true} if the given key can be used for signing.
+     *
+     * <p>There is no Method key.isSigningKey(), and encryption does not always mean signing.
+     * The algorithms here need to be kept in sync with {@code org.bouncycastle.openpgp.operator.jcajce.OperatorHelper#createSignature}.
+     *
+     * @param key they key to check if it is usable for signing.
+     * @return {@code true} if the given key can be used for signing.
+     */
+    private static boolean isSigningKey(PGPPublicKey key) {
+        final int algorithm = key.getAlgorithm();
+
+        return algorithm == PublicKeyAlgorithmTags.EDDSA ||
+            algorithm == PublicKeyAlgorithmTags.ECDSA ||
+            algorithm == PublicKeyAlgorithmTags.ELGAMAL_GENERAL ||
+            algorithm == PublicKeyAlgorithmTags.ELGAMAL_ENCRYPT ||
+            algorithm == PublicKeyAlgorithmTags.RSA_SIGN ||
+            algorithm == PublicKeyAlgorithmTags.RSA_GENERAL ||
+            algorithm == PublicKeyAlgorithmTags.DSA;
+    }
 }