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

🕸️ refactor: Migrate from crypto to Web Crypto API #3357

Merged
merged 8 commits into from
Aug 5, 2024

Conversation

mawburn
Copy link
Sponsor Contributor

@mawburn mawburn commented Jul 16, 2024

Summary

Why Web Crypto API?

  • Standardization: The Web Crypto API is a standardized API, ensuring consistent behavior across browsers and Node.js.
  • Security: Designed with modern security practices, it helps avoid common cryptographic pitfalls.
  • Asynchronous and Multithreaded: Uses Promises for non-blocking, asynchronous operations and leverages Node.js's internal thread pool for multithreading, enhancing performance and scalability.
    • Additionally, crypto calls are both very heavy on the processor and blocking calls. Slowing down the entire instance.
  • Modern Algorithms: Supports modern cryptographic algorithms like AES-GCM, RSA-OAEP, and ECC.

References

Node.js Support

  • Introduced: Node.js v15.0.0 (experimental)
  • Stabilized: Node.js v16.0.0

Change Type

Please delete any irrelevant options.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Testing

Running in production for my major deploy of LibreChat.

Checklist

Please delete any irrelevant options.

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code

Copilot Summary

This pull request introduces significant changes to the encryption and decryption methods in the codebase. The most important changes include migrating from Node's built-in crypto module to the webcrypto API, and introducing an asynchronous hashToken function. These changes affect multiple files and functions, including Session.js, AuthController.js, AuthService.js, ActionService.js, and crypto.js.

Migration from crypto to webcrypto:

Introduction of asynchronous encryption and decryption:

@danny-avila danny-avila changed the title Migrate from crypto to Web Crypto API 🕸️ refactor: Migrate from crypto to Web Crypto API Aug 5, 2024
@danny-avila danny-avila merged commit 3e0f954 into danny-avila:main Aug 5, 2024
1 check passed
@danny-avila
Copy link
Owner

danny-avila commented Aug 5, 2024

This PR is causing an Unrecognized algorithm name error when providing user API keys from frontend.

#3551

Testing a fix, seeing why it only seems to be affecting that

EDIT: Resolved by #3556!

@mawburn
Copy link
Sponsor Contributor Author

mawburn commented Aug 7, 2024

@danny-avila Thanks! Sorry about that, I was out of town.

@mawburn mawburn deleted the mawburn/webcrypto branch August 7, 2024 13:40
danny-avila added a commit that referenced this pull request Aug 17, 2024
* move crypto to async webcrypto

update encrypt/decrypt

forgot await

* chore: import order - openidStrategy.js

* chore: import order - Session.js

* chore: import order - AuthController.js

* Update AuthService.js

---------

Co-authored-by: Danny Avila <danacordially@gmail.com>
kenshinsamue pushed a commit to intelequia/LibreChat that referenced this pull request Sep 17, 2024
* move crypto to async webcrypto

update encrypt/decrypt

forgot await

* chore: import order - openidStrategy.js

* chore: import order - Session.js

* chore: import order - AuthController.js

* Update AuthService.js

---------

Co-authored-by: Danny Avila <danacordially@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants