15
15
*/
16
16
package dev .sigstore .conformance ;
17
17
18
- import static com .google .common .io .Files .asByteSource ;
19
18
import static dev .sigstore .encryption .certificates .Certificates .toPemString ;
20
19
21
- import com .google .common .hash .Hashing ;
22
20
import dev .sigstore .KeylessSigner ;
23
21
import dev .sigstore .KeylessVerifier ;
24
22
import dev .sigstore .oidc .client .GithubActionsOidcClient ;
23
+ import java .io .IOException ;
24
+ import java .io .InputStream ;
25
+ import java .nio .charset .StandardCharsets ;
25
26
import java .nio .file .Files ;
26
27
import java .nio .file .Path ;
27
28
import java .nio .file .Paths ;
29
+ import java .security .MessageDigest ;
30
+ import java .security .NoSuchAlgorithmException ;
28
31
29
32
public class Main {
30
33
private static final String SIGN_COMMAND = "sign" ;
@@ -101,16 +104,20 @@ private static void executeSign(SignArguments args) throws Exception {
101
104
.build ();
102
105
final var result = signer .signFile (args .artifact );
103
106
Files .write (args .signature , result .getSignature ());
104
- final var pemBytes = toPemString (result .getCertPath ()).getBytes ();
107
+ final var pemBytes = toPemString (result .getCertPath ()).getBytes (StandardCharsets . UTF_8 );
105
108
Files .write (args .certificate , pemBytes );
106
109
}
107
110
108
111
private static class VerifyArguments {
109
112
public Path signature ;
110
113
public Path certificate ;
114
+ public Path artifact ;
115
+
116
+ @ SuppressWarnings ("unused" ) // remove when verifier actually verifies these
111
117
public String certificateIdentity ;
118
+
119
+ @ SuppressWarnings ("unused" ) // remove when verifier actually verifies these
112
120
public String certificateOidcIssuer ;
113
- public Path artifact ;
114
121
}
115
122
116
123
private static VerifyArguments parseVerifyArguments (Arguments args ) {
@@ -129,9 +136,20 @@ private static VerifyArguments parseVerifyArguments(Arguments args) {
129
136
130
137
private static void executeVerify (VerifyArguments args ) throws Exception {
131
138
final var verifier = KeylessVerifier .builder ().sigstorePublicDefaults ().build ();
132
- final var artifactByteSource = asByteSource (args .artifact .toFile ());
133
- final byte [] artifactDigest = artifactByteSource .hash (Hashing .sha256 ()).asBytes ();
139
+ final byte [] artifactDigest = sha256 (args .artifact );
134
140
verifier .verifyOnline (
135
141
artifactDigest , Files .readAllBytes (args .certificate ), Files .readAllBytes (args .signature ));
136
142
}
143
+
144
+ private static byte [] sha256 (Path path ) throws IOException , NoSuchAlgorithmException {
145
+ MessageDigest digest = MessageDigest .getInstance ("SHA-256" );
146
+ try (InputStream in = Files .newInputStream (path )) {
147
+ byte [] buffer = new byte [1024 ];
148
+ int count ;
149
+ while ((count = in .read (buffer )) > 0 ) {
150
+ digest .update (buffer , 0 , count );
151
+ }
152
+ }
153
+ return digest .digest ();
154
+ }
137
155
}
0 commit comments