Skip to content

Commit 130f684

Browse files
authored
Merge pull request #302 from Yubico/conditional-publish
Apply publishing settings conditionally
2 parents 62b7312 + 6173188 commit 130f684

File tree

4 files changed

+30
-26
lines changed

4 files changed

+30
-26
lines changed

build.gradle

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,14 @@ buildscript {
44
}
55
dependencies {
66
classpath 'com.cinnober.gradle:semver-git:2.5.0'
7+
8+
if (project.findProperty('yubicoPublish') == 'true') {
9+
classpath 'io.github.gradle-nexus:publish-plugin:1.3.0'
10+
}
711
}
812
}
913
plugins {
1014
id 'java-platform'
11-
id 'io.github.gradle-nexus.publish-plugin' version '1.3.0'
1215

1316
// The root project has no sources, but the dependency platform also needs to be published as an artifact
1417
// See https://docs.gradle.org/current/userguide/java_platform_plugin.html
@@ -21,10 +24,7 @@ import com.yubico.gradle.GitUtils
2124
rootProject.description = "Metadata root for the com.yubico:webauthn-server-* module family"
2225

2326
project.ext.isCiBuild = System.env.CI == 'true'
24-
25-
project.ext.publishEnabled = !isCiBuild &&
26-
project.hasProperty('yubicoPublish') && project.yubicoPublish &&
27-
project.hasProperty('ossrhUsername') && project.hasProperty('ossrhPassword')
27+
project.ext.publishEnabled = !isCiBuild && project.findProperty('yubicoPublish') == 'true'
2828

2929
wrapper {
3030
gradleVersion = '8.1.1'
@@ -65,6 +65,8 @@ allprojects {
6565
}
6666

6767
if (publishEnabled) {
68+
apply plugin: 'io.github.gradle-nexus.publish-plugin'
69+
6870
nexusPublishing {
6971
repositories {
7072
sonatype {

buildSrc/src/main/groovy/project-convention-publish.gradle

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,10 @@ project.afterEvaluate {
4949
}
5050
}
5151

52-
signing {
53-
useGpgCmd()
54-
sign(publishing.publications.jars)
52+
if (project.findProperty("yubicoPublish") == "true") {
53+
signing {
54+
useGpgCmd()
55+
sign(publishing.publications.jars)
56+
}
5557
}
5658
}

doc/development.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,20 @@ Developer docs
22
===
33

44

5+
Setup for publishing
6+
---
7+
8+
To enable publishing to Maven Central via Sonatype Nexus, set
9+
`yubicoPublish=true` in `$HOME/.gradle/gradle.properties` and add your Sonatype
10+
username and password. Example:
11+
12+
```properties
13+
yubicoPublish=true
14+
ossrhUsername=8pnmjKQP
15+
ossrhPassword=bmjuyWSIik8P3Nq/ZM2G0Xs0sHEKBg+4q4zTZ8JDDRCr
16+
```
17+
18+
519
Code formatting
620
---
721

webauthn-server-core/src/main/java/com/yubico/webauthn/WebAuthnCodecs.java

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,11 @@
3131
import com.yubico.webauthn.data.ByteArray;
3232
import com.yubico.webauthn.data.COSEAlgorithmIdentifier;
3333
import java.io.IOException;
34-
import java.math.BigInteger;
3534
import java.security.KeyFactory;
3635
import java.security.NoSuchAlgorithmException;
3736
import java.security.PublicKey;
3837
import java.security.interfaces.ECPublicKey;
3938
import java.security.spec.InvalidKeySpecException;
40-
import java.security.spec.RSAPublicKeySpec;
4139
import java.security.spec.X509EncodedKeySpec;
4240
import java.util.Arrays;
4341
import java.util.HashMap;
@@ -125,29 +123,17 @@ static PublicKey importCosePublicKey(ByteArray key)
125123
final int kty = cose.get(CBORObject.FromObject(1)).AsInt32();
126124
switch (kty) {
127125
case 1:
126+
// COSE-JAVA is hardcoded to ed25519-java provider ("EdDSA") which would require an
127+
// additional dependency to parse EdDSA keys via the OneKey constructor
128128
return importCoseEdDsaPublicKey(cose);
129-
case 2:
130-
return importCoseP256PublicKey(cose);
129+
case 2: // Fall through
131130
case 3:
132-
return importCoseRsaPublicKey(cose);
131+
return new OneKey(cose).AsPublicKey();
133132
default:
134133
throw new IllegalArgumentException("Unsupported key type: " + kty);
135134
}
136135
}
137136

138-
private static PublicKey importCoseRsaPublicKey(CBORObject cose)
139-
throws NoSuchAlgorithmException, InvalidKeySpecException {
140-
RSAPublicKeySpec spec =
141-
new RSAPublicKeySpec(
142-
new BigInteger(1, cose.get(CBORObject.FromObject(-1)).GetByteString()),
143-
new BigInteger(1, cose.get(CBORObject.FromObject(-2)).GetByteString()));
144-
return KeyFactory.getInstance("RSA").generatePublic(spec);
145-
}
146-
147-
private static ECPublicKey importCoseP256PublicKey(CBORObject cose) throws CoseException {
148-
return (ECPublicKey) new OneKey(cose).AsPublicKey();
149-
}
150-
151137
private static PublicKey importCoseEdDsaPublicKey(CBORObject cose)
152138
throws InvalidKeySpecException, NoSuchAlgorithmException {
153139
final int curveId = cose.get(CBORObject.FromObject(-1)).AsInt32();

0 commit comments

Comments
 (0)