Skip to content

Commit 99ceb83

Browse files
committed
Generate sigstore bundle
Signed-off-by: Vladimir Sitnikov <[email protected]>
1 parent b2f3fdb commit 99ceb83

File tree

11 files changed

+214
-203
lines changed

11 files changed

+214
-203
lines changed

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,7 @@ end_of_line = crlf
1818

1919
[*.java]
2020
indent_size = 2
21+
ij_continuation_indent_size = 4
22+
# Doc: https://youtrack.jetbrains.com/issue/IDEA-170643#focus=streamItem-27-3708697.0-0
23+
# $ means "static"
24+
ij_java_imports_layout = $*,|,*

sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/SigstoreSignExtension.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ abstract class SigstoreSignExtension(private val project: Project) {
3939
abstract val sigstoreJavaVersion : Property<String>
4040

4141
init {
42-
sigstoreJavaVersion.convention("0.2.0")
42+
sigstoreJavaVersion.convention("0.3.0")
4343
(this as ExtensionAware).extensions.create<OidcClientExtension>(
4444
"oidcClient",
4545
project.objects,

sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/bundle/SigstoreBundle.kt

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

sigstore-gradle/sigstore-gradle-sign-base-plugin/src/main/kotlin/dev/sigstore/sign/work/SignWorkAction.kt

Lines changed: 3 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -16,26 +16,22 @@
1616
*/
1717
package dev.sigstore.sign.work
1818

19-
import com.fasterxml.jackson.databind.ObjectMapper
2019
import dev.sigstore.KeylessSigner
20+
import dev.sigstore.bundle.BundleFactory
2121
import dev.sigstore.oidc.client.OidcClient
2222
import dev.sigstore.sign.OidcClientConfiguration
23-
import dev.sigstore.sign.bundle.*
2423
import org.gradle.api.file.RegularFileProperty
2524
import org.gradle.api.provider.Property
2625
import org.gradle.workers.WorkAction
2726
import org.gradle.workers.WorkParameters
2827
import org.slf4j.LoggerFactory
29-
import java.util.*
3028

3129
abstract class SignWorkParameters : WorkParameters {
3230
abstract val inputFile: RegularFileProperty
3331
abstract val outputSignature: RegularFileProperty
3432
abstract val oidcClient: Property<OidcClientConfiguration>
3533
}
3634

37-
private val jsonMapper = ObjectMapper().writerWithDefaultPrettyPrinter()
38-
3935
abstract class SignWorkAction : WorkAction<SignWorkParameters> {
4036
companion object {
4137
val logger = LoggerFactory.getLogger(SignWorkAction::class.java)
@@ -53,32 +49,7 @@ abstract class SignWorkAction : WorkAction<SignWorkParameters> {
5349
}.build()
5450

5551
val result = signer.signFile(inputFile.toPath())
56-
val signature = SigstoreBundle(
57-
mediaType = BundleMediaTypes.V1_JSON.value,
58-
timestampProof = RekorEntry(
59-
logIndex = result.entry.logIndex,
60-
logId = result.entry.logID,
61-
integratedTime = result.entry.integratedTime,
62-
signedEntryTimestamp = Base64.getDecoder().decode(result.entry.verification.signedEntryTimestamp),
63-
),
64-
attestation = AttestationBlob(
65-
payloadHash = HashValue(
66-
// See https://github.com/sigstore/sigstore-java/issues/85
67-
algorithm = HashAlgorithm.sha256,
68-
// https://github.com/sigstore/sigstore-java/issues/86
69-
hash = result.digest.chunked(2)
70-
.map { it.toInt(16).toByte() }
71-
.toByteArray(),
72-
),
73-
signature = result.signature,
74-
),
75-
verificationMaterial = X509CertVerificationMaterial(
76-
chain = result.certPath.encoded,
77-
)
78-
)
79-
jsonMapper.writeValue(
80-
parameters.outputSignature.get().asFile,
81-
signature
82-
)
52+
val bundleJson = BundleFactory.createBundle(result)
53+
parameters.outputSignature.get().asFile.writeText(bundleJson)
8354
}
8455
}

sigstore-gradle/sigstore-gradle-sign-base-plugin/src/test/kotlin/dev/sigstore/gradle/SigstoreBundleTest.kt

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

sigstore-java/build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ dependencies {
2020

2121
implementation("io.github.erdtman:java-json-canonicalization:1.1")
2222

23-
implementation("dev.sigstore:protobuf-specs:0.0.1") {
23+
implementation("dev.sigstore:protobuf-specs:0.1.0") {
2424
because("It generates Sigstore Bundle file")
2525
}
2626
implementation("com.google.protobuf:protobuf-java-util:3.21.12") {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright 2022 The Sigstore Authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package dev.sigstore.bundle;
17+
18+
import com.google.protobuf.InvalidProtocolBufferException;
19+
import com.google.protobuf.util.JsonFormat;
20+
import dev.sigstore.KeylessSigningResult;
21+
import dev.sigstore.proto.bundle.v1.Bundle;
22+
23+
/**
24+
* Generates Sigstore Bundle.
25+
*
26+
* @see <a href="https://github.com/sigstore/protobuf-specs">Sigstore Bundle Protobuf
27+
* specifications</a>
28+
*/
29+
public class BundleFactory {
30+
private static final JsonFormat.Printer JSON_PRINTER = JsonFormat.printer();
31+
32+
/**
33+
* Generates Sigstore Bundle JSON from {@link KeylessSigningResult}.
34+
*
35+
* @param signingResult Keyless signing result.
36+
* @return Sigstore Bundle in JSON format
37+
*/
38+
public static String createBundle(KeylessSigningResult signingResult) {
39+
Bundle bundle = BundleFactoryInternal.createBundleBuilder(signingResult).build();
40+
try {
41+
return JSON_PRINTER.print(bundle);
42+
} catch (InvalidProtocolBufferException e) {
43+
throw new IllegalArgumentException(
44+
"Can't serialize signing result to Sigstore Bundle JSON", e);
45+
}
46+
}
47+
}

0 commit comments

Comments
 (0)