15
15
*/
16
16
package dev .sigstore .testing ;
17
17
18
+ import com .google .gson .Gson ;
19
+ import dev .sigstore .encryption .certificates .Certificates ;
18
20
import java .io .IOException ;
19
21
import java .net .URI ;
22
+ import java .net .http .HttpClient ;
23
+ import java .net .http .HttpRequest ;
24
+ import java .net .http .HttpResponse ;
25
+ import java .net .http .HttpResponse .BodyHandlers ;
20
26
import java .nio .file .Files ;
21
27
import java .nio .file .Path ;
28
+ import java .security .cert .CertPath ;
29
+ import java .security .cert .CertificateException ;
30
+ import java .util .List ;
22
31
import java .util .Locale ;
23
32
import org .junit .jupiter .api .extension .*;
24
33
@@ -40,14 +49,19 @@ public URI getURI() {
40
49
return URI .create ("http://localhost:5555" );
41
50
}
42
51
43
- public URI getGrpcURI () {
44
- return URI .create ("localhost:5554" );
45
- }
46
-
47
52
public URI getGrpcURI2 () {
48
53
return URI .create ("http://localhost:5554" );
49
54
}
50
55
56
+ public CertPath getTrustBundle () throws CertificateException , IOException , InterruptedException {
57
+ HttpRequest req =
58
+ HttpRequest .newBuilder ().uri (getURI ().resolve ("/api/v2/trustBundle" )).GET ().build ();
59
+ HttpResponse <String > response = HttpClient .newHttpClient ().send (req , BodyHandlers .ofString ());
60
+
61
+ TrustBundle tb = new Gson ().fromJson (response .body (), TrustBundle .class );
62
+ return Certificates .fromPemChain (tb .chains .get (0 ).certificates .get (0 ));
63
+ }
64
+
51
65
private Path createConfig (String issuer ) throws IOException {
52
66
fulcioConfig = Files .createTempFile ("fulcio-config" , ".json" );
53
67
Files .writeString (
@@ -99,6 +113,14 @@ public void beforeEach(ExtensionContext context) throws Exception {
99
113
Thread .sleep (1000 ); // wait for the server to come up
100
114
}
101
115
116
+ public static class TrustBundle {
117
+ private List <Chain > chains ;
118
+ }
119
+
120
+ public static class Chain {
121
+ private List <String > certificates ;
122
+ }
123
+
102
124
@ Override
103
125
public boolean supportsParameter (
104
126
ParameterContext parameterContext , ExtensionContext extensionContext )
0 commit comments