end end to end file encr encryp yption i in n the the web
play

End End-to-end File Encr Encryp yption i in n the the Web Br - PowerPoint PPT Presentation

End End-to-end File Encr Encryp yption i in n the the Web Br eb Browser er A Ca Case e Study dy Thomas Konrad, SBA Research Vue.js Meetup Vienna, Feb 11, 2020 SBA Research gGmbH, 2020 Classification: Public 1 ~ $ whoami Thomas


  1. End End-to-end File Encr Encryp yption i in n the the Web Br eb Browser er – A Ca Case e Study dy Thomas Konrad, SBA Research Vue.js Meetup Vienna, Feb 11, 2020 SBA Research gGmbH, 2020 Classification: Public 1

  2. ~ $ whoami Thomas Konrad ~ $ id uid=123 gid=1(Vienna, Austria) gid=2(SBA Research) gid=3(Software Security) gid=4(Penetration Testing) gid=5(Secure Development Lifecycle) gid=6(Security Training) gid=7(sec4dev Conference & Bootcamp) SBA Research gGmbH, 2020 Classification: Public 2

  3. Wha What t we’d e’d like t e to o do SBA Research gGmbH, 2020 Classification: Public 3

  4. Wh Why y al all th the e Fuzz? zz? Beecozz Sucurity! • No, seriously • To lower the attack o surface significantly! File read access on the o server gets worthless to attackers Maybe better o deployment options SBA Research gGmbH, 2020 Classification: Public 4

  5. I a I admi mit: I d : I didn’t i n’t inven nvent t th this. s. Firefox Send • End-to-end encrypted file sharing • Basic concepts in this talk are • taken from there https://send.firefox.com • https://github.com/mozilla/send • Good stuff! • SBA Research gGmbH, 2020 Classification: Public 5

  6. Req equiremen rements ts Ensure confidentiality, integrity, and authenticity Encrypt the file in the browser Support big files (> 10 GB) Support old browsers as well as possible Securely distribute keys SBA Research gGmbH, 2020 Classification: Public 6

  7. Ensure nsure Conf nfiden enti tial ality ty, Int Integri egrity ty, an and Authenti uthentici city ty First things first: Randomness . 1110 1101 0001 1101 0000 0000 0000 0000 “There is no such thing as a random number – there are only methods to produce random numbers.” – John von Neumann (1961) SBA Research gGmbH, 2020 Classification: Public 7

  8. Gener Generate e Secu ecure re Rand ndom B om Byt ytes es in th the e Browser ser https://gist.github.com/thomaskonrad/cfe4c9f6fd26f4382df1f8de3a2b97e8 GitHub Gist - Random Number Generator in TypeScript: public static generateRandomBytes ( length: number ): Uint8Array { return crypto.getRandomValues( new Uint8Array (length) ); } SBA Research gGmbH, 2020 Classification: Public 8

  9. Ensure nsure Conf nfiden enti tial ality ty, Int Integri egrity ty, an and Authenti uthentici city ty Let’s take as an example AES in CBC mode. What do you think we can guarantee with it? Confidentiality Integrity Authenticity SBA Research gGmbH, 2020 Classification: Public 9

  10. CBC (an (and other thers) s) Do N o Not Gu ot Guar aran antee ee Int Integri egrity ty • The ciphertext can be manipulated, and decryption will not fail. • Solution Authenticated Encryption with Associated Data o (AEAD) Examples: AES-GCM, ChaCha20-Poly1305 o SBA Research gGmbH, 2020 Classification: Public 10

  11. Req equiremen rements ts Ensure confidentiality, integrity, and authenticity Encrypt the file in the browser Support big files (> 10 GB) Support old browsers as well as possible Securely distribute keys SBA Research gGmbH, 2020 Classification: Public 11

  12. Symme ymmetric tric AEAD AEAD Enc Encryp yption tion in in the the Brow owse ser r 1/2 https://gist.github.com/thomaskonrad/c8ed4d73bb200ecc9ecdf5b85e2eb7f0 GitHub Gist - Authenticated Secret Key Cryptography (AEAD) in TypeScript: export default class AEAD { public static readonly KEY_LENGTH_IN_BYTES = 16; public static readonly IV_LENGTH_IN_BYTES = 16; public static readonly TAG_LENGTH_IN_BYTES = 16; private static readonly ALGORITHM = 'AES-GCM'; private readonly secretKey: CryptoKey; private readonly tagLengthInBytes: number; public constructor(secretKey: CryptoKey, tagLengthInBytes = AEAD. TAG_LENGTH_IN_BYTES ) { this.secretKey = secretKey; this.tagLengthInBytes = tagLengthInBytes; } public static async getCryptoKeyFromRawKey (rawKey: Uint8Array): Promise<CryptoKey> { return await crypto .subtle.importKey( 'raw', rawKey, { name: this. ALGORITHM , }, true, ['encrypt', 'decrypt'], ); } SBA Research gGmbH, 2020 Classification: Public 12

  13. Symme ymmetric tric AEAD AEAD Enc Encryp yption tion in in the the Brow owse ser r 2/2 https://gist.github.com/thomaskonrad/c8ed4d73bb200ecc9ecdf5b85e2eb7f0 GitHub Gist - Authenticated Secret Key Cryptography (AEAD) in TypeScript: public async encrypt(iv: Uint8Array, data: Uint8Array): Promise<ArrayBuffer> { return await crypto .subtle.encrypt({ name: AuthenticatedSecretKeyCryptography. ALGORITHM , iv, tagLength: this.tagLengthInBytes * 8, }, this.secretKey, data, ); } public async decrypt(iv: Uint8Array, data: Uint8Array): Promise<ArrayBuffer> { return await crypto .subtle.decrypt({ name: AuthenticatedSecretKeyCryptography. ALGORITHM , iv, tagLength: this.tagLengthInBytes * 8, }, this.secretKey, data, ); } } SBA Research gGmbH, 2020 Classification: Public 13

  14. Req equiremen rements ts Ensure confidentiality, integrity, and authenticity Encrypt the file in the browser Support big files (> 10 GB) Support old browsers as well as possible Securely distribute keys SBA Research gGmbH, 2020 Classification: Public 14

  15. Upload ad: C : Chu hunk a nk and nd Encr Encryp ypt SBA Research gGmbH, 2020 Classification: Public 15

  16. Upload load: : Splitting litting a a Fil File using using the the Fil FileRead ader r API API https://gist.github.com/thomaskonrad/8ced18322ebfcba47d7e8765176eeefb GitHub Gist - Split files into chunks of a given size using the FileReader API: <template> <input type="file" @change="files = $event .target.files"/> </template> // ... const readChunk = () => { const r = new FileReader (); const blob = file.slice(offset, chunkSize + offset); r.onload = readEventHandler; r.readAsArrayBuffer(blob); }; SBA Research gGmbH, 2020 Classification: Public 16

  17. Upload load: : Splitting litting a a Fil File using using the the Fil FileRead ader r API API https://gist.github.com/thomaskonrad/8ced18322ebfcba47d7e8765176eeefb GitHub Gist - Split files into chunks of a given size using the FileReader API: const readEventHandler = async (evt: any) => { if (evt.target.error == null) { const sequenceNumber = (offset / chunkSize); offset += evt.target.result.byteLength; let data = new Uint8Array (evt.target.result); data = await encrypt(data, sequenceNumber); await upload(data, sequenceNumber); } // Error handling, termination, read next chunk. }; SBA Research gGmbH, 2020 Classification: Public 17

  18. Upload load: : Cre Creating ating the the Enc Encryp yption tion Transf ansforme ormer const encrypt = async (chunk: Uint8Array, chunkIndex: number) => { return await this.keyChain.encrypt( chunk, file.nonce, // A random, 12-byte nonce! 'fileContents’, chunkIndex // This will be part of the nonce. ); }; SBA Research gGmbH, 2020 Classification: Public 18

  19. Fi FileR eRead eader er API: I: Brow owser ser Sup uppor ort SBA Research gGmbH, 2020 Classification: Public 19

  20. Dow ownl nloa oad: D : Dow ownl nload ad a as s Blob? async blobDownload(file: File) { const response = await this.$http.get( `/api/v1/files/${file.id}`, { responseType: 'blob' }, ); const cleartext = await this.keyChain.getDecryptedResponseData( response.data, file.nonce, file.totalClearTextSizeInBytes, ); await saveFile(cleartext, file.name, file.mimeType); } SBA Research gGmbH, 2020 Classification: Public 20

  21. Dow ownl nloa oad: : Crea reati ting ng a a ”S ”Save ave as” D s” Dialog https://gist.github.com/thomaskonrad/37772256a86d9f5b0472b3c2440cffee GitHub Gist: Downloading an Array Buffer via a "Save as" Dialog in the Browser: export default async function saveFile(plaintext: ArrayBuffer, fileName: string, fileType: string) { return new Promise ((resolve, reject) => { const dataView = new DataView (plaintext); const blob = new Blob ([dataView], { type: fileType }); const downloadUrl = URL .createObjectURL(blob); const a = document .createElement('a'); a.href = downloadUrl; a.download = fileName; document .body.appendChild(a); a.click(); URL .revokeObjectURL(downloadUrl); setTimeout(resolve, 100); }); } SBA Research gGmbH, 2020 Classification: Public 21

  22. Dow ownl nloa oad: : Dow ownsi nsides es of th f this s Approa oach • A 10 GB file will use 20 GB+ of memory • Using this approach, we cannot stream the data • Enter Service Workers ! SBA Research gGmbH, 2020 Classification: Public 22

  23. Ser ervi vice ce Worker ers: s: A Quick P k Pri rimer mer • A piece of JavaScript code that runs in the background of your website • It acts as a proxy server between your site and the server • It runs in a worker context and has no DOM access SBA Research gGmbH, 2020 Classification: Public 23

  24. Ser ervi vice ce Worker ers: s: A Quick P k Pri rimer mer • Service Worker use cases Intercepting and modifying requests o Caching resources o Convert images o Can make your app work even if no network is o available (Progressive Web Apps, PWA) SBA Research gGmbH, 2020 Classification: Public 24

  25. Ser ervi vice ce Worker ers: s: A Quick P k Pri rimer mer SBA Research gGmbH, 2020 Classification: Public 25

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend