1717
1818import com .google .common .annotations .VisibleForTesting ;
1919import com .google .common .base .Preconditions ;
20+ import dev .sigstore .http .URIFormat ;
2021import dev .sigstore .trustroot .SigstoreConfigurationException ;
2122import dev .sigstore .trustroot .SigstoreSigningConfig ;
2223import dev .sigstore .trustroot .SigstoreTrustedRoot ;
2324import java .io .IOException ;
24- import java .net .MalformedURLException ;
25- import java .net .URL ;
25+ import java .net .URI ;
2626import java .nio .file .Files ;
2727import java .nio .file .Path ;
2828import java .security .InvalidKeyException ;
@@ -65,21 +65,17 @@ public static class Builder {
6565 Path tufCacheLocation =
6666 Path .of (System .getProperty ("user.home" )).resolve (".sigstore-java" ).resolve ("root" );
6767
68- private URL remoteMirror ;
68+ private URI remoteMirror ;
6969 private RootProvider trustedRoot ;
7070
7171 public Builder usePublicGoodInstance () {
7272 if (remoteMirror != null || trustedRoot != null ) {
7373 throw new IllegalStateException (
7474 "Using public good after configuring remoteMirror and trustedRoot" );
7575 }
76- try {
77- tufMirror (
78- new URL ("https://tuf-repo-cdn.sigstore.dev/" ),
79- RootProvider .fromResource (PUBLIC_GOOD_ROOT_RESOURCE ));
80- } catch (MalformedURLException e ) {
81- throw new AssertionError (e );
82- }
76+ tufMirror (
77+ URI .create ("https://tuf-repo-cdn.sigstore.dev/" ),
78+ RootProvider .fromResource (PUBLIC_GOOD_ROOT_RESOURCE ));
8379 return this ;
8480 }
8581
@@ -88,13 +84,9 @@ public Builder useStagingInstance() {
8884 throw new IllegalStateException (
8985 "Using staging after configuring remoteMirror and trustedRoot" );
9086 }
91- try {
92- tufMirror (
93- new URL ("https://tuf-repo-cdn.sigstage.dev" ),
94- RootProvider .fromResource (STAGING_ROOT_RESOURCE ));
95- } catch (MalformedURLException e ) {
96- throw new AssertionError (e );
97- }
87+ tufMirror (
88+ URI .create ("https://tuf-repo-cdn.sigstage.dev" ),
89+ RootProvider .fromResource (STAGING_ROOT_RESOURCE ));
9890 tufCacheLocation =
9991 Path .of (System .getProperty ("user.home" ))
10092 .resolve (".sigstore-java" )
@@ -103,7 +95,7 @@ public Builder useStagingInstance() {
10395 return this ;
10496 }
10597
106- public Builder tufMirror (URL mirror , RootProvider trustedRoot ) {
98+ public Builder tufMirror (URI mirror , RootProvider trustedRoot ) {
10799 this .remoteMirror = mirror ;
108100 this .trustedRoot = trustedRoot ;
109101 return this ;
@@ -126,11 +118,7 @@ public SigstoreTufClient build() throws IOException {
126118 if (!Files .isDirectory (tufCacheLocation )) {
127119 Files .createDirectories (tufCacheLocation );
128120 }
129- var normalizedRemoteMirror =
130- remoteMirror .toString ().endsWith ("/" )
131- ? remoteMirror
132- : new URL (remoteMirror .toExternalForm () + "/" );
133- var remoteTargetsLocation = new URL (normalizedRemoteMirror .toExternalForm () + "targets" );
121+ var remoteTargetsLocation = URIFormat .appendPath (remoteMirror , "targets" );
134122 var filesystemTufStore = FileSystemTufStore .newFileSystemStore (tufCacheLocation );
135123 var tufUpdater =
136124 Updater .builder ()
@@ -139,8 +127,7 @@ public SigstoreTufClient build() throws IOException {
139127 TrustedMetaStore .newTrustedMetaStore (
140128 PassthroughCacheMetaStore .newPassthroughMetaCache (filesystemTufStore )))
141129 .setTargetStore (filesystemTufStore )
142- .setMetaFetcher (
143- MetaFetcher .newFetcher (HttpFetcher .newFetcher (normalizedRemoteMirror )))
130+ .setMetaFetcher (MetaFetcher .newFetcher (HttpFetcher .newFetcher (remoteMirror )))
144131 .setTargetFetcher (HttpFetcher .newFetcher (remoteTargetsLocation ))
145132 .build ();
146133 return new SigstoreTufClient (tufUpdater , cacheValidity );
0 commit comments