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

Android AES GCM support via preferedCipher option #123

Closed
wants to merge 1 commit into from
Closed

Android AES GCM support via preferedCipher option #123

wants to merge 1 commit into from

Conversation

Skvuddudutt
Copy link

by Joel's request.

@oblador oblador changed the title WIP. needs cleanup and testing Android AES GCM support via preferedCipher option Mar 29, 2018
@oblador oblador requested review from pcoltau and vonovak March 29, 2018 11:21
@pcoltau
Copy link
Collaborator

pcoltau commented Mar 29, 2018

I'll review this, but I would like to wait until the "cleaning" is done.

@oblador
Copy link
Owner

oblador commented Apr 4, 2018

@pcoltau Unfortunately, this was @Skvuddudutt's last assignment before his contract ended, so wouldn't assume it will be done. Can maybe help with cleaning up some of it later, but would be good if you could glance at the general approach first and see if you think it's worth continuing working on.

@pcoltau
Copy link
Collaborator

pcoltau commented Apr 5, 2018

@oblador

Fair enough - I'll give it a look as soon as time permits..

@Skvuddudutt
Copy link
Author

Skvuddudutt commented Apr 5, 2018 via email

@pcoltau
Copy link
Collaborator

pcoltau commented Apr 29, 2018

My review of this is done.

As @Skvuddudutt says, we need to address some issue before we can merge this. We just need to figure out who should do that. I can't promise that I'll have the time in the near future..

@mvayngrib
Copy link
Contributor

mvayngrib commented May 19, 2019

@pcoltau can you clarify what issue needs to be addressed? If it's "read
behaviour and auto migrating IIRC," could you expand that?

}

private String getPreferedCipherStorage(ReadableMap options) {
String preferedCipher = options.hasKey("preferedCipher") ? options.getString("preferedCipher") : CipherStorageKeystoreAESGCM.CIPHER_OPTION_NAME;
Copy link
Collaborator

Choose a reason for hiding this comment

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

We default to GCM here, which would indicate to the caller of this method that the user prefers GCM, which isn't the case. I would rename this method to getPreferedCipherStorage to getPreferedOrDefaultCipherStorage.

service = getDefaultServiceIfNull(service);

CipherStorage currentCipherStorage = getCipherStorageForCurrentAPILevel();
Log.w("CIPHER","getting generic password");
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm guessing all these logs are for debug purposes? If so, then we should remove them.

} else { // stored encryption data is different from the format we want to use, but we should not auto-migrate
Log.w("CIPHER","used cipher for "+service+":"+resultSet.cipherStorageName+" is old, silently falling back to use it");
CipherStorage oldCipherStorage = getCipherStorageByName(resultSet.cipherStorageName);
decryptionResult = oldCipherStorage.decrypt(service, resultSet.usernameBytes, resultSet.passwordBytes);
Copy link
Collaborator

Choose a reason for hiding this comment

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

If the caller of this method has added the "preferedCipher" option AESGCM, but has used the previous version of this library and thus stored it as AESCBC, then the values won't be migrated here. I'm not sure if they should, but we did that for Conceal (just above).

}

// currentCipherStorage now contains cipher with highest API-level, check if user prefer something else
if (preferedCipher != null && preferedCipher.length() > 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All callers of the method use the getPreferedCipherStorage method, which never returns null or the empty string, so this check is not needed.

"dev": true
}
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why has this been added?

return typeof serviceOrOptions === 'object'
? serviceOrOptions.service
: serviceOrOptions;
}
}*/
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just remove this code instead of commenting it out.

private String getDefaultServiceIfEmpty(@NonNull String service) {
return service.isEmpty() ? DEFAULT_SERVICE : service;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

The implementation of this class is a near copy-paste of the CipherStorageKeystoreAESCBC class (which is understandable, because the code for de-/encryption is nearly the same) - but perhaps we could move much of the shared functionality to a base CipherStorageKeystoreAES class.

}

private String getPreferedCipherStorage(ReadableMap options) {
String preferedCipher = options.hasKey("preferedCipher") ? options.getString("preferedCipher") : CipherStorageKeystoreAESGCM.CIPHER_OPTION_NAME;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Furthermore, we need to both document the preferedCipher string, so that users know that it exists, and perhaps also store it in a constant somewhere, so that it can be used from the RN side.

@pcoltau
Copy link
Collaborator

pcoltau commented Jun 18, 2019

@pcoltau can you clarify what issue needs to be addressed? If it's "read
behaviour and auto migrating IIRC," could you expand that?

I forgot to "commit" my review comments 🙄- that is done now. Let me know if you have any questions.

@dsumac
Copy link

dsumac commented Feb 22, 2021

Does anyone continue to work on this topic?

@gabimoncha
Copy link

I see this PR #513 is doing the same think. Maybe it's more up to date with the master?

@DorianMazur
Copy link
Collaborator

AES GCM will be added with #678

@DorianMazur DorianMazur closed this Nov 4, 2024
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.

7 participants