test_rfc6482.py 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Copyright (c) 2019, Vigil Security, LLC
  5. # License: http://snmplabs.com/pyasn1/license.html
  6. #
  7. import sys
  8. import unittest
  9. from pyasn1.codec.der.decoder import decode as der_decoder
  10. from pyasn1.codec.der.encoder import encode as der_encoder
  11. from pyasn1_modules import pem
  12. from pyasn1_modules import rfc5652
  13. from pyasn1_modules import rfc6482
  14. class RPKIROATestCase(unittest.TestCase):
  15. roa_pem_text = """\
  16. MIIGvwYJKoZIhvcNAQcCoIIGsDCCBqwCAQMxDTALBglghkgBZQMEAgEwKgYLKoZIhvcNAQkQ
  17. ARigGwQZMBcCAwDj+zAQMA4EAgABMAgwBgMEAJMcLaCCBLwwggS4MIIDoKADAgECAgIGGDAN
  18. BgkqhkiG9w0BAQsFADAzMTEwLwYDVQQDEyg2ZDZmYmZhOTc1M2RiOGQ4NDY0MzNkYjUzNTFk
  19. OWE5ZWMwN2M5NmJkMB4XDTE5MDgyMDAwNDkyOVoXDTIwMDcwMTAwMDAwMFowMzExMC8GA1UE
  20. AxMoNUI4M0REODdERTlBQzdDNkUzNEI4NzdERjUwMUEyQjEyMzBBODFCNDCCASIwDQYJKoZI
  21. hvcNAQEBBQADggEPADCCAQoCggEBAJcnDgSUtiQeelGQsTx2Ou5cgmfq6KPSEgMz/XyZrRzj
  22. wcqUQ/DyMYHyRJK8umKZjfMu+rItoPSkE26Wi9PcSnfuY+SyS9chTAtNOGMES6MbtHjNTmBF
  23. Xar5CFGM8teLIRHlCcScesgSR7q2eKgQ+cLiLTZnol0Mpmuf2NIs+V63Y4Hn/T7QOoudg9nU
  24. tmsh31hUN4jIENEXFvNDovkray25rl9aqFfW+dtkoNtdJjp367nNXCdp3GdE/3z0SIqT8wnh
  25. F67tgR22mwzex3umteQBwmM+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bdZnmWRuvqW1475mhxi0s/I4eE2ZdaCinvrgrglBp/jpZi1jitY14
  40. dx+A1PMxggGqMIIBpgIBA4AUW4Pdh96ax8bjS4d99QGisSMKgbQwCwYJYIZIAWUDBAIBoGsw
  41. GgYJKoZIhvcNAQkDMQ0GCyqGSIb3DQEJEAEYMBwGCSqGSIb3DQEJBTEPFw0xOTA4MjAwMDQ5
  42. MjlaMC8GCSqGSIb3DQEJBDEiBCCfuHnOmhF2iBF3JXMOnoZCJzmE+Tcf8b+zObvDUpUddzAN
  43. BgkqhkiG9w0BAQEFAASCAQBDlJIMKCqWsFV/tQj/XvpSJUxJybG+zwjrUKm4yTKv8QEGOzOD
  44. aIL6irSOhhXeax6Lw0P2J7x+L3jGW1we1qWslumEDTr9kTE+kN/6rZuptUhwdrXcu3p9G6gJ
  45. mAUQtzqe2jRN1T3eSBfz1CNU3C7+jSHXOc+4Tea5mKiVddsjotYHXX0PbSCS/ZZ1yzdeES0o
  46. KWhXhW9ogS0bwtXWVTrciSekaRpp2n/pqcVEDxWg/5NpPiDlPNrRL/9eTEHFp940RAUfhbBh
  47. pbC2J02N0KgxUJxIJnGnpZ7rXKpG4jMiTVry7XB9bnFxCvZGBdjQW1Hagrfpl2TiVxQFvJWl
  48. IzU1
  49. """
  50. def testDerCodec(self):
  51. substrate = pem.readBase64fromText(self.roa_pem_text)
  52. layers = {}
  53. layers.update(rfc5652.cmsContentTypesMap)
  54. getNextLayer = {
  55. rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
  56. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
  57. rfc6482.id_ct_routeOriginAuthz: lambda x: None
  58. }
  59. getNextSubstrate = {
  60. rfc5652.id_ct_contentInfo: lambda x: x['content'],
  61. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
  62. rfc6482.id_ct_routeOriginAuthz: lambda x: None
  63. }
  64. next_layer = rfc5652.id_ct_contentInfo
  65. while next_layer:
  66. asn1Object, rest = der_decoder(substrate, asn1Spec=layers[next_layer])
  67. self.assertFalse(rest)
  68. self.assertTrue(asn1Object.prettyPrint())
  69. self.assertEqual(substrate, der_encoder(asn1Object))
  70. substrate = getNextSubstrate[next_layer](asn1Object)
  71. next_layer = getNextLayer[next_layer](asn1Object)
  72. self.assertEqual(0, asn1Object['version'])
  73. self.assertEqual(58363, asn1Object['asID'])
  74. def testOpenTypes(self):
  75. substrate = pem.readBase64fromText(self.roa_pem_text)
  76. asn1Object, rest = der_decoder(
  77. substrate, asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=True)
  78. self.assertFalse(rest)
  79. self.assertTrue(asn1Object.prettyPrint())
  80. self.assertEqual(substrate, der_encoder(asn1Object))
  81. oid = asn1Object['content']['encapContentInfo']['eContentType']
  82. substrate = asn1Object['content']['encapContentInfo']['eContent']
  83. self.assertIn(oid, rfc5652.cmsContentTypesMap)
  84. asn1Object, rest = der_decoder(
  85. substrate, asn1Spec=rfc5652.cmsContentTypesMap[oid],
  86. decodeOpenTypes=True)
  87. self.assertFalse(rest)
  88. self.assertTrue(asn1Object.prettyPrint())
  89. self.assertEqual(substrate, der_encoder(asn1Object))
  90. self.assertEqual(0, asn1Object['version'])
  91. self.assertEqual(58363, asn1Object['asID'])
  92. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  93. if __name__ == '__main__':
  94. result = unittest.TextTestRunner(verbosity=2).run(suite)
  95. sys.exit(not result.wasSuccessful())