-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
While this will allow anyone to inject a trustedRoot instead of using sigstore public good, its been primarily included to allow conformance to inject alt trusted roots The cli now outputs signatures as Base64 instead of raw bytes Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
8d2d442
commit 9a98407
Showing
5 changed files
with
88 additions
and
10 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
57 changes: 57 additions & 0 deletions
57
sigstore-java/src/main/java/dev/sigstore/TrustedRootProvider.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,57 @@ | ||
/* | ||
* Copyright 2023 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; | ||
|
||
import com.google.common.base.Preconditions; | ||
import com.google.protobuf.util.JsonFormat; | ||
import dev.sigstore.proto.trustroot.v1.TrustedRoot; | ||
import dev.sigstore.trustroot.SigstoreTrustedRoot; | ||
import dev.sigstore.tuf.SigstoreTufClient; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
import java.security.InvalidAlgorithmParameterException; | ||
import java.security.InvalidKeyException; | ||
import java.security.NoSuchAlgorithmException; | ||
import java.security.cert.CertificateException; | ||
import java.security.spec.InvalidKeySpecException; | ||
|
||
@FunctionalInterface | ||
public interface TrustedRootProvider { | ||
|
||
SigstoreTrustedRoot get() | ||
throws InvalidAlgorithmParameterException, CertificateException, InvalidKeySpecException, | ||
NoSuchAlgorithmException, IOException, InvalidKeyException; | ||
|
||
static TrustedRootProvider from(SigstoreTufClient tufClient) { | ||
Preconditions.checkNotNull(tufClient); | ||
return () -> { | ||
tufClient.update(); | ||
return tufClient.getSigstoreTrustedRoot(); | ||
}; | ||
} | ||
|
||
static TrustedRootProvider from(Path trustedRoot) { | ||
Preconditions.checkNotNull(trustedRoot); | ||
return () -> { | ||
var trustedRootBuilder = TrustedRoot.newBuilder(); | ||
JsonFormat.parser() | ||
.merge(Files.readString(trustedRoot, StandardCharsets.UTF_8), trustedRootBuilder); | ||
return SigstoreTrustedRoot.from(trustedRootBuilder.build()); | ||
}; | ||
} | ||
} |