@@ -9,13 +9,13 @@ use crate::error::{CryptographyError, CryptographyResult};
9
9
use crate :: x509:: { extensions, sct, sign} ;
10
10
use crate :: { exceptions, x509} ;
11
11
use cryptography_x509:: common:: Asn1ReadableOrWritable ;
12
+ use cryptography_x509:: extensions:: Extension ;
12
13
use cryptography_x509:: extensions:: {
13
14
AuthorityKeyIdentifier , BasicConstraints , DisplayText , DistributionPoint ,
14
15
DistributionPointName , MSCertificateTemplate , NameConstraints , PolicyConstraints ,
15
- PolicyInformation , PolicyQualifierInfo , Qualifier , SequenceOfAccessDescriptions ,
16
+ PolicyInformation , PolicyQualifierInfo , Qualifier , RawExtensions , SequenceOfAccessDescriptions ,
16
17
SequenceOfSubtrees , UserNotice ,
17
18
} ;
18
- use cryptography_x509:: extensions:: { Extension , Extensions } ;
19
19
use cryptography_x509:: { common, name, oid} ;
20
20
use once_cell:: sync:: Lazy ;
21
21
use pyo3:: { IntoPy , ToPyObject } ;
@@ -193,9 +193,9 @@ impl Certificate {
193
193
let val = self . raw . borrow_value ( ) ;
194
194
let mut tbs_precert = val. tbs_cert . clone ( ) ;
195
195
// 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 ( ) ;
199
199
let ext_count = readable_extensions. len ( ) ;
200
200
let filtered_extensions: Vec < Extension < ' _ > > = readable_extensions
201
201
. filter ( |x| x. extn_id != oid:: PRECERT_SIGNED_CERTIFICATE_TIMESTAMPS_OID )
@@ -207,18 +207,26 @@ impl Certificate {
207
207
) ,
208
208
) ) ;
209
209
}
210
- let filtered_extensions: Extensions < ' _ > = Asn1ReadableOrWritable :: new_write (
210
+ let filtered_extensions: RawExtensions < ' _ > = Asn1ReadableOrWritable :: new_write (
211
211
asn1:: SequenceOfWriter :: new ( filtered_extensions) ,
212
212
) ;
213
- tbs_precert. extensions = Some ( filtered_extensions) ;
213
+ tbs_precert. raw_extensions = Some ( filtered_extensions) ;
214
214
let result = asn1:: write_single ( & tbs_precert) ?;
215
215
Ok ( pyo3:: types:: PyBytes :: new ( py, & result) )
216
216
}
217
- None => Err ( CryptographyError :: from (
217
+ Ok ( None ) => Err ( CryptographyError :: from (
218
218
pyo3:: exceptions:: PyValueError :: new_err (
219
219
"Could not find any extensions in TBS certificate" ,
220
220
) ,
221
221
) ) ,
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
+ }
222
230
}
223
231
}
224
232
@@ -360,7 +368,7 @@ impl Certificate {
360
368
x509:: parse_and_cache_extensions (
361
369
py,
362
370
& mut self . cached_extensions ,
363
- & self . raw . borrow_value ( ) . tbs_cert . extensions ,
371
+ & self . raw . borrow_value ( ) . tbs_cert . raw_extensions ,
364
372
|oid, ext_data| match * oid {
365
373
oid:: PRECERT_POISON_OID => {
366
374
asn1:: parse_single :: < ( ) > ( ext_data) ?;
@@ -1035,7 +1043,7 @@ fn create_x509_certificate(
1035
1043
spki : asn1:: parse_single ( spki_bytes) ?,
1036
1044
issuer_unique_id : None ,
1037
1045
subject_unique_id : None ,
1038
- extensions : x509:: common:: encode_extensions (
1046
+ raw_extensions : x509:: common:: encode_extensions (
1039
1047
py,
1040
1048
builder. getattr ( pyo3:: intern!( py, "_extensions" ) ) ?,
1041
1049
extensions:: encode_extension,
0 commit comments