-
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.
Signed-off-by: Appu Goundan <[email protected]>
- Loading branch information
1 parent
dfe3807
commit 0a3be1e
Showing
27 changed files
with
614 additions
and
2,404 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/* | ||
* 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 util; | ||
|
||
import com.code_intelligence.jazzer.api.FuzzedDataProvider; | ||
import com.google.common.hash.Hashing; | ||
import dev.sigstore.trustroot.CertificateAuthorities; | ||
import dev.sigstore.trustroot.CertificateAuthority; | ||
import dev.sigstore.trustroot.ImmutableCertificateAuthorities; | ||
import dev.sigstore.trustroot.ImmutableCertificateAuthority; | ||
import dev.sigstore.trustroot.ImmutableLogId; | ||
import dev.sigstore.trustroot.ImmutablePublicKey; | ||
import dev.sigstore.trustroot.ImmutableSubject; | ||
import dev.sigstore.trustroot.ImmutableTransparencyLog; | ||
import dev.sigstore.trustroot.ImmutableTransparencyLogs; | ||
import dev.sigstore.trustroot.ImmutableValidFor; | ||
import dev.sigstore.trustroot.TransparencyLog; | ||
import dev.sigstore.trustroot.TransparencyLogs; | ||
import java.io.ByteArrayInputStream; | ||
import java.net.URI; | ||
import java.security.cert.CertPath; | ||
import java.security.cert.Certificate; | ||
import java.security.cert.CertificateException; | ||
import java.security.cert.CertificateFactory; | ||
import java.time.Instant; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public final class Tuf { | ||
|
||
// arbitrarily decided max certificate size in bytes | ||
private static final int MAX_CERT_SIZE = 10240; | ||
|
||
// ecdsa key size in bytes | ||
private static final int ECDSA_KEY_BYTES = 91; | ||
|
||
public static TransparencyLogs transparencyLogsFrom(FuzzedDataProvider data) { | ||
return ImmutableTransparencyLogs.builder().addTransparencyLog(genTlog(data)).build(); | ||
} | ||
|
||
public static CertificateAuthorities certificateAuthoritiesFrom(FuzzedDataProvider data) | ||
throws CertificateException { | ||
return ImmutableCertificateAuthorities.builder().addCertificateAuthority(genCA(data)).build(); | ||
} | ||
|
||
private static CertPath genCertPath(FuzzedDataProvider data) throws CertificateException { | ||
List<Certificate> certList = new ArrayList<Certificate>(); | ||
CertificateFactory cf = CertificateFactory.getInstance("X.509"); | ||
certList.add( | ||
cf.generateCertificate(new ByteArrayInputStream(data.consumeBytes(MAX_CERT_SIZE)))); | ||
certList.add( | ||
cf.generateCertificate(new ByteArrayInputStream(data.consumeBytes(MAX_CERT_SIZE)))); | ||
return cf.generateCertPath(certList); | ||
} | ||
|
||
private static CertificateAuthority genCA(FuzzedDataProvider data) throws CertificateException { | ||
return ImmutableCertificateAuthority.builder() | ||
.validFor(ImmutableValidFor.builder().start(Instant.EPOCH).build()) | ||
.subject(ImmutableSubject.builder().commonName("test").organization("test").build()) | ||
.certPath(genCertPath(data)) | ||
.uri(URI.create("test")) | ||
.build(); | ||
} | ||
|
||
private static TransparencyLog genTlog(FuzzedDataProvider data) { | ||
var pk = | ||
ImmutablePublicKey.builder() | ||
.keyDetails("PKIX_ECDSA_P256_SHA_256") | ||
.rawBytes(data.consumeBytes(ECDSA_KEY_BYTES)) | ||
.validFor(ImmutableValidFor.builder().start(Instant.EPOCH).build()) | ||
.build(); | ||
var logId = Hashing.sha256().hashBytes(pk.getRawBytes()).asBytes(); | ||
return ImmutableTransparencyLog.builder() | ||
.baseUrl(URI.create("test")) | ||
.hashAlgorithm("SHA2_256") | ||
.publicKey(pk) | ||
.logId(ImmutableLogId.builder().keyId(logId).build()) | ||
.build(); | ||
} | ||
} |
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
Oops, something went wrong.