diff --git a/CHANGELOG.md b/CHANGELOG.md index a96af4fb..0bb8ffca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,8 @@ ### Breaking changes * Files written by Realm this version cannot be read by earlier versions of Realm. Old files can still be opened and files open in read-only mode will not be modified. +* The `setVerifyServersSslCertificate` method has been deleted +* The SyncConfig now gets two more optional parameters, `validate_ssl` and `ssl_trust_certificate_path`. ### Enhancements * None diff --git a/Jenkinsfile b/Jenkinsfile index 4438c36e..85629f2d 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -123,7 +123,7 @@ def reportStatus(target, state, String message) { ], reposSource: [$class: 'ManuallyEnteredRepositorySource', url: 'https://github.com/realm/realm-js'] ]) - } catch(Exception e) { + } catch(Exception err) { echo "Error posting to GitHub: ${err}" } } diff --git a/binding.gyp b/binding.gyp index 786fb567..dde627b7 100644 --- a/binding.gyp +++ b/binding.gyp @@ -80,7 +80,9 @@ ["OS=='mac'", { "sources": [ "src/object-store/src/impl/apple/external_commit_helper.cpp", - "src/object-store/src/impl/apple/keychain_helper.cpp" + "src/object-store/src/impl/apple/keychain_helper.cpp", + "src/object-store/src/sync/impl/apple/network_reachability_observer.cpp", + "src/object-store/src/sync/impl/apple/system_configuration.cpp" ] }], ["realm_enable_sync", { diff --git a/dependencies.list b/dependencies.list index 8a44bc5a..629028c2 100644 --- a/dependencies.list +++ b/dependencies.list @@ -1,5 +1,5 @@ PACKAGE_NAME=realm-js VERSION=1.2.0 REALM_CORE_VERSION=2.6.0 -REALM_SYNC_VERSION=1.5.2 +REALM_SYNC_VERSION=1.8.3 REALM_OBJECT_SERVER_VERSION=1.3.0 diff --git a/docs/sync.js b/docs/sync.js index d5ce84e7..18559058 100644 --- a/docs/sync.js +++ b/docs/sync.js @@ -31,6 +31,9 @@ class Sync { * _Currently only the 'change' event is supported_ * @param {function(change_event)} change_callback - called when changes are made to any Realm which * match the given regular expression + * @param {bool} validate_ssl=true - Validate the server's SSL chertificate. + * @param {string} ssl_trust_certificate_path=None - Path to a trust/anchor certificate used by the + * client to verify the server certificate. */ static addListener(server_url, admin_user, regex, name, change_callback) {} @@ -86,8 +89,8 @@ class ChangeEvent { * The change indexes for all added, removed, and modified objects in the changed Realm. * This object is a hashmap of object types to arrays of indexes for all changed objects: * @example - * { - * object_type_1: { + * { + * object_type_1: { * insertions: [indexes...], * deletions: [indexes...], * modifications: [indexes...] @@ -183,7 +186,7 @@ class User { * @type {User} */ static get current() {} - + /** * Gets the server URL that was used for authentication. * @type {string} @@ -191,14 +194,14 @@ class User { get server() {} /** - * Gets the identity of this user on the Realm Object Server. + * Gets the identity of this user on the Realm Object Server. * The identity is a guaranteed to be unique among all users on the Realm Object Server. * @type {string} */ get identity() {} /** - * Gets this user's refresh token. This is the user's credential for accessing the Realm + * Gets this user's refresh token. This is the user's credential for accessing the Realm * Object Server and should be treated as sensitive data. * @type {string} */ @@ -225,9 +228,9 @@ class User { } /** - * An object encapsulating a Realm Object Server session. Sessions represent the communication between the + * An object encapsulating a Realm Object Server session. Sessions represent the communication between the * client (and a local Realm file on disk), and the server (and a remote Realm at a given URL stored on a Realm Object Server). - * Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions + * Sessions are always created by the SDK and vended out through various APIs. The lifespans of sessions * associated with Realms are managed automatically. * @memberof Realm.Sync */ diff --git a/src/RealmJS.xcodeproj/project.pbxproj b/src/RealmJS.xcodeproj/project.pbxproj index 85d57fb2..74e7bdfd 100644 --- a/src/RealmJS.xcodeproj/project.pbxproj +++ b/src/RealmJS.xcodeproj/project.pbxproj @@ -41,6 +41,10 @@ 02F59EE21C88F2BB007F774C /* realm_coordinator.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EDB1C88F2BA007F774C /* realm_coordinator.cpp */; }; 02F59EE31C88F2BB007F774C /* transact_log_handler.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 02F59EDD1C88F2BB007F774C /* transact_log_handler.cpp */; }; 502B07E41E2CD201007A84ED /* object.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 502B07E31E2CD1FA007A84ED /* object.cpp */; }; + 504CF85E1EBCAE3600A9A4B6 /* network_reachability_observer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504CF8541EBCAE3600A9A4B6 /* network_reachability_observer.cpp */; }; + 504CF85F1EBCAE3600A9A4B6 /* system_configuration.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504CF8561EBCAE3600A9A4B6 /* system_configuration.cpp */; }; + 504CF8601EBCAE3600A9A4B6 /* sync_file.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504CF85A1EBCAE3600A9A4B6 /* sync_file.cpp */; }; + 504CF8611EBCAE3600A9A4B6 /* sync_metadata.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 504CF85C1EBCAE3600A9A4B6 /* sync_metadata.cpp */; }; 50C671001E1D2D31003CB63C /* thread_safe_reference.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 5D02C7791E1C83650048C13E /* thread_safe_reference.cpp */; }; 5D25F5A11D6284FD00EBBB30 /* libz.tbd in Frameworks */ = {isa = PBXBuildFile; fileRef = F63FF3301C16434400B3B8E0 /* libz.tbd */; }; 8507156E1E2CFCD000E548DB /* object_notifier.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 8507156B1E2CFC0100E548DB /* object_notifier.cpp */; }; @@ -174,6 +178,16 @@ 02F59EDE1C88F2BB007F774C /* transact_log_handler.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = transact_log_handler.hpp; sourceTree = ""; }; 502B07E31E2CD1FA007A84ED /* object.cpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.cpp; name = object.cpp; path = src/object.cpp; sourceTree = ""; }; 502B07E51E2CD20D007A84ED /* object.hpp */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.cpp.h; name = object.hpp; path = src/object.hpp; sourceTree = ""; }; + 504CF8541EBCAE3600A9A4B6 /* network_reachability_observer.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = network_reachability_observer.cpp; sourceTree = ""; }; + 504CF8551EBCAE3600A9A4B6 /* network_reachability_observer.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = network_reachability_observer.hpp; sourceTree = ""; }; + 504CF8561EBCAE3600A9A4B6 /* system_configuration.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = system_configuration.cpp; sourceTree = ""; }; + 504CF8571EBCAE3600A9A4B6 /* system_configuration.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = system_configuration.hpp; sourceTree = ""; }; + 504CF8581EBCAE3600A9A4B6 /* network_reachability.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = network_reachability.hpp; sourceTree = ""; }; + 504CF8591EBCAE3600A9A4B6 /* sync_client.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sync_client.hpp; sourceTree = ""; }; + 504CF85A1EBCAE3600A9A4B6 /* sync_file.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sync_file.cpp; sourceTree = ""; }; + 504CF85B1EBCAE3600A9A4B6 /* sync_file.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sync_file.hpp; sourceTree = ""; }; + 504CF85C1EBCAE3600A9A4B6 /* sync_metadata.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = sync_metadata.cpp; sourceTree = ""; }; + 504CF85D1EBCAE3600A9A4B6 /* sync_metadata.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; path = sync_metadata.hpp; sourceTree = ""; }; 5D02C7781E1C83650048C13E /* execution_context_id.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = execution_context_id.hpp; path = src/execution_context_id.hpp; sourceTree = ""; }; 5D02C7791E1C83650048C13E /* thread_safe_reference.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; name = thread_safe_reference.cpp; path = src/thread_safe_reference.cpp; sourceTree = ""; }; 5D02C77A1E1C83650048C13E /* thread_safe_reference.hpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.h; name = thread_safe_reference.hpp; path = src/thread_safe_reference.hpp; sourceTree = ""; }; @@ -426,6 +440,7 @@ 02E315CC1DB80DE000555337 /* sync */ = { isa = PBXGroup; children = ( + 504CF8521EBCAE3600A9A4B6 /* impl */, 02E315CD1DB80DF200555337 /* sync_client.hpp */, 02E315CE1DB80DF200555337 /* sync_file.cpp */, 02E315CF1DB80DF200555337 /* sync_file.hpp */, @@ -442,6 +457,32 @@ name = sync; sourceTree = ""; }; + 504CF8521EBCAE3600A9A4B6 /* impl */ = { + isa = PBXGroup; + children = ( + 504CF8531EBCAE3600A9A4B6 /* apple */, + 504CF8581EBCAE3600A9A4B6 /* network_reachability.hpp */, + 504CF8591EBCAE3600A9A4B6 /* sync_client.hpp */, + 504CF85A1EBCAE3600A9A4B6 /* sync_file.cpp */, + 504CF85B1EBCAE3600A9A4B6 /* sync_file.hpp */, + 504CF85C1EBCAE3600A9A4B6 /* sync_metadata.cpp */, + 504CF85D1EBCAE3600A9A4B6 /* sync_metadata.hpp */, + ); + name = impl; + path = src/sync/impl; + sourceTree = ""; + }; + 504CF8531EBCAE3600A9A4B6 /* apple */ = { + isa = PBXGroup; + children = ( + 504CF8541EBCAE3600A9A4B6 /* network_reachability_observer.cpp */, + 504CF8551EBCAE3600A9A4B6 /* network_reachability_observer.hpp */, + 504CF8561EBCAE3600A9A4B6 /* system_configuration.cpp */, + 504CF8571EBCAE3600A9A4B6 /* system_configuration.hpp */, + ); + path = apple; + sourceTree = ""; + }; F62A35131C18E6E2004A917D /* iOS */ = { isa = PBXGroup; children = ( @@ -837,10 +878,13 @@ 02022A581DA476CD000F0C4F /* external_commit_helper.cpp in Sources */, 02022A5A1DA476CD000F0C4F /* weak_realm_notifier.cpp in Sources */, 02022A5B1DA476CD000F0C4F /* placeholder.cpp in Sources */, + 504CF8611EBCAE3600A9A4B6 /* sync_metadata.cpp in Sources */, 502B07E41E2CD201007A84ED /* object.cpp in Sources */, 02414BA51CE6ABCF00A8669F /* collection_change_builder.cpp in Sources */, 02414BA61CE6ABCF00A8669F /* collection_notifier.cpp in Sources */, + 504CF85F1EBCAE3600A9A4B6 /* system_configuration.cpp in Sources */, 02414BA71CE6ABCF00A8669F /* list_notifier.cpp in Sources */, + 504CF8601EBCAE3600A9A4B6 /* sync_file.cpp in Sources */, 02414BA81CE6ABCF00A8669F /* results_notifier.cpp in Sources */, 02414BA91CE6ABCF00A8669F /* collection_notifications.cpp in Sources */, 02F59EE31C88F2BB007F774C /* transact_log_handler.cpp in Sources */, @@ -855,6 +899,7 @@ 02F59EBF1C88F17D007F774C /* index_set.cpp in Sources */, F63FF2C91C12469E00B3B8E0 /* js_realm.cpp in Sources */, 02F59EC51C88F17D007F774C /* shared_realm.cpp in Sources */, + 504CF85E1EBCAE3600A9A4B6 /* network_reachability_observer.cpp in Sources */, 02F59EE21C88F2BB007F774C /* realm_coordinator.cpp in Sources */, 02F59EC41C88F17D007F774C /* schema.cpp in Sources */, F63FF2CD1C12469E00B3B8E0 /* rpc.cpp in Sources */, diff --git a/src/js_sync.hpp b/src/js_sync.hpp index 784c013a..427a1268 100644 --- a/src/js_sync.hpp +++ b/src/js_sync.hpp @@ -175,12 +175,12 @@ class SessionClass : public ClassDefinition { using Object = js::Object; using Value = js::Value; using ReturnValue = js::ReturnValue; - + public: std::string const name = "Session"; static FunctionType create_constructor(ContextType); - + static void get_config(ContextType, ObjectType, ReturnValue &); static void get_user(ContextType, ObjectType, ReturnValue &); static void get_url(ContextType, ObjectType, ReturnValue &); @@ -289,7 +289,7 @@ template void SessionClass::get_state(ContextType ctx, ObjectType object, ReturnValue &return_value) { static const std::string invalid("invalid"); static const std::string inactive("inactive"); - static const std::string active("active"); + static const std::string active("active"); return_value.set(invalid); @@ -345,7 +345,6 @@ public: static FunctionType create_constructor(ContextType); static void set_sync_log_level(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); - static void set_verify_servers_ssl_certificate(ContextType, FunctionType, ObjectType, size_t, const ValueType[], ReturnValue &); // private static void populate_sync_config(ContextType, ObjectType realm_constructor, ObjectType config_object, Realm::Config&); @@ -355,7 +354,6 @@ public: MethodMap const static_methods = { {"setLogLevel", wrap}, - {"setVerifyServersSslCertificate", wrap} }; }; @@ -366,7 +364,7 @@ inline typename T::Function SyncClass::create_constructor(ContextType ctx) { PropertyAttributes attributes = ReadOnly | DontEnum | DontDelete; Object::set_property(ctx, sync_constructor, "User", ObjectWrap>::create_constructor(ctx), attributes); Object::set_property(ctx, sync_constructor, "Session", ObjectWrap>::create_constructor(ctx), attributes); - + // setup synced realmFile paths ensure_directory_exists_for_file(default_realm_file_directory()); SyncManager::shared().configure_file_system(default_realm_file_directory(), SyncManager::MetadataMode::NoEncryption); @@ -388,13 +386,6 @@ void SyncClass::set_sync_log_level(ContextType ctx, FunctionType, ObjectType realm::SyncManager::shared().set_log_level(log_level_2); } -template -void SyncClass::set_verify_servers_ssl_certificate(ContextType ctx, FunctionType, ObjectType this_object, size_t argc, const ValueType arguments[], ReturnValue &return_value) { - validate_argument_count(argc, 1); - bool verify_servers_ssl_certificate = Value::validated_to_boolean(ctx, arguments[0]); - realm::SyncManager::shared().set_client_should_validate_ssl(verify_servers_ssl_certificate); -} - template void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constructor, ObjectType config_object, Realm::Config& config) { @@ -437,7 +428,7 @@ void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constr if (!Value::is_undefined(ctx, error_func)) { error_handler = EventLoopDispatcher(SyncSessionErrorHandlerFunctor(ctx, Value::validated_to_function(ctx, error_func))); } - + ObjectType user = Object::validated_get_object(ctx, sync_config_object, "user"); SharedUser shared_user = *get_internal>(user); if (shared_user->state() != SyncUser::State::Active) { @@ -446,10 +437,27 @@ void SyncClass::populate_sync_config(ContextType ctx, ObjectType realm_constr std::string raw_realm_url = Object::validated_get_string(ctx, sync_config_object, "url"); + bool client_validate_ssl = true; + ValueType validate_ssl_temp = Object::get_property(ctx, sync_config_object, "validate_ssl"); + if (!Value::is_undefined(ctx, validate_ssl_temp)) { + client_validate_ssl = Value::validated_to_boolean(ctx, validate_ssl_temp, "validate_ssl"); + } + + util::Optional ssl_trust_certificate_path; + ValueType trust_certificate_path_temp = Object::get_property(ctx, sync_config_object, "ssl_trust_certificate_path"); + if (!Value::is_undefined(ctx, trust_certificate_path_temp)) { + ssl_trust_certificate_path = std::string(Value::validated_to_string(ctx, trust_certificate_path_temp, "ssl_trust_certificate_path")); + } + else { + ssl_trust_certificate_path = util::none; + } + // FIXME - use make_shared config.sync_config = std::shared_ptr(new SyncConfig{shared_user, raw_realm_url, SyncSessionStopPolicy::AfterChangesUploaded, - std::move(bind), std::move(error_handler)}); + std::move(bind), std::move(error_handler), + nullptr, util::none, + client_validate_ssl, ssl_trust_certificate_path}); config.schema_mode = SchemaMode::Additive; config.path = realm::SyncManager::shared().path_for_realm(shared_user->identity(), raw_realm_url); diff --git a/src/object-store b/src/object-store index 91b460fa..872a154b 160000 --- a/src/object-store +++ b/src/object-store @@ -1 +1 @@ -Subproject commit 91b460fa5ad4083bdb5c59955cfd231bb2b25c54 +Subproject commit 872a154b1bfd843f7dad98cab73e23a5aff2ee66