1# 2# This file is part of pyasn1-modules software. 3# 4# Created by Russ Housley 5# Copyright (c) 2019, Vigil Security, LLC 6# License: http://snmplabs.com/pyasn1/license.html 7# 8 9import sys 10 11from pyasn1.codec.der.decoder import decode as der_decode 12from pyasn1.codec.der.encoder import encode as der_encode 13 14from pyasn1.type import univ 15 16from pyasn1_modules import pem 17from pyasn1_modules import rfc5280 18from pyasn1_modules import rfc3279 19 20try: 21 import unittest2 as unittest 22except ImportError: 23 import unittest 24 25class RSACertificateTestCase(unittest.TestCase): 26 rsa_cert_pem_text = """\ 27MIIE8TCCA9mgAwIBAgIQbyXcFa/fXqMIVgw7ek/H+DANBgkqhkiG9w0BAQUFADBv 28MQswCQYDVQQGEwJTRTEUMBIGA1UEChMLQWRkVHJ1c3QgQUIxJjAkBgNVBAsTHUFk 29ZFRydXN0IEV4dGVybmFsIFRUUCBOZXR3b3JrMSIwIAYDVQQDExlBZGRUcnVzdCBF 30eHRlcm5hbCBDQSBSb290MB4XDTAwMDUzMDEwNDgzOFoXDTIwMDUzMDEwNDgzOFow 31gYExCzAJBgNVBAYTAkdCMRswGQYDVQQIExJHcmVhdGVyIE1hbmNoZXN0ZXIxEDAO 32BgNVBAcTB1NhbGZvcmQxGjAYBgNVBAoTEUNPTU9ETyBDQSBMaW1pdGVkMScwJQYD 33VQQDEx5DT01PRE8gQ2VydGlmaWNhdGlvbiBBdXRob3JpdHkwggEiMA0GCSqGSIb3 34DQEBAQUAA4IBDwAwggEKAoIBAQDQQIuLcuORG/dRwRtUBJjTqb/B5opdO4f7u4jO 35DeMvPwaW8KIpUJmu2zuhV7B0UXHN7UKRTUH+qcjYaoZ3RLtZZpdQXrTULHBEz9o3 36lUJpPDDEcbNS8CFNodi6OXwcnqMknfKDFpiqFnxDmxVbt640kf7UYiYYRpo/68H5 378ZBX66x6DYvbcjBqZtXgRqNw3GjZ/wRIiXfeten7Z21B6bw5vTLZYgLxsag9bjec 384i/i06Imi8a4VUOI4SM+pdIkOWpHqwDUobOpJf4NP6cdutNRwQuk2qw471VQJAVl 39RpM0Ty2NrcbUIRnSjsoFYXEHc0flihkSvQRNzk6cpUisuyb3AgMBAAGjggF0MIIB 40cDAfBgNVHSMEGDAWgBStvZh6NLQm9/rEJlTvA73gJMtUGjAdBgNVHQ4EFgQUC1jl 41i8ZMFTekQKkwqSG+RzZaVv8wDgYDVR0PAQH/BAQDAgEGMA8GA1UdEwEB/wQFMAMB 42Af8wEQYDVR0gBAowCDAGBgRVHSAAMEQGA1UdHwQ9MDswOaA3oDWGM2h0dHA6Ly9j 43cmwudXNlcnRydXN0LmNvbS9BZGRUcnVzdEV4dGVybmFsQ0FSb290LmNybDCBswYI 44KwYBBQUHAQEEgaYwgaMwPwYIKwYBBQUHMAKGM2h0dHA6Ly9jcnQudXNlcnRydXN0 45LmNvbS9BZGRUcnVzdEV4dGVybmFsQ0FSb290LnA3YzA5BggrBgEFBQcwAoYtaHR0 46cDovL2NydC51c2VydHJ1c3QuY29tL0FkZFRydXN0VVROU0dDQ0EuY3J0MCUGCCsG 47AQUFBzABhhlodHRwOi8vb2NzcC51c2VydHJ1c3QuY29tMA0GCSqGSIb3DQEBBQUA 48A4IBAQAHYJOZqs7Q00fQNzPeP2S35S6jJQzVMx0Njav2fkZ7WQaS44LE5/X289kF 49z0k0LTdf9CXH8PtrI3fx8UDXTLtJRTHdAChntylMdagfeTHJNjcPyjVPjPF+3vxG 50q79om3AjMC63xVx7ivsYE3lLkkKM3CyrbCK3KFOzGkrOG/soDrc6pNoN90AyT99v 51uwFQ/IfTdtn8+7aEA8rJNhj33Wzbu7qBHKat/ij5z7micV0ZBepKRtxzQe+JlEKx 52Q4hvNRevHmCDrHqMEHufyfaDbZ76iO4+3e6esL/garnQnweyCROa9aTlyFt5p0c1 53M2jlVZ6qW8swC53HD79oRIGXi1FK 54""" 55 56 def setUp(self): 57 self.asn1Spec = rfc5280.Certificate() 58 59 def testDerCodec(self): 60 substrate = pem.readBase64fromText(self.rsa_cert_pem_text) 61 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 62 assert not rest 63 assert asn1Object.prettyPrint() 64 assert der_encode(asn1Object) == substrate 65 66 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 67 assert spki_a['algorithm'] == rfc3279.rsaEncryption 68 69 spki_pk = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['subjectPublicKey'].asOctets() 70 pk, rest = der_decode(spki_pk, asn1Spec=rfc3279.RSAPublicKey()) 71 assert not rest 72 assert pk.prettyPrint() 73 assert der_encode(pk) == spki_pk 74 assert pk['publicExponent'] == 65537 75 76 assert asn1Object['tbsCertificate']['signature']['algorithm'] == rfc3279.sha1WithRSAEncryption 77 assert asn1Object['signatureAlgorithm']['algorithm'] == rfc3279.sha1WithRSAEncryption 78 79 def testOpenTypes(self): 80 substrate = pem.readBase64fromText(self.rsa_cert_pem_text) 81 asn1Object, rest = der_decode(substrate, 82 asn1Spec=self.asn1Spec, 83 decodeOpenTypes=True) 84 assert not rest 85 assert asn1Object.prettyPrint() 86 assert der_encode(asn1Object) == substrate 87 88 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 89 assert spki_a['algorithm'] == rfc3279.rsaEncryption 90 assert spki_a['parameters'] == univ.Null("") 91 92 93class ECCertificateTestCase(unittest.TestCase): 94 ec_cert_pem_text = """\ 95MIIDrDCCApSgAwIBAgIQCssoukZe5TkIdnRw883GEjANBgkqhkiG9w0BAQwFADBh 96MQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3 97d3cuZGlnaWNlcnQuY29tMSAwHgYDVQQDExdEaWdpQ2VydCBHbG9iYWwgUm9vdCBD 98QTAeFw0xMzAzMDgxMjAwMDBaFw0yMzAzMDgxMjAwMDBaMEwxCzAJBgNVBAYTAlVT 99MRUwEwYDVQQKEwxEaWdpQ2VydCBJbmMxJjAkBgNVBAMTHURpZ2lDZXJ0IEVDQyBT 100ZWN1cmUgU2VydmVyIENBMHYwEAYHKoZIzj0CAQYFK4EEACIDYgAE4ghC6nfYJN6g 101LGSkE85AnCNyqQIKDjc/ITa4jVMU9tWRlUvzlgKNcR7E2Munn17voOZ/WpIRllNv 10268DLP679Wz9HJOeaBy6Wvqgvu1cYr3GkvXg6HuhbPGtkESvMNCuMo4IBITCCAR0w 103EgYDVR0TAQH/BAgwBgEB/wIBADAOBgNVHQ8BAf8EBAMCAYYwNAYIKwYBBQUHAQEE 104KDAmMCQGCCsGAQUFBzABhhhodHRwOi8vb2NzcC5kaWdpY2VydC5jb20wQgYDVR0f 105BDswOTA3oDWgM4YxaHR0cDovL2NybDMuZGlnaWNlcnQuY29tL0RpZ2lDZXJ0R2xv 106YmFsUm9vdENBLmNybDA9BgNVHSAENjA0MDIGBFUdIAAwKjAoBggrBgEFBQcCARYc 107aHR0cHM6Ly93d3cuZGlnaWNlcnQuY29tL0NQUzAdBgNVHQ4EFgQUo53mH/naOU/A 108buiRy5Wl2jHiCp8wHwYDVR0jBBgwFoAUA95QNVbRTLtm8KPiGxvDl7I90VUwDQYJ 109KoZIhvcNAQEMBQADggEBAMeKoENL7HTJxavVHzA1Nm6YVntIrAVjrnuaVyRXzG/6 1103qttnMe2uuzO58pzZNvfBDcKAEmzP58mrZGMIOgfiA4q+2Y3yDDo0sIkp0VILeoB 111UEoxlBPfjV/aKrtJPGHzecicZpIalir0ezZYoyxBEHQa0+1IttK7igZFcTMQMHp6 112mCHdJLnsnLWSB62DxsRq+HfmNb4TDydkskO/g+l3VtsIh5RHFPVfKK+jaEyDj2D3 113loB5hWp2Jp2VDCADjT7ueihlZGak2YPqmXTNbk19HOuNssWvFhtOyPNV6og4ETQd 114Ea8/B6hPatJ0ES8q/HO3X8IVQwVs1n3aAr0im0/T+Xc= 115""" 116 117 def setUp(self): 118 self.asn1Spec = rfc5280.Certificate() 119 120 def testDerCodec(self): 121 substrate = pem.readBase64fromText(self.ec_cert_pem_text) 122 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 123 assert not rest 124 assert asn1Object.prettyPrint() 125 assert der_encode(asn1Object) == substrate 126 127 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 128 assert spki_a['algorithm'] == rfc3279.id_ecPublicKey 129 130 spki_a_p, rest = der_decode(spki_a['parameters'], 131 asn1Spec=rfc3279.EcpkParameters()) 132 assert not rest 133 assert spki_a_p.prettyPrint() 134 assert der_encode(spki_a_p) == spki_a['parameters'] 135 assert spki_a_p['namedCurve'] == univ.ObjectIdentifier('1.3.132.0.34') 136 137 def testOpenTypes(self): 138 asn1Spec = rfc5280.Certificate() 139 substrate = pem.readBase64fromText(self.ec_cert_pem_text) 140 asn1Object, rest = der_decode(substrate, 141 asn1Spec=self.asn1Spec, 142 decodeOpenTypes=True) 143 assert not rest 144 assert asn1Object.prettyPrint() 145 assert der_encode(asn1Object) == substrate 146 147 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 148 assert spki_a['algorithm'] == rfc3279.id_ecPublicKey 149 assert spki_a['parameters']['namedCurve'] == univ.ObjectIdentifier('1.3.132.0.34') 150 151 152class DSACertificateTestCase(unittest.TestCase): 153 dsa_cert_pem_text = """\ 154MIIDpjCCA0ygAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCkwCwYJYIZIAWUDBAMC 155MD8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJWQTEQMA4GA1UEBxMHSGVybmRvbjER 156MA8GA1UEChMIQm9ndXMgQ0EwHhcNMTkxMDIwMjAxMjMwWhcNMjAxMDE5MjAxMjMw 157WjBwMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24x 158EDAOBgNVBAoTB0V4YW1wbGUxDjAMBgNVBAsTBUFsaWNlMSAwHgYJKoZIhvcNAQkB 159FhFhbGljZUBleGFtcGxlLmNvbTCCAbYwggErBgcqhkjOOAQBMIIBHgKBgQCLpR53 160xHfe+SiknAK/L9lm/ZO1109c9iYkriPIW/5MMlM+qc/tdRkKpG6ELIpfXTPtKCJm 161zqqVIyTmAJryyE8Xw0Ie2mzYPU5ULvKmllQkjTsWgPGgQBkciZ0AW9ggD9VwZilg 1624qh3iSO7T97hVQFnpCh6vm8pOH6UP/5kpr9ZJQIVANzdbztBJlJfqCB1t4h/NvSu 163wCFvAoGAITP+jhYk9Rngd98l+5ccgauQ+cLEUBgNG2Wq56zBXQbLou6eKkQi7ecL 164NiRmExq3IU3LOj426wSxL72Kw6FPyOEv3edIFkJJEHL4Z+ZJeVe//dzya0ddOJ7k 165k6qNF2ic+viD/5Vm8yRyKiig2uHH/MgIesLdZnvbzvX+f/P0z50DgYQAAoGALAUl 166jkOi1PxjjFVvhGfK95yIsrfbfcIEKUBaTs9NR2rbGWUeP+93paoXwP39X9wrJx2M 167SWeHWhWKszNgoiyqYT0k4R9mem3WClotxOvB5fHfwIp2kQYvE7H0/TPdGhfUpHQG 168YpyLQgT6L80meSKMFnu4VXGzOANhWDxu3JxiADCjgZQwgZEwCwYDVR0PBAQDAgeA 169MEIGCWCGSAGG+EIBDQQ1FjNUaGlzIGNlcnRpZmljYXRlIGNhbm5vdCBiZSB0cnVz 170dGVkIGZvciBhbnkgcHVycG9zZS4wHQYDVR0OBBYEFO37wHcauyc03rDc6cDRRsHz 171gcK+MB8GA1UdIwQYMBaAFM1IZQGDsqYHWwb+I4EMxHPk0bU4MAsGCWCGSAFlAwQD 172AgNHADBEAiBBRbfMzLi7+SVyO8SM3xxwUsMf/k1B+Nkvf1kBTfCfGwIgSAx/6mI+ 173pNqdXqZZGESXy1MT1aBc4ynPGLFUr2r7cPY= 174""" 175 176 def setUp(self): 177 self.asn1Spec = rfc5280.Certificate() 178 179 def testDerCodec(self): 180 substrate = pem.readBase64fromText(self.dsa_cert_pem_text) 181 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 182 assert not rest 183 assert asn1Object.prettyPrint() 184 assert der_encode(asn1Object) == substrate 185 186 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 187 assert spki_a['algorithm'] == rfc3279.id_dsa 188 189 spki_a_p, rest = der_decode(spki_a['parameters'], 190 asn1Spec=rfc3279.Dss_Parms()) 191 assert not rest 192 assert spki_a_p.prettyPrint() 193 assert der_encode(spki_a_p) == spki_a['parameters'] 194 q_value = 1260916123897116834511257683105158021801897369967 195 assert spki_a_p['q'] == q_value 196 197 sig_value, rest = der_decode(asn1Object['signature'].asOctets(), 198 asn1Spec=rfc3279.Dss_Sig_Value()) 199 assert not rest 200 assert sig_value.prettyPrint() 201 assert der_encode(sig_value) == asn1Object['signature'].asOctets() 202 assert sig_value['r'].hasValue() 203 assert sig_value['s'].hasValue() 204 205 def testOpenTypes(self): 206 substrate = pem.readBase64fromText(self.dsa_cert_pem_text) 207 asn1Object, rest = der_decode(substrate, 208 asn1Spec=self.asn1Spec, 209 decodeOpenTypes=True) 210 assert not rest 211 assert asn1Object.prettyPrint() 212 assert der_encode(asn1Object) == substrate 213 214 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 215 assert spki_a['algorithm'] == rfc3279.id_dsa 216 q_value = 1260916123897116834511257683105158021801897369967 217 assert spki_a['parameters']['q'] == q_value 218 219 220class KEACertificateTestCase(unittest.TestCase): 221 kea_cert_pem_text = """\ 222MIICizCCAjOgAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCgwCQYHKoZIzjgEAzA/ 223MQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24xETAP 224BgNVBAoTCEJvZ3VzIENBMB4XDTE5MTAyMDIwMDkyMVoXDTIwMTAxOTIwMDkyMVow 225cDELMAkGA1UEBhMCVVMxCzAJBgNVBAgTAlZBMRAwDgYDVQQHEwdIZXJuZG9uMRAw 226DgYDVQQKEwdFeGFtcGxlMQ4wDAYDVQQDEwVBbGljZTEgMB4GCSqGSIb3DQEJARYR 227YWxpY2VAZXhhbXBsZS5jb20wgaAwFwYJYIZIAWUCAQEWBApc+PEn5ladbYizA4GE 228AAKBgB9Lc2QcoSW0E9/VnQ2xGBtpYh9MaDUBzIixbN8rhDwh0BBesD2TwHjzBpDM 2292PJ6DD1ZbBcz2M3vJaIKoZ8hA2EUtbbHX1BSnVfAdeqr5St5gfnuxSdloUjLQlWO 230rOYfpFVEp6hJoKAZiYfiXz0fohNXn8+fiU5k214byxlCPlU0o4GUMIGRMAsGA1Ud 231DwQEAwIDCDBCBglghkgBhvhCAQ0ENRYzVGhpcyBjZXJ0aWZpY2F0ZSBjYW5ub3Qg 232YmUgdHJ1c3RlZCBmb3IgYW55IHB1cnBvc2UuMB0GA1UdDgQWBBSE49bkPB9sQm27 233Rs2jgAPMyY6UCDAfBgNVHSMEGDAWgBTNSGUBg7KmB1sG/iOBDMRz5NG1ODAJBgcq 234hkjOOAQDA0cAMEQCIE9PWhUbnJVdNQcVYSc36BMZ+23uk2ITLsgSXtkScF6TAiAf 235TPnJ5Wym0hv2fOpnPPsWTgqvLFYfX27GGTquuOd/6A== 236""" 237 238 def setUp(self): 239 self.asn1Spec = rfc5280.Certificate() 240 241 def testDerCodec(self): 242 asn1Spec = rfc5280.Certificate() 243 substrate = pem.readBase64fromText(self.kea_cert_pem_text) 244 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 245 assert not rest 246 assert asn1Object.prettyPrint() 247 assert der_encode(asn1Object) == substrate 248 249 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 250 assert spki_a['algorithm'] == rfc3279.id_keyExchangeAlgorithm 251 252 spki_a_p, rest = der_decode(spki_a['parameters'], 253 asn1Spec=rfc3279.KEA_Parms_Id()) 254 assert not rest 255 assert spki_a_p.prettyPrint() 256 assert der_encode(spki_a_p) == spki_a['parameters'] 257 assert spki_a_p == univ.OctetString(hexValue='5cf8f127e6569d6d88b3') 258 259 assert asn1Object['tbsCertificate']['signature']['algorithm'] == rfc3279.id_dsa_with_sha1 260 assert asn1Object['signatureAlgorithm']['algorithm'] == rfc3279.id_dsa_with_sha1 261 262 sig_value, rest = der_decode(asn1Object['signature'].asOctets(), 263 asn1Spec=rfc3279.Dss_Sig_Value()) 264 assert not rest 265 assert sig_value.prettyPrint() 266 assert der_encode(sig_value) == asn1Object['signature'].asOctets() 267 assert sig_value['r'].hasValue() 268 assert sig_value['s'].hasValue() 269 270 def testOpenTypes(self): 271 substrate = pem.readBase64fromText(self.kea_cert_pem_text) 272 asn1Object, rest = der_decode(substrate, 273 asn1Spec=self.asn1Spec, 274 decodeOpenTypes=True) 275 assert not rest 276 assert asn1Object.prettyPrint() 277 assert der_encode(asn1Object) == substrate 278 279 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 280 assert spki_a['algorithm'] == rfc3279.id_keyExchangeAlgorithm 281 assert spki_a['parameters'] == univ.OctetString(hexValue='5cf8f127e6569d6d88b3') 282 283 assert asn1Object['tbsCertificate']['signature']['algorithm'] == rfc3279.id_dsa_with_sha1 284 assert asn1Object['signatureAlgorithm']['algorithm'] == rfc3279.id_dsa_with_sha1 285 286 287class DHCertificateTestCase(unittest.TestCase): 288 dh_cert_pem_text = """\ 289MIIEtDCCBFqgAwIBAgIUY8xt3l0B9nIPWSpjs0hDJUJZmCkwCwYJYIZIAWUDBAMC 290MD8xCzAJBgNVBAYTAlVTMQswCQYDVQQIEwJWQTEQMA4GA1UEBxMHSGVybmRvbjER 291MA8GA1UEChMIQm9ndXMgQ0EwHhcNMTkxMDIwMjAxMjMwWhcNMjAxMDE5MjAxMjMw 292WjBwMQswCQYDVQQGEwJVUzELMAkGA1UECBMCVkExEDAOBgNVBAcTB0hlcm5kb24x 293EDAOBgNVBAoTB0V4YW1wbGUxDjAMBgNVBAsTBUFsaWNlMSAwHgYJKoZIhvcNAQkB 294FhFhbGljZUBleGFtcGxlLmNvbTCCAsQwggI5BgcqhkjOPgIBMIICLAKCAQEAt9x/ 2950iwGww3k19h+wbODVK1yqjFzEY2pyfXthHcn+nEw+DpURJ+iOhYPr68E3XO5sB48 296r5xTZhPN5+YejD3T8qhnDtiq4qrrSH7BOaEzqCDpHE2Bpoy3SodQ5Obaiu9Kx1ix 297BRk/oRZUH+F+ATZmF0rPKrZGZOnmsh0IZm3dlmRR9FRGn0aJlZKXveqp+hZ97/r0 298cbSo6wdT47APfocgweZMvgWu1IQBs6FiunRgaeX3RyLr4fnkvCzUM7TmxpRJYtL6 299myAp007QvtgQ0AdEwVfNl3jQ0IIW7TtpXVxDDQaKZZe9yYrY4GV3etlYk8a4cpjN 300rBxBCCTMASE4+iVtPQKCAQAg3m19vWc1TlHmkeqLwgvHN0Ufdyw5axWtc8qIJGZ1 301MezhyLyD4RU0VFCSocJCCe2k2kS2P2vQERZZYcn/nCYuiswCjOCbnwKozfaTZ3Fc 3021KOCtb4EEcuk/th5XNhWCYJJ7Hasym8zuPaqh5TLcsHXp0/lQUiOV2uVHnAt503A 303HY1v4PhlZ3G0CRZMenafU0Ky7a6zhrqFvWgtSdo+vN0S9xS/KJuTaWsYgOAt4r2I 304K1uwuWuvA5L1Qrdj8pDzMLkdlyHU1Jgjzk0rNQDTbUkZX9CAi/xKUGZysjWfOn1F 305HC1vJ1sbP9nTXpWRain1/6yatB2RxLTvWYyAq9IsL/8PAiEAkY8lGryvcZI/pxXt 306XwSaXEL2d77GSGICMGZa1wOJtdEDgYQAAoGALAUljkOi1PxjjFVvhGfK95yIsrfb 307fcIEKUBaTs9NR2rbGWUeP+93paoXwP39X9wrJx2MSWeHWhWKszNgoiyqYT0k4R9m 308em3WClotxOvB5fHfwIp2kQYvE7H0/TPdGhfUpHQGYpyLQgT6L80meSKMFnu4VXGz 309OANhWDxu3JxiADCjgZQwgZEwCwYDVR0PBAQDAgMIMEIGCWCGSAGG+EIBDQQ1FjNU 310aGlzIGNlcnRpZmljYXRlIGNhbm5vdCBiZSB0cnVzdGVkIGZvciBhbnkgcHVycG9z 311ZS4wHQYDVR0OBBYEFO37wHcauyc03rDc6cDRRsHzgcK+MB8GA1UdIwQYMBaAFM1I 312ZQGDsqYHWwb+I4EMxHPk0bU4MAsGCWCGSAFlAwQDAgNHADBEAiB1LU0esRdHDvSj 313kqAm+3viU2a+hl66sLrK5lYBOYqGYAIgWG7bDxqFVP6/stHfdbeMovLejquEl9tr 314iPEBA+EDHjk= 315""" 316 317 def setUp(self): 318 self.asn1Spec = rfc5280.Certificate() 319 320 def testDerCodec(self): 321 substrate = pem.readBase64fromText(self.dh_cert_pem_text) 322 asn1Object, rest = der_decode(substrate, asn1Spec=self.asn1Spec) 323 assert not rest 324 assert asn1Object.prettyPrint() 325 assert der_encode(asn1Object) == substrate 326 327 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 328 assert spki_a['algorithm'] == rfc3279.dhpublicnumber 329 330 spki_a_p, rest = der_decode(spki_a['parameters'], 331 asn1Spec=rfc3279.DomainParameters()) 332 assert not rest 333 assert spki_a_p.prettyPrint() 334 assert der_encode(spki_a_p) == spki_a['parameters'] 335 q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537 336 assert spki_a_p['q'] == q_value 337 338 def testOpenTypes(self): 339 substrate = pem.readBase64fromText(self.dh_cert_pem_text) 340 asn1Object, rest = der_decode(substrate, 341 asn1Spec=self.asn1Spec, 342 decodeOpenTypes=True) 343 assert not rest 344 assert asn1Object.prettyPrint() 345 assert der_encode(asn1Object) == substrate 346 347 spki_a = asn1Object['tbsCertificate']['subjectPublicKeyInfo']['algorithm'] 348 assert spki_a['algorithm'] == rfc3279.dhpublicnumber 349 q_value = 65838278260281264030127352144753816831178774189428428256716126077244217603537 350 assert spki_a['parameters']['q'] == q_value 351 352 353suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 354 355if __name__ == '__main__': 356 unittest.TextTestRunner(verbosity=2).run(suite) 357