test_rfc5934.py 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299
  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. import sys
  10. import unittest
  11. from pyasn1.codec.der.decoder import decode as der_decoder
  12. from pyasn1.codec.der.encoder import encode as der_encoder
  13. from pyasn1.type import univ
  14. from pyasn1_modules import pem
  15. from pyasn1_modules import rfc5652
  16. from pyasn1_modules import rfc5934
  17. class TAMPStatusResponseTestCase(unittest.TestCase):
  18. tsr_pem_text = """\
  19. MIIU/QYJKoZIhvcNAQcCoIIU7jCCFOoCAQMxDTALBglghkgBZQMEAgEwgg/GBgpghkgBZQIB
  20. Ak0CoIIPtgSCD7Iwgg+uMAiDAAIEXXp3f6GCD50wgg+ZooIFFTCCBREwggEiMA0GCSqGSIb3
  21. DQEBAQUAA4IBDwAwggEKAoIBAQDALMH2jTus/z881nG+uHQiB+xwQRX8q0DjB6rBw9if/tpM
  22. Or8/yNgoe0s2AcCsRSXD0g4Kj4UYZBA9GhNwKm+O19yNk7NBDzghza2rwj0qBdNXETcNzYxR
  23. +ZPjzEZJIY4UtM3LFD44zXIx7qsS8mXqNC5WXf/uY3XLbbqRNPye8/QtHL5QxELfWYj/arP6
  24. qGw9y1ZxcQWWu5+A5YBFWWdBsOvDrWCkgHUGF5wO9EPgmQ4b+3/1s8yygYKx/TLBuL5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hmNPzkK4p
  109. h1pOxr3oKH4PoJTm/1y1XE/dimFZDgXS/8VpwNOJStHC5cj0yAjD/SojT4QAXCxELYOKwj0i
  110. xzxg8op44xtGZdqZj/hjwdR6oHCmeqcQm52sf74U8EQjh1isEBXo86C/HiXLNqsCaVqu/8Bu
  111. sEOeCJ4ZPKcwbo3CMYIBiTCCAYUCAQOAFKg8CZ1n9thHuqLQ/BhyVohAbZWVMAsGCWCGSAFl
  112. AwQCAaBMMBkGCSqGSIb3DQEJAzEMBgpghkgBZQIBAk0CMC8GCSqGSIb3DQEJBDEiBCAiPyBP
  113. FFwHJbHgGmoz+54OEJ/ppMyfSoZmbS/nkWfxxjALBgkqhkiG9w0BAQsEggEAHllTg+TMT2ll
  114. zVvrvRDwOwrzr6YIJSt96sLANqOXiqqnvrHDDWTdVMcRX/LccVbm9JP4sGSfGDdwbm3FqB+l
  115. kgSBlejFgjWfF/YVK5OpaVcPGg4DB3oAOwxtn0GVQtKgGkiGQF0r5389mTHYlQzS6BVDG2Oi
  116. sKIe4SBazrBGjnKANf9LEunpWPt15y6QCxiEKnJfPlAqiMuiIhHmXPIHi+d3sYkC+iu+5I68
  117. 2oeLdtBWCDcGh4+DdS6Qqzkpp14MpvzBMdfD3lKcI3NRmY+GmRYaGAiEalh83vggslF7N4SS
  118. iPxQyqz7LIQe9/5ynJV5/CPUDBL9QK2vSCOQaihWCg==
  119. """
  120. def setUp(self):
  121. self.asn1Spec = rfc5652.ContentInfo()
  122. def testDerCodec(self):
  123. substrate = pem.readBase64fromText(self.tsr_pem_text)
  124. layers = {
  125. rfc5652.id_ct_contentInfo: rfc5652.ContentInfo(),
  126. rfc5652.id_signedData: rfc5652.SignedData(),
  127. rfc5934.id_ct_TAMP_statusResponse: rfc5934.TAMPStatusResponse()
  128. }
  129. getNextLayer = {
  130. rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
  131. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
  132. rfc5934.id_ct_TAMP_statusResponse: lambda x: None
  133. }
  134. getNextSubstrate = {
  135. rfc5652.id_ct_contentInfo: lambda x: x['content'],
  136. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
  137. rfc5934.id_ct_TAMP_statusResponse: lambda x: None
  138. }
  139. next_layer = rfc5652.id_ct_contentInfo
  140. while next_layer:
  141. asn1Object, rest = der_decoder(substrate, asn1Spec=layers[next_layer])
  142. self.assertFalse(rest)
  143. self.assertTrue(asn1Object.prettyPrint())
  144. self.assertEqual(substrate, der_encoder(asn1Object))
  145. substrate = getNextSubstrate[next_layer](asn1Object)
  146. next_layer = getNextLayer[next_layer](asn1Object)
  147. def testOpenTypes(self):
  148. substrate = pem.readBase64fromText(self.tsr_pem_text)
  149. asn1Object, rest = der_decoder(
  150. substrate, asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=True)
  151. self.assertFalse(rest)
  152. self.assertTrue(asn1Object.prettyPrint())
  153. self.assertEqual(substrate, der_encoder(asn1Object))
  154. eci = asn1Object['content']['encapContentInfo']
  155. self.assertIn(eci['eContentType'], rfc5652.cmsContentTypesMap)
  156. self.assertEqual(rfc5934.id_ct_TAMP_statusResponse, eci['eContentType'])
  157. tsr, rest = der_decoder(
  158. eci['eContent'],
  159. asn1Spec=rfc5652.cmsContentTypesMap[eci['eContentType']],
  160. decodeOpenTypes=True)
  161. self.assertFalse(rest)
  162. self.assertTrue(tsr.prettyPrint())
  163. self.assertEqual(eci['eContent'], der_encoder(tsr))
  164. self.assertEqual(2, tsr['version'])
  165. self.assertEqual(univ.Null(""), tsr['query']['target'])
  166. self.assertEqual(1568307071, tsr['query']['seqNum'])
  167. self.assertFalse(tsr['usesApex'])
  168. count = 0
  169. for tai in tsr['response']['verboseResponse']['taInfo']:
  170. count += 1
  171. self.assertEqual(1, tai['taInfo']['version'])
  172. self.assertEqual(3, count)
  173. class TrustAnchorUpdateTestCase(unittest.TestCase):
  174. tau_pem_text = """\
  175. MIIGgwYJKoZIhvcNAQcCoIIGdDCC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tK17LGElJWvGPniRMChAJZJWoLjFBMe5JMzpqu2za50S1K3t
  204. YtkTOx/2FQdVApkTY1qMQooljDiuvSvOuSDXcyAA15uIypQJvfrBNqe6Ush+j7yS5UQyTm0o
  205. ZidB8vj4jIZT3S2gqWhtBLMUc11j+kWlXEZEigSL8WgCbAu7lqhItMwz2dy4C5aAWq8r"""
  206. def setUp(self):
  207. self.asn1Spec = rfc5652.ContentInfo()
  208. def testDerCodec(self):
  209. substrate = pem.readBase64fromText(self.tau_pem_text)
  210. layers = {
  211. rfc5652.id_ct_contentInfo: rfc5652.ContentInfo(),
  212. rfc5652.id_signedData: rfc5652.SignedData(),
  213. rfc5934.id_ct_TAMP_update: rfc5934.TAMPUpdate()
  214. }
  215. getNextLayer = {
  216. rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
  217. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
  218. rfc5934.id_ct_TAMP_update: lambda x: None
  219. }
  220. getNextSubstrate = {
  221. rfc5652.id_ct_contentInfo: lambda x: x['content'],
  222. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
  223. rfc5934.id_ct_TAMP_update: lambda x: None
  224. }
  225. next_layer = rfc5652.id_ct_contentInfo
  226. while next_layer:
  227. asn1Object, rest = der_decoder(substrate, asn1Spec=layers[next_layer])
  228. self.assertFalse(rest)
  229. self.assertTrue(asn1Object.prettyPrint())
  230. self.assertEqual(substrate, der_encoder(asn1Object))
  231. substrate = getNextSubstrate[next_layer](asn1Object)
  232. next_layer = getNextLayer[next_layer](asn1Object)
  233. def testOpenTypes(self):
  234. substrate = pem.readBase64fromText(self.tau_pem_text)
  235. asn1Object, rest = der_decoder(
  236. substrate, asn1Spec=rfc5652.ContentInfo(),
  237. decodeOpenTypes=True)
  238. self.assertFalse(rest)
  239. self.assertTrue(asn1Object.prettyPrint())
  240. self.assertEqual(substrate, der_encoder(asn1Object))
  241. eci = asn1Object['content']['encapContentInfo']
  242. self.assertIn(eci['eContentType'], rfc5652.cmsContentTypesMap)
  243. self.assertEqual(rfc5934.id_ct_TAMP_update, eci['eContentType'])
  244. tau, rest = der_decoder(
  245. eci['eContent'],
  246. asn1Spec=rfc5652.cmsContentTypesMap[eci['eContentType']],
  247. decodeOpenTypes=True)
  248. self.assertFalse(rest)
  249. self.assertTrue(tau.prettyPrint())
  250. self.assertEqual(eci['eContent'], der_encoder(tau))
  251. self.assertEqual(2, tau['version'])
  252. self.assertEqual(univ.Null(""), tau['msgRef']['target'])
  253. self.assertEqual(1568307088, tau['msgRef']['seqNum'])
  254. self.assertEqual(1, len(tau['updates']))
  255. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  256. if __name__ == '__main__':
  257. result = unittest.TextTestRunner(verbosity=2).run(suite)
  258. sys.exit(not result.wasSuccessful())