I can’t get to work HTTPS with certificate on Android
db server - 5.0
sync server 1.5
java/android
when I’m using BLIPS://myIP:4894/db
I got on sync server - 2017-12-06 00:13:17.584849 I | http: TLS handshake error from x.x.x.163:54269
: remote error: tls: unknown certificate
with openSSL I created .cer and .pem certificate files, inserted in json_config, but don’t understand where in java I should use the certificate.
Assuming you are not using client side certificate authentication (i.e. you are only validating server side cert), you shouldn’t have to do anything within your Android app. What is the authenticator mechanism that you have setup with the replicator?
Presumably, you followed the instructions here to configure the Sync Gateway with the cert.
Couple of points to double check during certificate generation:-
Install the certificates in a location accesible to the Sync Gateway
If you are generating a self-signed certificate, probably the most important field is the CommonName. It should be your Sync Gateway’s FQDN. If you Sync Gateway does not have one, then you must specify use localhost for localhost or the static IPAddress of your Sync Gateway. This issue will typically result in an “Unknown Certificate Authority” error though…
The certificate and corresponding private key must be in .pem format
As mentioned in my original response, for self signed cert
Basically use the IP Address that your client connects to.
Where exactly is the “ssl” folder relative to the folder that contains the SGW binary and what are the access permissions. For debugging purposes, to eliminate the possibility that the SGW can’t access it, can you put the cert and private key in the same folder that contains the Sync Gateway binary (and update the config file accordingly)
Also a terminology clarification - note that in CBM 2.0 you are using BLIP(S) which is websockets based protocol. It is not HTTP(s).
i’m running win7 x64 as admin, so it’s not access permission.
so, in common name I tried 10.10.10.2 and in sync base console got error.
SYNCGATEWAY_URL = “blips://10.10.10.2:4984/db/”
2017-12-07 00:08:37.647628 I | http: TLS handshake error from 10.10.10.141:60074
: remote error: tls: unknown certificate
I am referring to the access of the certs by the Sync Gateway. Did you try what I suggested about putting the certs and PK in same folder as sync gateway and updating the config file as such
Are you seeing “unknown certificate authority” or just “unknown certificate” ? I don’t know what the latter is (@traun - ideas?)
If I change URL string to BLIP, I got message about it’s wrong TLS - something.
private final static String SYNCGATEWAY_URL = “blips://10.10.10.2:4984/db/”;
to
private final static String SYNCGATEWAY_URL = “blip://10.10.10.2:4984/db/”;
2017-12-07 17:45:35.571782 I | http: TLS handshake error from 10.10.10.140:59233
: tls: first record does not look like a TLS handshake
You shouldn’t have to do this unless you are also bundling the server certificate in with your Android app. Are you doing that? If not, please remove this line from your app. It will cause problems if you do that because there is no cert that the client can check against.
This “pinning” of certificate is to guarantee that your app will only authorize a server whose cert matches the cert that it is bundled with
(FYI : Here is a blog post you are interested in learning about cert pinning . Its for iOS but concepts apply to any platform)
curl -k -X GET https://localhost:4984 -H 'cache-control: no-cache' --verbose
Open in your browser and let us know what you see.
https://localhost:4984
My cert and pem are located in ssl folder within the bin folder which contains sync-gateway
ls ssl/
cert.pem privkey.pem
The Android side code looks fine. Assuming the cert was generated correctly
openssl x509 -inform PEM -in cert.pem -outform DER -out cert.cer
Note : While not related to the issue, from your JSON config, it appears that you haven’t setup your server for shared bucket access. You may want to do that as discussed here
From curl output, it looks like your SGW is configured for SSL correctly. So we know that SGW is handling SSL requests correctly.
Are you trying to connect from Android device or emulator? If you are using a localhost, please generate the certificate for 10.0.2.2 FQDN and connect via blips://10.0.2.2/ .
Wondering if the version of TLS/SSL that is being used from the client is unsupported …confirm that it is at least v1.2.
Try to load the SGW url from the Android browser and see if it connects OK.