SlideShare a Scribd company logo
1 of 35
Download to read offline
Node.js Authentication
and Data Security!
Jonathan LeBlanc !
Twitter: @jcleblanc !
Book: http://bit.ly/iddatasecurity!
Release Date:!
August 2016!
!
Book Details:!
http://bit.ly/iddatasecurity!
Identity & Data Security Book!
Security is Hard!
1: 123456 !
2: password !
3: 12345678 !
4: qwerty !
5: 12345 !
6: 123456789!
7: football!
8: 1234!
9: 1234567!
Top 25 Passwords of 2015!
10: baseball!
11: welcome!
12: 1234567890!
13: abc123!
14: 111111!
15: 1qaz2wsx!
16: dragon!
17: master!
18: monkey!
19: letmein!
20: login!
21: princess!
22: qwertyuiop!
23: solo!
24: passw0rd!
25: starwars!
Protecting Identity!
Password Attack Vectors!
Brute Force Attacks!
Calculate all key variations within a given length, then
trying each one until the password is guessed. !
Protect via: Key stretching, CAPTCHA, 2FA!
!
Dictionary Attacks!
Use a list of predetermined words/phrase to guess password.!
Protect via: Salting!
!
Rainbow Tables!
Use precalculated password hashes to break encryption.!
Protect via: Salting !
Protecting Against Password Attacks!
Salting and Peppering!
//hashing identical messages with no salt!
hash('mechagodzilla') = !
162e0a91026a28f1f2afa11099d1fcbdd9f2e351095ebb196c90e10290ef1227!
hash('mechagodzilla') = !
162e0a91026a28f1f2afa11099d1fcbdd9f2e351095ebb196c90e10290ef1227!
!
//hashing identical messages with random salt!
hash('mechagodzilla' + '458cf2979ef27397db67077775225334') = !
f3499a916612e285612b32702114751f557a70606c32b54b92de55153d40d3b6!
hash('mechagodzilla' + 'ef5b72eff781b09a0784438af742dd6e') = !
7e29c5c48f44755598dec3549155ad66f1af4671091353be4c4d7694d71dc866!
hash('mechagodzilla' + 'cc989b105a1c6a5f0fb460e29dd272f3') = !
6dedd3dbb0639e6e00ca0bf6272c141fb741e24925cb7548491479a1df2c215e!
Hashing with and without salts!
Storing Salts!
Store alongside the hash!
!
Salt Reuse!
Salts should be be unique per password!
!
Salt Length!
Same size as hash? 64 bits? 128 bits?!
Considerations when using Salts!
bcrypt!
Designed for password security, based on the blowfish
cipher, CPU & RAM intensive.!
!
PBKDF2!
Comes from RSA laboratories, performs the HMAC (hash +
key) over a specific number of iterations.!
!
scrypt!
Designed to make it costly to perform large-scale
hardware attacks by requiring large amounts of memory!
Password Encryption Algorithms!
!
var bcrypt = require('bcrypt');!
!
app.post("/register", function(req, res){!
//capture user login information!
var username = req.body.username;!
var password = req.body.password;!
!
//generate salt, then hash!
bcrypt.genSalt(10, function(err, salt) {!
bcrypt.hash(password, salt, function(err, key) {!
console.log('key: ' + key.toString('hex'));!
console.log('salt: ' + salt.toString('hex'));!
});!
});!
});!
!
Hashing with bcrypt!
!
var bcrypt = require('bcrypt');!
!
app.post("/login", function(req, res){!
//capture user login information!
var username = req.body.username;!
var password = req.body.password;!
!
//fetch user record from database !
//required info: stored hash!
!
//compare password from login to stored user hash!
bcrypt.compare(password, hash, function(err, res){!
//returns true or false!
});!
});!
!
Login Hash Comparison with bcrypt!
!
var crypto = require('crypto');!
!
app.post("/register", function(req, res){!
//capture user login information!
var username = req.body.username;!
var password = req.body.password;!
!
//generate salt, then hash!
crypto.randomBytes(32, function(ex, salt){!
crypto.pbkdf2(password, salt, 4096, 512, 'sha256', function(err, key){!
if (err) throw err;!
//store username, hashed password, and salt in your database!
});!
});!
});!
!
Hashing with PBKDF2!
!
var crypto = require('crypto');!
!
app.post("/login", function(req, res){!
//capture user login information!
var username = req.body.username;!
var password = req.body.password;!
!
var dbsalt = 'USER RECORD SALT FROM YOUR DATABASE';!
var dbhash = 'USER RECORD KEY FROM YOUR DATABASE';!
!
//generate hash with login attempt, then compare to stored user hash!
crypto.pbkdf2(password, dbsalt, 4096, 512, 'sha256', function(err, comparehash){!
if (err) throw err;!
if (dbhash.toString('hex') === comparehash.toString('hex')){ !
//passwords match!
} else { !
//passwords don't match!
}!
});!
});!
!
Login Hash Comparison with PBKDF2!
Refreshing Hashes!
Protecting Data!
Ideal Scenario: SSL/TLS!
Domain Validation (DV)!
Certificate authority (CA) validates domain
access only!
Certificate Types!
Organization
Validation (OV)!
!
CA validates DV and
basic organization
information!
Certificate Types!
Extended Validation (EV)!
CA validates DV, OV, and legal existance of
the organization!
Certificate Types!
//generate private key and self-signed certificate valid for 1 year!
openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out
server.crt!
Generate your self-signed certificate and private key!
//package requirements!
var fs = require('fs'),!
https = require('https'),!
querystring = require('querystring'),!
bodyParser = require('body-parser')!
app = require('express')();!
!
//support JSON & URL encoded bodies!
app.use(bodyParser.json()); !
app.use(bodyParser.urlencoded({ !
extended: true!
})); !
Setting up Express server for HTTPS traffic!
//handle all POST requests!
app.post('/', function (req, res){!
var message = req.body;!
res.send('Message received:' + querystring.stringify(message));!
});!
!
//set certificate options!
var options = {!
key: fs.readFileSync('server.key'),!
cert: fs.readFileSync('server.crt'),!
passphrase: 'YOUR KEY PASSWORD' !
};!
!
//create server with certificate options!
https.createServer(options, app).listen(3000, function () {!
console.log('Server started: Listening on port 3000');!
});!
Setting up Express server for HTTPS traffic!
Synchronous Cryptography!
Single User Environment!
Encryption (ECB, CBC, OFB, CFB, CTR)!
Data privacy and confidentiality mode. Attacker
cannot obtain info on the plaintext data.!
!
Authentication(CMAC)!
Data authenticity mode. Receiver can validate
whether cleartext came from intended sender.!
!
Authenticated Encryption (CCM, GCM, KW/KWP/TKW)!
Includes both data privacy and authenticity.!
Modes of Operation!
var crypto = require('crypto');!
!
var text = "Encryption Testing AES";!
var key = crypto.randomBytes(32); //256 bit shared secret!
var iv = crypto.randomBytes(16); //initialization vector - 16 bytes!
var algorithm = 'aes-256-ctr'; //cypher and mode of operation!
!
//encrypt!
var cipher = crypto.createCipher(algorithm, key, iv);!
var encrypted = cipher.update(text, 'utf8', 'hex');!
encrypted += cipher.final('hex');!
console.log("Encrypted: " + encrypted);!
Configuring and encrypting message!
//----!
// data sent to server: ciphertext (encrypted var)!
// data known by server: key!
//----!
!
//cypher and mode of operation!
var algorithm = 'aes-256-gcm'; !
!
//decrypt!
var decipher = crypto.createDecipher(algorithm, key, iv);!
var decrypted = decipher.update(encrypted, 'hex', 'utf8');!
decrypted += decipher.final('utf8');!
console.log("Decrypted: " + decrypted);!
Decrypting ciphertext!
Security Fundamentals Wrapup!
Thank You!!
!
Slides: http://slideshare.net/jcleblanc!
Jonathan LeBlanc !
Twitter: @jcleblanc !
Book: http://bit.ly/iddatasecurity!

More Related Content

What's hot

WordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal MeetupWordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal Meetup
Veselin Nikolov
 
Craig Brown speaks on ElasticSearch
Craig Brown speaks on ElasticSearchCraig Brown speaks on ElasticSearch
Craig Brown speaks on ElasticSearch
imarcticblue
 

What's hot (20)

Couchdb w Ruby'm
Couchdb w Ruby'mCouchdb w Ruby'm
Couchdb w Ruby'm
 
Talk NullByteCon 2015
Talk NullByteCon 2015Talk NullByteCon 2015
Talk NullByteCon 2015
 
Redis
RedisRedis
Redis
 
Getting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot FrameworkGetting Started with Microsoft Bot Framework
Getting Started with Microsoft Bot Framework
 
Word Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with TraceryWord Play in the Digital Age: Building Text Bots with Tracery
Word Play in the Digital Age: Building Text Bots with Tracery
 
Automated Testing
Automated TestingAutomated Testing
Automated Testing
 
MongoDB shell games: Here be dragons .. and JavaScript!
MongoDB shell games: Here be dragons .. and JavaScript!MongoDB shell games: Here be dragons .. and JavaScript!
MongoDB shell games: Here be dragons .. and JavaScript!
 
Cool usage of Encoding and Decoding a URI in Javascript
Cool usage of Encoding and Decoding a URI in JavascriptCool usage of Encoding and Decoding a URI in Javascript
Cool usage of Encoding and Decoding a URI in Javascript
 
DEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them allDEF CON 23 - Phil Polstra - one device to pwn them all
DEF CON 23 - Phil Polstra - one device to pwn them all
 
CGI.pm - 3ло?!
CGI.pm - 3ло?!CGI.pm - 3ло?!
CGI.pm - 3ло?!
 
Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)Keep It Simple Security (Symfony cafe 28-01-2016)
Keep It Simple Security (Symfony cafe 28-01-2016)
 
NodeJS The edge of Reason - Lille fp#6
NodeJS The edge of Reason - Lille fp#6NodeJS The edge of Reason - Lille fp#6
NodeJS The edge of Reason - Lille fp#6
 
Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)Building Secure User Interfaces With JWTs (JSON Web Tokens)
Building Secure User Interfaces With JWTs (JSON Web Tokens)
 
Human Talks Riot.js
Human Talks Riot.jsHuman Talks Riot.js
Human Talks Riot.js
 
A bug bounty tale: Chrome, stylesheets, cookies, and AES
A bug bounty tale: Chrome, stylesheets, cookies, and AESA bug bounty tale: Chrome, stylesheets, cookies, and AES
A bug bounty tale: Chrome, stylesheets, cookies, and AES
 
WordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal MeetupWordPress Security @ Vienna WordPress + Drupal Meetup
WordPress Security @ Vienna WordPress + Drupal Meetup
 
Forbes MongoNYC 2011
Forbes MongoNYC 2011Forbes MongoNYC 2011
Forbes MongoNYC 2011
 
DevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screenDevLOVE ターミナル勉強会 zsh + screen
DevLOVE ターミナル勉強会 zsh + screen
 
Craig Brown speaks on ElasticSearch
Craig Brown speaks on ElasticSearchCraig Brown speaks on ElasticSearch
Craig Brown speaks on ElasticSearch
 
One Size Fits All
One Size Fits AllOne Size Fits All
One Size Fits All
 

Similar to Node.js Authentication and Data Security

(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
(Web Application Design track) "Liquid Stream Processing across Web Browsers ...(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
icwe2015
 

Similar to Node.js Authentication and Data Security (20)

I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
 
Modern API Security with JSON Web Tokens
Modern API Security with JSON Web TokensModern API Security with JSON Web Tokens
Modern API Security with JSON Web Tokens
 
Penetration Testing with Improved Input Vector Identification
Penetration Testing with Improved Input Vector IdentificationPenetration Testing with Improved Input Vector Identification
Penetration Testing with Improved Input Vector Identification
 
I Don't Care About Security
I Don't Care About Security I Don't Care About Security
I Don't Care About Security
 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
 
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridasFrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
FrontInBahia 2014: 10 dicas de desempenho para apps mobile híbridas
 
Webinar AWS 201 Delivering apps without servers
Webinar AWS 201 Delivering apps without serversWebinar AWS 201 Delivering apps without servers
Webinar AWS 201 Delivering apps without servers
 
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
Biting into the forbidden fruit. Lessons from trusting Javascript crypto.
 
(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
(Web Application Design track) "Liquid Stream Processing across Web Browsers ...(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
(Web Application Design track) "Liquid Stream Processing across Web Browsers ...
 
Roll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and LuaRoll Your Own API Management Platform with nginx and Lua
Roll Your Own API Management Platform with nginx and Lua
 
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
 
I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)I Don't Care About Security (And Neither Should You)
I Don't Care About Security (And Neither Should You)
 
KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!KazooCon 2014 - Introduction to Kazoo APIs!
KazooCon 2014 - Introduction to Kazoo APIs!
 
JavaScript Promise
JavaScript PromiseJavaScript Promise
JavaScript Promise
 
Maximize your Cache for No Cash
Maximize your Cache for No CashMaximize your Cache for No Cash
Maximize your Cache for No Cash
 
Es.next
Es.nextEs.next
Es.next
 
Transforming WebSockets
Transforming WebSocketsTransforming WebSockets
Transforming WebSockets
 
Building a real life application in node js
Building a real life application in node jsBuilding a real life application in node js
Building a real life application in node js
 
Going realtime with Socket.IO
Going realtime with Socket.IOGoing realtime with Socket.IO
Going realtime with Socket.IO
 
Finding Restfulness - Madrid.rb April 2014
Finding Restfulness - Madrid.rb April 2014Finding Restfulness - Madrid.rb April 2014
Finding Restfulness - Madrid.rb April 2014
 

More from Jonathan LeBlanc

More from Jonathan LeBlanc (20)

JavaScript App Security: Auth and Identity on the Client
JavaScript App Security: Auth and Identity on the ClientJavaScript App Security: Auth and Identity on the Client
JavaScript App Security: Auth and Identity on the Client
 
Improving Developer Onboarding Through Intelligent Data Insights
Improving Developer Onboarding Through Intelligent Data InsightsImproving Developer Onboarding Through Intelligent Data Insights
Improving Developer Onboarding Through Intelligent Data Insights
 
Better Data with Machine Learning and Serverless
Better Data with Machine Learning and ServerlessBetter Data with Machine Learning and Serverless
Better Data with Machine Learning and Serverless
 
Best Practices for Application Development with Box
Best Practices for Application Development with BoxBest Practices for Application Development with Box
Best Practices for Application Development with Box
 
Box Platform Overview
Box Platform OverviewBox Platform Overview
Box Platform Overview
 
Box Platform Developer Workshop
Box Platform Developer WorkshopBox Platform Developer Workshop
Box Platform Developer Workshop
 
Modern Cloud Data Security Practices
Modern Cloud Data Security PracticesModern Cloud Data Security Practices
Modern Cloud Data Security Practices
 
Box Authentication Types
Box Authentication TypesBox Authentication Types
Box Authentication Types
 
Understanding Box UI Elements
Understanding Box UI ElementsUnderstanding Box UI Elements
Understanding Box UI Elements
 
Understanding Box applications, tokens, and scoping
Understanding Box applications, tokens, and scopingUnderstanding Box applications, tokens, and scoping
Understanding Box applications, tokens, and scoping
 
The Future of Online Money: Creating Secure Payments Globally
The Future of Online Money: Creating Secure Payments GloballyThe Future of Online Money: Creating Secure Payments Globally
The Future of Online Money: Creating Secure Payments Globally
 
Creating an In-Aisle Purchasing System from Scratch
Creating an In-Aisle Purchasing System from ScratchCreating an In-Aisle Purchasing System from Scratch
Creating an In-Aisle Purchasing System from Scratch
 
Protecting the Future of Mobile Payments
Protecting the Future of Mobile PaymentsProtecting the Future of Mobile Payments
Protecting the Future of Mobile Payments
 
Future of Identity, Data, and Wearable Security
Future of Identity, Data, and Wearable SecurityFuture of Identity, Data, and Wearable Security
Future of Identity, Data, and Wearable Security
 
Kill All Passwords
Kill All PasswordsKill All Passwords
Kill All Passwords
 
BattleHack Los Angeles
BattleHack Los Angeles BattleHack Los Angeles
BattleHack Los Angeles
 
Building a Mobile Location Aware System with Beacons
Building a Mobile Location Aware System with BeaconsBuilding a Mobile Location Aware System with Beacons
Building a Mobile Location Aware System with Beacons
 
Identity in the Future of Embeddables & Wearables
Identity in the Future of Embeddables & WearablesIdentity in the Future of Embeddables & Wearables
Identity in the Future of Embeddables & Wearables
 
Internet Security and Trends
Internet Security and TrendsInternet Security and Trends
Internet Security and Trends
 
Rebuilding Commerce
Rebuilding CommerceRebuilding Commerce
Rebuilding Commerce
 

Recently uploaded

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Recently uploaded (20)

What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Advantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your BusinessAdvantages of Hiring UIUX Design Service Providers for Your Business
Advantages of Hiring UIUX Design Service Providers for Your Business
 

Node.js Authentication and Data Security

  • 1. Node.js Authentication and Data Security! Jonathan LeBlanc ! Twitter: @jcleblanc ! Book: http://bit.ly/iddatasecurity!
  • 2. Release Date:! August 2016! ! Book Details:! http://bit.ly/iddatasecurity! Identity & Data Security Book!
  • 4. 1: 123456 ! 2: password ! 3: 12345678 ! 4: qwerty ! 5: 12345 ! 6: 123456789! 7: football! 8: 1234! 9: 1234567! Top 25 Passwords of 2015! 10: baseball! 11: welcome! 12: 1234567890! 13: abc123! 14: 111111! 15: 1qaz2wsx! 16: dragon! 17: master! 18: monkey! 19: letmein! 20: login! 21: princess! 22: qwertyuiop! 23: solo! 24: passw0rd! 25: starwars!
  • 5.
  • 8. Brute Force Attacks! Calculate all key variations within a given length, then trying each one until the password is guessed. ! Protect via: Key stretching, CAPTCHA, 2FA! ! Dictionary Attacks! Use a list of predetermined words/phrase to guess password.! Protect via: Salting! ! Rainbow Tables! Use precalculated password hashes to break encryption.! Protect via: Salting ! Protecting Against Password Attacks!
  • 10. //hashing identical messages with no salt! hash('mechagodzilla') = ! 162e0a91026a28f1f2afa11099d1fcbdd9f2e351095ebb196c90e10290ef1227! hash('mechagodzilla') = ! 162e0a91026a28f1f2afa11099d1fcbdd9f2e351095ebb196c90e10290ef1227! ! //hashing identical messages with random salt! hash('mechagodzilla' + '458cf2979ef27397db67077775225334') = ! f3499a916612e285612b32702114751f557a70606c32b54b92de55153d40d3b6! hash('mechagodzilla' + 'ef5b72eff781b09a0784438af742dd6e') = ! 7e29c5c48f44755598dec3549155ad66f1af4671091353be4c4d7694d71dc866! hash('mechagodzilla' + 'cc989b105a1c6a5f0fb460e29dd272f3') = ! 6dedd3dbb0639e6e00ca0bf6272c141fb741e24925cb7548491479a1df2c215e! Hashing with and without salts!
  • 11. Storing Salts! Store alongside the hash! ! Salt Reuse! Salts should be be unique per password! ! Salt Length! Same size as hash? 64 bits? 128 bits?! Considerations when using Salts!
  • 12. bcrypt! Designed for password security, based on the blowfish cipher, CPU & RAM intensive.! ! PBKDF2! Comes from RSA laboratories, performs the HMAC (hash + key) over a specific number of iterations.! ! scrypt! Designed to make it costly to perform large-scale hardware attacks by requiring large amounts of memory! Password Encryption Algorithms!
  • 13. ! var bcrypt = require('bcrypt');! ! app.post("/register", function(req, res){! //capture user login information! var username = req.body.username;! var password = req.body.password;! ! //generate salt, then hash! bcrypt.genSalt(10, function(err, salt) {! bcrypt.hash(password, salt, function(err, key) {! console.log('key: ' + key.toString('hex'));! console.log('salt: ' + salt.toString('hex'));! });! });! });! ! Hashing with bcrypt!
  • 14. ! var bcrypt = require('bcrypt');! ! app.post("/login", function(req, res){! //capture user login information! var username = req.body.username;! var password = req.body.password;! ! //fetch user record from database ! //required info: stored hash! ! //compare password from login to stored user hash! bcrypt.compare(password, hash, function(err, res){! //returns true or false! });! });! ! Login Hash Comparison with bcrypt!
  • 15. ! var crypto = require('crypto');! ! app.post("/register", function(req, res){! //capture user login information! var username = req.body.username;! var password = req.body.password;! ! //generate salt, then hash! crypto.randomBytes(32, function(ex, salt){! crypto.pbkdf2(password, salt, 4096, 512, 'sha256', function(err, key){! if (err) throw err;! //store username, hashed password, and salt in your database! });! });! });! ! Hashing with PBKDF2!
  • 16. ! var crypto = require('crypto');! ! app.post("/login", function(req, res){! //capture user login information! var username = req.body.username;! var password = req.body.password;! ! var dbsalt = 'USER RECORD SALT FROM YOUR DATABASE';! var dbhash = 'USER RECORD KEY FROM YOUR DATABASE';! ! //generate hash with login attempt, then compare to stored user hash! crypto.pbkdf2(password, dbsalt, 4096, 512, 'sha256', function(err, comparehash){! if (err) throw err;! if (dbhash.toString('hex') === comparehash.toString('hex')){ ! //passwords match! } else { ! //passwords don't match! }! });! });! ! Login Hash Comparison with PBKDF2!
  • 20. Domain Validation (DV)! Certificate authority (CA) validates domain access only! Certificate Types!
  • 21. Organization Validation (OV)! ! CA validates DV and basic organization information! Certificate Types!
  • 22. Extended Validation (EV)! CA validates DV, OV, and legal existance of the organization! Certificate Types!
  • 23.
  • 24. //generate private key and self-signed certificate valid for 1 year! openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout server.key -out server.crt! Generate your self-signed certificate and private key!
  • 25. //package requirements! var fs = require('fs'),! https = require('https'),! querystring = require('querystring'),! bodyParser = require('body-parser')! app = require('express')();! ! //support JSON & URL encoded bodies! app.use(bodyParser.json()); ! app.use(bodyParser.urlencoded({ ! extended: true! })); ! Setting up Express server for HTTPS traffic!
  • 26. //handle all POST requests! app.post('/', function (req, res){! var message = req.body;! res.send('Message received:' + querystring.stringify(message));! });! ! //set certificate options! var options = {! key: fs.readFileSync('server.key'),! cert: fs.readFileSync('server.crt'),! passphrase: 'YOUR KEY PASSWORD' ! };! ! //create server with certificate options! https.createServer(options, app).listen(3000, function () {! console.log('Server started: Listening on port 3000');! });! Setting up Express server for HTTPS traffic!
  • 27.
  • 29.
  • 31. Encryption (ECB, CBC, OFB, CFB, CTR)! Data privacy and confidentiality mode. Attacker cannot obtain info on the plaintext data.! ! Authentication(CMAC)! Data authenticity mode. Receiver can validate whether cleartext came from intended sender.! ! Authenticated Encryption (CCM, GCM, KW/KWP/TKW)! Includes both data privacy and authenticity.! Modes of Operation!
  • 32. var crypto = require('crypto');! ! var text = "Encryption Testing AES";! var key = crypto.randomBytes(32); //256 bit shared secret! var iv = crypto.randomBytes(16); //initialization vector - 16 bytes! var algorithm = 'aes-256-ctr'; //cypher and mode of operation! ! //encrypt! var cipher = crypto.createCipher(algorithm, key, iv);! var encrypted = cipher.update(text, 'utf8', 'hex');! encrypted += cipher.final('hex');! console.log("Encrypted: " + encrypted);! Configuring and encrypting message!
  • 33. //----! // data sent to server: ciphertext (encrypted var)! // data known by server: key! //----! ! //cypher and mode of operation! var algorithm = 'aes-256-gcm'; ! ! //decrypt! var decipher = crypto.createDecipher(algorithm, key, iv);! var decrypted = decipher.update(encrypted, 'hex', 'utf8');! decrypted += decipher.final('utf8');! console.log("Decrypted: " + decrypted);! Decrypting ciphertext!
  • 35. Thank You!! ! Slides: http://slideshare.net/jcleblanc! Jonathan LeBlanc ! Twitter: @jcleblanc ! Book: http://bit.ly/iddatasecurity!