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

feat: support stronger ciphers #810

Merged
merged 10 commits into from
Feb 28, 2024
Merged

feat: support stronger ciphers #810

merged 10 commits into from
Feb 28, 2024

Conversation

shetzel
Copy link
Contributor

@shetzel shetzel commented Apr 10, 2023

What does this PR do?

Supports stronger ciphers for encryption/decryption.

What issues does this PR fix or reference?

@W-12422652@

QA Notes
MAKE A BACKUP OF YOUR ~/.sfdx DIRECTORY BEFORE DOING ANYTHING. Use the backup to revert everything done during testing.

Link this library to plugin-auth and plugin-org.
Enable Crypto debug output. export DEBUG=sf:crypto and export SF_LOG_LEVEL=trace
You'll probably want to set SF_USE_GENERIC_UNIX_KEYCHAIN=true for initial testing.
Run commands from those plugins without SF_CRYPTO_V2 env var.
Run commands from those plugins with SF_CRYPTO_V2=false.
Run commands from those plugins with SF_CRYPTO_V2=true.
Move the ~/.sfdx dir so that a new key is generated, then:
Run commands from those plugins with SF_CRYPTO_V2=true.

See the doc in the WI for more usecases.

@shetzel shetzel requested a review from a team as a code owner January 25, 2024 17:03
Copy link
Contributor

@mshanemc mshanemc left a comment

Choose a reason for hiding this comment

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

left some comments to get the thinking going.

src/crypto/crypto.ts Outdated Show resolved Hide resolved
src/crypto/crypto.ts Outdated Show resolved Hide resolved
src/crypto/crypto.ts Outdated Show resolved Hide resolved
src/crypto/crypto.ts Show resolved Hide resolved
src/crypto/crypto.ts Outdated Show resolved Hide resolved
@@ -54,20 +98,20 @@ const keychainPromises = {
* @param service The keychain service name.
* @param account The keychain account name.
*/
getPassword(_keychain: KeyChain, service: string, account: string): Promise<CredType> {
getPassword(_keychain: KeyChain, service: string, account: string, encoding: 'utf8' | 'hex'): Promise<CredType> {
const cacheKey = `${Global.DIR}:${service}:${account}`;
const sb = Cache.get<SecureBuffer<string>>(cacheKey);
Copy link
Contributor

Choose a reason for hiding this comment

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

Cache here is an example of overengineering. We could just have a Map<string, SecureBuffer> in this module.

But there's this whole other non-exported class only used by Crypto with methods that aren't being used and a whole test for it, etc.

Copy link
Contributor

Choose a reason for hiding this comment

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

but I can't tell if I'm wrong and it's necessary because of the weird returned promises structure here.

@@ -107,6 +151,13 @@ export class Crypto extends AsyncOptionalCreatable<CryptoOptions> {

private noResetOnClose!: boolean;
Copy link
Contributor

Choose a reason for hiding this comment

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

meta: Crypto is never exported, so its only consumers would be here in core (only configStore).

I've not seen anyone create it with the options. They're not even used in UT to inject stuff.

So I guess if we have to go through QAing this, it's probably the best time to remove all the unused bits?

src/crypto/crypto.ts Outdated Show resolved Hide resolved
src/crypto/crypto.ts Outdated Show resolved Hide resolved
src/crypto/crypto.ts Outdated Show resolved Hide resolved
@shetzel shetzel changed the title fix: support stronger ciphers feat: support stronger ciphers Jan 31, 2024
@cristiand391
Copy link
Member

QA notes:

deleted the sfdx entry from keychain
and linked this branch of core to auth/org/user plugins

fresh start with v2 key

backed up .sfdx and .sf, then deleted them.
SF_CRYPTO_V2=true

mac (native keychain):

✅ auth to a hub with org login web, access/refresh tokens in auth file are encrypted using new cipher.
✅ created scratch org and generated a pwd for it, tokens and pwd encrypted
✅ AT and pwd from org display are correctly decrypted: used with curl to hit the scratch org limits endpoint/can auth with user/pwd
✅ auth with sfdxURL: grabbed it from the scratch org, logged out of all orgs and auth'd using it.
✅ JWT auth

linux and windows (generic keychain)
same results as on mac +
~/.sfdx/key.json contains 64char key.

existing v1 key + auth files with crypto v2 enabled

✅ sfdx-core users v1 crypto even with SF_CRYPTO_V2=true, auth/org commands work

@cristiand391 cristiand391 merged commit dfe8a17 into main Feb 28, 2024
66 checks passed
@cristiand391 cristiand391 deleted the sh/crypto branch February 28, 2024 16:33
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.

4 participants