-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support SSL Sync Configuration #5507
Conversation
static auto make_ssl_verify_callback(std::function<bool(const std::string& server_address, int server_port, | ||
std::string_view pem_data, int preverify_ok, int depth)> callback) { | ||
return [callback = std::move(callback)](const std::string& server_address, uint16_t server_port, | ||
const char* pem_data, size_t pem_size, int preverify_ok, int depth) { | ||
return callback(server_address, server_port, { pem_data, pem_size }, preverify_ok, depth); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [line 269] Take the JS-wrapped version of the callback as the argument. This callback will (when invoked) call the user-provided callback for validating certificates.
- [line 271] Return the CPP (Core-friendly) version of the callback (stored in the binding).
- [line 273] When the CPP callback is invoked, invoke the JS-wrapped callback and return its result.
...parseClientResetConfig(clientReset, onError), | ||
}; | ||
} | ||
|
||
/** @internal */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
On second thought, don't think this annotation is necessary since the function is not exported. (Ps. there are several non-exported functions in this file using this annotation already.)
dc2da79
to
9ca326b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Would be great to see some tests, but I think that's not so straightforward. I assume you have tested this manually?
@takameyer, you can look at the separate PR for the tests. We decided to split up the PRs as with the Jira issues (v12 and final v12). All tests pass in my Docker container. |
893101c
to
a15ad76
Compare
static auto make_ssl_verify_callback(std::function<bool(const std::string& server_address, int server_port, | ||
std::string_view pem_data, int preverify_ok, int depth)> | ||
callback) | ||
{ | ||
return [callback = std::move(callback)](const std::string& server_address, uint16_t server_port, | ||
const char* pem_data, size_t pem_size, int preverify_ok, int depth) { | ||
return callback(server_address, server_port, std::string_view(pem_data, pem_size), preverify_ok, depth); | ||
}; | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- [signature]: Take the JS-wrapped version of the callback as the argument. This callback will (when invoked) call the user-provided callback for validating certificates.
- [1st
return
]: Return the CPP (Core-friendly) version of the callback (stored in the binding). - [2nd
return
]: When the CPP callback is invoked, invoke the JS-wrapped callback and return its result.
Getting the following error when building locally and on the
This is not appearing on |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to fix the build issues before this is merged.
type: bool | ||
default: true | ||
ssl_trust_certificate_path: util::Optional<std::string> | ||
ssl_verify_callback: Nullable<SSLVerifyCallback> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should it be off_thread
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is. See line 642.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if it can be marked as off_thread
here.
As this is the SSLVerifyCallback
:
SSLVerifyCallback:
cppName: std::function<SyncConfig::SSLVerifyCallback>
And having ssl_verify_callback
as:
SyncConfig:
fields:
# ...
ssl_verify_callback: Nullable<SSLVerifyCallback>
It's unsure how/if it should be applied. These are 2 examples of other how other methods use it:
should_compact_on_launch_function: 'Nullable<std::function<(total_bytes: uint64_t, used_bytes: uint64_t) off_thread -> bool>>'
error_handler: 'Nullable<std::function<(session: SharedSyncSession, error: SyncError) off_thread -> void>>'
We do however need it for our helper make_ssl_verify_callback
:
classes:
Helpers:
staticMethods:
# ...
make_ssl_verify_callback: '(callback: (server_address: const std::string&, server_port: int, pem_data: std::string_view, preverify_ok: int, depth: int) off_thread -> bool) -> SSLVerifyCallback'
But @RedBeard0531 could chime in here 🙂
@@ -286,11 +286,22 @@ export class SyncSession { | |||
// TODO: Figure out a way to avoid passing a mocked app instance when constructing the User. | |||
get config(): SyncConfiguration { | |||
const user = new User(this.internal.user, mockApp); | |||
const { partitionValue, flxSyncRequested, customHttpHeaders } = this.internal.config; | |||
const { partitionValue, flxSyncRequested, customHttpHeaders, clientValidateSsl, sslTrustCertificatePath } = |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the clientValidateSsl
and sslTrustCertificatePath
have sane defaults when coming from core? (i.e. not just an empty string or something).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will be whatever the user has provided as their validate
(binding: clientValidateSsl
) and certificatePath
(binding: sslTrustCertificatePath
).
export type SSLConfiguration = {
validate?: boolean;
certificatePath?: string;
// ...
};
If you don't provide a value for certificatePath
, the value can be undefined as in this test. validate
defaults to true
.
What, How & Why?
When opening a synced realm, users can provide an SSL configuration containing either:
Examples:
This closes #5485.
☑️ ToDos