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

Stop using CryptoJS for signing token requests #1325

Conversation

lawrence-forooghian
Copy link
Collaborator

@lawrence-forooghian lawrence-forooghian commented Jun 7, 2023

Note: This is based on top of #1320; please review that one first.

This introduces a lightweight implementation of HMAC-SHA-256 and uses that for signing token requests instead of CryptoJS. See commit messages for more details.

Resolves #1295. SDK-3605

We already have BufferUtils methods that provide this functionality.
Move the platform-specific code to the BufferUtils classes (the Crypto
classes might seem more appropriate, but we need HMAC functionality to
be available even in the noencryption version of the library, which
doesn’t have a Crypto class).
@github-actions github-actions bot temporarily deployed to staging/pull/1325/features June 7, 2023 18:52 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1325/bundle-report June 7, 2023 18:53 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1325/typedoc June 7, 2023 18:54 Inactive
We’re going to use this to replace our current usage of CryptoJS, which
we intend to remove in #1239.

We considered using the implementation of HMAC from the Web Crypto API,
but after weighing the implications of doing so (token signing becoming
unavailable in non-secure contexts) against the mildly-increased library
size (1.61 kB increase) from adding an HMAC implementation, decided to
go with the latter [1].

I picked this implementation because it's a single file that contains
precisely the functionality that we need and it claims to be “designed
for efficient minification”. It doesn’t come with any tests, but since
our SDK has quite a few tests that will fail if the result of token
signing is incorrect, I believe we’re OK.

The code added here is taken verbatim from the linked gist, and then
I’ve added an attribution comment and run Prettier.

[1] https://ably-real-time.slack.com/archives/C030C5YLY/p1686152214032779?thread_ts=1686096207.512069&cid=C030C5YLY
Instead, use the HMAC implementation added in fc94b80.

Resolves #1295.
@lawrence-forooghian lawrence-forooghian force-pushed the 1295-stop-using-CryptoJS-for-signing-token-requests branch from 2eae3df to 1794a74 Compare June 7, 2023 18:57
@github-actions github-actions bot temporarily deployed to staging/pull/1325/features June 7, 2023 18:57 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1325/bundle-report June 7, 2023 18:58 Inactive
@github-actions github-actions bot temporarily deployed to staging/pull/1325/typedoc June 7, 2023 18:59 Inactive
This message was added in the very first commit of this repo — perhaps
it was relevant then, but it certainly no longer is, since the `hmac`
function is always present.
Copy link
Member

@owenpearson owenpearson left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good!

@lawrence-forooghian lawrence-forooghian merged commit d2e87fb into integration/v2 Jun 12, 2023
@lawrence-forooghian lawrence-forooghian deleted the 1295-stop-using-CryptoJS-for-signing-token-requests branch June 12, 2023 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants