17
17
18
18
import com .google .common .io .Resources ;
19
19
import com .google .protobuf .util .JsonFormat ;
20
+ import dev .sigstore .bundle .BundleFactory ;
20
21
import dev .sigstore .encryption .certificates .transparency .SerializationException ;
21
22
import dev .sigstore .proto .trustroot .v1 .TrustedRoot ;
22
23
import dev .sigstore .trustroot .ImmutableLogId ;
23
24
import dev .sigstore .trustroot .ImmutableTransparencyLog ;
24
25
import dev .sigstore .trustroot .ImmutableTransparencyLogs ;
25
26
import dev .sigstore .trustroot .SigstoreTrustedRoot ;
26
27
import java .io .IOException ;
28
+ import java .io .StringReader ;
27
29
import java .nio .charset .StandardCharsets ;
28
30
import java .security .InvalidAlgorithmParameterException ;
29
31
import java .security .NoSuchAlgorithmException ;
37
39
public class FulcioVerifier2Test {
38
40
private static String sctBase64 ;
39
41
private static String certs ;
40
- private static String certs2 ;
41
- private static byte [] fulcioRoot ;
42
- private static byte [] ctfePub ;
43
- private static byte [] badCtfePub ;
44
42
private static String certsWithEmbeddedSct ;
43
+ private static String bundleFile ;
45
44
46
45
private static SigstoreTrustedRoot trustRoot ;
47
46
@@ -56,23 +55,14 @@ public static void loadResources() throws IOException {
56
55
Resources .getResource ("dev/sigstore/samples/fulcio-response/valid/cert.pem" ),
57
56
StandardCharsets .UTF_8 );
58
57
59
- certs2 =
58
+ certsWithEmbeddedSct =
60
59
Resources .toString (
61
- Resources .getResource ("dev/sigstore/samples/certs/cert-githuboidc .pem" ),
60
+ Resources .getResource ("dev/sigstore/samples/fulcio-response/valid/certWithSct .pem" ),
62
61
StandardCharsets .UTF_8 );
63
62
64
- fulcioRoot =
65
- Resources .toByteArray (
66
- Resources .getResource ("dev/sigstore/samples/fulcio-response/valid/fulcio.crt.pem" ));
67
- ctfePub =
68
- Resources .toByteArray (
69
- Resources .getResource ("dev/sigstore/samples/fulcio-response/valid/ctfe.pub" ));
70
- badCtfePub =
71
- Resources .toByteArray (Resources .getResource ("dev/sigstore/samples/keys/test-rsa.pub" ));
72
-
73
- certsWithEmbeddedSct =
63
+ bundleFile =
74
64
Resources .toString (
75
- Resources .getResource ("dev/sigstore/samples/fulcio-response/valid/certWithSct.pem " ),
65
+ Resources .getResource ("dev/sigstore/samples/bundles/bundle-with-leaf-cert.sigstore " ),
76
66
StandardCharsets .UTF_8 );
77
67
}
78
68
@@ -95,16 +85,18 @@ public void detachedSctNotSupported() throws Exception {
95
85
var signingCertificate = SigningCertificate .newSigningCertificate (certs , sctBase64 );
96
86
var ex =
97
87
Assertions .assertThrows (
98
- FulcioVerificationException .class , () -> fulcioVerifier .verifySct (signingCertificate ));
88
+ FulcioVerificationException .class ,
89
+ () -> fulcioVerifier .verifySct (signingCertificate , signingCertificate .getCertPath ()));
99
90
Assertions .assertEquals (
100
- ex . getMessage (), "Detached SCTs are not supported for validating certificates" );
91
+ "Detached SCTs are not supported for validating certificates" , ex . getMessage () );
101
92
}
102
93
103
94
@ Test
104
95
public void testVerifySct_nullCtLogKey ()
105
96
throws IOException , SerializationException , CertificateException , InvalidKeySpecException ,
106
97
NoSuchAlgorithmException , InvalidAlgorithmParameterException {
107
- var signingCertificate = SigningCertificate .newSigningCertificate (certs , sctBase64 );
98
+ var signingCertificate =
99
+ SigningCertificate .newSigningCertificate (certsWithEmbeddedSct , sctBase64 );
108
100
var fulcioVerifier =
109
101
FulcioVerifier2 .newFulcioVerifier (
110
102
trustRoot .getCAs (),
@@ -113,7 +105,7 @@ public void testVerifySct_nullCtLogKey()
113
105
.build ());
114
106
115
107
try {
116
- fulcioVerifier .verifySct (signingCertificate );
108
+ fulcioVerifier .verifySigningCertificate (signingCertificate );
117
109
Assertions .fail ();
118
110
} catch (FulcioVerificationException fve ) {
119
111
Assertions .assertEquals ("No ct logs were provided to verifier" , fve .getMessage ());
@@ -126,7 +118,7 @@ public void testVerifySct_noSct() throws Exception {
126
118
var fulcioVerifier = FulcioVerifier2 .newFulcioVerifier (trustRoot );
127
119
128
120
try {
129
- fulcioVerifier .verifySct (signingCertificate );
121
+ fulcioVerifier .verifySct (signingCertificate , signingCertificate . getCertPath () );
130
122
Assertions .fail ();
131
123
} catch (FulcioVerificationException fve ) {
132
124
Assertions .assertEquals ("No valid SCTs were found during verification" , fve .getMessage ());
@@ -138,8 +130,16 @@ public void validSigningCertAndEmbeddedSct() throws Exception {
138
130
var signingCertificate = SigningCertificate .newSigningCertificate (certsWithEmbeddedSct , null );
139
131
var fulcioVerifier = FulcioVerifier2 .newFulcioVerifier (trustRoot );
140
132
141
- fulcioVerifier .verifyCertChain (signingCertificate );
142
- fulcioVerifier .verifySct (signingCertificate );
133
+ fulcioVerifier .verifySigningCertificate (signingCertificate );
134
+ }
135
+
136
+ @ Test
137
+ public void validBundle () throws Exception {
138
+ var bundle = BundleFactory .readBundle (new StringReader (bundleFile ));
139
+ var fulcioVerifier = FulcioVerifier2 .newFulcioVerifier (trustRoot );
140
+
141
+ Assertions .assertEquals (1 , bundle .getCertPath ().getCertificates ().size ());
142
+ fulcioVerifier .verifySigningCertificate (SigningCertificate .from (bundle .getCertPath ()));
143
143
}
144
144
145
145
@ Test
@@ -161,7 +161,8 @@ public void invalidEmbeddedSct() throws Exception {
161
161
162
162
var fve =
163
163
Assertions .assertThrows (
164
- FulcioVerificationException .class , () -> fulcioVerifier .verifySct (signingCertificate ));
164
+ FulcioVerificationException .class ,
165
+ () -> fulcioVerifier .verifySct (signingCertificate , signingCertificate .getCertPath ()));
165
166
Assertions .assertEquals ("No valid SCTs were found, all(1) SCTs were invalid" , fve .getMessage ());
166
167
}
167
168
}
0 commit comments