1
1
//! Certificate tests
2
2
#![ allow( clippy:: bool_assert_comparison) ]
3
+ use const_oid:: db:: rfc5280:: * ;
4
+ use const_oid:: db:: rfc5912:: ID_CE_CERTIFICATE_POLICIES ;
3
5
use const_oid:: AssociatedOid ;
4
6
use der:: asn1:: { Ia5StringRef , OctetString , PrintableStringRef , Utf8StringRef } ;
7
+ use der:: TagNumber ;
5
8
use der:: { Decode , Encode , ErrorKind , Length , Tag , Tagged } ;
6
9
use hex_literal:: hex;
7
10
use x509_cert:: ext:: pkix:: crl:: dp:: { DistributionPoint , ReasonFlags , Reasons } ;
@@ -11,9 +14,6 @@ use x509_cert::ext::Extensions;
11
14
use x509_cert:: name:: Name ;
12
15
use x509_cert:: { serial_number:: SerialNumber , Certificate , Version } ;
13
16
14
- use const_oid:: db:: rfc5280:: * ;
15
- use const_oid:: db:: rfc5912:: ID_CE_CERTIFICATE_POLICIES ;
16
-
17
17
fn spin_over_exts ( exts : & Extensions ) {
18
18
for ext in exts {
19
19
match ext. extn_id {
@@ -840,8 +840,6 @@ fn decode_cert() {
840
840
841
841
#[ test]
842
842
fn decode_idp ( ) {
843
- use der:: TagNumber ;
844
-
845
843
// IDP from 04A8739769B3C090A11DCDFABA3CF33F4BEF21F3.crl in PKITS 2048 in ficam-scvp-testing repo
846
844
let idp = IssuingDistributionPoint :: from_der ( & hex ! ( "30038201FF" ) ) . unwrap ( ) ;
847
845
assert_eq ! ( idp. only_contains_ca_certs, true ) ;
@@ -1109,10 +1107,13 @@ fn decode_idp() {
1109
1107
panic ! ( "Expected FullName" )
1110
1108
}
1111
1109
}
1110
+ }
1112
1111
1113
- //---------------------------------
1114
- // Negative tests
1115
- //---------------------------------
1112
+ //---------------------------------
1113
+ // Negative tests
1114
+ //---------------------------------
1115
+ #[ test]
1116
+ fn decode_idp_negative_reasonflags ( ) {
1116
1117
// Value contains more than length value indicates
1117
1118
let reason_flags = ReasonFlags :: from_der ( & hex ! ( "0302079F80" ) ) ;
1118
1119
let err = reason_flags. err ( ) . unwrap ( ) ;
@@ -1135,19 +1136,6 @@ fn decode_idp() {
1135
1136
err. kind( )
1136
1137
) ;
1137
1138
1138
- // Value incomplete relative to length value
1139
- let idp =
1140
- IssuingDistributionPoint :: from_der ( & hex ! ( "3067A060A05EA45C305A310B3009060355040613025553311F301D060355040A131654657374204365727469666963617465732032303137311C301A060355040B13136F6E6C79536F6D65526561736F6E7320434133310C300A0603550403130343524C8304079F80" ) ) ;
1141
- let err = idp. err ( ) . unwrap ( ) ;
1142
- assert_eq ! ( err. position( ) . unwrap( ) , 103u8 . into( ) ) ;
1143
- assert_eq ! (
1144
- ErrorKind :: Incomplete {
1145
- expected_len: 106u8 . into( ) ,
1146
- actual_len: 105u8 . into( )
1147
- } ,
1148
- err. kind( )
1149
- ) ;
1150
-
1151
1139
// Truncated
1152
1140
let reason_flags = ReasonFlags :: from_der ( & hex ! ( "0303079F" ) ) ;
1153
1141
let err = reason_flags. err ( ) . unwrap ( ) ;
@@ -1174,7 +1162,26 @@ fn decode_idp() {
1174
1162
} ,
1175
1163
err. kind( )
1176
1164
) ;
1165
+ }
1166
+
1167
+ #[ test]
1168
+ fn decode_idp_negative_incomplete ( ) {
1169
+ // Value incomplete relative to length value
1170
+ let idp =
1171
+ IssuingDistributionPoint :: from_der ( & hex ! ( "3067A060A05EA45C305A310B3009060355040613025553311F301D060355040A131654657374204365727469666963617465732032303137311C301A060355040B13136F6E6C79536F6D65526561736F6E7320434133310C300A0603550403130343524C8304079F80" ) ) ;
1172
+ let err = idp. err ( ) . unwrap ( ) ;
1173
+ assert_eq ! ( err. position( ) . unwrap( ) , 103u8 . into( ) ) ;
1174
+ assert_eq ! (
1175
+ ErrorKind :: Incomplete {
1176
+ expected_len: 106u8 . into( ) ,
1177
+ actual_len: 105u8 . into( )
1178
+ } ,
1179
+ err. kind( )
1180
+ ) ;
1181
+ }
1177
1182
1183
+ #[ test]
1184
+ fn decode_idp_negative_constructed ( ) {
1178
1185
// Context specific tag that should be primitive is constructed
1179
1186
let idp = IssuingDistributionPoint :: from_der ( & hex ! ( "3003A201FF" ) ) ;
1180
1187
let err = idp. err ( ) . unwrap ( ) ;
@@ -1187,19 +1194,28 @@ fn decode_idp() {
1187
1194
} ,
1188
1195
err. kind( )
1189
1196
) ;
1197
+ }
1190
1198
1199
+ #[ test]
1200
+ fn decode_idp_negative_bool_long ( ) {
1191
1201
// Boolean value is two bytes long
1192
1202
let idp =
1193
1203
IssuingDistributionPoint :: from_der ( & hex ! ( "30820168A0820161A082015DA4753073310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434136A4753073310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434137A46D306B310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353121301F0603550403131843524C3120666F7220696E64697265637443524C204341358402FFFF" ) ) ;
1194
1204
let err = idp. err ( ) . unwrap ( ) ;
1195
1205
assert_eq ! ( ErrorKind :: Length { tag: Tag :: Boolean } , err. kind( ) ) ;
1206
+ }
1196
1207
1208
+ #[ test]
1209
+ fn decode_idp_negative_bool_invalid ( ) {
1197
1210
// Boolean value is neither 0x00 nor 0xFF
1198
1211
let idp =
1199
1212
IssuingDistributionPoint :: from_der ( & hex ! ( "30820168A0820161A082015DA4753073310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434136A4753073310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434137A46D306B310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353121301F0603550403131843524C3120666F7220696E64697265637443524C20434135840175" ) ) ;
1200
1213
let err = idp. err ( ) . unwrap ( ) ;
1201
1214
assert_eq ! ( ErrorKind :: Noncanonical { tag: Tag :: Boolean } , err. kind( ) ) ;
1215
+ }
1202
1216
1217
+ #[ test]
1218
+ fn decode_idp_negative_length_rdn ( ) {
1203
1219
// Length on second RDN in first name indicates more bytes than are present
1204
1220
let idp =
1205
1221
IssuingDistributionPoint :: from_der ( & hex ! ( "30820168A0820161A082015DA4753073310B3009060355040613025553311F301D060355040A13995465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434136A4753073310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353129302706035504031320696E6469726563742043524C20666F7220696E64697265637443524C20434137A46D306B310B3009060355040613025553311F301D060355040A13165465737420436572746966696361746573203230313731183016060355040B130F696E64697265637443524C204341353121301F0603550403131843524C3120666F7220696E64697265637443524C204341358401FF" ) ) ;
0 commit comments