Upgrade to Pro — share decks privately, control downloads, hide ads and more …

SSL Connection with Realm Mobile Platform

fromkk
December 21, 2016

SSL Connection with Realm Mobile Platform

Realm Object Serverにプロキシ接続でSSL化してみた

fromkk

December 21, 2016
Tweet

More Decks by fromkk

Other Decks in Technology

Transcript

  1. PROFILE KAZUYA UEOKA iOS engineer in Timers inc. Twitter: @fromkk

    Github: fromkk Qiita: fromkk 1 — (C) fromkk. 2016
  2. PLATFOTM > Sakura VPS > CentOS 7 > Nginx(proxy) >

    Let's Encrypt > Realm Object Server 10 — (C) fromkk. 2016
  3. FIREWALL firewall-cmd --add-service=http --zone=public --permanent firewall-cmd --add-service=https --zone=public --permanent firewall-cmd

    --permanent --add-port=9080/tcp --permanent firewall-cmd --reload 11 — (C) fromkk. 2016
  4. INSTALL REALM OBJECT SERVER # Setup Realm's PackageCloud repository curl

    -s https://packagecloud.io/install/repositories/realm/realm/script.rpm.sh | sudo bash # Install the Realm Object Server sudo yum -y install realm-object-server-de # Enable and start the service sudo systemctl enable realm-object-server sudo systemctl start realm-object-server 12 — (C) fromkk. 2016
  5. TRY PROXY /etc/nginx/conf.d/default.conf server { listen 80; server_name _; location

    / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:9080; } } 15 — (C) fromkk. 2016
  6. INSTALL LET'S ENCRYPT cd /opt git clone https://github.com/certbot/certbot cd ./certbot

    ./certbot-auto certonly --standalone -d yourdomain.com 18 — (C) fromkk. 2016
  7. IMPORTANT NOTES: - Congratulations! Your certificate and chain have been

    saved at /etc/letsencrypt/live/yourdomain.com/fullchain.pem. Your cert will expire on 2017-03-03. To obtain a new or tweaked version of this certificate in the future, simply run certbot-auto again. To non-interactively renew *all* of your certificates, run "certbot-auto renew" - If you lose your account credentials, you can recover through e-mails sent to [email protected]. - Your account credentials have been saved in your Certbot configuration directory at /etc/letsencrypt. You should make a secure backup of this folder now. This configuration directory will also contain certificates and private keys obtained by Certbot so making regular backups of this folder is ideal. - If you like Certbot, please consider supporting our work by: Donating to ISRG / Let's Encrypt: https://letsencrypt.org/donate Donating to EFF: https://eff.org/donate-le 20 — (C) fromkk. 2016
  8. /etc/nginx/conf.d/default.conf server { listen 443 ssl; server_name yourdomain.com; ssl_certificate /etc/letsencrypt/live/yourdomain.com/fullchain.pem;

    ssl_trusted_certificate /etc/letsencrypt/live/yourdomain.com/chain.pem; ssl_certificate_key /etc/letsencrypt/live/yourdomain.com/privkey.pem; ssl_session_timeout 1d; ssl_session_cache shared:SSL:50m; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers ECDHE+RSAGCM:ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:!aNULL!eNull:!EXPORT:!DES:!3DES:!MD5:!DSS; ssl_prefer_server_ciphers on; ssl_stapling on; ssl_stapling_verify on; location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header Host $http_host; proxy_pass http://127.0.0.1:9080; } } 21 — (C) fromkk. 2016
  9. SAMPLE SWIFT CODE WITH REALM import Realm import RealmSwift let

    credential: SyncCredentials = SyncCredentials.usernamePassword(username: "YOUR USER NAME", password: "YOUR PASSWORD") SyncUser.logIn(with: credential, server: URL(string: "https://yourdomain.com/")!, onCompletion: { [weak self] (user, error) in if let user = user { let configuration = Realm.Configuration(syncConfiguration: SyncConfiguration(user: user, realmURL: URL(string: "realm://yourdomain.com:9080/~/realm")!)) Realm.Configuration.defaultConfiguration = configuration //write your code! } else if let error = error { print("login failed \(error)") } }) 25 — (C) fromkk. 2016
  10. REMOVE ATS SETTING FROM Info.plist - <key>NSAppTransportSecurity</key> - <dict> -

    <key>NSAllowsArbitraryLoads</key> - <true/> - </dict> 26 — (C) fromkk. 2016
  11. SUMMARY > Your can use Realm Object Server with SSL

    on Nginx proxy. > SSL certification for Free with Let's encrypt. > Ready for 2017 with Realm Mobile Platform! 27 — (C) fromkk. 2016