@@ -9,13 +9,13 @@ use crate::error::{CryptographyError, CryptographyResult};
99use crate :: x509:: { extensions, sct, sign} ;
1010use crate :: { exceptions, x509} ;
1111use cryptography_x509:: common:: Asn1ReadableOrWritable ;
12+ use cryptography_x509:: extensions:: Extension ;
1213use cryptography_x509:: extensions:: {
1314 AuthorityKeyIdentifier , BasicConstraints , DisplayText , DistributionPoint ,
1415 DistributionPointName , MSCertificateTemplate , NameConstraints , PolicyConstraints ,
15- PolicyInformation , PolicyQualifierInfo , Qualifier , SequenceOfAccessDescriptions ,
16+ PolicyInformation , PolicyQualifierInfo , Qualifier , RawExtensions , SequenceOfAccessDescriptions ,
1617 SequenceOfSubtrees , UserNotice ,
1718} ;
18- use cryptography_x509:: extensions:: { Extension , Extensions } ;
1919use cryptography_x509:: { common, name, oid} ;
2020use once_cell:: sync:: Lazy ;
2121use pyo3:: { IntoPy , ToPyObject } ;
@@ -193,9 +193,9 @@ impl Certificate {
193193 let val = self . raw . borrow_value ( ) ;
194194 let mut tbs_precert = val. tbs_cert . clone ( ) ;
195195 // Remove the SCT list extension
196- match tbs_precert . extensions {
197- Some ( extensions) => {
198- let readable_extensions = extensions. unwrap_read ( ) . clone ( ) ;
196+ match val . tbs_cert . extensions ( ) {
197+ Ok ( Some ( extensions) ) => {
198+ let readable_extensions = extensions. as_raw ( ) . unwrap_read ( ) . clone ( ) ;
199199 let ext_count = readable_extensions. len ( ) ;
200200 let filtered_extensions: Vec < Extension < ' _ > > = readable_extensions
201201 . filter ( |x| x. extn_id != oid:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS_OID )
@@ -207,18 +207,26 @@ impl Certificate {
207207 ) ,
208208 ) ) ;
209209 }
210- let filtered_extensions: Extensions < ' _ > = Asn1ReadableOrWritable :: new_write (
210+ let filtered_extensions: RawExtensions < ' _ > = Asn1ReadableOrWritable :: new_write (
211211 asn1:: SequenceOfWriter :: new ( filtered_extensions) ,
212212 ) ;
213- tbs_precert. extensions = Some ( filtered_extensions) ;
213+ tbs_precert. raw_extensions = Some ( filtered_extensions) ;
214214 let result = asn1:: write_single ( & tbs_precert) ?;
215215 Ok ( pyo3:: types:: PyBytes :: new ( py, & result) )
216216 }
217- None => Err ( CryptographyError :: from (
217+ Ok ( None ) => Err ( CryptographyError :: from (
218218 pyo3:: exceptions:: PyValueError :: new_err (
219219 "Could not find any extensions in TBS certificate" ,
220220 ) ,
221221 ) ) ,
222+ Err ( oid) => {
223+ let oid_obj = oid_to_py_oid ( py, & oid) ?;
224+ Err ( exceptions:: DuplicateExtension :: new_err ( (
225+ format ! ( "Duplicate {} extension found" , oid) ,
226+ oid_obj. into_py ( py) ,
227+ ) )
228+ . into ( ) )
229+ }
222230 }
223231 }
224232
@@ -360,7 +368,7 @@ impl Certificate {
360368 x509:: parse_and_cache_extensions (
361369 py,
362370 & mut self . cached_extensions ,
363- & self . raw . borrow_value ( ) . tbs_cert . extensions ,
371+ & self . raw . borrow_value ( ) . tbs_cert . raw_extensions ,
364372 |oid, ext_data| match * oid {
365373 oid:: PRECERT_POISON_OID => {
366374 asn1:: parse_single :: < ( ) > ( ext_data) ?;
@@ -1035,7 +1043,7 @@ fn create_x509_certificate(
10351043 spki : asn1:: parse_single ( spki_bytes) ?,
10361044 issuer_unique_id : None ,
10371045 subject_unique_id : None ,
1038- extensions : x509:: common:: encode_extensions (
1046+ raw_extensions : x509:: common:: encode_extensions (
10391047 py,
10401048 builder. getattr ( pyo3:: intern!( py, "_extensions" ) ) ?,
10411049 extensions:: encode_extension,
0 commit comments