Skip to content

Commit 7402c14

Browse files
authored
Merge pull request #850 from sigstore/cleanup
Cleanup
2 parents ce09d39 + 372bf41 commit 7402c14

File tree

49 files changed

+12
-2644
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+12
-2644
lines changed

fuzzing/src/main/java/fuzzing/TufKeysFuzzer.java

Lines changed: 0 additions & 39 deletions
This file was deleted.

sigstore-java/src/main/java/dev/sigstore/encryption/Keys.java

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -15,32 +15,22 @@
1515
*/
1616
package dev.sigstore.encryption;
1717

18-
import static org.bouncycastle.jce.ECPointUtil.decodePoint;
19-
2018
import java.io.ByteArrayInputStream;
2119
import java.io.IOException;
2220
import java.io.InputStreamReader;
2321
import java.nio.charset.StandardCharsets;
2422
import java.security.KeyFactory;
2523
import java.security.NoSuchAlgorithmException;
26-
import java.security.NoSuchProviderException;
2724
import java.security.PublicKey;
2825
import java.security.Security;
29-
import java.security.spec.ECPoint;
30-
import java.security.spec.ECPublicKeySpec;
3126
import java.security.spec.InvalidKeySpecException;
3227
import java.security.spec.RSAPublicKeySpec;
3328
import java.security.spec.X509EncodedKeySpec;
3429
import java.util.List;
3530
import org.bouncycastle.asn1.ASN1Integer;
3631
import org.bouncycastle.asn1.ASN1Sequence;
37-
import org.bouncycastle.asn1.edec.EdECObjectIdentifiers;
38-
import org.bouncycastle.asn1.x509.AlgorithmIdentifier;
3932
import org.bouncycastle.asn1.x509.SubjectPublicKeyInfo;
40-
import org.bouncycastle.jce.ECNamedCurveTable;
4133
import org.bouncycastle.jce.provider.BouncyCastleProvider;
42-
import org.bouncycastle.jce.spec.ECNamedCurveParameterSpec;
43-
import org.bouncycastle.jce.spec.ECNamedCurveSpec;
4434
import org.bouncycastle.openssl.PEMParser;
4535
import org.bouncycastle.openssl.jcajce.JcaPEMKeyConverter;
4636
import org.bouncycastle.util.encoders.DecoderException;
@@ -74,6 +64,7 @@ public static PublicKey parsePublicKey(byte[] keyBytes)
7464
"sigstore public keys must be only a single PEM encoded public key");
7565
}
7666
JcaPEMKeyConverter converter = new JcaPEMKeyConverter();
67+
converter.setProvider(BouncyCastleProvider.PROVIDER_NAME);
7768
if (keyObj instanceof SubjectPublicKeyInfo) {
7869
PublicKey pk = converter.getPublicKey((SubjectPublicKeyInfo) keyObj);
7970
if (!SUPPORTED_KEY_TYPES.contains(pk.getAlgorithm())) {
@@ -115,78 +106,4 @@ public static PublicKey parsePkcs1RsaPublicKey(byte[] contents)
115106
KeyFactory factory = KeyFactory.getInstance("RSA");
116107
return factory.generatePublic(keySpec);
117108
}
118-
119-
/**
120-
* Valid values for scheme are:
121-
*
122-
* <ol>
123-
* <li><a href="https://ed25519.cr.yp.to/">ed25519</a>
124-
* <li><a
125-
* href="https://en.wikipedia.org/wiki/Elliptic_Curve_Digital_Signature_Algorithm">ecdsa-sha2-nistp256</a>
126-
* </ol>
127-
*
128-
* @see <a
129-
* href="https://theupdateframework.github.io/specification/latest/index.html#role-role">spec</a>
130-
* @param contents keyBytes
131-
* @param scheme signing scheme
132-
* @return java {link PublicKey}
133-
* @throws NoSuchAlgorithmException if we don't support the scheme provided
134-
* @throws InvalidKeySpecException if the public key material is invalid
135-
*/
136-
public static PublicKey constructTufPublicKey(byte[] contents, String scheme)
137-
throws NoSuchAlgorithmException, InvalidKeySpecException {
138-
if (contents == null || contents.length == 0) {
139-
throw new InvalidKeySpecException("key contents was empty");
140-
}
141-
switch (scheme) {
142-
case "ed25519":
143-
{
144-
final KeyFactory kf = KeyFactory.getInstance("Ed25519");
145-
X509EncodedKeySpec keySpec;
146-
// tuf allows raw keys only for ed25519 (non PEM):
147-
// https://github.com/theupdateframework/specification/blob/c51875f445d8a57efca9dadfbd5dbdece06d87e6/tuf-spec.md#key-objects--file-formats-keys
148-
if (contents.length == 32) {
149-
var params =
150-
new SubjectPublicKeyInfo(
151-
new AlgorithmIdentifier(EdECObjectIdentifiers.id_Ed25519), contents);
152-
try {
153-
keySpec = new X509EncodedKeySpec(params.getEncoded());
154-
} catch (IOException e) {
155-
throw new RuntimeException(e);
156-
}
157-
} else {
158-
keySpec = new X509EncodedKeySpec(contents);
159-
}
160-
return kf.generatePublic(keySpec);
161-
}
162-
case "ecdsa":
163-
case "ecdsa-sha2-nistp256":
164-
{
165-
// spec for P-256 curve
166-
ECNamedCurveParameterSpec spec = ECNamedCurveTable.getParameterSpec("P-256");
167-
// create a KeyFactory with ECDSA (Elliptic Curve Diffie-Hellman) algorithm and use
168-
// BouncyCastle as the provider
169-
KeyFactory kf = null;
170-
try {
171-
kf = KeyFactory.getInstance("ECDSA", BouncyCastleProvider.PROVIDER_NAME);
172-
} catch (NoSuchProviderException e) {
173-
throw new RuntimeException(e);
174-
}
175-
176-
// code below just creates the public key from key contents using the curve parameters
177-
// (spec variable)
178-
try {
179-
ECNamedCurveSpec params =
180-
new ECNamedCurveSpec("P-256", spec.getCurve(), spec.getG(), spec.getN());
181-
ECPoint point = decodePoint(params.getCurve(), contents);
182-
ECPublicKeySpec pubKeySpec = new ECPublicKeySpec(point, params);
183-
return kf.generatePublic(pubKeySpec);
184-
} catch (IllegalArgumentException | NullPointerException ex) {
185-
throw new InvalidKeySpecException("ecdsa key was not parseable", ex);
186-
}
187-
}
188-
default:
189-
throw new RuntimeException(scheme + " not currently supported");
190-
}
191-
}
192109
}

sigstore-java/src/main/java/dev/sigstore/encryption/signers/Verifiers.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,6 @@
2020

2121
/** Autodetection for verification algorithms based on public keys used. */
2222
public class Verifiers {
23-
@FunctionalInterface
24-
public interface Supplier {
25-
public Verifier newVerifier(PublicKey publicKey) throws NoSuchAlgorithmException;
26-
}
27-
2823
/** Returns a new verifier for the provided public key to use during verification. */
2924
public static Verifier newVerifier(PublicKey publicKey) throws NoSuchAlgorithmException {
3025
if (publicKey.getAlgorithm().equals("RSA")) {

sigstore-java/src/test/java/dev/sigstore/encryption/KeysTest.java

Lines changed: 3 additions & 118 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,11 @@
2121
import java.io.IOException;
2222
import java.nio.charset.StandardCharsets;
2323
import java.security.NoSuchAlgorithmException;
24-
import java.security.NoSuchProviderException;
2524
import java.security.PublicKey;
2625
import java.security.spec.InvalidKeySpecException;
2726
import org.bouncycastle.util.encoders.Base64;
28-
import org.bouncycastle.util.encoders.Hex;
2927
import org.junit.jupiter.api.Assertions;
3028
import org.junit.jupiter.api.Test;
31-
import org.junit.jupiter.api.condition.EnabledForJreRange;
32-
import org.junit.jupiter.api.condition.JRE;
3329

3430
class KeysTest {
3531

@@ -73,24 +69,15 @@ void parsePublicKey_ec() throws IOException, InvalidKeySpecException, NoSuchAlgo
7369
}
7470

7571
@Test
76-
@EnabledForJreRange(max = JRE.JAVA_14)
77-
void parsePublicKey_ed25519_withBouncyCastle()
72+
void parsePublicKey_ed25519()
7873
throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
7974
PublicKey result =
8075
Keys.parsePublicKey(Resources.toByteArray(Resources.getResource(ED25519_PUB_PATH)));
81-
// BouncyCastle names the algorithm differently than the JDK (Ed25519 vs EdDSA)
76+
// BouncyCastle names the algorithm differently than the JDK (Ed25519 vs EdDSA) but we
77+
// force the converter to use BouncyCastle always.
8278
assertEquals("Ed25519", result.getAlgorithm());
8379
}
8480

85-
@Test
86-
@EnabledForJreRange(min = JRE.JAVA_15)
87-
void parsePublicKey_ed25519_withStdLib()
88-
throws IOException, InvalidKeySpecException, NoSuchAlgorithmException {
89-
PublicKey result =
90-
Keys.parsePublicKey(Resources.toByteArray(Resources.getResource(ED25519_PUB_PATH)));
91-
assertEquals("EdDSA", result.getAlgorithm());
92-
}
93-
9481
@Test
9582
void parsePublicKey_dsaShouldFail() {
9683
Assertions.assertThrows(
@@ -106,108 +93,6 @@ void parseTufPublicKeyPemEncoded_sha2_nistp256()
10693
assertEquals("ECDSA", result.getAlgorithm());
10794
}
10895

109-
@Test
110-
void parseTufPublicKey_ecdsa() throws NoSuchAlgorithmException, InvalidKeySpecException {
111-
PublicKey key =
112-
Keys.constructTufPublicKey(
113-
Hex.decode(
114-
"04cbc5cab2684160323c25cd06c3307178a6b1d1c9b949328453ae473c5ba7527e35b13f298b41633382241f3fd8526c262d43b45adee5c618fa0642c82b8a9803"),
115-
"ecdsa-sha2-nistp256");
116-
assertNotNull(key);
117-
assertEquals("ECDSA", key.getAlgorithm());
118-
}
119-
120-
@Test
121-
void parseTufPublicKey_ecdsaBad() {
122-
Assertions.assertThrows(
123-
InvalidKeySpecException.class,
124-
() -> {
125-
Keys.constructTufPublicKey(
126-
Hex.decode(
127-
"04cbcdcab2684160323c25cd06c3307178a6b1d1c9b949328453ae473c5ba7527e35b13f298b41633382241f3fd8526c262d43b45adee5c618fa0642c82b8a9803"),
128-
"ecdsa-sha2-nistp256");
129-
});
130-
}
131-
132-
@Test
133-
@EnabledForJreRange(min = JRE.JAVA_15)
134-
void parseTufPublicKey_ed25519_java15Plus()
135-
throws NoSuchAlgorithmException, InvalidKeySpecException {
136-
// {@code step crypto keypair ed25519.pub /dev/null --kty OKP --curve Ed25519}
137-
// copy just the key part out of ed25519.pub removing PEM header and footer
138-
// {@code echo $(copied content) | base64 -d | hexdump -v -e '/1 "%02x" '}
139-
PublicKey key =
140-
Keys.constructTufPublicKey(
141-
Hex.decode(
142-
"302a300506032b65700321008b2e369230c3b97f4627fd6a59eb054a83ec15ed929ab3d983a40ffd322a223d"),
143-
"ed25519");
144-
assertNotNull(key);
145-
assertEquals("EdDSA", key.getAlgorithm());
146-
}
147-
148-
@Test
149-
@EnabledForJreRange(max = JRE.JAVA_14)
150-
void parseTufPublicKey_ed25519_lteJava14()
151-
throws NoSuchAlgorithmException, InvalidKeySpecException, NoSuchProviderException {
152-
// {@code step crypto keypair ed25519.pub /dev/null --kty OKP --curve Ed25519}
153-
// copy just the key part out of ed25519.pub removing PEM header and footer
154-
// {@code echo $(copied content) | base64 -d | hexdump -v -e '/1 "%02x" '}
155-
PublicKey key =
156-
Keys.constructTufPublicKey(
157-
Hex.decode(
158-
"302a300506032b65700321008b2e369230c3b97f4627fd6a59eb054a83ec15ed929ab3d983a40ffd322a223d"),
159-
"ed25519");
160-
assertNotNull(key);
161-
assertEquals("Ed25519", key.getAlgorithm());
162-
}
163-
164-
@Test
165-
@EnabledForJreRange(min = JRE.JAVA_15)
166-
void parseTufPublicKey_ed25519_rawBytes_java15plus() throws Exception {
167-
PublicKey key =
168-
Keys.constructTufPublicKey(
169-
Hex.decode("2d7218ce609f85de4b0d29d9e679cfd73e96756652f7069a0cf00acb752e5d3c"),
170-
"ed25519");
171-
assertNotNull(key);
172-
assertEquals("EdDSA", key.getAlgorithm());
173-
}
174-
175-
@Test
176-
@EnabledForJreRange(max = JRE.JAVA_14)
177-
void parseTufPublicKey_ed25519_rawBytes_lteJava14() throws Exception {
178-
PublicKey key =
179-
Keys.constructTufPublicKey(
180-
Hex.decode("2d7218ce609f85de4b0d29d9e679cfd73e96756652f7069a0cf00acb752e5d3c"),
181-
"ed25519");
182-
assertNotNull(key);
183-
assertEquals("Ed25519", key.getAlgorithm());
184-
}
185-
186-
@Test
187-
void parseTufPublicKey_ed25519Bad() {
188-
Assertions.assertThrows(
189-
InvalidKeySpecException.class,
190-
() ->
191-
Keys.constructTufPublicKey(
192-
Hex.decode(
193-
"302b300506032b65700321008b2e369230c3b97f4627fd6a59eb054a83ec15ed929ab3d983a40ffd322a223d"),
194-
"ed25519"));
195-
}
196-
197-
@Test
198-
void parseTufPublicKey_rsa() throws NoSuchAlgorithmException, InvalidKeySpecException {
199-
// {@code step crypto keypair ed25519.pub /dev/null --kty OKP --curve Ed25519}
200-
// copy just the key part out of ed25519.pub removing PEM header and footer
201-
// {@code echo $(copied content) | base64 -d | hexdump -v -e '/1 "%02x" '}
202-
Assertions.assertThrows(
203-
RuntimeException.class,
204-
() ->
205-
Keys.constructTufPublicKey(
206-
Hex.decode(
207-
"302a300506032b65700321008b2e369230c3b97f4627fd6a59eb054a83ec15ed929ab3d983a40ffd322a223d"),
208-
"rsassa-pss-sha256"));
209-
}
210-
21196
@Test
21297
void parsePkixPublicKey_rsa() throws NoSuchAlgorithmException, InvalidKeySpecException {
21398
var base64Key =

sigstore-java/src/test/java/dev/sigstore/tuf/FileSystemTufStoreTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727

2828
class FileSystemTufStoreTest {
2929

30-
public static final String PROD_REPO = "real/prod";
30+
public static final String REPO = "synthetic/test-template";
3131

3232
@Test
3333
void newFileSystemStore_empty(@TempDir Path repoBase) throws IOException {
@@ -37,7 +37,7 @@ void newFileSystemStore_empty(@TempDir Path repoBase) throws IOException {
3737

3838
@Test
3939
void newFileSystemStore_hasRepo(@TempDir Path repoBase) throws IOException {
40-
TestResources.setupRepoFiles(PROD_REPO, repoBase, "root.json");
40+
TestResources.setupRepoFiles(REPO, repoBase, "root.json");
4141
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
4242
assertTrue(tufStore.readMeta(RootRole.ROOT, Root.class).isPresent());
4343
}
@@ -47,15 +47,15 @@ void writeMeta(@TempDir Path repoBase) throws IOException {
4747
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
4848
assertFalse(repoBase.resolve("root.json").toFile().exists());
4949
tufStore.writeMeta(
50-
RootRole.ROOT, TestResources.loadRoot(TestResources.UPDATER_REAL_TRUSTED_ROOT));
50+
RootRole.ROOT, TestResources.loadRoot(TestResources.UPDATER_SYNTHETIC_TRUSTED_ROOT));
5151
assertEquals(2, repoBase.toFile().list().length, "Expect 2: root.json plus the /targets dir.");
5252
assertTrue(repoBase.resolve("root.json").toFile().exists());
5353
assertTrue(repoBase.resolve("targets").toFile().isDirectory());
5454
}
5555

5656
@Test
5757
void clearMeta(@TempDir Path repoBase) throws IOException {
58-
TestResources.setupRepoFiles(PROD_REPO, repoBase, "snapshot.json", "timestamp.json");
58+
TestResources.setupRepoFiles(REPO, repoBase, "snapshot.json", "timestamp.json");
5959
FileSystemTufStore tufStore = FileSystemTufStore.newFileSystemStore(repoBase);
6060
assertTrue(repoBase.resolve("snapshot.json").toFile().exists());
6161
assertTrue(repoBase.resolve("timestamp.json").toFile().exists());

sigstore-java/src/test/java/dev/sigstore/tuf/PassthroughCacheMetaStoreTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,9 @@ class PassthroughCacheMetaStoreTest {
4242
@BeforeAll
4343
public static void readAllMeta() throws IOException {
4444
Path timestampResource =
45-
Path.of(Resources.getResource("dev/sigstore/tuf/real/prod/timestamp.json").getPath());
45+
Path.of(
46+
Resources.getResource("dev/sigstore/tuf/synthetic/test/repository/timestamp.json")
47+
.getPath());
4648
timestamp = GSON.get().fromJson(Files.newBufferedReader(timestampResource), Timestamp.class);
4749
}
4850

0 commit comments

Comments
 (0)