SlideShare a Scribd company logo
JWT! JWT!
Let it all out!
John SJ Anderson | @genehack | Hack Salem | 14 Sep 2016
Hack Salem | 14 Sep 2016 | @genehack 1
JSON Web Tokens
want to rule your world
John SJ Anderson | @genehack | Hack Salem | 14 Sep 2016
Hack Salem | 14 Sep 2016 | @genehack 2
Hi, I'm John
Hack Salem | 14 Sep 2016 | @genehack 3
VP, Tech
Infinity
Interactive
Hack Salem | 14 Sep 2016 | @genehack 4
So, what's a JWT?
Hack Salem | 14 Sep 2016 | @genehack 5
jwt.io
Hack Salem | 14 Sep 2016 | @genehack 6
What
Does
That
Even
MeanHack Salem | 14 Sep 2016 | @genehack 7
Think of it as…
• A lightweight alternative to cookies
• A form of access control without authentication
• Cross-site single sign on (SSO) without cross domain pain
Hack Salem | 14 Sep 2016 | @genehack 8
Made of stuff you already know
• JSON Objects
• Cryptographically signed and hashed
• Transmitted during HTTP request
Hack Salem | 14 Sep 2016 | @genehack 9
JWT teardown
• dot-delimited string ('.')
• 3 parts
• header
• payload
• signature
• Example: xxx.yyyyy.zzz
Hack Salem | 14 Sep 2016 | @genehack 10
JWT teardown: header
• Plain ole JSON object
• Base64Url encoded
• Typically indicates token type and hashing algorithm
{
"alg": "HS256",
"typ": "JWT"
}
Hack Salem | 14 Sep 2016 | @genehack 11
JWT teardown: payload
• Also plain ole JSON object
• Contains "claims" -- really just data
• Reserved, public, private
• Also Base64Url encoded
{
"name": "Hack Salem",
"admin": false
}
Hack Salem | 14 Sep 2016 | @genehack 12
JWT teardown: signature
• Encoded header, plus
• Encoded payload, plus
• A secret, plus
• Signing algorithm from header
HMACSHA256(
base64UrlEncode(header) + "." + base64UrlEncode(payload),
secret
)
Hack Salem | 14 Sep 2016 | @genehack 13
Putting it all together
Hack Salem | 14 Sep 2016 | @genehack 14
Putting it all together
Hack Salem | 14 Sep 2016 | @genehack 15
More advanced usage
• Encrypted payloads (JWE)
• Nested JWT
(Won't get any further into these tonight…)
Hack Salem | 14 Sep 2016 | @genehack 16
Libraries for DAYS
• .NET, Python, Node, Java, Javascript, Ruby, Perl, Go, PHP
• Haskell, Rust, Lua, Scala, Clojure, ObjectiveC, Swift, Delphi
• Support for your favorite language/platform is probably not
an issue
Hack Salem | 14 Sep 2016 | @genehack 17
OK,
you've
got
my
attentionHack Salem | 14 Sep 2016 | @genehack 18
How
Do
I
Use
It?Hack Salem | 14 Sep 2016 | @genehack 19
Basic auth/authz usage
(stolen from jwt.io)
Hack Salem | 14 Sep 2016 | @genehack 20
Things to be aware of
• Payload/header NOT encrypted (in this setup)
• …don't send anything sensitive!
• Need to control expiration, re-issue, etc.
• Some APIs will send a fresh JWT to the client per-request
• Sites other than issuing site can receive JWT
• …if they share the secret
Hack Salem | 14 Sep 2016 | @genehack 21
How is it actually transmitted?
• Up to you! Various methods:
• As part of the URL
• In the POST body
• In the Authorization header using bearer scheme:
Authorization: Bearer <token>
Hack Salem | 14 Sep 2016 | @genehack 22
Authorization without authentication
• Scenario:
• You have an API
• You don't want to make anybody authenticate to use it
• You don't want it wide open to the Internet either
• a/k/a authz without authn
Hack Salem | 14 Sep 2016 | @genehack 23
Solution: JWT with RSA keys
• Alternative to secret in previous scenario: RSA key-pair
• Can include the public key in the JWT header using JWK
• JSON Web Key, natch
• Allows API client to produce claims in a verifiable way
Hack Salem | 14 Sep 2016 | @genehack 24
To set it up:
• Give authorized user a RSA key-pair
• You can even let them generate it — you just need to:
• Record the fingerprint of the public key (important later!)
Hack Salem | 14 Sep 2016 | @genehack 25
On their side:
• They make JWT using the private key
• They include the public key in the header
• Include iat (issued-at) and exp (expires) claims
• Send JWT in Authorization header with API request
Hack Salem | 14 Sep 2016 | @genehack 26
On our side:
• Get the public key out of the JWT header
• Validate the JWT signature using the key
• Validate that public key fingerprint is white-listed
• Signature produced with private key
• Public key is white-listed
• Therefore we know JWT is valid!
Hack Salem | 14 Sep 2016 | @genehack 27
Things to be aware of:
• You still want to validate iat and exp and any other rules
• Your library should probably do that stuff for you, mostly
• Again, nothing is encrypted, so don't plan on sensitive stuff
in the payload or header
Hack Salem | 14 Sep 2016 | @genehack 28
Let's see some code!
• May look a bit strange
• New experimental language, Nacre
• Transpiles to Javascript
Hack Salem | 14 Sep 2016 | @genehack 29
Client side
my $pri_key = Crypt::PK::RSA->new('./key.pri');
my $pub_key = Crypt::PK::RSA->new('./key.pub');
my $token = encode_jwt(
alg => 'RS512',
extra_headers => {
jwk => $pub_key->export_key_jwk('public', 1),
nonce => undef ,
},
key => $pri_key ,
payload => { iat => time() },
relative_exp => 1800,
);
HTTP::Request->new(
'POST' => 'https://example.com/endpoint',
['Authorization' => "Bearer $token"],
encode_json({ request => 'body' })
);
Hack Salem | 14 Sep 2016 | @genehack 30
Client side: making the token
my $token = encode_jwt(
alg => 'RS512',
extra_headers => {
jwk => $pub_key->export_key_jwk('public', 1),
nonce => undef ,
},
key => $pri_key ,
payload => { iat => time() },
relative_exp => 1800,
);
Hack Salem | 14 Sep 2016 | @genehack 31
Client side: adding the public key
extra_headers => {
jwk => $pub_key->export_key_jwk('public', 1),
},
Key: find an RSA library that supports export to JWK format!
Hack Salem | 14 Sep 2016 | @genehack 32
BTW,
just
kidding
about
Nacre…Hack Salem | 14 Sep 2016 | @genehack 33
it's
Perl!
(of course)
Hack Salem | 14 Sep 2016 | @genehack 34
Server side
my $auth_header = request_header 'Authorization' ;
status_401 unless ( $token ) = $auth_header =~ /^Bearer (.*)$/;
# try to decode it and confirm valid sig,
# and valid iat and exp claims
my( $header, $payload );
try {
( $header, $payload ) = decode_jwt( token => $token , decode_header => 1 ,
accepted_alg => 'RS512' ,
verify_iat => 1 , verify_exp => 1 );
};
# no catch block, just drop the error, we're out of here in that case
status_401 unless $header and $payload;
# check that expiration time is less than one hour
status_401 unless $payload->{exp} - $payload->{iat} < 3600;
# check that the included public key is on the whitelist
my $pk = Crypt::PK::RSA->new;
$pk->import_key($header->{jwk});
my $thumbprint = $pk->export_key_jwk_thumbprint;
status_401 unless config->{whitelist}{$thumbprint};
# if we get here, we're all good!
...
Hack Salem | 14 Sep 2016 | @genehack 35
Server side: get the token
my $auth_header = request_header 'Authorization' ;
status_401 unless ( $token ) = $auth_header =~ /^Bearer (.*)$/;
Hack Salem | 14 Sep 2016 | @genehack 36
Server side: decode the token
# try to decode it and confirm valid sig,
# and valid iat and exp claims
my( $header, $payload );
try {
( $header, $payload ) = decode_jwt( token => $token , decode_header => 1 ,
accepted_alg => 'RS512' ,
verify_iat => 1 , verify_exp => 1 );
};
# no catch block, just drop the error, we're out of here in that case
status_401 unless $header and $payload;
Hack Salem | 14 Sep 2016 | @genehack 37
Server side: decode the token
• Key in header wrong? FAILS
• Not right algorithm? FAILS
• Doesn't have iat and exp? FAILS
ALL that validation is happening inside the library, so I don't
have to worry about it.
• Me? WINS
Hack Salem | 14 Sep 2016 | @genehack 38
Server side: do more checks
# check that expiration time is less than one hour
status_401 unless $payload->{exp} - $payload->{iat} < 3600;
# check that the included public key is on the whitelist
my $pk = Crypt::PK::RSA->new;
$pk->import_key($header->{jwk});
my $thumbprint = $pk->export_key_jwk_thumbprint;
status_401 unless config->{whitelist}{$thumbprint};
Hack Salem | 14 Sep 2016 | @genehack 39
Server side: more checks
• We specify in the API docs that tokens can only be valid for
one hour
• Have to check that ourselves
• Also need to make sure this isn't some random RSA keypair
• Need to make sure we know this public key
Hack Salem | 14 Sep 2016 | @genehack 40
Server side: THAT'S ALL FOLKS
# if we get here, we're all good!
• If we know the public key in the header,
• then we know the private key was used to sign the JWT
• (or it wouldn't validate)
• and therefore the JWT is from the private key holder
• (who is, by definition, authorized!)
Hack Salem | 14 Sep 2016 | @genehack 41
IMPORTANT NOTE!
This does, of course, depend on the client keeping the private
key actually private
…
But access revocation is as simple as removing a public
keyprint from the whitelist.
Hack Salem | 14 Sep 2016 | @genehack 42
Conclusions
• JWTs solve some really common problems.
• JWTs solve them in a pretty elegant way.
• This is really pretty damn cool.
Hack Salem | 14 Sep 2016 | @genehack 43
Conclusions
• JWTs solve some really common problems.
• JWTs solve them in a pretty elegant way.
• This is really pretty damn cool!!!
• You should think about using JWTs.
Hack Salem | 14 Sep 2016 | @genehack 44
Questions?
Hack Salem | 14 Sep 2016 | @genehack 45
Thanks!
Hack Salem | 14 Sep 2016 | @genehack 46

More Related Content

What's hot

Kamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleKamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With Style
Daniel-Constantin Mierla
 
We-built-a-honeypot-and-p4wned-ransomware-developers-too
We-built-a-honeypot-and-p4wned-ransomware-developers-tooWe-built-a-honeypot-and-p4wned-ransomware-developers-too
We-built-a-honeypot-and-p4wned-ransomware-developers-too
Christiaan Beek
 
I See You
I See YouI See You
I See You
Andrew Beard
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
Daniel-Constantin Mierla
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
Mattias Geniar
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
Nicola Iarocci
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscation
Sandro Zaccarini
 
Cracking Salted Hashes
Cracking Salted HashesCracking Salted Hashes
Cracking Salted Hashes
n|u - The Open Security Community
 
Advanced Weapons Training for the Empire
Advanced Weapons Training for the EmpireAdvanced Weapons Training for the Empire
Advanced Weapons Training for the Empire
Jeremy Johnson
 
JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
John Anderson
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use cases
Enrico Zimuel
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
Sandro Zaccarini
 
Gauntlt: Go Ahead, Be Mean to your Code
Gauntlt: Go Ahead, Be Mean to your CodeGauntlt: Go Ahead, Be Mean to your Code
Gauntlt: Go Ahead, Be Mean to your Code
James Wickett
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
John Anderson
 
Bitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & WalletsBitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & Wallets
Christopher Allen
 
Malicious Payloads vs Deep Visibility: A PowerShell Story
Malicious Payloads vs Deep Visibility: A PowerShell StoryMalicious Payloads vs Deep Visibility: A PowerShell Story
Malicious Payloads vs Deep Visibility: A PowerShell Story
Daniel Bohannon
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
Daniel Bohannon
 
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Don't Loose Sleep - Secure Your Rest - php[tek] 2017Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Adam Englander
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011
Tatsuhiko Miyagawa
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
Tatsuhiko Miyagawa
 

What's hot (20)

Kamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With StyleKamailio - Surfing Big Waves Of SIP With Style
Kamailio - Surfing Big Waves Of SIP With Style
 
We-built-a-honeypot-and-p4wned-ransomware-developers-too
We-built-a-honeypot-and-p4wned-ransomware-developers-tooWe-built-a-honeypot-and-p4wned-ransomware-developers-too
We-built-a-honeypot-and-p4wned-ransomware-developers-too
 
I See You
I See YouI See You
I See You
 
Kamailio and VoIP Wild World
Kamailio and VoIP Wild WorldKamailio and VoIP Wild World
Kamailio and VoIP Wild World
 
Code obfuscation, php shells & more
Code obfuscation, php shells & moreCode obfuscation, php shells & more
Code obfuscation, php shells & more
 
Eve - REST API for Humans™
Eve - REST API for Humans™Eve - REST API for Humans™
Eve - REST API for Humans™
 
Php web backdoor obfuscation
Php web backdoor obfuscationPhp web backdoor obfuscation
Php web backdoor obfuscation
 
Cracking Salted Hashes
Cracking Salted HashesCracking Salted Hashes
Cracking Salted Hashes
 
Advanced Weapons Training for the Empire
Advanced Weapons Training for the EmpireAdvanced Weapons Training for the Empire
Advanced Weapons Training for the Empire
 
JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
 
Cryptography in PHP: use cases
Cryptography in PHP: use casesCryptography in PHP: use cases
Cryptography in PHP: use cases
 
PHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vulnPHP Backdoor: The rise of the vuln
PHP Backdoor: The rise of the vuln
 
Gauntlt: Go Ahead, Be Mean to your Code
Gauntlt: Go Ahead, Be Mean to your CodeGauntlt: Go Ahead, Be Mean to your Code
Gauntlt: Go Ahead, Be Mean to your Code
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
 
Bitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & WalletsBitcoin Keys, Addresses & Wallets
Bitcoin Keys, Addresses & Wallets
 
Malicious Payloads vs Deep Visibility: A PowerShell Story
Malicious Payloads vs Deep Visibility: A PowerShell StoryMalicious Payloads vs Deep Visibility: A PowerShell Story
Malicious Payloads vs Deep Visibility: A PowerShell Story
 
Revoke-Obfuscation
Revoke-ObfuscationRevoke-Obfuscation
Revoke-Obfuscation
 
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Don't Loose Sleep - Secure Your Rest - php[tek] 2017Don't Loose Sleep - Secure Your Rest - php[tek] 2017
Don't Loose Sleep - Secure Your Rest - php[tek] 2017
 
Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011Deploying Plack Web Applications: OSCON 2011
Deploying Plack Web Applications: OSCON 2011
 
Plack at YAPC::NA 2010
Plack at YAPC::NA 2010Plack at YAPC::NA 2010
Plack at YAPC::NA 2010
 

Similar to JWT! JWT! Let it all out!

JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
John Anderson
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
Nobuo Danjou
 
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
Safely Protect PostgreSQL Passwords - Tell Others to SCRAMSafely Protect PostgreSQL Passwords - Tell Others to SCRAM
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
Jonathan Katz
 
Get Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAMGet Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAM
Jonathan Katz
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
Tatsuhiko Miyagawa
 
6.2. Hacking most popular websites
6.2. Hacking most popular websites6.2. Hacking most popular websites
6.2. Hacking most popular websites
defconmoscow
 
Approach to find critical vulnerabilities
Approach to find critical vulnerabilitiesApproach to find critical vulnerabilities
Approach to find critical vulnerabilities
Ashish Kunwar
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Yandex
 
Introduction To Encryption in Lasso 8.5
Introduction To Encryption in Lasso 8.5Introduction To Encryption in Lasso 8.5
Introduction To Encryption in Lasso 8.5
bilcorry
 
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails exampleRoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
Railwaymen
 
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Anna Klepacka
 
JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
John Anderson
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)security
Enrico Zimuel
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
Christoph Matthies
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
hubx
 
Jwt == insecurity?
Jwt == insecurity?Jwt == insecurity?
Jwt == insecurity?
snyff
 
CIS14: I Left My JWT in San JOSE
CIS14: I Left My JWT in San JOSECIS14: I Left My JWT in San JOSE
CIS14: I Left My JWT in San JOSE
CloudIDSummit
 
JWT: jku x5u
JWT: jku x5uJWT: jku x5u
JWT: jku x5u
snyff
 
Tatu: ssh as a service
Tatu: ssh as a serviceTatu: ssh as a service
Tatu: ssh as a service
Pino deCandia
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
Workhorse Computing
 

Similar to JWT! JWT! Let it all out! (20)

JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
 
plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6plackdo, plack-like web interface on perl6
plackdo, plack-like web interface on perl6
 
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
Safely Protect PostgreSQL Passwords - Tell Others to SCRAMSafely Protect PostgreSQL Passwords - Tell Others to SCRAM
Safely Protect PostgreSQL Passwords - Tell Others to SCRAM
 
Get Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAMGet Your Insecure PostgreSQL Passwords to SCRAM
Get Your Insecure PostgreSQL Passwords to SCRAM
 
PSGI/Plack OSDC.TW
PSGI/Plack OSDC.TWPSGI/Plack OSDC.TW
PSGI/Plack OSDC.TW
 
6.2. Hacking most popular websites
6.2. Hacking most popular websites6.2. Hacking most popular websites
6.2. Hacking most popular websites
 
Approach to find critical vulnerabilities
Approach to find critical vulnerabilitiesApproach to find critical vulnerabilities
Approach to find critical vulnerabilities
 
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
Обмен учетными данными между iOS 8 приложениями и вебом, Константин Чернухо, ...
 
Introduction To Encryption in Lasso 8.5
Introduction To Encryption in Lasso 8.5Introduction To Encryption in Lasso 8.5
Introduction To Encryption in Lasso 8.5
 
RoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails exampleRoR Workshop - Web applications hacking - Ruby on Rails example
RoR Workshop - Web applications hacking - Ruby on Rails example
 
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
Workshop KrakYourNet2016 - Web applications hacking Ruby on Rails example
 
JSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your LifeJSON Web Tokens Will Improve Your Life
JSON Web Tokens Will Improve Your Life
 
Password (in)security
Password (in)securityPassword (in)security
Password (in)security
 
How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...How to reverse engineer Android applications—using a popular word game as an ...
How to reverse engineer Android applications—using a popular word game as an ...
 
How to reverse engineer Android applications
How to reverse engineer Android applicationsHow to reverse engineer Android applications
How to reverse engineer Android applications
 
Jwt == insecurity?
Jwt == insecurity?Jwt == insecurity?
Jwt == insecurity?
 
CIS14: I Left My JWT in San JOSE
CIS14: I Left My JWT in San JOSECIS14: I Left My JWT in San JOSE
CIS14: I Left My JWT in San JOSE
 
JWT: jku x5u
JWT: jku x5uJWT: jku x5u
JWT: jku x5u
 
Tatu: ssh as a service
Tatu: ssh as a serviceTatu: ssh as a service
Tatu: ssh as a service
 
Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.Selenium sandwich-3: Being where you aren't.
Selenium sandwich-3: Being where you aren't.
 

More from John Anderson

#speakerlife
#speakerlife#speakerlife
#speakerlife
John Anderson
 
Introduction to Git (even for non-developers)
Introduction to Git (even for non-developers)Introduction to Git (even for non-developers)
Introduction to Git (even for non-developers)
John Anderson
 
Logs are-magic-devfestweekend2018
Logs are-magic-devfestweekend2018Logs are-magic-devfestweekend2018
Logs are-magic-devfestweekend2018
John Anderson
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
John Anderson
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
John Anderson
 
Do you want to be right or do you want to WIN?
Do you want to be right or do you want to WIN?Do you want to be right or do you want to WIN?
Do you want to be right or do you want to WIN?
John Anderson
 
An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)
John Anderson
 
You got chocolate in my peanut butter! .NET on Mac & Linux
You got chocolate in my peanut butter! .NET on Mac & LinuxYou got chocolate in my peanut butter! .NET on Mac & Linux
You got chocolate in my peanut butter! .NET on Mac & Linux
John Anderson
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
John Anderson
 
Old Dogs & New Tricks: What's New with Perl5 This Century
Old Dogs & New Tricks: What's New with Perl5 This CenturyOld Dogs & New Tricks: What's New with Perl5 This Century
Old Dogs & New Tricks: What's New with Perl5 This Century
John Anderson
 
Introduction to Git (even for non-developers!)
Introduction to Git (even for non-developers!)Introduction to Git (even for non-developers!)
Introduction to Git (even for non-developers!)
John Anderson
 
Introduction to Git for Non-Developers
Introduction to Git for Non-DevelopersIntroduction to Git for Non-Developers
Introduction to Git for Non-Developers
John Anderson
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
John Anderson
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
John Anderson
 
Old Dogs & New Tricks: What's New With Perl5 This Century
Old Dogs & New Tricks: What's New With Perl5 This CenturyOld Dogs & New Tricks: What's New With Perl5 This Century
Old Dogs & New Tricks: What's New With Perl5 This Century
John Anderson
 
A Modest Introduction to Swift
A Modest Introduction to SwiftA Modest Introduction to Swift
A Modest Introduction to Swift
John Anderson
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
John Anderson
 
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
John Anderson
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
John Anderson
 
Logs Are Magic! Why git workflows & commit structure should matter to you
Logs Are Magic! Why git workflows & commit structure should matter to youLogs Are Magic! Why git workflows & commit structure should matter to you
Logs Are Magic! Why git workflows & commit structure should matter to you
John Anderson
 

More from John Anderson (20)

#speakerlife
#speakerlife#speakerlife
#speakerlife
 
Introduction to Git (even for non-developers)
Introduction to Git (even for non-developers)Introduction to Git (even for non-developers)
Introduction to Git (even for non-developers)
 
Logs are-magic-devfestweekend2018
Logs are-magic-devfestweekend2018Logs are-magic-devfestweekend2018
Logs are-magic-devfestweekend2018
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
 
Do you want to be right or do you want to WIN?
Do you want to be right or do you want to WIN?Do you want to be right or do you want to WIN?
Do you want to be right or do you want to WIN?
 
An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)An Introduction to Git (even for non-developers)
An Introduction to Git (even for non-developers)
 
You got chocolate in my peanut butter! .NET on Mac & Linux
You got chocolate in my peanut butter! .NET on Mac & LinuxYou got chocolate in my peanut butter! .NET on Mac & Linux
You got chocolate in my peanut butter! .NET on Mac & Linux
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
 
Old Dogs & New Tricks: What's New with Perl5 This Century
Old Dogs & New Tricks: What's New with Perl5 This CenturyOld Dogs & New Tricks: What's New with Perl5 This Century
Old Dogs & New Tricks: What's New with Perl5 This Century
 
Introduction to Git (even for non-developers!)
Introduction to Git (even for non-developers!)Introduction to Git (even for non-developers!)
Introduction to Git (even for non-developers!)
 
Introduction to Git for Non-Developers
Introduction to Git for Non-DevelopersIntroduction to Git for Non-Developers
Introduction to Git for Non-Developers
 
A static site generator should be your next language learning project
A static site generator should be your next language learning projectA static site generator should be your next language learning project
A static site generator should be your next language learning project
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
 
Old Dogs & New Tricks: What's New With Perl5 This Century
Old Dogs & New Tricks: What's New With Perl5 This CenturyOld Dogs & New Tricks: What's New With Perl5 This Century
Old Dogs & New Tricks: What's New With Perl5 This Century
 
A Modest Introduction to Swift
A Modest Introduction to SwiftA Modest Introduction to Swift
A Modest Introduction to Swift
 
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To YouLogs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
Logs Are Magic: Why Git Workflows and Commit Structure Should Matter To You
 
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
Friends Don't Let Friends Browse Unencrypted: Running a VPN for friends and f...
 
A Modest Introduction To Swift
A Modest Introduction To SwiftA Modest Introduction To Swift
A Modest Introduction To Swift
 
Logs Are Magic! Why git workflows & commit structure should matter to you
Logs Are Magic! Why git workflows & commit structure should matter to youLogs Are Magic! Why git workflows & commit structure should matter to you
Logs Are Magic! Why git workflows & commit structure should matter to you
 

Recently uploaded

快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
3a0sd7z3
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
3a0sd7z3
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
k4ncd0z
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
thezot
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
APNIC
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
Donato Onofri
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
Paul Walk
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
APNIC
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
xjq03c34
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
davidjhones387
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
rtunex8r
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
Tarandeep Singh
 

Recently uploaded (12)

快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
快速办理(新加坡SMU毕业证书)新加坡管理大学毕业证文凭证书一模一样
 
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
快速办理(Vic毕业证书)惠灵顿维多利亚大学毕业证完成信一模一样
 
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理一比一原版(USYD毕业证)悉尼大学毕业证如何办理
一比一原版(USYD毕业证)悉尼大学毕业证如何办理
 
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
一比一原版新西兰林肯大学毕业证(Lincoln毕业证书)学历如何办理
 
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
Honeypots Unveiled: Proactive Defense Tactics for Cyber Security, Phoenix Sum...
 
HijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process HollowingHijackLoader Evolution: Interactive Process Hollowing
HijackLoader Evolution: Interactive Process Hollowing
 
Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?Should Repositories Participate in the Fediverse?
Should Repositories Participate in the Fediverse?
 
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...Securing BGP: Operational Strategies and Best Practices for Network Defenders...
Securing BGP: Operational Strategies and Best Practices for Network Defenders...
 
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
办理新西兰奥克兰大学毕业证学位证书范本原版一模一样
 
Discover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to IndiaDiscover the benefits of outsourcing SEO to India
Discover the benefits of outsourcing SEO to India
 
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
怎么办理(umiami毕业证书)美国迈阿密大学毕业证文凭证书实拍图原版一模一样
 
Bengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal BrandingBengaluru Dreamin' 24 - Personal Branding
Bengaluru Dreamin' 24 - Personal Branding
 

JWT! JWT! Let it all out!

  • 1. JWT! JWT! Let it all out! John SJ Anderson | @genehack | Hack Salem | 14 Sep 2016 Hack Salem | 14 Sep 2016 | @genehack 1
  • 2. JSON Web Tokens want to rule your world John SJ Anderson | @genehack | Hack Salem | 14 Sep 2016 Hack Salem | 14 Sep 2016 | @genehack 2
  • 3. Hi, I'm John Hack Salem | 14 Sep 2016 | @genehack 3
  • 4. VP, Tech Infinity Interactive Hack Salem | 14 Sep 2016 | @genehack 4
  • 5. So, what's a JWT? Hack Salem | 14 Sep 2016 | @genehack 5
  • 6. jwt.io Hack Salem | 14 Sep 2016 | @genehack 6
  • 7. What Does That Even MeanHack Salem | 14 Sep 2016 | @genehack 7
  • 8. Think of it as… • A lightweight alternative to cookies • A form of access control without authentication • Cross-site single sign on (SSO) without cross domain pain Hack Salem | 14 Sep 2016 | @genehack 8
  • 9. Made of stuff you already know • JSON Objects • Cryptographically signed and hashed • Transmitted during HTTP request Hack Salem | 14 Sep 2016 | @genehack 9
  • 10. JWT teardown • dot-delimited string ('.') • 3 parts • header • payload • signature • Example: xxx.yyyyy.zzz Hack Salem | 14 Sep 2016 | @genehack 10
  • 11. JWT teardown: header • Plain ole JSON object • Base64Url encoded • Typically indicates token type and hashing algorithm { "alg": "HS256", "typ": "JWT" } Hack Salem | 14 Sep 2016 | @genehack 11
  • 12. JWT teardown: payload • Also plain ole JSON object • Contains "claims" -- really just data • Reserved, public, private • Also Base64Url encoded { "name": "Hack Salem", "admin": false } Hack Salem | 14 Sep 2016 | @genehack 12
  • 13. JWT teardown: signature • Encoded header, plus • Encoded payload, plus • A secret, plus • Signing algorithm from header HMACSHA256( base64UrlEncode(header) + "." + base64UrlEncode(payload), secret ) Hack Salem | 14 Sep 2016 | @genehack 13
  • 14. Putting it all together Hack Salem | 14 Sep 2016 | @genehack 14
  • 15. Putting it all together Hack Salem | 14 Sep 2016 | @genehack 15
  • 16. More advanced usage • Encrypted payloads (JWE) • Nested JWT (Won't get any further into these tonight…) Hack Salem | 14 Sep 2016 | @genehack 16
  • 17. Libraries for DAYS • .NET, Python, Node, Java, Javascript, Ruby, Perl, Go, PHP • Haskell, Rust, Lua, Scala, Clojure, ObjectiveC, Swift, Delphi • Support for your favorite language/platform is probably not an issue Hack Salem | 14 Sep 2016 | @genehack 17
  • 18. OK, you've got my attentionHack Salem | 14 Sep 2016 | @genehack 18
  • 19. How Do I Use It?Hack Salem | 14 Sep 2016 | @genehack 19
  • 20. Basic auth/authz usage (stolen from jwt.io) Hack Salem | 14 Sep 2016 | @genehack 20
  • 21. Things to be aware of • Payload/header NOT encrypted (in this setup) • …don't send anything sensitive! • Need to control expiration, re-issue, etc. • Some APIs will send a fresh JWT to the client per-request • Sites other than issuing site can receive JWT • …if they share the secret Hack Salem | 14 Sep 2016 | @genehack 21
  • 22. How is it actually transmitted? • Up to you! Various methods: • As part of the URL • In the POST body • In the Authorization header using bearer scheme: Authorization: Bearer <token> Hack Salem | 14 Sep 2016 | @genehack 22
  • 23. Authorization without authentication • Scenario: • You have an API • You don't want to make anybody authenticate to use it • You don't want it wide open to the Internet either • a/k/a authz without authn Hack Salem | 14 Sep 2016 | @genehack 23
  • 24. Solution: JWT with RSA keys • Alternative to secret in previous scenario: RSA key-pair • Can include the public key in the JWT header using JWK • JSON Web Key, natch • Allows API client to produce claims in a verifiable way Hack Salem | 14 Sep 2016 | @genehack 24
  • 25. To set it up: • Give authorized user a RSA key-pair • You can even let them generate it — you just need to: • Record the fingerprint of the public key (important later!) Hack Salem | 14 Sep 2016 | @genehack 25
  • 26. On their side: • They make JWT using the private key • They include the public key in the header • Include iat (issued-at) and exp (expires) claims • Send JWT in Authorization header with API request Hack Salem | 14 Sep 2016 | @genehack 26
  • 27. On our side: • Get the public key out of the JWT header • Validate the JWT signature using the key • Validate that public key fingerprint is white-listed • Signature produced with private key • Public key is white-listed • Therefore we know JWT is valid! Hack Salem | 14 Sep 2016 | @genehack 27
  • 28. Things to be aware of: • You still want to validate iat and exp and any other rules • Your library should probably do that stuff for you, mostly • Again, nothing is encrypted, so don't plan on sensitive stuff in the payload or header Hack Salem | 14 Sep 2016 | @genehack 28
  • 29. Let's see some code! • May look a bit strange • New experimental language, Nacre • Transpiles to Javascript Hack Salem | 14 Sep 2016 | @genehack 29
  • 30. Client side my $pri_key = Crypt::PK::RSA->new('./key.pri'); my $pub_key = Crypt::PK::RSA->new('./key.pub'); my $token = encode_jwt( alg => 'RS512', extra_headers => { jwk => $pub_key->export_key_jwk('public', 1), nonce => undef , }, key => $pri_key , payload => { iat => time() }, relative_exp => 1800, ); HTTP::Request->new( 'POST' => 'https://example.com/endpoint', ['Authorization' => "Bearer $token"], encode_json({ request => 'body' }) ); Hack Salem | 14 Sep 2016 | @genehack 30
  • 31. Client side: making the token my $token = encode_jwt( alg => 'RS512', extra_headers => { jwk => $pub_key->export_key_jwk('public', 1), nonce => undef , }, key => $pri_key , payload => { iat => time() }, relative_exp => 1800, ); Hack Salem | 14 Sep 2016 | @genehack 31
  • 32. Client side: adding the public key extra_headers => { jwk => $pub_key->export_key_jwk('public', 1), }, Key: find an RSA library that supports export to JWK format! Hack Salem | 14 Sep 2016 | @genehack 32
  • 33. BTW, just kidding about Nacre…Hack Salem | 14 Sep 2016 | @genehack 33
  • 34. it's Perl! (of course) Hack Salem | 14 Sep 2016 | @genehack 34
  • 35. Server side my $auth_header = request_header 'Authorization' ; status_401 unless ( $token ) = $auth_header =~ /^Bearer (.*)$/; # try to decode it and confirm valid sig, # and valid iat and exp claims my( $header, $payload ); try { ( $header, $payload ) = decode_jwt( token => $token , decode_header => 1 , accepted_alg => 'RS512' , verify_iat => 1 , verify_exp => 1 ); }; # no catch block, just drop the error, we're out of here in that case status_401 unless $header and $payload; # check that expiration time is less than one hour status_401 unless $payload->{exp} - $payload->{iat} < 3600; # check that the included public key is on the whitelist my $pk = Crypt::PK::RSA->new; $pk->import_key($header->{jwk}); my $thumbprint = $pk->export_key_jwk_thumbprint; status_401 unless config->{whitelist}{$thumbprint}; # if we get here, we're all good! ... Hack Salem | 14 Sep 2016 | @genehack 35
  • 36. Server side: get the token my $auth_header = request_header 'Authorization' ; status_401 unless ( $token ) = $auth_header =~ /^Bearer (.*)$/; Hack Salem | 14 Sep 2016 | @genehack 36
  • 37. Server side: decode the token # try to decode it and confirm valid sig, # and valid iat and exp claims my( $header, $payload ); try { ( $header, $payload ) = decode_jwt( token => $token , decode_header => 1 , accepted_alg => 'RS512' , verify_iat => 1 , verify_exp => 1 ); }; # no catch block, just drop the error, we're out of here in that case status_401 unless $header and $payload; Hack Salem | 14 Sep 2016 | @genehack 37
  • 38. Server side: decode the token • Key in header wrong? FAILS • Not right algorithm? FAILS • Doesn't have iat and exp? FAILS ALL that validation is happening inside the library, so I don't have to worry about it. • Me? WINS Hack Salem | 14 Sep 2016 | @genehack 38
  • 39. Server side: do more checks # check that expiration time is less than one hour status_401 unless $payload->{exp} - $payload->{iat} < 3600; # check that the included public key is on the whitelist my $pk = Crypt::PK::RSA->new; $pk->import_key($header->{jwk}); my $thumbprint = $pk->export_key_jwk_thumbprint; status_401 unless config->{whitelist}{$thumbprint}; Hack Salem | 14 Sep 2016 | @genehack 39
  • 40. Server side: more checks • We specify in the API docs that tokens can only be valid for one hour • Have to check that ourselves • Also need to make sure this isn't some random RSA keypair • Need to make sure we know this public key Hack Salem | 14 Sep 2016 | @genehack 40
  • 41. Server side: THAT'S ALL FOLKS # if we get here, we're all good! • If we know the public key in the header, • then we know the private key was used to sign the JWT • (or it wouldn't validate) • and therefore the JWT is from the private key holder • (who is, by definition, authorized!) Hack Salem | 14 Sep 2016 | @genehack 41
  • 42. IMPORTANT NOTE! This does, of course, depend on the client keeping the private key actually private … But access revocation is as simple as removing a public keyprint from the whitelist. Hack Salem | 14 Sep 2016 | @genehack 42
  • 43. Conclusions • JWTs solve some really common problems. • JWTs solve them in a pretty elegant way. • This is really pretty damn cool. Hack Salem | 14 Sep 2016 | @genehack 43
  • 44. Conclusions • JWTs solve some really common problems. • JWTs solve them in a pretty elegant way. • This is really pretty damn cool!!! • You should think about using JWTs. Hack Salem | 14 Sep 2016 | @genehack 44
  • 45. Questions? Hack Salem | 14 Sep 2016 | @genehack 45
  • 46. Thanks! Hack Salem | 14 Sep 2016 | @genehack 46