-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- update embedded tuf roots to newer roots - move key parsing into tuf package - have separate tuf signature verifiers - remove copy of prod data - have all ed25519 key handling done by bc Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
764abc9
commit ee0e0fe
Showing
65 changed files
with
809 additions
and
2,912 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,15 @@ | |
|
||
import com.google.common.annotations.VisibleForTesting; | ||
import com.google.common.hash.Hashing; | ||
import dev.sigstore.encryption.Keys; | ||
import dev.sigstore.encryption.signers.Verifiers; | ||
import dev.sigstore.tuf.encryption.Verifiers; | ||
import dev.sigstore.tuf.model.*; | ||
import dev.sigstore.tuf.model.TargetMeta.TargetData; | ||
import dev.sigstore.tuf.model.Targets; | ||
import dev.sigstore.tuf.model.Timestamp; | ||
import dev.sigstore.tuf.model.TufMeta; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PublicKey; | ||
import java.security.SignatureException; | ||
import java.security.spec.InvalidKeySpecException; | ||
import java.time.Clock; | ||
|
@@ -247,34 +247,34 @@ void verifyDelegate( | |
// look for the public key that matches the key ID and use it for verification. | ||
var key = publicKeys.get(signature.getKeyId()); | ||
if (key != null) { | ||
String publicKeyContents = key.getKeyVal().get("public"); | ||
PublicKey pubKey; | ||
// TUF root version 4 and less is raw hex encoded key while 5+ is PEM. | ||
// TODO([email protected]): remove hex handling code once we upgrade the trusted root | ||
// to v5. | ||
if (publicKeyContents.startsWith("-----BEGIN PUBLIC KEY-----")) { | ||
pubKey = Keys.parsePublicKey(publicKeyContents.getBytes(StandardCharsets.UTF_8)); | ||
} else { | ||
pubKey = Keys.constructTufPublicKey(Hex.decode(publicKeyContents), key.getScheme()); | ||
} | ||
try { | ||
// while we error on keys that are not readable, we are intentionally more permissive | ||
// about signatures. If for ANY reason (except unparsed keys) we cannot validate a | ||
// signature, we continue as long as we find enough valid signatures within the | ||
// threshold. We still warn the user as this could be an indicator of data issues | ||
byte[] signatureBytes = Hex.decode(signature.getSignature()); | ||
if (verifiers.newVerifier(pubKey).verify(verificationMaterial, signatureBytes)) { | ||
if (verifiers.newVerifier(key).verify(verificationMaterial, signatureBytes)) { | ||
goodSigs.add(signature.getKeyId()); | ||
} else { | ||
log.log( | ||
Level.FINE, | ||
() -> | ||
String.format( | ||
Locale.ROOT, | ||
"TUF: ignored failed signature verification: '%s' for keyid: '%s'", | ||
signature.getSignature(), | ||
signature.getKeyId())); | ||
} | ||
} catch (SignatureException e) { | ||
log.log( | ||
Level.FINE, | ||
() -> | ||
String.format( | ||
Locale.ROOT, | ||
"TUF: ignored unverifiable signature: '%s' for keyid: '%s'", | ||
"TUF: ignored unverifiable signature: '%s' for keyid: '%s', because '%s'", | ||
signature.getSignature(), | ||
signature.getKeyId())); | ||
signature.getKeyId(), | ||
e.getMessage())); | ||
} catch (DecoderException | NoSuchAlgorithmException | InvalidKeyException e) { | ||
log.log( | ||
Level.WARNING, | ||
|
41 changes: 41 additions & 0 deletions
41
sigstore-java/src/main/java/dev/sigstore/tuf/encryption/EcdsaVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore.tuf.encryption; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PublicKey; | ||
import java.security.Signature; | ||
import java.security.SignatureException; | ||
|
||
/** ECDSA verifier, instantiated in {@link Verifiers}. */ | ||
class EcdsaVerifier implements Verifier { | ||
|
||
private final PublicKey publicKey; | ||
|
||
EcdsaVerifier(PublicKey publicKey) { | ||
this.publicKey = publicKey; | ||
} | ||
|
||
@Override | ||
public boolean verify(byte[] artifact, byte[] signature) | ||
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { | ||
var verifier = Signature.getInstance("SHA256withECDSA"); | ||
verifier.initVerify(publicKey); | ||
verifier.update(artifact); | ||
return verifier.verify(signature); | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
sigstore-java/src/main/java/dev/sigstore/tuf/encryption/Ed25519Verifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
/* | ||
* Copyright 2022 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore.tuf.encryption; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PublicKey; | ||
import java.security.Signature; | ||
import java.security.SignatureException; | ||
|
||
/** Ed25519 verifier, instantiated by {@link Verifiers}. */ | ||
class Ed25519Verifier implements Verifier { | ||
|
||
private final PublicKey publicKey; | ||
|
||
Ed25519Verifier(PublicKey publicKey) { | ||
this.publicKey = publicKey; | ||
} | ||
|
||
/** EdDSA verifiers hash implicitly for ed25519 keys. */ | ||
@Override | ||
public boolean verify(byte[] artifact, byte[] signature) | ||
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { | ||
var verifier = Signature.getInstance("Ed25519"); | ||
verifier.initVerify(publicKey); | ||
verifier.update(artifact); | ||
return verifier.verify(signature); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
sigstore-java/src/main/java/dev/sigstore/tuf/encryption/RsaPssVerifier.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2022 The Sigstore Authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package dev.sigstore.tuf.encryption; | ||
|
||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.PublicKey; | ||
import java.security.Signature; | ||
import java.security.SignatureException; | ||
|
||
/** RSA verifier using PSS and MGF1, instantiated by {@link Verifiers}. */ | ||
class RsaPssVerifier implements Verifier { | ||
|
||
private final PublicKey publicKey; | ||
|
||
RsaPssVerifier(PublicKey publicKey) { | ||
this.publicKey = publicKey; | ||
} | ||
|
||
@Override | ||
public boolean verify(byte[] artifact, byte[] signature) | ||
throws NoSuchAlgorithmException, InvalidKeyException, SignatureException { | ||
var verifier = Signature.getInstance("SHA256withRSAandMGF1"); | ||
verifier.initVerify(publicKey); | ||
verifier.update(artifact); | ||
return verifier.verify(signature); | ||
} | ||
} |
Oops, something went wrong.