@@ -22,52 +22,25 @@ message us on the [sigstore#java](https://sigstore.slack.com/archives/C03239XUL9
22
22
Path testArtifact = Paths . get(" path/to/my/file.jar" )
23
23
24
24
var signer = KeylessSigner . builder(). sigstorePublicDefaults(). build();
25
- var result = signer. sign(testArtifact);
26
-
27
- // resulting signature information
25
+ Bundle result = signer. sign(testArtifact);
28
26
29
27
// sigstore bundle format (serialized as <artifact>.sigstore.json)
30
- String bundle = BundleFactory . createBundle(result)
31
-
32
- // artifact digest
33
- byte [] digest = result. getDigest();
34
-
35
- // certificate from fulcio
36
- CertPath certs = result. getCertPath() // java representation of a certificate path
37
- byte [] certsBytes = Certificates . toPemBytes(result. getCertPath()) // converted to PEM encoded byte array
38
-
39
- // artifact signature
40
- byte [] sig = result. getSignature()
41
-
28
+ String bundleJson = result. toJson();
42
29
```
43
30
44
31
#### Verification
45
32
46
- ##### KeylessSignature from bundle
33
+ ##### Read bundle
47
34
``` java
48
- var bundleFile = // java.nio.Path to a .sigstore.json signature bundle file
49
- var keylessSignature = BundleFactory . readBundle (Files . newBufferedReader(bundleFile, StandardCharsets . UTF_8 ));
35
+ Path bundleFile = // java.nio.Path to a .sigstore.json signature bundle file
36
+ Bundle bundle = Bundle . from (Files . newBufferedReader(bundleFile, StandardCharsets . UTF_8 ));
50
37
```
51
38
52
- ##### KeylessSignature from certificate and signature
53
- ``` java
54
- byte [] digest = // byte array sha256 artifact digest
55
- byte [] certificateChain = // byte array of PEM encoded cert chain
56
- byte [] signature = // byte array of artifact signature
57
- var keylessSignature =
58
- KeylessSignature . builder()
59
- .signature(signature)
60
- .certPath(Certificates . fromPemChain(certPath))
61
- .digest(digest)
62
- .build();
63
- ```
64
-
65
-
66
39
##### Configure verification options
67
40
``` java
68
- var verificationOptions =
41
+ // add certificate policy to verify the identity of the signer
42
+ VerificationOptions verificationOptions =
69
43
VerificationOptions . builder()
70
- // add certificate policy to verify the identity of the signer
71
44
.addCertificateIdentities(
72
45
CertificateIdentity . builder()
73
46
.issuer(" https://accounts.example.com" ))
@@ -78,15 +51,10 @@ var verificationOptions =
78
51
79
52
##### Do verification
80
53
``` java
81
- var artifact = // java.nio.Path to artifact file
54
+ Path artifact = // java.nio.Path to artifact file
82
55
try {
83
56
var verifier = new KeylessVerifier .Builder (). sigstorePublicDefaults(). build();
84
- verifier. verify(
85
- artifact,
86
- KeylessVerificationRequest . builder()
87
- .keylessSignature(keylessSignature)
88
- .verificationOptions(verificationOptions)
89
- .build());
57
+ verifier. verify(artifact, bundle, verificationOptions);
90
58
// verification passed!
91
59
} catch (KeylessVerificationException e) {
92
60
// verification failed
0 commit comments