1# 2# This file is part of pyasn1-modules software. 3# 4# Created by Russ Housley 5# Acknowledgement to Carl Wallace for the test messages. 6# Copyright (c) 2019, Vigil Security, LLC 7# License: http://snmplabs.com/pyasn1/license.html 8# 9 10import sys 11 12from pyasn1.codec.der.decoder import decode as der_decode 13from pyasn1.codec.der.encoder import encode as der_encode 14 15from pyasn1.type import univ 16 17from pyasn1_modules import pem 18from pyasn1_modules import rfc5652 19from pyasn1_modules import rfc5934 20 21try: 22 import unittest2 as unittest 23 24except ImportError: 25 import unittest 26 27 28class TAMPStatusResponseTestCase(unittest.TestCase): 29 tsr_pem_text = """\ 30MIIU/QYJKoZIhvcNAQcCoIIU7jCCFOoCAQMxDTALBglghkgBZQMEAgEwgg/GBgpghkgBZQIB 31Ak0CoIIPtgSCD7Iwgg+uMAiDAAIEXXp3f6GCD50wgg+ZooIFFTCCBREwggEiMA0GCSqGSIb3 32DQEBAQUAA4IBDwAwggEKAoIBAQDALMH2jTus/z881nG+uHQiB+xwQRX8q0DjB6rBw9if/tpM 33Or8/yNgoe0s2AcCsRSXD0g4Kj4UYZBA9GhNwKm+O19yNk7NBDzghza2rwj0qBdNXETcNzYxR 34+ZPjzEZJIY4UtM3LFD44zXIx7qsS8mXqNC5WXf/uY3XLbbqRNPye8/QtHL5QxELfWYj/arP6 35qGw9y1ZxcQWWu5+A5YBFWWdBsOvDrWCkgHUGF5wO9EPgmQ4b+3/1s8yygYKx/TLBuL5BpGS1 36YDpaUTCMzt5BLBlHXEkQZLl0qYdBr31uusG4ob9lMToEZ/m1u46SigBjuLHmjDhfg/9Q1Tui 37XWuyEMxjAgMBAAEEFEl0uwxeunr+AlTve6DGlcYJgHCWMIID0TBbMQswCQYDVQQGEwJVUzEY 38MBYGA1UEChMPVS5TLiBHb3Zlcm5tZW50MQwwCgYDVQQLEwNEb0QxDDAKBgNVBAsTA1BLSTEW 39MBQGA1UEAxMNRG9EIFJvb3QgQ0EgMqCCA3AwggJYoAMCAQICAQUwDQYJKoZIhvcNA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K5OpaVcPGg4DB3oAOwxtn0GVQtKgGkiGQF0r5389mTHYlQzS6BVDG2Oi 127sKIe4SBazrBGjnKANf9LEunpWPt15y6QCxiEKnJfPlAqiMuiIhHmXPIHi+d3sYkC+iu+5I68 1282oeLdtBWCDcGh4+DdS6Qqzkpp14MpvzBMdfD3lKcI3NRmY+GmRYaGAiEalh83vggslF7N4SS 129iPxQyqz7LIQe9/5ynJV5/CPUDBL9QK2vSCOQaihWCg== 130""" 131 132 def setUp(self): 133 self.asn1Spec = rfc5652.ContentInfo() 134 135 def testDerCodec(self): 136 substrate = pem.readBase64fromText(self.tsr_pem_text) 137 138 layers = { 139 rfc5652.id_ct_contentInfo: rfc5652.ContentInfo(), 140 rfc5652.id_signedData: rfc5652.SignedData(), 141 rfc5934.id_ct_TAMP_statusResponse: rfc5934.TAMPStatusResponse() 142 } 143 144 getNextLayer = { 145 rfc5652.id_ct_contentInfo: lambda x: x['contentType'], 146 rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'], 147 rfc5934.id_ct_TAMP_statusResponse: lambda x: None 148 } 149 150 getNextSubstrate = { 151 rfc5652.id_ct_contentInfo: lambda x: x['content'], 152 rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'], 153 rfc5934.id_ct_TAMP_statusResponse: lambda x: None 154 } 155 156 next_layer = rfc5652.id_ct_contentInfo 157 158 while next_layer: 159 asn1Object, rest = der_decode(substrate, asn1Spec=layers[next_layer]) 160 assert not rest 161 assert asn1Object.prettyPrint() 162 assert der_encode(asn1Object) == substrate 163 164 substrate = getNextSubstrate[next_layer](asn1Object) 165 next_layer = getNextLayer[next_layer](asn1Object) 166 167 def testOpenTypes(self): 168 substrate = pem.readBase64fromText(self.tsr_pem_text) 169 asn1Object, rest = der_decode(substrate, 170 asn1Spec=rfc5652.ContentInfo(), 171 decodeOpenTypes=True) 172 assert not rest 173 assert asn1Object.prettyPrint() 174 assert der_encode(asn1Object) == substrate 175 176 eci = asn1Object['content']['encapContentInfo'] 177 assert eci['eContentType'] in rfc5652.cmsContentTypesMap.keys() 178 assert eci['eContentType'] == rfc5934.id_ct_TAMP_statusResponse 179 tsr, rest = der_decode(eci['eContent'], 180 asn1Spec=rfc5652.cmsContentTypesMap[eci['eContentType']], 181 decodeOpenTypes=True) 182 assert not rest 183 assert tsr.prettyPrint() 184 assert der_encode(tsr) == eci['eContent'] 185 186 assert tsr['version'] == 2 187 assert tsr['query']['target'] == univ.Null("") 188 assert tsr['query']['seqNum'] == 1568307071 189 assert tsr['usesApex'] == False 190 191 count = 0 192 for tai in tsr['response']['verboseResponse']['taInfo']: 193 count += 1 194 assert tai['taInfo']['version'] == 1 195 196 assert count == 3 197 198 199class TrustAnchorUpdateTestCase(unittest.TestCase): 200 tau_pem_text = """\ 201MIIGgwYJKoZIhvcNAQcCoIIGdDCCBnACAQMxDTALBglghkgBZQMEAgEwggFMBgpghkgBZQIB 202Ak0DoIIBPASCATgwggE0MAiDAAIEXXp3kDCCASaiggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw 203ggEKAoIBAQDALMH2jTus/z881nG+uHQiB+xwQRX8q0DjB6rBw9if/tpMOr8/yNgoe0s2AcCs 204RSXD0g4Kj4UYZBA9GhNwKm+O19yNk7NBDzghza2rwj0qBdNXETcNzYxR+ZPjzEZJIY4UtM3L 205FD44zXIx7qsS8mXqNC5WXf/uY3XLbbqRNPye8/QtHL5QxELfWYj/arP6qGw9y1ZxcQWWu5+A 2065YBFWWdBsOvDrWCkgHUGF5wO9EPgmQ4b+3/1s8yygYKx/TLBuL5BpGS1YDpaUTCMzt5BLBlH 207XEkQZLl0qYdBr31uusG4ob9lMToEZ/m1u46SigBjuLHmjDhfg/9Q1TuiXWuyEMxjAgMBAAGg 208ggN9MIIDeTCCAmGgAwIBAgIBATANBgkqhkiG9w0BAQsFADBAMQswCQYDVQQGEwJVUzEfMB0G 209A1UEChMWVGVzdCBDZXJ0aWZpY2F0ZXMgMjAxMTEQMA4GA1UEAxMHR29vZCBDQTA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/wG6wQ54Inhk8pzBujcIxggGJMIIBhQIBA4AUqDwJnWf22Ee6 225otD8GHJWiEBtlZUwCwYJYIZIAWUDBAIBoEwwGQYJKoZIhvcNAQkDMQwGCmCGSAFlAgECTQMw 226LwYJKoZIhvcNAQkEMSIEINq+nldSoCoJuEe/lhrRhfx0ArygsPJ7mCMbOFrpr1dFMAsGCSqG 227SIb3DQEBCwSCAQBTeRE1DzwF2dnv2yJAOYOxNnAtTs72ZG8mv5Ad4M/9n1+MPiAykLcBslW8 2287D1KjBdwB3oxIT4sjwGh0kxKLe4G+VuvQuPwtT8MqMl3hounnFOM5nMSj1TSbfHVPs3dhEyk 229Wu1gQ5g9gxLF3MpwEJGJKvhRtK17LGElJWvGPniRMChAJZJWoLjFBMe5JMzpqu2za50S1K3t 230YtkTOx/2FQdVApkTY1qMQooljDiuvSvOuSDXcyAA15uIypQJvfrBNqe6Ush+j7yS5UQyTm0o 231ZidB8vj4jIZT3S2gqWhtBLMUc11j+kWlXEZEigSL8WgCbAu7lqhItMwz2dy4C5aAWq8r""" 232 233 def setUp(self): 234 self.asn1Spec = rfc5652.ContentInfo() 235 236 def testDerCodec(self): 237 substrate = pem.readBase64fromText(self.tau_pem_text) 238 239 layers = { 240 rfc5652.id_ct_contentInfo: rfc5652.ContentInfo(), 241 rfc5652.id_signedData: rfc5652.SignedData(), 242 rfc5934.id_ct_TAMP_update: rfc5934.TAMPUpdate() 243 } 244 245 getNextLayer = { 246 rfc5652.id_ct_contentInfo: lambda x: x['contentType'], 247 rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'], 248 rfc5934.id_ct_TAMP_update: lambda x: None 249 } 250 251 getNextSubstrate = { 252 rfc5652.id_ct_contentInfo: lambda x: x['content'], 253 rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'], 254 rfc5934.id_ct_TAMP_update: lambda x: None 255 } 256 257 next_layer = rfc5652.id_ct_contentInfo 258 259 while next_layer: 260 asn1Object, rest = der_decode(substrate, asn1Spec=layers[next_layer]) 261 assert not rest 262 assert asn1Object.prettyPrint() 263 assert der_encode(asn1Object) == substrate 264 265 substrate = getNextSubstrate[next_layer](asn1Object) 266 next_layer = getNextLayer[next_layer](asn1Object) 267 268 def testOpenTypes(self): 269 substrate = pem.readBase64fromText(self.tau_pem_text) 270 asn1Object, rest = der_decode(substrate, 271 asn1Spec=rfc5652.ContentInfo(), 272 decodeOpenTypes=True) 273 assert not rest 274 assert asn1Object.prettyPrint() 275 assert der_encode(asn1Object) == substrate 276 277 eci = asn1Object['content']['encapContentInfo'] 278 assert eci['eContentType'] in rfc5652.cmsContentTypesMap.keys() 279 assert eci['eContentType'] == rfc5934.id_ct_TAMP_update 280 tau, rest = der_decode(eci['eContent'], 281 asn1Spec=rfc5652.cmsContentTypesMap[eci['eContentType']], 282 decodeOpenTypes=True) 283 assert not rest 284 assert tau.prettyPrint() 285 assert der_encode(tau) == eci['eContent'] 286 287 assert tau['version'] == 2 288 assert tau['msgRef']['target'] == univ.Null("") 289 assert tau['msgRef']['seqNum'] == 1568307088 290 291 count = 0 292 for u in tau['updates']: 293 count += 1 294 295 assert count == 1 296 297 298suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__]) 299 300if __name__ == '__main__': 301 import sys 302 303 result = unittest.TextTestRunner(verbosity=2).run(suite) 304 sys.exit(not result.wasSuccessful()) 305