SlideShare a Scribd company logo
@adam_englander
Don’t Lose Sleep
Secure Your REST
Adam Englander, iovation
@adam_englander
A Little Background About Me
And APIs
@adam_englander
This is what I looked
like when I started
working on APIs
It was so long ago that SOAP was the
new hotness.
@adam_englander
Over The Years
• 2001 — Global Authentication Service API
• 2008 — Loan Application Ping Tree
• 2010 — Loan Management System API
• 2012 — Advertising Network API
• 2013 — Real Time Loan Risk Assessment API
• 2015 — Decentralized Multi-Factor Authorization API
@adam_englander
Some Were More Secure Than
Others
@adam_englander
Auth and Crypto Was Messy
• Auth as part of the message added complexity
• Auth outside of the message lost context
• Every implementation was specialized
• Crypto was non-standard and static
• Non-experts had to write a lot of code
@adam_englander
My current product, LaunchKey,
suffered as well.
@adam_englander
We Identified Gaps
• Authentication was part of the request
• Signature was incomplete on request and absent on
response
• Key rotation was difficult if not impossible
• Algorithms were pinned to lowest common denominator
• To much crypto knowledge required without SDK
@adam_englander
JOSE To The Rescue!
Javascript Object Signing and Encryption (JOSE)
@adam_englander
Why JOSE?
• Authentication, authorization, encryption, and
data integrity validation are not tied to the
protocol
• OAuth, OpenID, and FIDO adopting the
standard gave it credibility, stability, and
longevity as an IETF working group
@adam_englander
What Changed?
• JWT with custom claims used to validate entire
request and critical portions of the response
• JWE to encrypt request and response
• JWA for future proofing cryptography
• JWK for credential rotation
• Removed password entirely
@adam_englander
How Did We Do It?
@adam_englander
A Whole Lot of JOSE
• JSON Web Token (JWT)
• JSON Web Signature (JWS)
• JSON Web Encryption (JWE)
• JSON Web Algorithm (JWA)
• JSON Web Key (KWK)
@adam_englander
JSON Web Signature (JWS)
JWS is comprised of three segments:
1. Header provides key information, signature
algorithm, and optionally content metadata
2. Payload is the data to be signed
3. Signature of the header and payload
@adam_englander
JSON Web Token (JWT)
• JWT is actually a JSON Web Signature (JWS)
package with standardized payload in the form
of Claims.
• Provides for credentials, nonce, timestamp, and
duration
• Private claims can be added for extensibility
@adam_englander
JSON Web Encryption (JWE)
JSON Web Encryption contains five segments:
1. Header provides key management mode, key
information, key encryption algorithm, content
encryption algorithm, and optionally content metadata
2. Content Encryption Key (CEK) may contain generated
symmetric keys used for encryption and HMAC that
are encrypted using asymmetric key encryption
@adam_englander
JSON Web Encryption (JWE)
3. Initialization Vector for encrypting the payload
4. Encrypted payload
5. Authentication tag is an HMAC of the header,
IV, and encrypted payload
@adam_englander
JSON Web Algorithm
• Standardized format for expressing encryption
and signature algorithms.
• Used by JWE/JWS with “enc” and “alg” keys in
the header.
@adam_englander
JSON Web Key
• Standardized format for expressing keys used
for JWE and JWS.
• Provides for key identification.
• Used by JWE/JWS with number of keys in the
header which are determined by the key type.
@adam_englander
The Good — Decoupling
• Authentication, authorization, validation, encryption
and decryption was moved to middleware
• Controllers handled only HTTP/JSON which greatly
reduced code complexity
• Better unit testing across the board
• Reduced development times for new functionality
@adam_englander
The Good — OSS Libraries
• We can test our API without requiring our own
client SDK
• Client SDKs are less complex
• OSS contributions are actually possible
• Documentation complexity was reduced
@adam_englander
The Good — Uniformity Across APIs
• All APIs will be migrated to JOSE
• Different key implementations are possible
• Shared knowledge across vastly different teams
• Federated authentication is attainable
@adam_englander
The Good — Hierarchical Auth
• JWT inclusion of issuer, subject, and audience
allows for a parent to provide credentials for
action on a sibling with proper context.
• JWK allows for easy identification of credentials
used
@adam_englander
The Bad
• Some languages have minimal support for
algorithms and strengths
• Some languages have no support for JWE. We
had to write our own minimal Objective-C
implementation
• Some good documentation but a good working
knowledge requires reading RFCs
@adam_englander
How We Use JOSE
JOSE Solved Every Problem We Had
@adam_englander
Request Example Representation
POST /service/v3/auths HTTP/1.1
Content-Type: application/jose
Content-Length: 112
Authorization: IOV-JWT eyJhb.VuYyI6IkEy.OKOaw
eyJhbGciO.Ppd6dIAkG.71lYoW6jA.t-4rRH6GsoXt0.1DGC4k
@adam_englander
JWT Header Example
{

"kid": "09:f7:e0:2f:12:90:be:21:1d:a7:07:a2:66:f1:53:b3",

"alg": "RS256",

"typ": "JWT",

"cty": "JWT"

}
@adam_englander
Key Rotation
• Key ID id provided in request and response
• Current and specific public keys are available via
endpoint
• https://api.launchkey.com/public/v3/public-key/
09:f7:e0:2f:12:90:be:21:1d:a7:07:a2:66:f1:53:b3
• https://api.launchkey.com/public/v3/public-key
@adam_englander
Key Rotation
{

"kid": "09:f7:e0:2f:12:90:be:21:1d:a7:07:a2:66:f1:53:b3",

"alg": "RS256",

"typ": "JWT",

"cty": "JWT"

}
/v3/public-key/09:f7:e0:2f:12:90:be:21:1d:a7:07:a2:66:f1:53:b3
@adam_englander
Request Authorization
• Single use JSON Web Token (JWT) in Authorization
header as Authorization scheme IOV-JWT
• RSA key signature
• Hierarchical ACL: Org -> Dir -> Service
• Token ID as nonce
• Private claims: request
@adam_englander
Private Request Claims
• Method
• Path
• Body hash
• Body hash algorithm
• Query parameters
@adam_englander
JWT Request Claims Example
{

"iss": "dir:fd57bffe-7391-47c4-94d0-a0ad4b6bc979",

"sub": "svc:d2083969-b5aa-4753-909d-472ce2517fd1",

"aud": "lka",

"iat": 1234567890,

"nbf": 1234567890,

"exp": 1234567895,

"jti": "bec95e07-cee2-4c77-b080-56a8b24b2e54",

"request": {

"meth": "POST",

"path": "/service/v3/auths",

"func": "S256",

"hash": "66a045b452102c59d840ec097d59d9467e13a3f34f6494e539ffd32c1bb35f18"

}

}
@adam_englander
Hierarchical Credentials
…

"iss": "dir:fd57bffe-7391-47c4-94d0-a0ad4b6bc979",

"sub": "svc:d2083969-b5aa-4753-909d-472ce2517fd1",

"aud": "lka",
…

@adam_englander
Timestamp and Duration
…

"iat": 1487244120,

"nbf": 1487244120,

"exp": 1487244125,

…
JWT hash stored until expiration to prevent replay
attacks.
@adam_englander
Nonce
…
"jti": "bec95e07-cee2-4c77-b080-56a8b24b2e54",

…
@adam_englander
Request Validation
POST /service/v3/auths HTTP/1.1
…
"request": {

"meth": "POST",

"path": "/service/v3/auths",

"func": "S256",

"hash": "66a045b452102c59d840e…"

}

…
@adam_englander
Response Authorization
• Single use JSON Web Token (JWT) in custom
header X-IOV-JWT
• RSA key signature
• Hierarchical credentials
• Token ID nonce is echoed
• Private claims: response
@adam_englander
Private Response Claims
• Status Code
• Cache-Control Header
• Location Header
• Body hash
• Body hash algorithm
@adam_englander
Response Example Representation
HTTP/1.1 201 Created
Content-Type: application/jose
Content-Length: 112
Cache-Control: no-cache
Location: /directory/v3/users/518f5d3e-7cdf-4ef1-…
X-IOV-JWT: eyJhb.VuYyI6IkEy.OKOaw
eyJhbGciO.Ppd6dIAkG.71lYoW6jA.t-4rRH6GsoXt0.1DGC4k
@adam_englander
JWT Response Claims Example
{

"iss": "lka",

"sub": "svc:d2083969-b5aa-4753-909d-472ce2517fd1",

"aud": "dir:fd57bffe-7391-47c4-94d0-a0ad4b6bc979",

"iat": 1234567891,

"nbf": 1234567891,

"exp": 1234567896,

"jti": "bec95e07-cee2-4c77-b080-56a8b24b2e54",

"response": {

"status": 201,

"cache": "no-cache",

"location": "/directory/v3/users/518f5d3e-7cdf-4ef1-…",

"func": "S256",

"hash": "66a045b452102c59d840ec097d59d9467e13a3f34f6494e539ffd32c1bb35f18"

}

}
@adam_englander
Hierarchical Credentials
…

"iss": "lka",

"sub": "svc:d2083969-b5aa-4753-909d-472ce2517fd1",

"aud": "dir:fd57bffe-7391-47c4-94d0-a0ad4b6bc979",
…

@adam_englander
Timestamp and Duration
…

"iat": 1487244121,

"nbf": 1487244121,

"exp": 1487244126,

…
@adam_englander
Nonce
…
"jti": "bec95e07-cee2-4c77-b080-56a8b24b2e54",

…
Nonce is echoed in JTI to allow for detection of
Man In The Middle attacks
@adam_englander
Response Validation
HTTP/1.1 201 Created
Cache-Control: no-cache
Location: /directory/v3/users/518f5d3e-7c…
…
"response": {

"status": 201,

"cache": "no-cache",

"location": "/directory/v3/users/518f5d3e-7c…",

"func": "S256",

"hash": “66a045b452102c59d840ec097d59d9467e13…”

}
…
@adam_englander
JWT Creation Example
$jwt = (new JWTCreator(new Signer(['RS512'])))->sign(

[

'iat' => time(),

'exp' => time() + 5,

'jti' => 'abc123',



],

['alg' => 'RS512'],

JWKFactory::createFromKeyFile(

'./private.key'

)

);
@adam_englander
JWT Validation Example
$checkerManager = new CheckerManager();

$checkerManager->addClaimChecker(new IssuedAtChecker());

$jwtLoader = new JWTLoader(

$checkerManager,

new Verifier(['RS512'])

);

$keySet = new JWKSet();

$keySet->addKey(JWKFactory::createFromKeyFile(

'./public.key'

));

$jws = $jwtLoader->load($jwt, $keySet);

$jwtLoader->verify($jws, $keySet);
@adam_englander
Encrypted Data with JWE
• JWK provides for key rotation
• Combination of RSA and AES encryption is always
used
• Algorithms and modes are always the same
• Key size is variable in allowed range
• Response uses same AES key size as request
@adam_englander
JWE Header Example
{

"kid": "09:f7:e0:2f:12:90:be:21:1d:a7:07:a2:66:f1:53:b3",

"alg": “RSA-OAEP-256",

"enc": "A256CBC-HS512",

"cty": “application/json"

}
@adam_englander
JWE Encryption Example
$encrypted = JWEFactory::createJWEToCompactJSON(

"Hello World!",

JWKFactory::createFromKeyFile(

'./public.key'

),

[

'enc' => 'A256CBC-HS512',

'alg' => 'RSA-OAEP-256',

'zip' => 'DEF',

]
);
@adam_englander
JWE Decryption Example
$decrypted = (new Loader)->loadAndDecryptUsingKey(

$encrypted,

JWKFactory::createFromKeyFile(

'./private.key'

),

['RSA-OAEP-256'], // Acceptable algs

['A256CBC-HS512'] // Acceptable encs

);
@adam_englander
Conclusion
• JOSE has made our secure API more secure
• JOSE has made our API easier to use
• JOSE has made our code less complex
• JOSE has homogenized auth and crypto across
multiple platforms regardless of language
@adam_englander
Resources
• https://github.com/Spomky-Labs/jose
• https://tools.ietf.org/wg/jose/
• https://jwt.io/
Thanks to our
Sponsors!
@adam_englander
Please Rate This Talk
https://joind.in/talk/4fea6
@adam_englander
If You Want To Follow Up
• @adam_englander
• adam.englander@iovation.com
• https://www.iovation.com/blog/author/aenglander

More Related Content

PDF
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
PDF
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
PPTX
JWTs and JOSE in a flash
PPTX
Kerberos survival guide - SPS Ozarks 2010
PDF
Enforcing Bespoke Policies in Kubernetes
PPTX
MongoDB.local Seattle 2019: Introduction to MongoDB Atlas for Your Enterprise
PDF
2018 SDJUG Deconstructing and Evolving REST Security
PDF
Implementing Authorization
Con Foo 2017 - Don't Loose Sleep - Secure Your REST
PHP UK 2017 - Don't Lose Sleep - Secure Your REST
JWTs and JOSE in a flash
Kerberos survival guide - SPS Ozarks 2010
Enforcing Bespoke Policies in Kubernetes
MongoDB.local Seattle 2019: Introduction to MongoDB Atlas for Your Enterprise
2018 SDJUG Deconstructing and Evolving REST Security
Implementing Authorization

What's hot (20)

PDF
Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)
PDF
What the Heck is OAuth and OpenID Connect? Connect.Tech 2017
PDF
Designing software with security in mind?
PDF
Arm yourself with Domain Driven Security. It's time to slay some security trolls
PPTX
Open source security
PDF
Domain driven security_java_zone2016
PDF
OPA: The Cloud Native Policy Engine
PDF
JWT! JWT! Let it all out!
PDF
ZendCon 2017 - Cryptography for Beginners
PPTX
CQRS and Event Sourcing
PPTX
Secure socket layer
 
PPTX
Policy Enforcement on Kubernetes with Open Policy Agent
PDF
Insecure Implementation of Security Best Practices: of hashing, CAPTCHA's and...
PPTX
RESTful modules in zf2
PPTX
Locking the Doors -7 Pernicious Pitfalls to avoid with Java
PDF
2018 Denver JUG Deconstructing and Evolving REST Security
PDF
Open Policy Agent Deep Dive Seattle 2018
PDF
How Netflix Is Solving Authorization Across Their Cloud
PDF
Kubernetes Security with Calico and Open Policy Agent
PDF
Rest api design by george reese
Istio's mixer policy enforcement with custom adapters (cloud nativecon 17)
What the Heck is OAuth and OpenID Connect? Connect.Tech 2017
Designing software with security in mind?
Arm yourself with Domain Driven Security. It's time to slay some security trolls
Open source security
Domain driven security_java_zone2016
OPA: The Cloud Native Policy Engine
JWT! JWT! Let it all out!
ZendCon 2017 - Cryptography for Beginners
CQRS and Event Sourcing
Secure socket layer
 
Policy Enforcement on Kubernetes with Open Policy Agent
Insecure Implementation of Security Best Practices: of hashing, CAPTCHA's and...
RESTful modules in zf2
Locking the Doors -7 Pernicious Pitfalls to avoid with Java
2018 Denver JUG Deconstructing and Evolving REST Security
Open Policy Agent Deep Dive Seattle 2018
How Netflix Is Solving Authorization Across Their Cloud
Kubernetes Security with Calico and Open Policy Agent
Rest api design by george reese
Ad

Similar to Don't Loose Sleep - Secure Your Rest - php[tek] 2017 (20)

PDF
Java EE Security API - JSR375: Getting Started
PDF
What is tackled in the Java EE Security API (Java EE 8)
PPTX
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
KEY
Android lessons you won't learn in school
PDF
Securing Web Applications with Token Authentication
PPTX
Microservices Security Patterns & Protocols with Spring & PCF
PPTX
Austin Day of Rest - Introduction
PDF
Api FUNdamentals #MHA2017
PDF
Api fundamentals
PPTX
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
PDF
OSDC 2015: Tudor Golubenco | Application Performance Management with Packetbe...
PDF
Coding 100-session-slides
PDF
RESTful web
PDF
Embracing HTTP in the era of API’s
PDF
Middleware in Golang: InVision's Rye
PDF
[4developers2016] - Security in the era of modern applications and services (...
PPTX
Rest API with Swagger and NodeJS
PPTX
Scaling with swagger
PPTX
Java ee 8 + security overview
Java EE Security API - JSR375: Getting Started
What is tackled in the Java EE Security API (Java EE 8)
WAF Bypass Techniques - Using HTTP Standard and Web Servers’ Behaviour
Android lessons you won't learn in school
Securing Web Applications with Token Authentication
Microservices Security Patterns & Protocols with Spring & PCF
Austin Day of Rest - Introduction
Api FUNdamentals #MHA2017
Api fundamentals
MongoDB.local Dallas 2019: Pissing Off IT and Delivery: A Tale of 2 ODS's
OSDC 2015: Tudor Golubenco | Application Performance Management with Packetbe...
Coding 100-session-slides
RESTful web
Embracing HTTP in the era of API’s
Middleware in Golang: InVision's Rye
[4developers2016] - Security in the era of modern applications and services (...
Rest API with Swagger and NodeJS
Scaling with swagger
Java ee 8 + security overview
Ad

More from Adam Englander (20)

PPTX
Making PHP Smarter - Dutch PHP 2023.pptx
PDF
Practical API Security - PyCon 2019
PDF
Threat Modeling for Dummies
PDF
ZendCon 2018 - Practical API Security
PDF
ZendCon 2018 - Cryptography in Depth
PDF
Threat Modeling for Dummies - Cascadia PHP 2018
PDF
Dutch PHP 2018 - Cryptography for Beginners
PDF
php[tek] 2108 - Cryptography Advances in PHP 7.2
PDF
php[tek] 2018 - Biometrics, fantastic failure point of the future
PDF
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
PPTX
Practical API Security - PyCon 2018
PDF
Practical API Security - Midwest PHP 2018
PDF
Cryptography for Beginners - Midwest PHP 2018
PDF
Cryptography for Beginners - Sunshine PHP 2018
PDF
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
PDF
ZendCon 2017: The Red Team is Coming
PDF
ZendCon 2017 - Build a Bot Workshop - Async Primer
PDF
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
PDF
Coder Cruise 2017 - The Red Team Is Coming
PDF
Build a bot workshop async primer - php[tek]
Making PHP Smarter - Dutch PHP 2023.pptx
Practical API Security - PyCon 2019
Threat Modeling for Dummies
ZendCon 2018 - Practical API Security
ZendCon 2018 - Cryptography in Depth
Threat Modeling for Dummies - Cascadia PHP 2018
Dutch PHP 2018 - Cryptography for Beginners
php[tek] 2108 - Cryptography Advances in PHP 7.2
php[tek] 2018 - Biometrics, fantastic failure point of the future
Biometrics: Sexy, Secure and... Stupid - RSAC 2018
Practical API Security - PyCon 2018
Practical API Security - Midwest PHP 2018
Cryptography for Beginners - Midwest PHP 2018
Cryptography for Beginners - Sunshine PHP 2018
ConFoo Vancouver 2017 - Biometrics: Fantastic Failure Point of the Future
ZendCon 2017: The Red Team is Coming
ZendCon 2017 - Build a Bot Workshop - Async Primer
Symfony Live San Franciso 2017 - BDD API Development with Symfony and Behat
Coder Cruise 2017 - The Red Team Is Coming
Build a bot workshop async primer - php[tek]

Recently uploaded (20)

PPTX
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
PDF
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
PDF
medical staffing services at VALiNTRY
PPTX
history of c programming in notes for students .pptx
PDF
Which alternative to Crystal Reports is best for small or large businesses.pdf
PDF
2025 Textile ERP Trends: SAP, Odoo & Oracle
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
top salesforce developer skills in 2025.pdf
PPTX
Introduction to Artificial Intelligence
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PPTX
VVF-Customer-Presentation2025-Ver1.9.pptx
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Design an Analysis of Algorithms I-SECS-1021-03
PDF
Nekopoi APK 2025 free lastest update
Agentic AI Use Case- Contract Lifecycle Management (CLM).pptx
Addressing The Cult of Project Management Tools-Why Disconnected Work is Hold...
How Creative Agencies Leverage Project Management Software.pdf
Claude Code: Everyone is a 10x Developer - A Comprehensive AI-Powered CLI Tool
medical staffing services at VALiNTRY
history of c programming in notes for students .pptx
Which alternative to Crystal Reports is best for small or large businesses.pdf
2025 Textile ERP Trends: SAP, Odoo & Oracle
Wondershare Filmora 15 Crack With Activation Key [2025
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
top salesforce developer skills in 2025.pdf
Introduction to Artificial Intelligence
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Raksha Bandhan Grocery Pricing Trends in India 2025.pdf
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
VVF-Customer-Presentation2025-Ver1.9.pptx
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Design an Analysis of Algorithms I-SECS-1021-03
Nekopoi APK 2025 free lastest update

Don't Loose Sleep - Secure Your Rest - php[tek] 2017