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

Add CMS Implimentation and support of Windows Autheticode Code Signing #83

Merged
merged 19 commits into from
May 27, 2021

Conversation

RRRadicalEdward
Copy link
Collaborator

- Remove hardcoded sha256 hash alog in into_win_certificate func
- Intermediate certificate is a signer certificate
- SignedData::certificates should contain leaf and any intermediate
  certificates, but doesn't contain the root certificate
- Add support of default Certificate::version field processing while deserializing
  and serializing
- Replace SpcLink::File AplicationTag2 with ContextTag2
- Add new_rsa_encypthion_with_sha func to AlgorithmIdentifier
- Add padding processing to the WinCertificate::certificat vector
- Add ApplicationTag0 to SpcImageData::SpcLink as otherwise Authenticode singature is invalid
- Documentation and general renaming according to the CMS RFC
Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

PKCS7 implementation looks good, but I have a few change requests related to API and others details.

@@ -285,4 +305,14 @@ mod tests {
fn valid_utf8_string() {
Utf8String::from_str("1224na÷日本語はむずかちー−×—«BUeisuteurnt").expect("invalid string");
}

#[test]
fn valid_unicode_string() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn valid_unicode_string() {
fn valid_bmp_string() {

}

#[test]
fn invalid_unicode_string() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn invalid_unicode_string() {
fn invalid_bmp_string() {

@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
oid = { version = "0.2", features = ["serde_support"] }
base64 = "0.13"
num-bigint-dig = { version = "0.7", optional = true }
widestring = "0.4.3"
Copy link
Member

Choose a reason for hiding this comment

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

Disable unused features:

Suggested change
widestring = "0.4.3"
widestring = { version = "0.4", default-features = false }

(also we don't specify patch version number in this repo)

@@ -21,6 +21,7 @@ serde = { version = "1.0", features = ["derive"] }
oid = { version = "0.2", features = ["serde_support"] }
base64 = "0.13"
num-bigint-dig = { version = "0.7", optional = true }
widestring = "0.4.3"
Copy link
Member

Choose a reason for hiding this comment

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

Put this behind a pkcs7 feature for now

Comment on lines 157 to 160
PKCS7 => pkcs7 => "1.2.840.113549.1.7.1",
SIGNED_DATA => signed_data => "1.2.840.113549.1.7.2",
CONTENT_TYPE => content_type => "1.2.840.113549.1.9.3",
MESSAGE_DIGEST => message_digest => "1.2.840.113549.1.9.4",
Copy link
Member

Choose a reason for hiding this comment

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

Move this under the // RSADSI comment in increasing order

Comment on lines 132 to 135
/// SpcAttributeTypeAndOptionalValue ::= SEQUENCE {
/// type ObjectID,
/// value [0] EXPLICIT ANY OPTIONAL
/// }
Copy link
Member

Choose a reason for hiding this comment

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

This should be the docstring of SpcAttributeAndOptionalValue

Comment on lines 207 to 211
/// SpcLink ::= CHOICE {
/// url [0] IMPLICIT IA5STRING,
/// moniker [1] IMPLICIT SpcSerializedObject,
/// file [2] EXPLICIT SpcString
/// } --#public--
Copy link
Member

Choose a reason for hiding this comment

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

Put in SpcLink's docstring

Comment on lines 213 to 216
/// SpcString ::= CHOICE {
/// unicode [0] IMPLICIT BMPSTRING,
/// ascii [1] IMPLICIT IA5STRING
/// }
Copy link
Member

Choose a reason for hiding this comment

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

In SpcString's docstring

Comment on lines 201 to 205
/// SpcPeImageFlags ::= BIT STRING {
/// includeResources (0),
/// includeDebugInfo (1),
/// includeImportAddressTable (2)
/// }
Copy link
Member

Choose a reason for hiding this comment

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

In SpcPeImageFlags's docstring.

Comment on lines 13 to 20
/// RevocationInfoChoice ::= CHOICE {
/// crl CertificateList,
/// other [1] IMPLICIT OtherRevocationInfoFormat }
///
/// OtherRevocationInfoFormat ::= SEQUENCE {
/// otherRevInfoFormat OBJECT IDENTIFIER,
/// otherRevInfo ANY DEFINED BY otherRevInfoFormat }
/// ```
Copy link
Member

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
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

Thank you! Minor changes are required. As for the CI, I sent a PR to update the rust toolchain, no action is required on your part.

Comment on lines 260 to 266
let buffer = data
.chunks_exact(2)
.into_iter()
.map(|elem| u16::from_be_bytes([elem[1], elem[0]]))
.collect::<Vec<u16>>();

String::from_utf16(buffer.as_ref()).is_ok()
Copy link
Member

Choose a reason for hiding this comment

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

Oops, I didn't realize it got stabilized recently. I'll update wayk-builders so it builds, no problem.

Comment on lines +113 to +129
/// TBSCertList ::= SEQUENCE {
/// version Version OPTIONAL,
/// -- if present, MUST be v2
/// signature AlgorithmIdentifier,
/// issuer Name,
/// thisUpdate Time,
/// nextUpdate Time OPTIONAL,
/// revokedCertificates SEQUENCE OF SEQUENCE {
/// userCertificate CertificateSerialNumber,
/// revocationDate Time,
/// crlEntryExtensions Extensions OPTIONAL
/// -- if present, version MUST be v2
/// } OPTIONAL,
/// crlExtensions [0] EXPLICIT Extensions OPTIONAL
/// -- if present, version MUST be v2
/// }
/// ```
Copy link
Member

Choose a reason for hiding this comment

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

Sorry, maybe I missed in the first review, but this one should be in the docstring of TBSCertList

Comment on lines 21 to 23
/// DigestAlgorithmIdentifiers ::= SET OF DigestAlgorithmIdentifier
///
/// SignerInfos ::= SET OF SignerInfo
Copy link
Member

Choose a reason for hiding this comment

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

Same as above

Comment on lines 20 to 28
/// SignerIdentifier ::= CHOICE {
/// issuerAndSerialNumber IssuerAndSerialNumber,
/// subjectKeyIdentifier [0] SubjectKeyIdentifier }
///
/// SignedAttributes ::= SET SIZE (1..MAX) OF Attribute
///
/// UnsignedAttributes ::= SET SIZE (1..MAX) OF Attribute
///
/// SignatureValue ::= OCTET STRING
Copy link
Member

Choose a reason for hiding this comment

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

Same as above (if we define a type)

@@ -29,6 +47,39 @@ impl From<HashAlgorithm> for rsa::Hash {
}
}
}
impl TryFrom<HashAlgorithm> for SHAVariant {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
impl TryFrom<HashAlgorithm> for SHAVariant {
impl TryFrom<HashAlgorithm> for SHAVariant {

@@ -126,6 +126,11 @@
//!# Ok(())
//!# }
//! ```
#[cfg(feature = "pkcs7")]
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[cfg(feature = "pkcs7")]
#[cfg(feature = "pkcs7")]

picky/src/pem.rs Outdated
Comment on lines 259 to 260
#[cfg(not(windows))]
// This test should not run on Windows. writeln! add `/r` ending character to Pem in String format on Windows targets.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[cfg(not(windows))]
// This test should not run on Windows. writeln! add `/r` ending character to Pem in String format on Windows targets.
// This test should not run on Windows. writeln! add `/r` ending character to Pem in String format on Windows targets.
#[cfg(not(windows))]

Comment on lines 14 to 15
pub const AUTHENTICODE_ATTRIBUTES_COUNT: usize = 3;

Copy link
Member

Choose a reason for hiding this comment

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

We probably don't need that at all? Is that something you use in consumer code?

Suggested change
pub const AUTHENTICODE_ATTRIBUTES_COUNT: usize = 3;

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, We don't need it. I forget to remove it.

#[error("Certificates must contain at least Leaf and Intermediate certificates, but got no certificates")]
NoCertificates,
}
const PKCS7_PEM_LABEL: &str = "PKCS7";
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const PKCS7_PEM_LABEL: &str = "PKCS7";
const PKCS7_PEM_LABEL: &str = "PKCS7";

@RRRadicalEdward
Copy link
Collaborator Author

RRRadicalEdward commented May 27, 2021

@CBenoit I resolved the latest issues. Is there still something that blocks the merging that I missed? 🙂

Copy link
Member

@CBenoit CBenoit left a comment

Choose a reason for hiding this comment

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

Thank you, this looks good to me! 😄

(I just moved a docstring around, since it's not much I went ahead and pushed directly)

@RRRadicalEdward
Copy link
Collaborator Author

RRRadicalEdward commented May 27, 2021

Thank you, this looks good to me! 😄

(I just moved a docstring around, since it's not much I went ahead and pushed directly)

Thank you for the review. picky is awesome.

@RRRadicalEdward
Copy link
Collaborator Author

@awakecoding Could you approve this PR?

Copy link
Contributor

@awakecoding awakecoding left a comment

Choose a reason for hiding this comment

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

LGTM

@RRRadicalEdward
Copy link
Collaborator Author

@CBenoit Could you merge it? Seems like I cannot merge because of falling CI checks.

@awakecoding
Copy link
Contributor

@RRRadicalEdward Benoit has been working on fixing the CI with the Rust update, it should be updated soon

@CBenoit
Copy link
Member

CBenoit commented May 27, 2021

CI is green!
@RRRadicalEdward I'll publish a new version of picky & ci 🙂

@CBenoit CBenoit merged commit 3834f93 into master May 27, 2021
@CBenoit CBenoit deleted the authenticode branch May 27, 2021 17:25
@CBenoit CBenoit mentioned this pull request May 27, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants