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

reject non canonical encoding length. #29

Merged
merged 1 commit into from
Feb 21, 2024
Merged

Conversation

longlongyang
Copy link
Collaborator

fix #28.

length[i] = *b;
let length_byte0 = data[0];
let (length, byte_comsumed) = match length_byte0 {
n if (n & 0x80) == 0 => (n as usize, 1),
Copy link
Member

Choose a reason for hiding this comment

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

please don't use hardcoded 0x80 or 0x81.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please don't use hardcoded 0x80 or 0x81.

updated.

@@ -25,7 +25,6 @@ const ASN1_TAG_SEQUENCE: u8 =
ASN1_TAG_CLASS_UNIVERSAL_MASK | ASN1_FORM_CONSTRUCTED_MASK | ASN1_TAG_NUMBER_SEQUENCE;
const ASN1_TAG_EXPLICIT_EXTENSION: u8 = 0xA3;
const ASN1_TAG_EXTN_VALUE: u8 = 0x04;
const ASN1_LENGTH_MULTI_OCTET_MASK: u8 = 0x80;
Copy link
Member

Choose a reason for hiding this comment

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

why remove it?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

why remove it?

updated.

let length_byte0 = data[0];
let (length, byte_comsumed) = match length_byte0 {
n if (n & ASN1_LENGTH_MULTI_OCTET_MASK) == 0 => (n as usize, 1),
one_octet if one_octet == ASN1_LENGTH_MULTI_OCTET_MASK + 1 => {
Copy link
Member

Choose a reason for hiding this comment

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

please define a new static variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please define a new static variable.

updated.

}
Ok((usize::from_le_bytes(length), length_count as usize + 1))
}
two_octet if two_octet == ASN1_LENGTH_MULTI_OCTET_MASK + 2 => {
Copy link
Member

Choose a reason for hiding this comment

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

please define a new static variable.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

please define a new static variable.

updated.

@jyao1 jyao1 merged commit 6b6d756 into ccc-spdm-tools:main Feb 21, 2024
47 checks passed
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.

function check_length in x509v3.rs doesn't reject non canonical encoding length
2 participants