Skip to content

Commit 42a67b3

Browse files
Merge branch '25-sync-certificate-api' into 'sync'
Java: add option to pass trusted certificate paths See merge request objectbox/objectbox-java!27
2 parents 75a0c98 + 3307ea1 commit 42a67b3

File tree

2 files changed

+19
-10
lines changed

2 files changed

+19
-10
lines changed

objectbox-java/src/main/java/io/objectbox/sync/SyncBuilder.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
package io.objectbox.sync;
22

3+
import javax.annotation.Nullable;
4+
35
import io.objectbox.BoxStore;
46
import io.objectbox.annotation.apihint.Experimental;
57
import io.objectbox.sync.internal.Platform;
68

7-
import javax.annotation.Nullable;
8-
99
/**
1010
* A builder to create a {@link SyncClient}; the builder itself should be created via
1111
* {@link Sync#client(BoxStore, String, SyncCredentials)}.
@@ -19,12 +19,11 @@ public class SyncBuilder {
1919
final String url;
2020
final SyncCredentials credentials;
2121

22-
@Nullable
23-
String certificatePath;
24-
2522
SyncClientListener listener;
2623
SyncChangesListener changesListener;
2724

25+
@Nullable
26+
String[] trustedCertPaths;
2827
boolean uncommittedAcks;
2928
boolean manualStart;
3029

@@ -72,9 +71,15 @@ public SyncBuilder(BoxStore boxStore, String url, SyncCredentials credentials) {
7271
this.credentials = credentials;
7372
}
7473

75-
// TODO Check if this should remain exposed in the final API
76-
public SyncBuilder certificatePath(String certificatePath) {
77-
this.certificatePath = certificatePath;
74+
/**
75+
* Configures a custom set of directory or file paths to search for trusted certificates in.
76+
* The first path that exists will be used.
77+
* <p>
78+
* Using this option is not recommended in most cases, as by default the sync client uses
79+
* the certificate authorities trusted by the host platform.
80+
*/
81+
public SyncBuilder trustedCertificates(String[] paths) {
82+
this.trustedCertPaths = paths;
7883
return this;
7984
}
8085

objectbox-java/src/main/java/io/objectbox/sync/SyncClientImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class SyncClientImpl implements SyncClient {
3232
this.connectivityMonitor = builder.platform.getConnectivityMonitor();
3333

3434
long boxStoreHandle = InternalAccess.getHandle(builder.boxStore);
35-
this.handle = nativeCreate(boxStoreHandle, serverUrl, builder.certificatePath);
35+
this.handle = nativeCreate(boxStoreHandle, serverUrl, builder.trustedCertPaths);
3636
if (handle == 0) {
3737
throw new RuntimeException("Failed to create sync client: handle is zero.");
3838
}
@@ -214,7 +214,11 @@ private void checkNotNull(Object object, String message) {
214214
}
215215
}
216216

217-
private static native long nativeCreate(long storeHandle, String uri, @Nullable String certificatePath);
217+
/**
218+
* Creates a native sync client for the given store handle ready to connect to the server at the given URI.
219+
* Uses certificate authorities trusted by the host if no trusted certificate paths are passed.
220+
*/
221+
private static native long nativeCreate(long storeHandle, String uri, @Nullable String[] certificateDirsOrPaths);
218222

219223
private native void nativeDelete(long handle);
220224

0 commit comments

Comments
 (0)