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

PGP for Developers

PGP for Developers

Have you ever sent your team API credentials over email? Accidentally checked secrets.yml into source control? As developers, we touch sensitive information every day, but we don’t always share it securely. Learn how to get started with PGP and why every developer should have a public key.

Avatar for Connor Mendenhall

Connor Mendenhall

July 11, 2014
Tweet

More Decks by Connor Mendenhall

Other Decks in Technology

Transcript

  1. Pretty good privacy Send sensitive information: passwords, secrets, keys !

    Receive sensitive information ! Store sensitive information in source control ! Sign your code so users can verify it ! Wrap insecure protocols
  2. Pretty good privacy > “Our twelve test participants were generally

    > educated and experienced at using email, yet only > one third of them were able to use PGP 5.0 to > correctly sign and encrypt an email message when > given 90 minutes in which to do so. Furthermore, > one quarter of them accidentally exposed the > secret they were meant to protect in the process” ! —-“Why Johnny Can’t Encrypt” http://www.gaudior.net/alma/johnny.pdf
  3. Pretty good privacy NAME git-reflog - Manage reflog information !

    SYNOPSIS git reflog <subcommand> <options> ! ! DESCRIPTION The command takes various subcommands, and different options depending on the subcommand: ! git reflog expire [--dry-run] [--stale-fix] [--verbose] [--expire=<time>] [--expire-unreachable=<time>] [--all] <refs>... git reflog delete ref@{specifier}... git reflog [show] [log-options] [<ref>] ! ! Reflog is a mechanism to record when the tip of branches are updated. This command is to manage the information recorded in it. ! The subcommand "expire" is used to prune older reflog entries. Entries older than expire time, or entries older than expire-unreachable time and not reachable from the current tip, are removed from the reflog. This is typically not used directly by the end users -- instead, see git-gc(1).
  4. Install GPG PGP is an open standard. We’ll use Gnu

    Privacy Guard (GPG), a free and open source implementation. ! OS X: brew install gpg or http://gpgtools.org/ Ubuntu: sudo apt-get install gnupg2 Windows: http://www.gpg4win.org/
  5. Generating a new key $ gpg --gen-key ! gpg (GnuPG)

    2.0.22; Copyright (C) 2013 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. ! Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? !
  6. Generating a new key $ gpg --gen-key ! gpg (GnuPG)

    2.0.22; Copyright (C) 2013 Free Software Foundation, Inc. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. ! Please select what kind of key you want: (1) RSA and RSA (default) (2) DSA and Elgamal (3) DSA (sign only) (4) RSA (sign only) Your selection? 1
  7. Generating a new key RSA keys may be between 1024

    and 4096 bits long. What keysize do you want? (2048)
  8. Generating a new key RSA keys may be between 1024

    and 4096 bits long. What keysize do you want? (2048) 4096
  9. Generating a new key Please specify how long the key

    should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0)
  10. Generating a new key Please specify how long the key

    should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 0
  11. Generating a new key Please specify how long the key

    should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 0 ! Key does not expire at all Is this correct? (y/N)
  12. Generating a new key Please specify how long the key

    should be valid. 0 = key does not expire <n> = key expires in n days <n>w = key expires in n weeks <n>m = key expires in n months <n>y = key expires in n years Key is valid for? (0) 0 ! Key does not expire at all Is this correct? (y/N) y
  13. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name:
  14. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander
  15. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander Email address:
  16. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander Email address: [email protected]
  17. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander Email address: [email protected] Comment:
  18. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander Email address: [email protected] Comment: ! You selected this USER-ID: “Keith Alexander <[email protected]>” ! Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit?
  19. Generating a new key GnuPG needs to construct a user

    ID to identify your key. ! Real name: Keith Alexander Email address: [email protected] Comment: ! You selected this USER-ID: “Keith Alexander <[email protected]>” ! Change (N)ame, (C)omment, (E)mail or (O)kay/(Q)uit? O
  20. Generating a new key Enter passphrase: ********************************** Please reenter passphrase:

    ********************************** ! We need to generate a lot of random bytes. It is a good idea to perform some other action (type on the keyboard, move the mouse, utilize the disks) during the prime generation; this gives the random number generator a better chance to gain enough entropy.
  21. Generating a new key gpg: key 76DE234F marked as ultimately

    trusted public and secret key created and signed. ! gpg: checking the trustdb gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 2 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 2u pub 4096R/76DE234F 2014-07-10 Key fingerprint = 51F0 E1D4 E737 B3CF 4466 456C 2741 7EBB 76DE 234F ! uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10
  22. Listing keys $ gpg -—list-keys ! gpg: checking the trustdb

    gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10
  23. Listing keys $ gpg -—list-keys ! gpg: checking the trustdb

    gpg: 3 marginal(s) needed, 1 complete(s) needed, PGP trust model gpg: depth: 0 valid: 1 signed: 0 trust: 0-, 0q, 0n, 0m, 0f, 1u /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10
  24. Export your public key $ gpg -—export —-armor > keith_pubkey.asc

    ! $ ls keith_pubkey.asc ! $ cat keith_pubkey.asc
  25. Export your public key $ gpg -—export —-armor > keith_pubkey.asc

    ! $ ls keith_pubkey.asc ! $ cat keith_pubkey.asc -----BEGIN PGP PUBLIC KEY BLOCK----- Version: GnuPG v2.0.22 (GNU/Linux) ! mQINBFO+Dc8BEACli07maa/Xj1gRfLyNMzv3dTByTPkgFXY7k7cLxsK5DBL6jsvb FgcbylXbvMHGH/jgD7D+2VenXjwPYxeNORJ6lnGHOvKcAp2lRVtdFgkBuzDztirt gZBrbtE7nbujjakx4oTB9C0hUqSn0E8JmFvQkCBZZuWRZ3HAZKbzRUaoWrpgYRU8 JI8TWyg3I1dwxzlgIKkhklVeG8up74wsOwQyutOxEUDrM+X26Z4NOSHNNf2B3DrM wjUvFu+j2eThM1Zt6Un7UoInfeNdONzBWYPEBdGppmUAKzglH+zxov2czFj02fQL zZ/4sY7KNf9C417YNLfIZ4ZuZVhL0pTmqSN/7/o9Un726sJxJfzlbDjJ9GI8C72n a/koFNs8M1fYskT2q6u9/w35798bFUw/rcCNzfOQIr07ZGBYC51NuGMMlRn8/3kf
  26. Try it! Copy your public key into an email message

    and send it to [email protected] ! (Send plaintext if possible)
  27. Decrypt Adele’s response $ gpg —-decrypt reply.asc ! Hello, !

    here is the encrypted reply to your email. ! I have received your public key ID 27417EBB76DE234F, described as `Keith Alexander <[email protected]>'. ! Below please find the public key of [email protected] the friendly OpenPGP email robot. ! Yours sincerely, [email protected] ! -----BEGIN PGP PUBLIC KEY BLOCK-----
  28. Good key hygiene Generate a revocation certificate ! Back up

    your private key and revocation cert ! Seriously, back it up
  29. Send sensitive config $ cat message.txt ! Hey Sandro, !

    Here’s the API key and secret for our Sorting.io account: ! SUPER_SECRET_API_KEY=fc44a9de4a2a97a0dcaaca16d3c9b2b9e2ed031e API_TOKEN=152052948eb58063fd ! Connor ! $
  30. Send sensitive config $ gpg --keyserver pgp.mit.edu --search-keys 8thlight.com !

    gpg: searching for "8thlight.com" from hkp server pgp.mit.edu (1) Sandro Padin <[email protected]> 4096 bit RSA key 9E691D66, created: 2014-01-27 (2) Connor Mendenhall <[email protected]> 2048 bit RSA key BA6447F3, created: 2013-07-30 (3) Colin Jones <[email protected]> 2048 bit RSA key A82D3A63, created: 2012-11-03 (4) Doug Bradbury <[email protected]> 2048 bit RSA key 64D9887B, created: 2012-08-01 ! Keys 1-4 of 4 for "8thlight.com". Enter number(s), N)ext, or Q)uit>
  31. Send sensitive config $ gpg --keyserver pgp.mit.edu --search-keys 8thlight.com !

    gpg: searching for "8thlight.com" from hkp server pgp.mit.edu (1) Sandro Padin <[email protected]> 4096 bit RSA key 9E691D66, created: 2014-01-27 (2) Connor Mendenhall <[email protected]> 2048 bit RSA key BA6447F3, created: 2013-07-30 (3) Colin Jones <[email protected]> 2048 bit RSA key A82D3A63, created: 2012-11-03 (4) Doug Bradbury <[email protected]> 2048 bit RSA key 64D9887B, created: 2012-08-01 ! Keys 1-4 of 4 for "8thlight.com". Enter number(s), N)ext, or Q)uit> 1
  32. Send sensitive config gpg: requesting key 9E691D66 from hkp server

    pgp.mit.edu gpg: key 9E691D66: public key "Sandro Padin <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) ! $
  33. Send sensitive config gpg: requesting key 9E691D66 from hkp server

    pgp.mit.edu gpg: key 9E691D66: public key "Sandro Padin <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) ! $ gpg —-list-keys
  34. Send sensitive config gpg: requesting key 9E691D66 from hkp server

    pgp.mit.edu gpg: key 9E691D66: public key "Sandro Padin <[email protected]>" imported gpg: Total number processed: 1 gpg: imported: 1 (RSA: 1) ! $ gpg —-list-keys /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10 ! pub 4096R/9E691D66 2014-01-27 [expires: 2018-01-27] uid Sandro Padin <[email protected]> sub 4096R/55913676 2014-01-27 [expires: 2018-01-27]
  35. Send sensitive config $ gpg --fingerprint "Sandro Padin" ! pub

    4096R/9E691D66 2014-01-27 [expires: 2018-01-27] Fingerprint = 20C7 8310 4EA6 39F4 45E7 847A 4ED0 DA57 9E69 1D66 ui Sandro Padin <[email protected]> sub 4096R/55913676 2014-01-27 [expires: 2018-01-27]
  36. Send sensitive config $ gpg --encrypt —-sign —-armor -r [email protected]

    message.txt ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! gpg: 55913676: There is no assurance this key belongs to the named user ! pub 4096R/55913676 2014-01-27 Sandro Padin <[email protected]> Primary key fingerprint: 20C7 8310 4EA6 39F4 45E7 847A 4ED0 DA57 9E69 1D66 Subkey fingerprint: B7D4 BAB6 027B C1F9 A0BB 5112 5B0A DCCB 5591 3676 !
  37. Send sensitive config It is NOT certain that the key

    belongs to the person named in the user ID. If you *really* know what you are doing, you may answer the next question with yes. ! Use this key anyway? (y/N) y ! $ cat message.txt.asc ! -----BEGIN PGP MESSAGE----- Version: GnuPG v2.0.22 (GNU/Linux) ! hQIMA1sK3MtVkTZ2ARAAqL8KrnK3klnJ8L5IV8nFdg2yrQHdXZZKct1E7Swni1ai EySbWDGXSkysP4UwGPszmExEaZ3mwm216m2HeYG9wsmIRzx5FmzuqdYg0H+MuRsc pIEBPNa9MeWbRYK+8tCi1RDH5fdrd89Pi0j0n0zXw+4tAEw6hQexs9Pw1H4lvZm8 DFYxlApwlX6YIFfXXYldhgZ81yEBsu5KCM3IOyFmyIiBpbSt3ov6TtuhCEfRfNbV ivwaVuyO3g0aKZS3/Khkhu+FCHWQH52273JTyDodSswywGa80bQD3TyyAEyJWwWp
  38. Receive private messages $ gpg -—export —-armor -o keith_pubkey.asc !

    $ gpg —-list-keys ! /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10 ! pub 4096R/9E691D66 2014-01-27 [expires: 2018-01-27] uid Sandro Padin <[email protected]> sub 4096R/55913676 2014-01-27 [expires: 2018-01-27] ! $ !
  39. Receive private messages $ gpg -—export —-armor -o keith_pubkey.asc !

    $ gpg —-list-keys ! /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10 ! pub 4096R/9E691D66 2014-01-27 [expires: 2018-01-27] uid Sandro Padin <[email protected]> sub 4096R/55913676 2014-01-27 [expires: 2018-01-27] ! $ gpg --keyserver pgp.mit.edu —-send-keys 76DE234F !
  40. Receive private messages $ gpg -—export —-armor -o keith_pubkey.asc !

    $ gpg —-list-keys ! /home/ubuntu/.gnupg/pubring.gpg ------------------------------- pub 4096R/76DE234F 2014-07-10 uid Keith Alexander <[email protected]> sub 4096R/89C65041 2014-07-10 ! pub 4096R/9E691D66 2014-01-27 [expires: 2018-01-27] uid Sandro Padin <[email protected]> sub 4096R/55913676 2014-01-27 [expires: 2018-01-27] ! $ gpg --keyserver pgp.mit.edu —-send-keys 76DE234F gpg: sending key 76DE234F to hkp server pgp.mit.edu
  41. Sharing your public key Don’t rely on keyservers: share your

    key from a domain you own, over SSL ! Share your full fingerprint where possible, not just the first 8 characters
  42. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig —-detach-sig xkeyscore ! ! !
  43. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig —-detach-sig xkeyscore ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! $ !
  44. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig —-detach-sig xkeyscore ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! $ ls ! !
  45. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig —-detach-sig xkeyscore ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! $ ls Makefile src xkeyscore xkeyscore.sig ! $ !
  46. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig —-detach-sig xkeyscore ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! $ ls Makefile src xkeyscore xkeyscore.sig ! $ gpg -—verify xkeyscore.sig ! !
  47. Tamper-proof code $ ls Makefile src xkeyscore ! $ gpg

    —-output xkeyscore.sig -—detach-sig xkeyscore ! You need a passphrase to unlock the secret key for user: “Keith Alexander <[email protected]>” 4096-bit RSA key, ID 76DE234F, created 2014-07-10 ! $ ls Makefile src xkeyscore xkeyscore.sig ! $ gpg -—verify xkeyscore.sig gpg: Signature made Thu Jul 10 20:08:27 2014 CDT using RSA key ID 76DE234F gpg: Good signature from "Keith Alexander <[email protected]>"
  48. Store sensitive config $ cat secrets.env SUPER_SECRET_API_KEY=fc44a9de4a2a97a0dcaaca16d3c9b2b9e2ed031e API_TOKEN=152052948eb58063fd DB_PASSWORD=hunter2 !

    $ gpg --encrypt -r [email protected] -r [email protected] -o secrets.env.gpg secrets.env ! $ gpg -o secrets.env.gpg —-symmetric secrets.env ! $ echo ‘secrets.env’ >> .gitignore