Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SDK-3570] Use Web Crypto API for encrypting and decrypting #1299

Commits on Jun 5, 2023

  1. Remove IBufferUtils’s ComparableBuffer generic parameter

    Instead, make it so that we can compare any two Bufferlike objects. When
    I was changing some test code (hence, not TypeScript) that made use of
    bufferCompare, I found myself having to think more than I would have
    liked about which type of objects I could pass it.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    cbb98f1 View commit details
    Browse the repository at this point in the history
  2. Always use instanceof for checking if something is an ArrayBuffer

    Gives richer type information to compiler (i.e. whether the object was
    created with the ArrayBuffer constructor instead of whether it just
    conforms to the ArrayBuffer interface), which I believe a type guard
    can't express.
    
    I’m doing this because the the compiler seemed to consider a TypedArray
    to satisfy the ArrayBuffer interface:
    
    > const foo: TypedArray = new Uint8Array();
    > const bar: ArrayBuffer = foo; // This compiles, weird!
    
    The effect of this was that, given an object of TypeScript type
    `ArrayBuffer | TypedArray`, then, after performing an `is ArrayBuffer`
    type guard that returned false, the compiler believed the object to be
    of type `never` (when in fact it could still be a TypedArray).
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    683e88f View commit details
    Browse the repository at this point in the history
  3. Replace use of TypedArray with ArrayBufferView

    This is a more broad definition that means that our web Bufferlike type
    agrees with the web standards’ list of binary data types [1].
    
    [1] https://www.w3.org/TR/WebIDL-1/#common-BufferSource
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    bbdf8b0 View commit details
    Browse the repository at this point in the history
  4. Replace isArrayBufferView with direct call to ArrayBuffer.isView

    There’s no need for this indirection.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    44e4e04 View commit details
    Browse the repository at this point in the history
  5. Remove WordArray from web Bufferlike type

    Part of #1300 (removing CryptoJS functionality from web’s BufferUtils).
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    5450e80 View commit details
    Browse the repository at this point in the history
  6. Rename IBufferUtils.bufferCompare to areBuffersEqual

    And make it return just a boolean instead of a number — we aren’t making
    use of the ordering information it provides, which I don’t really
    understand and don’t want to spend time trying to reproduce when I
    reimplement the web version of this method.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    79668b1 View commit details
    Browse the repository at this point in the history
  7. Don’t use CryptoJS in web implementation of BufferUtils.areBuffersEqual

    Now, web’s BufferUtils only uses the CryptoJS library to provide the
    functionality needed by our web Crypto class for:
    
    - checking if something is a WordArray
    - converting something to a WordArray
    - converting a WordArray to an ArrayBuffer
    
    We will remove this remaining CryptoJS code after implementing #1299
    (removing the use of CryptoJS in our web Crypto class).
    
    Resolves #1300.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    bbd9c9d View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    73ccbe6 View commit details
    Browse the repository at this point in the history
  9. Rename misnamed test

    It’s only a WordArray on web, not in Node.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    b8881cf View commit details
    Browse the repository at this point in the history
  10. Fix comment in test

    This test is executed on all platforms, but WordArray is only used on
    web.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    50af8e7 View commit details
    Browse the repository at this point in the history
  11. Convert React Native platform config to a factory function

    I’m going to want to inject a BufferUtils instance in an upcoming
    commit.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    fd833ab View commit details
    Browse the repository at this point in the history
  12. Change getRandomWordArray to getRandomArrayBuffer

    Preparation for #1292 (using Web Crypto API for encrypting and
    decrypting).
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    7832b44 View commit details
    Browse the repository at this point in the history
  13. Make CipherParams.key an ArrayBuffer on web instead of a WordArray

    Preparation for #1292 (using Web Crypto API for encrypting and
    decrypting).
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    e14f1bf View commit details
    Browse the repository at this point in the history
  14. Change plain/ciphertext output of web Crypto to ArrayBuffer

    The web crypto code now no longer emits any WordArray objects — it only
    uses them internally.
    
    Preparation for #1292 (using Web Crypto API for encrypting and
    decrypting).
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    af675d4 View commit details
    Browse the repository at this point in the history
  15. Remove blockLengthWords property of web CBCCipher

    All of the rest of the crypto code is built around a non-configurable
    block length, so this property is just misleading.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    dd848f3 View commit details
    Browse the repository at this point in the history
  16. Use Web Crypto for encrypting and decrypting on web

    This removes our use of the CryptoJS library for performing encryption
    and decryption operations, instead using the browser’s built-in crypto
    APIs. We’re doing this as part of our work to remove the CryptoJS
    library (#1239) to reduce the size of our SDK.
    
    Resolves #1292.
    lawrence-forooghian committed Jun 5, 2023
    Configuration menu
    Copy the full SHA
    fcdb9f3 View commit details
    Browse the repository at this point in the history