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

My TLS was broken

My TLS was broken

Piyush Verma

January 19, 2019
Tweet

More Decks by Piyush Verma

Other Decks in Technology

Transcript

  1. My TLS is broken
    and probably yours too.

    View full-size slide

  2. My TLS was broken
    My TLS is broken
    My TLS was broken
    My TLS is broken
    My TLS was broken
    My TLS will be broken

    View full-size slide

  3. Part 1: The GreenLock

    View full-size slide

  4. HTTPS
    func main() {
    http.ListenAndServeTLS(":443",
    "server.crt", "server.key", nil)
    }

    View full-size slide

  5. Picture or it didn’t happen

    View full-size slide

  6. HTTPS Server

    View full-size slide

  7. Part 2: TCP TLS

    View full-size slide

  8. TCP TLS Server
    func main() {
    cer, err := tls.LoadX509KeyPair("server.crt", "server.key")
    config := &tls.Config{Certificates: []tls.Certificate{cer}}
    ln , err := tls.Listen("tcp", ":443", config)
    conn, err := ln.Accept()
    go handleConnection(conn)
    }

    View full-size slide

  9. TLS Client
    func main() {
    conf := &tls.Config{//InsecureSkipVerify: true}
    conn, err := tls.Dial("tcp", "ldap.ha.tsengine.io:847", conf)
    n, err := conn.Write([]byte("hello\n"))
    buf := make([]byte, 100)
    n, err = conn.Read(buf)
    log.Println(n, err)
    }

    View full-size slide

  10. Server Client TCP

    View full-size slide

  11. Part 3: Opportunistic TLS

    View full-size slide

  12. func main() {
    listener, _ := net.Listen("tcp", "127.0.0.1:8000")
    conn, err := listener.Accept()
    bytesRead, err := conn.Read(...)
    if string(buffer[0:bytesRead]) == STARTTLS {
    conn := tls.Server(unenc_conn, &config)
    var buffer = make([]byte, 1024)
    conn.Handshake()
    ...
    }
    }
    TLS Client

    View full-size slide

  13. TLS Client Auth Handshake

    View full-size slide

  14. TLS Exchange

    View full-size slide

  15. Certificates

    View full-size slide

  16. meson10@DESKTOP-S7PEUGG:~$ openssl x509 -in <(openssl s_client -connect
    wikipedia.com:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p') -text
    Certificate:
    Data:
    Version: 3 (0x2)
    Serial Number:
    08:30:94:62:d1:fe:a6:0a:e0:ba:bf:f5:ef:8b:c5:45
    Validity
    Not Before: Dec 21 00:00:00 2017 GMT
    Not After : Jan 24 12:00:00 2019 GMT
    X509v3 CRL Distribution Points:
    Full Name:
    URI:http://crl3.digicert.com/sha2-ha-server-g6.crl
    Full Name:
    URI:http://crl4.digicert.com/sha2-ha-server-g6.crl
    Authority Information Access:
    OCSP - URI:http://ocsp.digicert.com

    View full-size slide

  17. Sharing is not Caring,
    Your parents have been lying.

    View full-size slide

  18. Part 5: Client Authentication

    View full-size slide

  19. Client Authentication

    View full-size slide

  20. Why is Client Auth needed?

    View full-size slide

  21. But we use API Keys

    View full-size slide

  22. Client Certificate
    Certificate:
    Issuer: C = IN, ST = MH, L = Pune, OU = TS Sre Certificate
    Authority, CN = TS Sre CA
    Validity
    Not Before: Jan 18 06:53:00 2019 GMT
    Not After : Jan 17 06:53:00 2024 GMT
    Subject: C = IN, ST = MH, L = Pune, OU = TrustingSocial, CN =
    tls_demo_client
    Authority Information Access:
    OCSP - URI:http://ca.ha.tsengine.io:7889
    CA Issuers -
    URI:http://ca.ha.tsengine.io:1500/intermediate/intermediate.crt
    X509v3 CRL Distribution Points:
    Full Name:
    URI:http://ca.ha.tsengine.io:6688/api/v1/cfssl/crl

    View full-size slide

  23. certificate, err := tls.LoadX509KeyPair(cert, key)
    tlsConfig := &tls.Config{
    ServerName: "my-server",
    ClientAuth: tls.RequireAndVerifyClientCert,
    Certificates: []tls.Certificate{certificate},
    }
    ln, err := tls.Listen("tcp", ":443", config)
    conn, err := ln.Accept()
    go handleConnection(conn)
    Accepting Client Certs

    View full-size slide

  24. Deprecation of Internal &
    Reserved IP Addresses
    Circa 2012

    View full-size slide

  25. PKI Infrastructure

    View full-size slide

  26. certPool := x509.NewCertPool()
    b, err := ioutil.ReadFile(rootPath)
    certPool.AppendCertsFromPEM(bs)
    tlsConfig := &tls.Config{
    ServerName: "my-server",
    ClientAuth: tls.RequireAndVerifyClientCert,
    Certificates: []tls.Certificate{certificate},
    ClientCAs: certPool,
    }
    Accepting Client Certs

    View full-size slide

  27. certificate, err := tls.LoadX509KeyPair(cert, key)
    certPool := x509.NewCertPool()
    b, err := ioutil.ReadFile(rootPath)
    certPool.AppendCertsFromPEM(bs)
    tlsConfig := &tls.Config{
    Certificates: []tls.Certificate{certificate},
    RootCAs: certPool,
    }
    Accepting Server Certs

    View full-size slide

  28. Part 7: Take it Back

    View full-size slide

  29. How do you take-back a Cert?

    View full-size slide

  30. meson10@DESKTOP-S7PEUGG:~$ openssl x509 -in <(openssl s_client -connect
    wikipedia.com:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p') -text
    Certificate:
    Data:
    Version: 3 (0x2)
    Serial Number:
    08:30:94:62:d1:fe:a6:0a:e0:ba:bf:f5:ef:8b:c5:45
    Validity
    Not Before: Dec 21 00:00:00 2017 GMT
    Not After : Jan 24 12:00:00 2019 GMT
    X509v3 CRL Distribution Points:
    Full Name:
    URI:http://crl3.digicert.com/sha2-ha-server-g6.crl
    Authority Information Access:
    OCSP - URI:http://ocsp.digicert.com

    View full-size slide

  31. Problems with CRL

    View full-size slide

  32. meson10@DESKTOP-S7PEUGG:~$ openssl x509 -in <(openssl s_client -connect
    wikipedia.com:443 2>&1 < /dev/null | sed -n '/-----BEGIN/,/-----END/p') -text
    Certificate:
    Data:
    Version: 3 (0x2)
    Serial Number:
    08:30:94:62:d1:fe:a6:0a:e0:ba:bf:f5:ef:8b:c5:45
    Validity
    Not Before: Dec 21 00:00:00 2017 GMT
    Not After : Jan 24 12:00:00 2019 GMT
    X509v3 CRL Distribution Points:
    Full Name:
    URI:http://crl3.digicert.com/sha2-ha-server-g6.crl
    Authority Information Access:
    OCSP - URI:http://ocsp.digicert.com

    View full-size slide

  33. - Server Down?
    - DDOS CA
    - Privacy Compromise
    OCSP Challenges

    View full-size slide

  34. Soft Fail: Firefox

    View full-size slide

  35. Soft Fail: Chrome

    View full-size slide

  36. What’s the most
    fragile thing in
    the Universe?
    a) Silence
    b) Taylor Swift’s heart.
    c) Neymar’s Shin
    d) Internet Security

    View full-size slide

  37. Why do you revoke keys?

    View full-size slide

  38. https://github.com/indutny/heartbleed

    View full-size slide

  39. cert, err := x509.ParseCertificate(cert)
    // ok := callOCSPServer(cert)
    if !ok {
    // Certificate is revoked
    }
    tlsConfig := &tls.Config{
    ServerName: "my-server",
    ClientAuth: tls.RequireAndVerifyClientCert,
    Certificates: []tls.Certificate{certificate},
    ClientCAs: certPool,
    VerifyPeerCertificate: certValidator,
    }
    Accepting Client Certs

    View full-size slide

  40. CAtoolkit
    http:/
    /github.com/tsocial/ca
    toolkit

    View full-size slide

  41. Maybe, Security is just a
    feeling?

    View full-size slide

  42. xps:~$ whoami
    Piyush Verma
    Site Reliability Engineering
    Trusting Social
    Twitter: meson10

    View full-size slide