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

Keymaster CTS Fixes #69

Conversation

subrahmanyaman
Copy link
Contributor

No description provided.

subrahmanyaman and others added 30 commits October 21, 2021 13:34
2. Able to generate key when both FINGERPRINT and BIOMETRIC were passed
as USER_AUTH types.
3. USER_SECURE_ID and NO_AUTH_REQUIRED Mutual exclusive.
2. Validate Tokens in littleEndian and BigEndian formats.
2. Combined cert chain and cert params command in a single command
…_to_static_final

Applet version upgrade move to static final
if (magicNumber != KMKeymasterApplet.KM_MAGIC_NUMBER) {
// Previous version of the applet does not have versioning support.
// In this case the first byte is the provision status.
provisionStatus = magicNumber;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Maybe a good idea to add validation here to ensure provisionStatus is from the enums itself and not something out of bounds etc.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in the meeting no validation is required.

// Previous version of the applet does not have versioning support.
// In this case the first byte is the provision status.
provisionStatus = magicNumber;
keymasterState = element.readByte();
Copy link
Collaborator

Choose a reason for hiding this comment

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

same as above

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in the meeting no validation is required.

ISOException.throwIt(ISO7816.SW_CONDITIONS_NOT_SATISFIED);
}
packageVersion = version;
provisionStatus = element.readByte();
Copy link
Collaborator

Choose a reason for hiding this comment

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

line #68 - 71 seems to be duplicate in if/else. Please optimize.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Optimized the code.

// In this case the first byte is the provision status.
provisionStatus = magicNumber;
keymasterState = element.readByte();
repository.onRestore(element, packageVersion, CURRENT_PACKAGE_VERSION);
Copy link
Collaborator

Choose a reason for hiding this comment

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

what is the value of packageVersion here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated this code. In this scenario the packageVersion is null.
When applet is installed for the first time the package version is set to zeros and when applet is getting upgraded this packageVersion holds the previous package version. And for the old applets where no versioning information this value will be null.

// provisionStatus + keymasterState
return (short) 4;
// provisionStatus + keymasterState + magic byte
return (short) 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Was it a mistake to have "4" before ? As we are reducing the size now while adding more data ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The previous value used to be 2. I even verified the divegeek:Javacard_KM_41_AOSP_UPMerge branch the value is 2 only. May be in this pull request some how it is showing the diff between the previous commits and latest.

short oldMinorVersion = Util.getShort(version, (short) 2);
short currentMajorVersion = Util.getShort(CURRENT_PACKAGE_VERSION, (short) 0);
short currentMinorVersion = Util.getShort(CURRENT_PACKAGE_VERSION, (short) 2);
// Downgrade of the Applet is not allowed.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Check, if we can simplify the logic like this ?

Status = false;
if(currentMajorVersion - oldMajorVersion == 1) {
Status = true;
} else if (currentMajorVersion - oldMajorVersion == 0) {
if(currentMinorVersoin - oldMinorVersion == 1) {
Status = true;
}
return status;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes I used this logic and simplified the code.

computedHmacKey = KMHmacKey.onRestore(element);
short oldMajorVersion = Util.getShort(oldVersion, (short) 0);
short oldMinorVersion = Util.getShort(oldVersion, (short) 2);
if (oldMajorVersion == 0 && oldMinorVersion == 0) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

how do we know that these values will be 0 in olderVersion ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As discussed in this link #69 (comment). The value of the old applets package version will be null. so updated the code accordingly.

2. Removed transactions in onRestore
@mdwivedi mdwivedi merged commit 45eae4d into divegeek:Javacard_KM_41_AOSP_UPMERGE_0630 Dec 2, 2021
mdwivedi pushed a commit that referenced this pull request Jun 1, 2022
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