SlideShare a Scribd company logo
Developer's Guide to
JavaScript and Web
Cryptography
Kevin Hakanson
Kevin Hakanson
@hakanson
+KevinHakanson
Abstract
The increasing capabilities and performance of the web
platform allow for more feature-rich user experiences. How
can JavaScript based applications utilize information security
and cryptography principles? This session will explore the
current state of JavaScript and Web Cryptography. We will
review some basic concepts and definitions, discuss the role
of TLS/SSL, show some working examples that apply
cryptography to real-world use cases and take a peek at the
upcoming W3C WebCryptoAPI. Code samples will use
CryptoJS in the browser and the Node.js Crypto module on
the server. An extended example will secure the popular
TodoMVC project using PBKDF2 for key generation, HMAC
for data integrity and AES for encryption.
(Less) Abstract
The increasing capabilities and performance of the web platformallow for more feature-
rich user experiences. How can JavaScript based applications utilize information security and
cryptography principles? This session will explore the current state of JavaScript and
Web Cryptography. We will review some basic concepts and
definitions, discuss the role of TLS/SSL, show some working examples that apply
cryptography to real-world use cases and take a peek at the upcoming W3C WebCryptoAPI. Code
samples will use CryptoJS in the browserand the Node.js
Crypto module on the server. An extended example will
secure the popular TodoMVCproject using PBKDF2 for key
generation, HMAC for data integrity and AES for encryption.
+ :) & ?s
Technology Logos (NASCAR Style)
Project which offers the same Todo application
implemented using MV* concepts in most of the
popular JavaScript MV* frameworks of today.
http://todomvc.com/
https://github.com/addyosmani/todomvc
Today's Session "todos"
● Review the relevant cryptography concepts.
● Apply these concepts using JavaScript and
Web technologies.
Why? TodoMVC Uses
Chrome keeps in an SQLite file:
OS X:
Windows:
This Is What I Want
● Enter Password before access to "todos"
● Encrypted "at rest" in
Java script and web cryptography (cf.objective)
Acronymphobia?
AES CA CBC CSRF DES
DSA ECC FIPS HMAC
ISO IV MD5 MITM NIST
OCB OWASP PBKDF2
PKCS PII PKI PRNG RC4
RSA SHA1 SSL TLS XSS
Glossary
Glossary of Key Information Security Terms
(Draft)
http://csrc.nist.gov/publications/drafts/ir-7298-
rev2/nistir7298_r2_draft.pdf
Cryptography
The discipline that embodies principles, means,
and methods for providing information security,
including confidentiality, data integrity, non-
repudiation, and authenticity.
SOURCE: SP 800-21
Cipher, Plaintext and Ciphertext
Cipher - Series of transformations that
converts plaintext to ciphertext using the
Cipher Key.
See Also: Inverse Cipher
SOURCE: FIPS 197
Cryptographic Key
A parameter used in conjunction with a cryptographic
algorithm that determines
● the transformation of plaintext data into ciphertext data,
● the transformation of ciphertext data into plaintext data,
● a digital signature computed from data,
● ...
SOURCE: FIPS 140-2
Secure Socket Layer (SSL)
A protocol used for protecting private
information during transmission via the Internet.
By convention, URLs that require an SSL
connection start with https: instead of http:
SOURCE: CNSSI-4009
TLS (not SSL)
Web Standard?
W3C Web Cryptography API
This specification describes a JavaScript API
for performing basic cryptographic operations in
web applications, such as hashing, signature
generation and verification, and encryption and
decryption.
http://www.w3.org/TR/WebCryptoAPI/
WebCryptoAPI Use Cases
● Multi-factor Authentication
● Protected Document Exchange
● Cloud Storage
● Document Signing
● Data Integrity Protection
● Secure Messaging
● Javascript Object Signing and Encryption
(JOSE)
http://www.w3.org/TR/WebCryptoAPI/#use-cases
Perfect!
Web Cryptography Working Group
Key Dates
○ April 2012: Group Formation
○ March 2014: Last Call Working Draft
Comments are welcome through 20 May 2014.
○ 2015: Expected Recommendation
http://www.w3.org/2012/webcrypto/Overview.html
2015? Other Options?
Participate in Mailing List?
Require Internet Explorer 11?
● Internet Explorer 11 added support for the
Web Cryptography API
○ Included in Windows 8.1 or as update to Windows 7
or Windows Server 2008
○ However, based on spec before CryptoOperation
changed to support TC39/DOM Promises
Use Case: Netflix
HTML5 Video in IE 11 on Windows 8.1
Wednesday, June 26, 2013
"Microsoft implemented the Web Cryptography
API (WebCrypto) in Internet Explorer, which
allows us to encrypt and decrypt
communication between our JavaScript
application and the Netflix servers."
http://techblog.netflix.com/2013/06/html5-video-in-ie-11-on-windows-81.html
Contribute to Chromium?
● Chromium is the open-source project behind
Google Chrome.
○ Issue 245025: Implement WebCrypto in blink
Chromium Crypto Status
● Runtime Enabled Features
http://www.chromium.org/blink/runtime-enabled-features
chrome://flags/#enable-experimental-web-platform-features
Contribute to Firefox?
● Bug 865789 - (web-crypto) Implement W3C
Web Crypto API
PolyCrypt: A WebCrypto Polyfill
"a pure JavaScript implementation of the
WebCrypto API that people can use to get a
feel for how they can use the API in practice"
http://polycrypt.net/
https://github.com/polycrypt/polycrypt
Google: javascript cryptography
Stanford Javascript Crypto Library
● SJCL is "a secure, powerful, fast, small,
easy-to-use, cross-browser library for
cryptography in Javascript"
● 2009 whitepaper focused on k-weight,
performance and cryptographic randomness
○ "In Internet Explorer 8 our code is 11 times faster than the fastest
current implementation."
http://crypto.stanford.edu/sjcl/
CryptoJS
CryptoJS is a growing collection of standard
and secure cryptographic algorithms
implemented in JavaScript using best practices
and patterns.
● Hashers
● HMAC
● PBKDF2
● Ciphers
● Encoders
https://code.google.com/p/crypto-js/
Node.js Crypto
● Use to access this
module.
● The crypto module requires OpenSSL to be
available on the underlying platform.
● It also offers a set of wrappers for
OpenSSL's hash, hmac, cipher, decipher,
sign and verify methods.
http://nodejs.org/api/crypto.html
OpenSSL
The OpenSSL Project is a collaborative effort to
develop a robust, commercial-grade, full-
featured, and Open Source toolkit
implementing the Secure Sockets Layer (SSL
v2/v3) and Transport Layer Security (TLS v1)
protocols as well as a full-strength general
purpose cryptography library.
http://www.openssl.org/
Javascript Cryptography Considered
Harmful (circa 2010)
● Opinion on browser Javascript cryptography
○ "no reliable way for any piece of Javascript code to
verify its execution environment"
○ "can't outsource random number generation in a
cryptosystem"
○ "practically no value to doing crypto in Javascript
once you add SSL to the mix"
○ "store the key on that server [and] documents there"
http://www.matasano.com/articles/javascript-cryptography/
● Didn't consider the "offline" user experience
Host-Proof Hosting
● In A Blink
○ Sketch: Locked inside data cloud, key at browser.
● Solution
○ Host sensitive data in encrypted form, so that clients
can only access and manipulate it by providing a
pass-phrase which is never transmitted to the
server.
○ All encryption and decryption takes place inside the
browser itself.
http://ajaxpatterns.org/Host-Proof_Hosting (July 2005)
Web-browser encryption of personal health information [http://www.biomedcentral.com/1472-6947/11/70]
Encryption data flow. A diagram laying out how the encrypted data and the user-supplied passcode are used to decrypt the data.
Morse et al. BMC Medical Informatics and Decision Making 2011 11:70 doi:10.1186/1472-6947-11-70
Host-Proof Hosting "Requirements"
● Secure transport mechanism (HTTPS).
● Trust provider that hosts web application and
serves HTML and JavaScript resources.
● Defend against and accept risk of script
injection (XSS) threat.
○ However, unauthorized access by hackers only
attacks users who access the application while
infected, and not the entire persisted data store.
Kevin’s "Requirement"
● Avoid proving "Schneier's Law"
○ Anyone can invent a security system that he himself
cannot break.
http://www.schneier.com/blog/archives/2011/04/schneiers_law.html
OWASP Top 10 2013
● A1-Injection
● A2-Broken Authentication and Session Management
● A3-Cross-Site Scripting (XSS)
● A4-Insecure Direct Object References
● A5-Security Misconfiguration
● A6-Sensitive Data Exposure
● A7-Missing Function Level Action Control
● A8-Cross-Site Request Forgery (CSRF)
● A9-Using Components with Known Vulnerabilities
● A10-Unvalidated Redirects and Forwards
https://www.owasp.org/index.php/Top_10_2013
OWASP Top 10 Change From 2010
2013-A6: Sensitive Data Exposure
● Merged 2010-A7 – Insecure Cryptographic Storage &
2010-A9 - Insufficient Transport Layer Protection.
● Covers sensitive data protection from the moment
sensitive data is provided by the user, sent to and
stored within the application, and then sent back to the
browser again.
https://www.owasp.org/index.php/Top_10_2013-Release_Notes
A6-Sensitive Data Exposure
Am I Vulnerable To 'Sensitive Data Exposure'?
1. Is any of this data stored in clear text long term,
including backups of this data?
2. …
3. …
4. …
5. …
https://www.owasp.org/index.php/Top_10_2013-A6
Download CryptoJS
Cryptographic Hash Function
A function that maps a bit string of arbitrary
length to a fixed length bit string.
Approved hash functions satisfy the following
properties:
● One-way
● Collision resistant
SOURCE: SP 800-21
SHA-1 Definition
SHA-1 uses a sequence of logical functions, f0
, f1
,…, f79
.
Each function ft
, where 0 ≤ t < 79, operates on three 32-bit
words, x, y, and z, and produces a 32-bit word as output.
The function f(x, y, z) is defined as follows:
SOURCE: FIPS 180-4
Java script and web cryptography (cf.objective)
OpenSSL
OpenSSL
CryptoJS
OpenSSL
CryptoJS
Node.js
Demo
Hash-based Message Authentication
Code (HMAC)
A message authentication code that uses a
cryptographic key in conjunction with a hash
function.
SOURCE: FIPS 201; CNSSI-4009
Symmetric Key
A cryptographic key that is used to perform
both the cryptographic operation and its
inverse, for example to encrypt and decrypt, or
create a message authentication code and to
verify the code.
SOURCE: SP 800-63; CNSSI-4009
Digital Signature
The result of a cryptographic transformation of
data which, when properly implemented,
provides the services of:
1. origin authentication,
2. data integrity, and
3. signer non-repudiation.
SOURCE: FIPS 140-2
require('cookie-signature')
● Node module used by , which is
used by
● Signs the value of a cookie
exports.sign = function(val, secret){
if ('string' != typeof val) throw new TypeError('cookie required');
if ('string' != typeof secret) throw new TypeError('secret required');
return val + '.' + crypto
.createHmac('sha256', secret)
.update(val)
.digest('base64')
.replace(/=+$/, '');
};
https://github.com/visionmedia/node-cookie-signature
This express code
This express code
creates this signed cookie
This express code
creates this signed cookie
which matches our CryptoJS test
This express code
creates this signed cookie
which matches our CryptoJS test
and OpenSSL command line.
Demo
Java script and web cryptography (cf.objective)
Password-Based Key Derivation
Functions (PBKDF)
● The randomness of cryptographic keys is
essential for the security of cryptographic
applications.
SOURCE: SP 800-132
Password-Based Key Derivation
Functions (PBKDF)
● The randomness of cryptographic keys is
essential for the security of cryptographic
applications.
● Most user-chosen passwords have low
entropy and weak randomness properties.
○ shall not be used directly as cryptographic keys
SOURCE: SP 800-132
Password-Based Key Derivation
Functions (PBKDF)
● The randomness of cryptographic keys is
essential for the security of cryptographic
applications.
● Most user-chosen passwords have low
entropy and weak randomness properties.
○ shall not be used directly as cryptographic keys
● KDFs are deterministic algorithms that are
used to derive cryptographic keying material
from a secret value, such as a password.
SOURCE: SP 800-132
PBKDF Specification
Input:
P Password
S Salt
C Iteration count
kLen Length of MK in bits; at most (232
-1) x hLen
Parameter:
PRF HMAC with an approved hash function
hlen Digest size of the hash function
Output:
mk Master key
http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf
Salt
A non-secret value that is used in a
cryptographic process, usually to ensure that
the results of computations for one instance
cannot be reused by an Attacker.
SOURCE: SP 800-63; CNSSI-4009
Demo
TypedArray
ECMAScript [ECMA-262] has traditionally been used in
contexts where there is no access to binary data.
Where binary data has needed to be manipulated, it is
often stored as a String and accessed using charCodeAt(),
or stored as an Array with conversion to and from base64
for transmission.
https://www.khronos.org/registry/typedarray/specs/latest/
Binary Data Structures
● JavaScript
○ "binary" String
● Node.js
○ Buffer
● "HTML5"
○ TypedArray
● CryptoJS
○ CryptoJS.lib.WordArray
● SJCL
○ sjcl.bitArray
Pseudorandom number generator
(PRNG)
An algorithm that produces a sequence of bits
that are uniquely determined from an initial
value called a seed. The output of the PRNG
“appears” to be random.
A cryptographic PRNG has the additional
property that the output is unpredictable, given
that the seed is not known.
SOURCE: CNSSI-4009
Random Data Functions
● JavaScript
○ Math.random()
● Node.js
○ crypto.randomBytes(n)
● WebCryptoAPI
○ window.crypto.getRandomValues(array)
● CryptoJS
○ CryptoJS.lib.WordArray.random(n)
● SJCL
○ sjcl.random.randomWords(n, paranoia)
Node.js crypto.randomBytes()
● Generates cryptographically strong pseudo-
random data.
http://nodejs.org/api/crypto.html
window.crypto.getRandomValues()
If you provide an integer-based ,
the function is going fill the array with
cryptographically random numbers.
https://developer.mozilla.org/en-US/docs/DOM/window.crypto.getRandomValues
http://msdn.microsoft.com/en-us/library/ie/dn302324(v=vs.85).aspx
CryptoJS.lib.WordArray.random(n)
Creates a word array filled with random bytes.
Java script and web cryptography (cf.objective)
AES
The Advanced Encryption Standard specifies a U.S.
government approved cryptographic algorithm that can be
used to protect electronic data.
The AES algorithm is a symmetric block cipher that can
encrypt (encipher) and decrypt (decipher) information.
This standard specifies the Rijndael algorithm, a symmetric
block cipher that can process data blocks of 128 bits, using
cipher keys with lengths of 128, 192, and 256 bits.
SOURCE: FIPS 197
(CC BY 3.0) http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html
Initialization Vector (IV)
A vector used in defining the starting point of an
encryption process within a cryptographic
algorithm.
SOURCE: FIPS 140-2
OpenSSL Encryption Format
Since OpenSSL 0.9.5 (early 2000),
produces output in the following format :
● "Salted__" magic string
● 8 bytes of salt
● encrypted data
To decrypt a file encrypted with 0.9.4 (or
earlier) or other crypto software, use the
command line option.
http://www.mail-archive.com/openssl-users@openssl.org/msg35646.html
Java script and web cryptography (cf.objective)
Java script and web cryptography (cf.objective)
Java script and web cryptography (cf.objective)
OpenSSL EVP_BytesToKey()
Derives a key and IV from a password and salt.
Not compatible with PBKDF2.
http://www.openssl.org/docs/crypto/EVP_BytesToKey.html
OpenSSL Encryption
OpenSSL command line encryption with key
and IV instead of password and salt.
CryptoJS Key and IV
CryptoJS Password and Salt
CryptoJS Password and NoSalt
Node.js Crypto Key and IV
Node.js Crypto Password and NoSalt
Demo
Java script and web cryptography (cf.objective)
Data Flow and Storage
● Salt = initial random
● IV = initial random
● HMAC = SHA256( Salt, Key )
● Ciphertext = AES( todos, Key, IV )
Add Password Entry Field
Set and Confirm Password
On first use, password must be established.
Enter and Validate Password
On subsequent uses, password must be
entered to unlock todos.
An invalid password will shake the password
input field and outline in red.
Password Validation
CSS3 Shake Animation
Demo
Generate Key from Password
Java script and web cryptography (cf.objective)
Encrypt todos
Decrypt todos and Check Integrity
Store Encrypted (Write)
Store Encrypted (Read)
Encrypted in
Java script and web cryptography (cf.objective)
Q & A

More Related Content

What's hot (20)

PDF
Hashgraph as Code
Calvin Cheng
 
PDF
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP
 
PDF
[OPD 2019] Trusted types and the end of DOM XSS
OWASP
 
PDF
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
SecuRing
 
PDF
Continuous Security in Pipelines
Thoughtworks
 
PDF
[OPD 2019] Attacking JWT tokens
OWASP
 
PDF
Identity and Access Management At Mozilla
Michael Van Kleeck
 
PDF
Let's get evil - threat modeling at scale
SecuRing
 
PDF
Network Security and Cryptography.pdf
AdityaKumar1548
 
PDF
Web Security.pdf
AdityaKumar1548
 
PDF
Building & Hacking Modern iOS Apps
SecuRing
 
PPTX
Web security: Securing untrusted web content at browsers
Phú Phùng
 
PPTX
Improving privacy in blockchain using homomorphic encryption
Razi Rais
 
PDF
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
Codemotion
 
PPTX
Build your own Blockchain with the right tool for your application
Anthony Chow
 
PDF
The 2nd Official W3C DID Working Group Meeting (The Netherlands)
SSIMeetup
 
PPTX
Understanding gRPC Authentication Methods
Anthony Chow
 
PDF
Introduction to Web Application Security - Blackhoodie US 2018
Niranjanaa Ragupathy
 
PDF
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
PROIDEA
 
PDF
Dev and Blind - Attacking the weakest Link in IT Security
Mario Heiderich
 
Hashgraph as Code
Calvin Cheng
 
OWASP Poland Day 2018 - Amir Shladovsky - Crypto-mining
OWASP
 
[OPD 2019] Trusted types and the end of DOM XSS
OWASP
 
Outsmarting Smart Contracts - an essential walkthrough a blockchain security ...
SecuRing
 
Continuous Security in Pipelines
Thoughtworks
 
[OPD 2019] Attacking JWT tokens
OWASP
 
Identity and Access Management At Mozilla
Michael Van Kleeck
 
Let's get evil - threat modeling at scale
SecuRing
 
Network Security and Cryptography.pdf
AdityaKumar1548
 
Web Security.pdf
AdityaKumar1548
 
Building & Hacking Modern iOS Apps
SecuRing
 
Web security: Securing untrusted web content at browsers
Phú Phùng
 
Improving privacy in blockchain using homomorphic encryption
Razi Rais
 
Marco Balduzzi - Cyber-crime and attacks in the dark side of the web - Codemo...
Codemotion
 
Build your own Blockchain with the right tool for your application
Anthony Chow
 
The 2nd Official W3C DID Working Group Meeting (The Netherlands)
SSIMeetup
 
Understanding gRPC Authentication Methods
Anthony Chow
 
Introduction to Web Application Security - Blackhoodie US 2018
Niranjanaa Ragupathy
 
CONFidence 2018: Defense-in-depth techniques for modern web applications and ...
PROIDEA
 
Dev and Blind - Attacking the weakest Link in IT Security
Mario Heiderich
 

Similar to Java script and web cryptography (cf.objective) (20)

PDF
Web cryptography javascript
Jose Manuel Ortega Candel
 
PDF
What Every Software Engineer Should Know About Security and Encryption
All Things Open
 
PPTX
Crypto academy
Paul Gillingwater, MBA
 
PPT
PKI_Applications digital certificate.ppt
ubaidullah75790
 
PPT
Public Key Infrastructure and Application_Applications.ppt
lanhuongvernon
 
PPT
Java Crypto
phanleson
 
PPTX
Enterprise Cloud Security - Concepts Mash-up
Dileep Kalidindi
 
PPTX
Cyber Security
amit bezalel
 
PPTX
CompTIASecPLUS-Part6 - UnlimitedEdited.pptx
mohedkhadar60
 
PPTX
501 ch 10 cryptography
Toyeeb Onimole
 
PDF
The SSL Problem and How to Deploy SHA2 Certificates
Gabriella Davis
 
PPTX
Certificates, PKI, and SSL/TLS for infrastructure builders and operators
David Ochel
 
PDF
computer-security-and-cryptography-a-simple-presentation
Alex Punnen
 
PDF
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Krzysztof Kotowicz
 
PDF
Introduction to cryptography for software developers
Intopalo Digital Oy
 
PDF
"Is your browser secure? Breaking cryptography in PKI based systems, opening ...
PROIDEA
 
PPTX
How to do Cryptography right in Android Part One
Arash Ramez
 
PPTX
Public key Cryptography for beginners.pptx
pskoberko
 
PPT
Security via Java
Bahaa Zaid
 
DOCX
Chapter 8Secret and Public KeysChapter 8 OverviewManag.docx
bartholomeocoombs
 
Web cryptography javascript
Jose Manuel Ortega Candel
 
What Every Software Engineer Should Know About Security and Encryption
All Things Open
 
Crypto academy
Paul Gillingwater, MBA
 
PKI_Applications digital certificate.ppt
ubaidullah75790
 
Public Key Infrastructure and Application_Applications.ppt
lanhuongvernon
 
Java Crypto
phanleson
 
Enterprise Cloud Security - Concepts Mash-up
Dileep Kalidindi
 
Cyber Security
amit bezalel
 
CompTIASecPLUS-Part6 - UnlimitedEdited.pptx
mohedkhadar60
 
501 ch 10 cryptography
Toyeeb Onimole
 
The SSL Problem and How to Deploy SHA2 Certificates
Gabriella Davis
 
Certificates, PKI, and SSL/TLS for infrastructure builders and operators
David Ochel
 
computer-security-and-cryptography-a-simple-presentation
Alex Punnen
 
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Krzysztof Kotowicz
 
Introduction to cryptography for software developers
Intopalo Digital Oy
 
"Is your browser secure? Breaking cryptography in PKI based systems, opening ...
PROIDEA
 
How to do Cryptography right in Android Part One
Arash Ramez
 
Public key Cryptography for beginners.pptx
pskoberko
 
Security via Java
Bahaa Zaid
 
Chapter 8Secret and Public KeysChapter 8 OverviewManag.docx
bartholomeocoombs
 
Ad

More from ColdFusionConference (20)

PDF
Api manager preconference
ColdFusionConference
 
PDF
Cf ppt vsr
ColdFusionConference
 
PDF
Building better SQL Server Databases
ColdFusionConference
 
PDF
API Economy, Realizing the Business Value of APIs
ColdFusionConference
 
PDF
Don't just pdf, Smart PDF
ColdFusionConference
 
PDF
Crafting ColdFusion Applications like an Architect
ColdFusionConference
 
PDF
Security And Access Control For APIS using CF API Manager
ColdFusionConference
 
PDF
Monetizing Business Models: ColdFusion and APIS
ColdFusionConference
 
PDF
Become a Security Rockstar with ColdFusion 2016
ColdFusionConference
 
PDF
ColdFusion in Transit action
ColdFusionConference
 
PDF
Developer Insights for Application Upgrade to ColdFusion 2016
ColdFusionConference
 
PDF
Where is cold fusion headed
ColdFusionConference
 
PDF
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusionConference
 
PDF
Instant ColdFusion with Vagrant
ColdFusionConference
 
PPT
Restful services with ColdFusion
ColdFusionConference
 
PDF
Super Fast Application development with Mura CMS
ColdFusionConference
 
PDF
Build your own secure and real-time dashboard for mobile and web
ColdFusionConference
 
PDF
Why Everyone else writes bad code
ColdFusionConference
 
PDF
Securing applications
ColdFusionConference
 
PDF
Testing automaton
ColdFusionConference
 
Api manager preconference
ColdFusionConference
 
Building better SQL Server Databases
ColdFusionConference
 
API Economy, Realizing the Business Value of APIs
ColdFusionConference
 
Don't just pdf, Smart PDF
ColdFusionConference
 
Crafting ColdFusion Applications like an Architect
ColdFusionConference
 
Security And Access Control For APIS using CF API Manager
ColdFusionConference
 
Monetizing Business Models: ColdFusion and APIS
ColdFusionConference
 
Become a Security Rockstar with ColdFusion 2016
ColdFusionConference
 
ColdFusion in Transit action
ColdFusionConference
 
Developer Insights for Application Upgrade to ColdFusion 2016
ColdFusionConference
 
Where is cold fusion headed
ColdFusionConference
 
ColdFusion Keynote: Building the Agile Web Since 1995
ColdFusionConference
 
Instant ColdFusion with Vagrant
ColdFusionConference
 
Restful services with ColdFusion
ColdFusionConference
 
Super Fast Application development with Mura CMS
ColdFusionConference
 
Build your own secure and real-time dashboard for mobile and web
ColdFusionConference
 
Why Everyone else writes bad code
ColdFusionConference
 
Securing applications
ColdFusionConference
 
Testing automaton
ColdFusionConference
 
Ad

Recently uploaded (20)

PPTX
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
PPTX
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
PPTX
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PDF
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PPTX
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
PDF
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
PPTX
Tally software_Introduction_Presentation
AditiBansal54083
 
PPTX
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
PDF
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
PDF
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
PPTX
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Change Common Properties in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
MailsDaddy Outlook OST to PST converter.pptx
abhishekdutt366
 
Agentic Automation Journey Series Day 2 – Prompt Engineering for UiPath Agents
klpathrudu
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Digger Solo: Semantic search and maps for your local files
seanpedersen96
 
Fundamentals_of_Microservices_Architecture.pptx
MuhammadUzair504018
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Odoo CRM vs Zoho CRM: Honest Comparison 2025
Odiware Technologies Private Limited
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Transforming Mining & Engineering Operations with Odoo ERP | Streamline Proje...
SatishKumar2651
 
Online Queue Management System for Public Service Offices in Nepal [Focused i...
Rishab Acharya
 
Tally software_Introduction_Presentation
AditiBansal54083
 
Tally_Basic_Operations_Presentation.pptx
AditiBansal54083
 
Alarm in Android-Scheduling Timed Tasks Using AlarmManager in Android.pdf
Nabin Dhakal
 
Open Chain Q2 Steering Committee Meeting - 2025-06-25
Shane Coughlan
 
How Cloud Computing is Reinventing Financial Services
Isla Pandora
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
ChiSquare Procedure in IBM SPSS Statistics Version 31.pptx
Version 1 Analytics
 

Java script and web cryptography (cf.objective)

  • 1. Developer's Guide to JavaScript and Web Cryptography Kevin Hakanson
  • 3. Abstract The increasing capabilities and performance of the web platform allow for more feature-rich user experiences. How can JavaScript based applications utilize information security and cryptography principles? This session will explore the current state of JavaScript and Web Cryptography. We will review some basic concepts and definitions, discuss the role of TLS/SSL, show some working examples that apply cryptography to real-world use cases and take a peek at the upcoming W3C WebCryptoAPI. Code samples will use CryptoJS in the browser and the Node.js Crypto module on the server. An extended example will secure the popular TodoMVC project using PBKDF2 for key generation, HMAC for data integrity and AES for encryption.
  • 4. (Less) Abstract The increasing capabilities and performance of the web platformallow for more feature- rich user experiences. How can JavaScript based applications utilize information security and cryptography principles? This session will explore the current state of JavaScript and Web Cryptography. We will review some basic concepts and definitions, discuss the role of TLS/SSL, show some working examples that apply cryptography to real-world use cases and take a peek at the upcoming W3C WebCryptoAPI. Code samples will use CryptoJS in the browserand the Node.js Crypto module on the server. An extended example will secure the popular TodoMVCproject using PBKDF2 for key generation, HMAC for data integrity and AES for encryption. + :) & ?s
  • 6. Project which offers the same Todo application implemented using MV* concepts in most of the popular JavaScript MV* frameworks of today. http://todomvc.com/ https://github.com/addyosmani/todomvc
  • 7. Today's Session "todos" ● Review the relevant cryptography concepts. ● Apply these concepts using JavaScript and Web technologies.
  • 8. Why? TodoMVC Uses Chrome keeps in an SQLite file: OS X: Windows:
  • 9. This Is What I Want ● Enter Password before access to "todos" ● Encrypted "at rest" in
  • 11. Acronymphobia? AES CA CBC CSRF DES DSA ECC FIPS HMAC ISO IV MD5 MITM NIST OCB OWASP PBKDF2 PKCS PII PKI PRNG RC4 RSA SHA1 SSL TLS XSS
  • 12. Glossary Glossary of Key Information Security Terms (Draft) http://csrc.nist.gov/publications/drafts/ir-7298- rev2/nistir7298_r2_draft.pdf
  • 13. Cryptography The discipline that embodies principles, means, and methods for providing information security, including confidentiality, data integrity, non- repudiation, and authenticity. SOURCE: SP 800-21
  • 14. Cipher, Plaintext and Ciphertext Cipher - Series of transformations that converts plaintext to ciphertext using the Cipher Key. See Also: Inverse Cipher SOURCE: FIPS 197
  • 15. Cryptographic Key A parameter used in conjunction with a cryptographic algorithm that determines ● the transformation of plaintext data into ciphertext data, ● the transformation of ciphertext data into plaintext data, ● a digital signature computed from data, ● ... SOURCE: FIPS 140-2
  • 16. Secure Socket Layer (SSL) A protocol used for protecting private information during transmission via the Internet. By convention, URLs that require an SSL connection start with https: instead of http: SOURCE: CNSSI-4009
  • 19. W3C Web Cryptography API This specification describes a JavaScript API for performing basic cryptographic operations in web applications, such as hashing, signature generation and verification, and encryption and decryption. http://www.w3.org/TR/WebCryptoAPI/
  • 20. WebCryptoAPI Use Cases ● Multi-factor Authentication ● Protected Document Exchange ● Cloud Storage ● Document Signing ● Data Integrity Protection ● Secure Messaging ● Javascript Object Signing and Encryption (JOSE) http://www.w3.org/TR/WebCryptoAPI/#use-cases
  • 22. Web Cryptography Working Group Key Dates ○ April 2012: Group Formation ○ March 2014: Last Call Working Draft Comments are welcome through 20 May 2014. ○ 2015: Expected Recommendation http://www.w3.org/2012/webcrypto/Overview.html
  • 25. Require Internet Explorer 11? ● Internet Explorer 11 added support for the Web Cryptography API ○ Included in Windows 8.1 or as update to Windows 7 or Windows Server 2008 ○ However, based on spec before CryptoOperation changed to support TC39/DOM Promises
  • 26. Use Case: Netflix HTML5 Video in IE 11 on Windows 8.1 Wednesday, June 26, 2013 "Microsoft implemented the Web Cryptography API (WebCrypto) in Internet Explorer, which allows us to encrypt and decrypt communication between our JavaScript application and the Netflix servers." http://techblog.netflix.com/2013/06/html5-video-in-ie-11-on-windows-81.html
  • 27. Contribute to Chromium? ● Chromium is the open-source project behind Google Chrome. ○ Issue 245025: Implement WebCrypto in blink
  • 28. Chromium Crypto Status ● Runtime Enabled Features http://www.chromium.org/blink/runtime-enabled-features chrome://flags/#enable-experimental-web-platform-features
  • 29. Contribute to Firefox? ● Bug 865789 - (web-crypto) Implement W3C Web Crypto API
  • 30. PolyCrypt: A WebCrypto Polyfill "a pure JavaScript implementation of the WebCrypto API that people can use to get a feel for how they can use the API in practice" http://polycrypt.net/ https://github.com/polycrypt/polycrypt
  • 32. Stanford Javascript Crypto Library ● SJCL is "a secure, powerful, fast, small, easy-to-use, cross-browser library for cryptography in Javascript" ● 2009 whitepaper focused on k-weight, performance and cryptographic randomness ○ "In Internet Explorer 8 our code is 11 times faster than the fastest current implementation." http://crypto.stanford.edu/sjcl/
  • 33. CryptoJS CryptoJS is a growing collection of standard and secure cryptographic algorithms implemented in JavaScript using best practices and patterns. ● Hashers ● HMAC ● PBKDF2 ● Ciphers ● Encoders https://code.google.com/p/crypto-js/
  • 34. Node.js Crypto ● Use to access this module. ● The crypto module requires OpenSSL to be available on the underlying platform. ● It also offers a set of wrappers for OpenSSL's hash, hmac, cipher, decipher, sign and verify methods. http://nodejs.org/api/crypto.html
  • 35. OpenSSL The OpenSSL Project is a collaborative effort to develop a robust, commercial-grade, full- featured, and Open Source toolkit implementing the Secure Sockets Layer (SSL v2/v3) and Transport Layer Security (TLS v1) protocols as well as a full-strength general purpose cryptography library. http://www.openssl.org/
  • 36. Javascript Cryptography Considered Harmful (circa 2010) ● Opinion on browser Javascript cryptography ○ "no reliable way for any piece of Javascript code to verify its execution environment" ○ "can't outsource random number generation in a cryptosystem" ○ "practically no value to doing crypto in Javascript once you add SSL to the mix" ○ "store the key on that server [and] documents there" http://www.matasano.com/articles/javascript-cryptography/ ● Didn't consider the "offline" user experience
  • 37. Host-Proof Hosting ● In A Blink ○ Sketch: Locked inside data cloud, key at browser. ● Solution ○ Host sensitive data in encrypted form, so that clients can only access and manipulate it by providing a pass-phrase which is never transmitted to the server. ○ All encryption and decryption takes place inside the browser itself. http://ajaxpatterns.org/Host-Proof_Hosting (July 2005)
  • 38. Web-browser encryption of personal health information [http://www.biomedcentral.com/1472-6947/11/70] Encryption data flow. A diagram laying out how the encrypted data and the user-supplied passcode are used to decrypt the data. Morse et al. BMC Medical Informatics and Decision Making 2011 11:70 doi:10.1186/1472-6947-11-70
  • 39. Host-Proof Hosting "Requirements" ● Secure transport mechanism (HTTPS). ● Trust provider that hosts web application and serves HTML and JavaScript resources. ● Defend against and accept risk of script injection (XSS) threat. ○ However, unauthorized access by hackers only attacks users who access the application while infected, and not the entire persisted data store.
  • 40. Kevin’s "Requirement" ● Avoid proving "Schneier's Law" ○ Anyone can invent a security system that he himself cannot break. http://www.schneier.com/blog/archives/2011/04/schneiers_law.html
  • 41. OWASP Top 10 2013 ● A1-Injection ● A2-Broken Authentication and Session Management ● A3-Cross-Site Scripting (XSS) ● A4-Insecure Direct Object References ● A5-Security Misconfiguration ● A6-Sensitive Data Exposure ● A7-Missing Function Level Action Control ● A8-Cross-Site Request Forgery (CSRF) ● A9-Using Components with Known Vulnerabilities ● A10-Unvalidated Redirects and Forwards https://www.owasp.org/index.php/Top_10_2013
  • 42. OWASP Top 10 Change From 2010 2013-A6: Sensitive Data Exposure ● Merged 2010-A7 – Insecure Cryptographic Storage & 2010-A9 - Insufficient Transport Layer Protection. ● Covers sensitive data protection from the moment sensitive data is provided by the user, sent to and stored within the application, and then sent back to the browser again. https://www.owasp.org/index.php/Top_10_2013-Release_Notes
  • 43. A6-Sensitive Data Exposure Am I Vulnerable To 'Sensitive Data Exposure'? 1. Is any of this data stored in clear text long term, including backups of this data? 2. … 3. … 4. … 5. … https://www.owasp.org/index.php/Top_10_2013-A6
  • 45. Cryptographic Hash Function A function that maps a bit string of arbitrary length to a fixed length bit string. Approved hash functions satisfy the following properties: ● One-way ● Collision resistant SOURCE: SP 800-21
  • 46. SHA-1 Definition SHA-1 uses a sequence of logical functions, f0 , f1 ,…, f79 . Each function ft , where 0 ≤ t < 79, operates on three 32-bit words, x, y, and z, and produces a 32-bit word as output. The function f(x, y, z) is defined as follows: SOURCE: FIPS 180-4
  • 51. Demo
  • 52. Hash-based Message Authentication Code (HMAC) A message authentication code that uses a cryptographic key in conjunction with a hash function. SOURCE: FIPS 201; CNSSI-4009
  • 53. Symmetric Key A cryptographic key that is used to perform both the cryptographic operation and its inverse, for example to encrypt and decrypt, or create a message authentication code and to verify the code. SOURCE: SP 800-63; CNSSI-4009
  • 54. Digital Signature The result of a cryptographic transformation of data which, when properly implemented, provides the services of: 1. origin authentication, 2. data integrity, and 3. signer non-repudiation. SOURCE: FIPS 140-2
  • 55. require('cookie-signature') ● Node module used by , which is used by ● Signs the value of a cookie exports.sign = function(val, secret){ if ('string' != typeof val) throw new TypeError('cookie required'); if ('string' != typeof secret) throw new TypeError('secret required'); return val + '.' + crypto .createHmac('sha256', secret) .update(val) .digest('base64') .replace(/=+$/, ''); }; https://github.com/visionmedia/node-cookie-signature
  • 57. This express code creates this signed cookie
  • 58. This express code creates this signed cookie which matches our CryptoJS test
  • 59. This express code creates this signed cookie which matches our CryptoJS test and OpenSSL command line.
  • 60. Demo
  • 62. Password-Based Key Derivation Functions (PBKDF) ● The randomness of cryptographic keys is essential for the security of cryptographic applications. SOURCE: SP 800-132
  • 63. Password-Based Key Derivation Functions (PBKDF) ● The randomness of cryptographic keys is essential for the security of cryptographic applications. ● Most user-chosen passwords have low entropy and weak randomness properties. ○ shall not be used directly as cryptographic keys SOURCE: SP 800-132
  • 64. Password-Based Key Derivation Functions (PBKDF) ● The randomness of cryptographic keys is essential for the security of cryptographic applications. ● Most user-chosen passwords have low entropy and weak randomness properties. ○ shall not be used directly as cryptographic keys ● KDFs are deterministic algorithms that are used to derive cryptographic keying material from a secret value, such as a password. SOURCE: SP 800-132
  • 65. PBKDF Specification Input: P Password S Salt C Iteration count kLen Length of MK in bits; at most (232 -1) x hLen Parameter: PRF HMAC with an approved hash function hlen Digest size of the hash function Output: mk Master key http://csrc.nist.gov/publications/nistpubs/800-132/nist-sp800-132.pdf
  • 66. Salt A non-secret value that is used in a cryptographic process, usually to ensure that the results of computations for one instance cannot be reused by an Attacker. SOURCE: SP 800-63; CNSSI-4009
  • 67. Demo
  • 68. TypedArray ECMAScript [ECMA-262] has traditionally been used in contexts where there is no access to binary data. Where binary data has needed to be manipulated, it is often stored as a String and accessed using charCodeAt(), or stored as an Array with conversion to and from base64 for transmission. https://www.khronos.org/registry/typedarray/specs/latest/
  • 69. Binary Data Structures ● JavaScript ○ "binary" String ● Node.js ○ Buffer ● "HTML5" ○ TypedArray ● CryptoJS ○ CryptoJS.lib.WordArray ● SJCL ○ sjcl.bitArray
  • 70. Pseudorandom number generator (PRNG) An algorithm that produces a sequence of bits that are uniquely determined from an initial value called a seed. The output of the PRNG “appears” to be random. A cryptographic PRNG has the additional property that the output is unpredictable, given that the seed is not known. SOURCE: CNSSI-4009
  • 71. Random Data Functions ● JavaScript ○ Math.random() ● Node.js ○ crypto.randomBytes(n) ● WebCryptoAPI ○ window.crypto.getRandomValues(array) ● CryptoJS ○ CryptoJS.lib.WordArray.random(n) ● SJCL ○ sjcl.random.randomWords(n, paranoia)
  • 72. Node.js crypto.randomBytes() ● Generates cryptographically strong pseudo- random data. http://nodejs.org/api/crypto.html
  • 73. window.crypto.getRandomValues() If you provide an integer-based , the function is going fill the array with cryptographically random numbers. https://developer.mozilla.org/en-US/docs/DOM/window.crypto.getRandomValues http://msdn.microsoft.com/en-us/library/ie/dn302324(v=vs.85).aspx
  • 74. CryptoJS.lib.WordArray.random(n) Creates a word array filled with random bytes.
  • 76. AES The Advanced Encryption Standard specifies a U.S. government approved cryptographic algorithm that can be used to protect electronic data. The AES algorithm is a symmetric block cipher that can encrypt (encipher) and decrypt (decipher) information. This standard specifies the Rijndael algorithm, a symmetric block cipher that can process data blocks of 128 bits, using cipher keys with lengths of 128, 192, and 256 bits. SOURCE: FIPS 197
  • 77. (CC BY 3.0) http://www.moserware.com/2009/09/stick-figure-guide-to-advanced.html
  • 78. Initialization Vector (IV) A vector used in defining the starting point of an encryption process within a cryptographic algorithm. SOURCE: FIPS 140-2
  • 79. OpenSSL Encryption Format Since OpenSSL 0.9.5 (early 2000), produces output in the following format : ● "Salted__" magic string ● 8 bytes of salt ● encrypted data To decrypt a file encrypted with 0.9.4 (or earlier) or other crypto software, use the command line option. http://www.mail-archive.com/[email protected]/msg35646.html
  • 83. OpenSSL EVP_BytesToKey() Derives a key and IV from a password and salt. Not compatible with PBKDF2. http://www.openssl.org/docs/crypto/EVP_BytesToKey.html
  • 84. OpenSSL Encryption OpenSSL command line encryption with key and IV instead of password and salt.
  • 90. Demo
  • 92. Data Flow and Storage ● Salt = initial random ● IV = initial random ● HMAC = SHA256( Salt, Key ) ● Ciphertext = AES( todos, Key, IV )
  • 94. Set and Confirm Password On first use, password must be established.
  • 95. Enter and Validate Password On subsequent uses, password must be entered to unlock todos. An invalid password will shake the password input field and outline in red.
  • 98. Demo
  • 99. Generate Key from Password
  • 102. Decrypt todos and Check Integrity
  • 107. Q & A