@@ -10,7 +10,7 @@ use crate::{
1010 Certificate , CertificateParams , Error , Issuer , PublicKeyData , SignatureAlgorithm , SigningKey ,
1111} ;
1212#[ cfg( feature = "x509-parser" ) ]
13- use crate :: { DistinguishedName , SanType } ;
13+ use crate :: { DistinguishedName , ExtendedKeyUsagePurpose , KeyUsagePurpose , SanType } ;
1414
1515/// A public key, extracted from a CSR
1616#[ derive( Clone , Debug , PartialEq , Eq , Hash ) ]
@@ -75,7 +75,7 @@ pub struct CertificateSigningRequestParams {
7575}
7676
7777impl CertificateSigningRequestParams {
78- /// Parse a certificate signing request from the ASCII PEM format
78+ /// Parse and verify a certificate signing request from the ASCII PEM format
7979 ///
8080 /// See [`from_der`](Self::from_der) for more details.
8181 #[ cfg( all( feature = "pem" , feature = "x509-parser" ) ) ]
@@ -84,9 +84,13 @@ impl CertificateSigningRequestParams {
8484 Self :: from_der ( & csr. contents ( ) . into ( ) )
8585 }
8686
87- /// Parse a certificate signing request from DER-encoded bytes
87+ /// Parse and verify a certificate signing request from DER-encoded bytes
88+ ///
89+ /// Currently, this supports the following extensions:
90+ /// - `Subject Alternative Name` (see [`SanType`])
91+ /// - `Key Usage` (see [`KeyUsagePurpose`])
92+ /// - `Extended Key Usage` (see [`ExtendedKeyUsagePurpose`])
8893 ///
89- /// Currently, this only supports the `Subject Alternative Name` extension.
9094 /// On encountering other extensions, this function will return an error.
9195 ///
9296 /// [`rustls_pemfile::csr()`] is often used to obtain a [`CertificateSigningRequestDer`] from
@@ -96,7 +100,6 @@ impl CertificateSigningRequestParams {
96100 /// [`rustls_pemfile::csr()`]: https://docs.rs/rustls-pemfile/latest/rustls_pemfile/fn.csr.html
97101 #[ cfg( feature = "x509-parser" ) ]
98102 pub fn from_der ( csr : & CertificateSigningRequestDer < ' _ > ) -> Result < Self , Error > {
99- use crate :: KeyUsagePurpose ;
100103 use x509_parser:: prelude:: FromDer ;
101104
102105 let csr = x509_parser:: certification_request:: X509CertificationRequest :: from_der ( csr)
@@ -135,37 +138,27 @@ impl CertificateSigningRequestParams {
135138 } ,
136139 x509_parser:: extensions:: ParsedExtension :: ExtendedKeyUsage ( eku) => {
137140 if eku. any {
138- params. insert_extended_key_usage ( crate :: ExtendedKeyUsagePurpose :: Any ) ;
141+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: Any ) ;
139142 }
140143 if eku. server_auth {
141- params. insert_extended_key_usage (
142- crate :: ExtendedKeyUsagePurpose :: ServerAuth ,
143- ) ;
144+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: ServerAuth ) ;
144145 }
145146 if eku. client_auth {
146- params. insert_extended_key_usage (
147- crate :: ExtendedKeyUsagePurpose :: ClientAuth ,
148- ) ;
147+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: ClientAuth ) ;
149148 }
150149 if eku. code_signing {
151- params. insert_extended_key_usage (
152- crate :: ExtendedKeyUsagePurpose :: CodeSigning ,
153- ) ;
150+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: CodeSigning ) ;
154151 }
155152 if eku. email_protection {
156153 params. insert_extended_key_usage (
157- crate :: ExtendedKeyUsagePurpose :: EmailProtection ,
154+ ExtendedKeyUsagePurpose :: EmailProtection ,
158155 ) ;
159156 }
160157 if eku. time_stamping {
161- params. insert_extended_key_usage (
162- crate :: ExtendedKeyUsagePurpose :: TimeStamping ,
163- ) ;
158+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: TimeStamping ) ;
164159 }
165160 if eku. ocsp_signing {
166- params. insert_extended_key_usage (
167- crate :: ExtendedKeyUsagePurpose :: OcspSigning ,
168- ) ;
161+ params. insert_extended_key_usage ( ExtendedKeyUsagePurpose :: OcspSigning ) ;
169162 }
170163 if !eku. other . is_empty ( ) {
171164 return Err ( Error :: UnsupportedExtension ) ;
@@ -178,7 +171,6 @@ impl CertificateSigningRequestParams {
178171
179172 // Not yet handled:
180173 // * is_ca
181- // * extended_key_usages
182174 // * name_constraints
183175 // and any other extensions.
184176
0 commit comments