SlideShare a Scribd company logo
1 of 50
Download to read offline
JavaScript End-to-End
2 AES
1),2)
1)
2)
January 26, 2020
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 1 / 50
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 2 / 50
( 1 )
End-to-End (E2E)
Web E2E JavaScript
(AES)
E2E
AES
App AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 3 / 50
AES
AES 1
( )2
AES
3
1
RFC8018 PBES2 https://tools.ietf.org/html/rfc8018 AES
2
.env Base64
3
RFC5869 HKDF https://tools.ietf.org/html/rfc5869 AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 4 / 50
4
4
php hash hkdf() (2018 )
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 5 / 50
:
Web Web
:
Bash, Git
Node.js, npm, yarn
Google Chrome and/or Firefox
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 6 / 50
( )
1 &JS
2 AES
3
4 MAC
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 7 / 50
AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 8 / 50
AES (Advanced Encryption Standard)
AES
NIST
3 : 128-bit, 192-bit, 256-bit
NESSIE CRYPTREC
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 9 / 50
AES
AES 3
1 AES
2 AES 5
3 AES
5
1 2
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 10 / 50
: AES
AES
AES
AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 11 / 50
1: AES
⇒
6
6
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 12 / 50
⇒ 1
1
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 13 / 50
⇒
7
7
PBKDF2 (RFC8018), HKDF (RFC5869)
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 14 / 50
2: AES
⇒
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 15 / 50
8
8 628
< 248
⇒ 48bits 1.5PB
⇒
48bits 8
8
2009 60 GPU
https://web.archive.org/web/20180412051235/http:
//www.lockdown.co.uk/?pg=combi&s=articles
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 16 / 50
(Salt ) AES
9
9
PBKDF2
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 17 / 50
Salt
1 1 AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 18 / 50
3: AES
⇒ AES API (’AES256-CBC’ )
AES
AES 1 16bytes
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 19 / 50
AES 2
(IV) 10
CTR CBC ECB
ECB ( )
10
API (Nonce)
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 20 / 50
ECB
⇒ 11
⇒
JavaScript
ECB
11
1 16Bytes
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 21 / 50
ECB CBC
16Bytes
16Bytes 16Bytes
CBC 16Bytes
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 22 / 50
AES :
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 23 / 50
REST API E2E
Amazon S3
bucket
Amazon S3
bucket
JavaScript
JavaScript
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 24 / 50
Node.js
1
12
2 AES-CBC 13
REST API
12
1,2
13
3
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 25 / 50
:
Node.js (> v10) yarn 14
Google Chrome ( )
Firefox
Visual Studio Code WebStorm
14
: npm i -g yarn
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 26 / 50
JavaScript
GitHub 15
Clone
$ git clone
https://github.com/junkurihara/slides-e2e-security-js.git
$ cd sample02
$ yarn install
$ yarn build
15
https://github.com/junkurihara/slides-e2e-security-js/
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 27 / 50
REST API
SSL
(https://e2e.zettant.com/)16
$ yarn start
localhost 3000 HTTP
16
2020/1/25
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 28 / 50
Node.js
AES
AES
jscu 17
API Code snippet
17
https://github.com/junkurihara/jscu
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 29 / 50
yarn execute post -r -p ‘ ’ ‘ ’
sample
$ yarn execute post -r -p ’my password’ ’my private data’ // -r
Register encrypted data to remote server
Data: my private data
Password: my password
Derived key and its related params: //
Derived key in Base64: fiP4flrlhd3Iwg5MOyln7zNNk4Au9If429n2uvfi43s=
PBKDF2 Param - Salt in Base64: zyD7/TGDq3dig3l4zJ5SRzFKVnIjw2KG26XUrMZFkkw=
PBKDF2 Param - Hash: SHA-256
PBKDF2 Param - Iteration: 2048
Registered id: 1 // id=1
S4lFVWrvLj4OjPfFRTgVJFfRUI+6LIlw1VooFzG2J5E=
my password
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 30 / 50
https://e2e.zettant.com/data
AES CBC IV
Salt, iteration Hash
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 31 / 50
yarn execute get -r -p ‘ ’ ‘id ’
$ yarn execute get -r -p ’my password’ 1 // -r
Retrieve encrypted data to remote server
Id: 1
Password: my password
Derived key and its related params: //
Derived key in Base64: fiP4flrlhd3Iwg5MOyln7zNNk4Au9If429n2uvfi43s=
PBKDF2 Param - Salt in Base64: zyD7/TGDq3dig3l4zJ5SRzFKVnIjw2KG26XUrMZFkkw=
PBKDF2 Param - Hash: SHA-256
PBKDF2 Param - Iteration: 2048
Decrypted data: my private data //
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 32 / 50
( )
yarn execute post -r -m ‘ ’ ‘ ’ 18
sample
$ yarn execute gen-secret 32 // Base64
Generated master secret in Base64: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=
$ yarn execute post -r -m ’mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=’ ’my
private data’
Register encrypted data to remote server
Data: my private data
Master secret: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=
Derived key and its related params: //
Derived key in Base64: 1vgTfxp3FEi3kpJiQ6h0vxtDCkdz+u5XQUF1tPm1VMY=
HKDF Param - Salt in Base64: 8SM9tyXJUX+JGwLswIUnnGyHPL+7hzkSHXaKY7z0AF0=
HKDF Param - Hash: SHA-256
Registered id: 2
18
Base64
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 33 / 50
AES CBC IV
Salt, Hash
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 34 / 50
yarn execute get -r -m ‘ ’ ‘id ’
$ yarn execute get -r -m ’mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=’ 2 // -r
Retrieve encrypted data to remote server
Id: 2
Master secret: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=
Derived key and its related params: //
Derived key in Base64: 1vgTfxp3FEi3kpJiQ6h0vxtDCkdz+u5XQUF1tPm1VMY=
HKDF Param - Salt in Base64: 8SM9tyXJUX+JGwLswIUnnGyHPL+7hzkSHXaKY7z0AF0=
HKDF Param - Hash: SHA-256
Decrypted data: my private data //
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 35 / 50
sample02/src/post-get-browser.html
( html )
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 36 / 50
ECB API
$ yarn execute aes-mode-compare ’0123456789ABCDEF0123456789ABCDEF’ 16bytes
random key (Base64): 4gfrl+/OMyFt2ALLEp24sIXyHsyjvlYZZxRj4lkJe9M=
data (Hex): 3031323334353637383941424344454630313233343536373839414243444546
AES-ECB (Hex): c871e345b92951236059676b0866c7af c871e345b92951236059676b0866c7af
...
AES-CBC (Hex): d34ad4cc8816edcf3ad1a56c355c9067 69c4f525903b607960e377649abef648
...
16bytes ECB
ECB
⇒
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 37 / 50
CBC
19
ECB WebCryptoAPI
20
ECB
CBC CTR
19
ECB
20
CBC ECB
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 38 / 50
AES :
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 39 / 50
PBKDF2 in JavaScript
AES
PBKDF2: Password-based Key Derivation Function
PKCS #5 v2.1 (RFC808121
) PBKDF1
PBKDF2 (AES) Password-based
Encryption Scheme 2 (PBES2)
BCrypt 22
21
https://tools.ietf.org/html/rfc8018
22
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 40 / 50
PBKDF2 WebCrypto API, Node.js Crypto
API jscu
sample/src/derive-key.js: deriveKeyFromPassword
const jscu = getJscu(); // jscu script require
if(!salt){ // salt Salt
salt = jscu.random.getRandomBytes(32); // Uint8Array
}
else {
salt = jseu.encoder.decodeBase64(salt); // Base64 Uint8Array
}
const key = await jscu.pbkdf.pbkdf2( // PBKDF2
password, //
salt, // ( )
iterationCount, // 1000 ( )
len, // ( )
hash // HMAC Hash ’SHA-256’ ( )
);
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 41 / 50
HKDF in JavaScript
AES
HKDF: HMAC-based Key Derivation Function
RFC808123
PBKDF2
23
https://tools.ietf.org/html/rfc5869
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 42 / 50
HKDF WebCrypto API
jscu
sample/src/derive-key.js: deriveKeyFromMasterSecret
const jscu = getJscu(); // jscu script require
if(!salt){ // salt Salt
salt = jscu.random.getRandomBytes(32); // Uint8Array
}
else {
salt = jseu.encoder.decodeBase64(salt); // Base64 Uint8Array
}
const keyObj = await jscu.hkdf.compute(
masterSecret, //
hash // HMAC Hash ’SHA-256’ ( )
len, // ( )
’’, // ’info’ field for RFC5869. This could be always blank.
salt // ( )
);
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 43 / 50
jscu CBC CTR CTR
GCM24
sample/src/encrypt.js: encrypt
const jscu = getJscu(); // jscu script require
const uint8iv = jscu.random.getRandomBytes(16); // IV CBC 16Bytes
const encrypted = await jscu.aes.encrypt( // AES
jseu.encoder.stringToArrayBuffer(data), // string data Uint8Array
key, // HKDF/PBKDF
{ // CBC
name: ’AES-CBC’,
iv: uint8iv
}
);
24
GCM(Galois/Counter Mode) CTR
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 44 / 50
sample/src/encrypt.js: decrypt
const jscu = getJscu(); // jscu script require
const decrypted = await jscu.aes.decrypt( // AES
jseu.encoder.decodeBase64(data), // Base64
key, // HKDF/PBKDF
{ // CBC
name: ’AES-CBC’,
iv: jseu.encoder.decodeBase64(iv) // Base64 IV
}
);
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 45 / 50
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 46 / 50
AES
Key
Derivation Function
( PBKDF2/HKDF 25
)
CBC CTR
JavaScript
25
e.g., JOSE Concat KDF with AESKW https://tools.ietf.org/html/rfc8037
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 47 / 50
:
RSA-OAEP
EDCH-Ephemeral + AES
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 48 / 50
: iTransfy by Zettant
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 49 / 50
:
: recruit@zettant.com
URL: https://www.zettant.com
Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 50 / 50

More Related Content

Similar to JavaScriptを使って学ぶEnd-to-Endセキュリティ 第2回

Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUKiwamu Okabe
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesOdoo
 
Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Jarek Ratajski
 
Bsides
BsidesBsides
Bsidesm j
 
Summer Camp Live sessions.pdf
Summer Camp Live sessions.pdfSummer Camp Live sessions.pdf
Summer Camp Live sessions.pdfHCIA2020
 
ใบงานที่ 4
ใบงานที่ 4ใบงานที่ 4
ใบงานที่ 4KaRn Tik Tok
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019Matt Raible
 
Scrypt Chacha by Travis Tolle (Ultracoin)
Scrypt Chacha by Travis Tolle (Ultracoin)Scrypt Chacha by Travis Tolle (Ultracoin)
Scrypt Chacha by Travis Tolle (Ultracoin)Hashers United
 
I made some more expansion board for M5Stack
I made some more expansion  board for M5StackI made some more expansion  board for M5Stack
I made some more expansion board for M5StackMasawo Yamazaki
 
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...Matt Raible
 
Krzysztof Mazepa - IOS XR - IP Fast Convergence
Krzysztof Mazepa - IOS XR - IP Fast ConvergenceKrzysztof Mazepa - IOS XR - IP Fast Convergence
Krzysztof Mazepa - IOS XR - IP Fast ConvergencePROIDEA
 
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringPiwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringTakashi Yamamoto
 
Webshield internet of things
Webshield internet of thingsWebshield internet of things
Webshield internet of thingsRaghav Shetty
 
Capital onehadoopclass
Capital onehadoopclassCapital onehadoopclass
Capital onehadoopclassDoug Chang
 
Internet of Things Magic Show
Internet of Things Magic ShowInternet of Things Magic Show
Internet of Things Magic ShowStephen Chin
 
Swift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSwift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSally Shepard
 

Similar to JavaScriptを使って学ぶEnd-to-Endセキュリティ 第2回 (20)

Metasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCUMetasepi team meeting #20: Start! ATS programming on MCU
Metasepi team meeting #20: Start! ATS programming on MCU
 
Licencias nod 32
Licencias nod 32Licencias nod 32
Licencias nod 32
 
Best Practices in Handling Performance Issues
Best Practices in Handling Performance IssuesBest Practices in Handling Performance Issues
Best Practices in Handling Performance Issues
 
Eta lang Beauty And The Beast
Eta lang Beauty And The Beast Eta lang Beauty And The Beast
Eta lang Beauty And The Beast
 
Bsides
BsidesBsides
Bsides
 
Microcontroller part 2
Microcontroller part 2Microcontroller part 2
Microcontroller part 2
 
Summer Camp Live sessions.pdf
Summer Camp Live sessions.pdfSummer Camp Live sessions.pdf
Summer Camp Live sessions.pdf
 
ใบงานที่ 4
ใบงานที่ 4ใบงานที่ 4
ใบงานที่ 4
 
&lt;img src="xss.com">
&lt;img src="xss.com">&lt;img src="xss.com">
&lt;img src="xss.com">
 
Fav
FavFav
Fav
 
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 201910 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
10 Excellent Ways to Secure Your Spring Boot Application - Devoxx Belgium 2019
 
Scrypt Chacha by Travis Tolle (Ultracoin)
Scrypt Chacha by Travis Tolle (Ultracoin)Scrypt Chacha by Travis Tolle (Ultracoin)
Scrypt Chacha by Travis Tolle (Ultracoin)
 
I made some more expansion board for M5Stack
I made some more expansion  board for M5StackI made some more expansion  board for M5Stack
I made some more expansion board for M5Stack
 
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...
10 Excellent Ways to Secure Your Spring Boot Application - The Secure Develop...
 
Krzysztof Mazepa - IOS XR - IP Fast Convergence
Krzysztof Mazepa - IOS XR - IP Fast ConvergenceKrzysztof Mazepa - IOS XR - IP Fast Convergence
Krzysztof Mazepa - IOS XR - IP Fast Convergence
 
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 SpringPiwik elasticsearch kibana at OSC Tokyo 2016 Spring
Piwik elasticsearch kibana at OSC Tokyo 2016 Spring
 
Webshield internet of things
Webshield internet of thingsWebshield internet of things
Webshield internet of things
 
Capital onehadoopclass
Capital onehadoopclassCapital onehadoopclass
Capital onehadoopclass
 
Internet of Things Magic Show
Internet of Things Magic ShowInternet of Things Magic Show
Internet of Things Magic Show
 
Swift hardware hacking @ try! Swift
Swift hardware hacking @ try! SwiftSwift hardware hacking @ try! Swift
Swift hardware hacking @ try! Swift
 

Recently uploaded

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Scott Keck-Warren
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetEnjoy Anytime
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraDeakin University
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 

Recently uploaded (20)

Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024Advanced Test Driven-Development @ php[tek] 2024
Advanced Test Driven-Development @ php[tek] 2024
 
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your BudgetHyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
Hyderabad Call Girls Khairatabad ✨ 7001305949 ✨ Cheap Price Your Budget
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
The transition to renewables in India.pdf
The transition to renewables in India.pdfThe transition to renewables in India.pdf
The transition to renewables in India.pdf
 
Artificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning eraArtificial intelligence in the post-deep learning era
Artificial intelligence in the post-deep learning era
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 

JavaScriptを使って学ぶEnd-to-Endセキュリティ 第2回

  • 1. JavaScript End-to-End 2 AES 1),2) 1) 2) January 26, 2020 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 1 / 50
  • 2. Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 2 / 50
  • 3. ( 1 ) End-to-End (E2E) Web E2E JavaScript (AES) E2E AES App AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 3 / 50
  • 4. AES AES 1 ( )2 AES 3 1 RFC8018 PBES2 https://tools.ietf.org/html/rfc8018 AES 2 .env Base64 3 RFC5869 HKDF https://tools.ietf.org/html/rfc5869 AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 4 / 50
  • 5. 4 4 php hash hkdf() (2018 ) Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 5 / 50
  • 6. : Web Web : Bash, Git Node.js, npm, yarn Google Chrome and/or Firefox Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 6 / 50
  • 7. ( ) 1 &JS 2 AES 3 4 MAC Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 7 / 50
  • 8. AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 8 / 50
  • 9. AES (Advanced Encryption Standard) AES NIST 3 : 128-bit, 192-bit, 256-bit NESSIE CRYPTREC Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 9 / 50
  • 10. AES AES 3 1 AES 2 AES 5 3 AES 5 1 2 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 10 / 50
  • 11. : AES AES AES AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 11 / 50
  • 12. 1: AES ⇒ 6 6 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 12 / 50
  • 13. ⇒ 1 1 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 13 / 50
  • 14. ⇒ 7 7 PBKDF2 (RFC8018), HKDF (RFC5869) Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 14 / 50
  • 15. 2: AES ⇒ Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 15 / 50
  • 16. 8 8 628 < 248 ⇒ 48bits 1.5PB ⇒ 48bits 8 8 2009 60 GPU https://web.archive.org/web/20180412051235/http: //www.lockdown.co.uk/?pg=combi&s=articles Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 16 / 50
  • 17. (Salt ) AES 9 9 PBKDF2 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 17 / 50
  • 18. Salt 1 1 AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 18 / 50
  • 19. 3: AES ⇒ AES API (’AES256-CBC’ ) AES AES 1 16bytes Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 19 / 50
  • 20. AES 2 (IV) 10 CTR CBC ECB ECB ( ) 10 API (Nonce) Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 20 / 50
  • 21. ECB ⇒ 11 ⇒ JavaScript ECB 11 1 16Bytes Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 21 / 50
  • 22. ECB CBC 16Bytes 16Bytes 16Bytes CBC 16Bytes Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 22 / 50
  • 23. AES : Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 23 / 50
  • 24. REST API E2E Amazon S3 bucket Amazon S3 bucket JavaScript JavaScript Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 24 / 50
  • 25. Node.js 1 12 2 AES-CBC 13 REST API 12 1,2 13 3 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 25 / 50
  • 26. : Node.js (> v10) yarn 14 Google Chrome ( ) Firefox Visual Studio Code WebStorm 14 : npm i -g yarn Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 26 / 50
  • 27. JavaScript GitHub 15 Clone $ git clone https://github.com/junkurihara/slides-e2e-security-js.git $ cd sample02 $ yarn install $ yarn build 15 https://github.com/junkurihara/slides-e2e-security-js/ Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 27 / 50
  • 28. REST API SSL (https://e2e.zettant.com/)16 $ yarn start localhost 3000 HTTP 16 2020/1/25 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 28 / 50
  • 29. Node.js AES AES jscu 17 API Code snippet 17 https://github.com/junkurihara/jscu Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 29 / 50
  • 30. yarn execute post -r -p ‘ ’ ‘ ’ sample $ yarn execute post -r -p ’my password’ ’my private data’ // -r Register encrypted data to remote server Data: my private data Password: my password Derived key and its related params: // Derived key in Base64: fiP4flrlhd3Iwg5MOyln7zNNk4Au9If429n2uvfi43s= PBKDF2 Param - Salt in Base64: zyD7/TGDq3dig3l4zJ5SRzFKVnIjw2KG26XUrMZFkkw= PBKDF2 Param - Hash: SHA-256 PBKDF2 Param - Iteration: 2048 Registered id: 1 // id=1 S4lFVWrvLj4OjPfFRTgVJFfRUI+6LIlw1VooFzG2J5E= my password Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 30 / 50
  • 31. https://e2e.zettant.com/data AES CBC IV Salt, iteration Hash Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 31 / 50
  • 32. yarn execute get -r -p ‘ ’ ‘id ’ $ yarn execute get -r -p ’my password’ 1 // -r Retrieve encrypted data to remote server Id: 1 Password: my password Derived key and its related params: // Derived key in Base64: fiP4flrlhd3Iwg5MOyln7zNNk4Au9If429n2uvfi43s= PBKDF2 Param - Salt in Base64: zyD7/TGDq3dig3l4zJ5SRzFKVnIjw2KG26XUrMZFkkw= PBKDF2 Param - Hash: SHA-256 PBKDF2 Param - Iteration: 2048 Decrypted data: my private data // Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 32 / 50
  • 33. ( ) yarn execute post -r -m ‘ ’ ‘ ’ 18 sample $ yarn execute gen-secret 32 // Base64 Generated master secret in Base64: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0= $ yarn execute post -r -m ’mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=’ ’my private data’ Register encrypted data to remote server Data: my private data Master secret: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0= Derived key and its related params: // Derived key in Base64: 1vgTfxp3FEi3kpJiQ6h0vxtDCkdz+u5XQUF1tPm1VMY= HKDF Param - Salt in Base64: 8SM9tyXJUX+JGwLswIUnnGyHPL+7hzkSHXaKY7z0AF0= HKDF Param - Hash: SHA-256 Registered id: 2 18 Base64 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 33 / 50
  • 34. AES CBC IV Salt, Hash Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 34 / 50
  • 35. yarn execute get -r -m ‘ ’ ‘id ’ $ yarn execute get -r -m ’mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0=’ 2 // -r Retrieve encrypted data to remote server Id: 2 Master secret: mP95WFEv3G/iWsjQKC4mEuEmCkiS8dRK80Q6CpC1bc0= Derived key and its related params: // Derived key in Base64: 1vgTfxp3FEi3kpJiQ6h0vxtDCkdz+u5XQUF1tPm1VMY= HKDF Param - Salt in Base64: 8SM9tyXJUX+JGwLswIUnnGyHPL+7hzkSHXaKY7z0AF0= HKDF Param - Hash: SHA-256 Decrypted data: my private data // Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 35 / 50
  • 36. sample02/src/post-get-browser.html ( html ) Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 36 / 50
  • 37. ECB API $ yarn execute aes-mode-compare ’0123456789ABCDEF0123456789ABCDEF’ 16bytes random key (Base64): 4gfrl+/OMyFt2ALLEp24sIXyHsyjvlYZZxRj4lkJe9M= data (Hex): 3031323334353637383941424344454630313233343536373839414243444546 AES-ECB (Hex): c871e345b92951236059676b0866c7af c871e345b92951236059676b0866c7af ... AES-CBC (Hex): d34ad4cc8816edcf3ad1a56c355c9067 69c4f525903b607960e377649abef648 ... 16bytes ECB ECB ⇒ Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 37 / 50
  • 38. CBC 19 ECB WebCryptoAPI 20 ECB CBC CTR 19 ECB 20 CBC ECB Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 38 / 50
  • 39. AES : Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 39 / 50
  • 40. PBKDF2 in JavaScript AES PBKDF2: Password-based Key Derivation Function PKCS #5 v2.1 (RFC808121 ) PBKDF1 PBKDF2 (AES) Password-based Encryption Scheme 2 (PBES2) BCrypt 22 21 https://tools.ietf.org/html/rfc8018 22 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 40 / 50
  • 41. PBKDF2 WebCrypto API, Node.js Crypto API jscu sample/src/derive-key.js: deriveKeyFromPassword const jscu = getJscu(); // jscu script require if(!salt){ // salt Salt salt = jscu.random.getRandomBytes(32); // Uint8Array } else { salt = jseu.encoder.decodeBase64(salt); // Base64 Uint8Array } const key = await jscu.pbkdf.pbkdf2( // PBKDF2 password, // salt, // ( ) iterationCount, // 1000 ( ) len, // ( ) hash // HMAC Hash ’SHA-256’ ( ) ); Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 41 / 50
  • 42. HKDF in JavaScript AES HKDF: HMAC-based Key Derivation Function RFC808123 PBKDF2 23 https://tools.ietf.org/html/rfc5869 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 42 / 50
  • 43. HKDF WebCrypto API jscu sample/src/derive-key.js: deriveKeyFromMasterSecret const jscu = getJscu(); // jscu script require if(!salt){ // salt Salt salt = jscu.random.getRandomBytes(32); // Uint8Array } else { salt = jseu.encoder.decodeBase64(salt); // Base64 Uint8Array } const keyObj = await jscu.hkdf.compute( masterSecret, // hash // HMAC Hash ’SHA-256’ ( ) len, // ( ) ’’, // ’info’ field for RFC5869. This could be always blank. salt // ( ) ); Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 43 / 50
  • 44. jscu CBC CTR CTR GCM24 sample/src/encrypt.js: encrypt const jscu = getJscu(); // jscu script require const uint8iv = jscu.random.getRandomBytes(16); // IV CBC 16Bytes const encrypted = await jscu.aes.encrypt( // AES jseu.encoder.stringToArrayBuffer(data), // string data Uint8Array key, // HKDF/PBKDF { // CBC name: ’AES-CBC’, iv: uint8iv } ); 24 GCM(Galois/Counter Mode) CTR Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 44 / 50
  • 45. sample/src/encrypt.js: decrypt const jscu = getJscu(); // jscu script require const decrypted = await jscu.aes.decrypt( // AES jseu.encoder.decodeBase64(data), // Base64 key, // HKDF/PBKDF { // CBC name: ’AES-CBC’, iv: jseu.encoder.decodeBase64(iv) // Base64 IV } ); Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 45 / 50
  • 46. Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 46 / 50
  • 47. AES Key Derivation Function ( PBKDF2/HKDF 25 ) CBC CTR JavaScript 25 e.g., JOSE Concat KDF with AESKW https://tools.ietf.org/html/rfc8037 Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 47 / 50
  • 48. : RSA-OAEP EDCH-Ephemeral + AES Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 48 / 50
  • 49. : iTransfy by Zettant Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 49 / 50
  • 50. : : recruit@zettant.com URL: https://www.zettant.com Jun Kurihara (Zettant Inc./U-Hyogo) E2E Security with JS 02 January 26, 2020 50 / 50