test_rfc6486.py 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  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 rfc6486
  14. class SignedManifestTestCase(unittest.TestCase):
  15. manifest_pem_text = """\
  16. MIIHVAYJKoZIhvcNAQcCoIIHRTCCB0ECAQMxDTALBglghkgBZQMEAgEwgYwGCyqGSIb3DQEJ
  17. EAEaoH0EezB5AgIK5xgPMjAxMjEwMjMyMjI2MDNaGA8yMDEyMTAyNTIyMjYwM1oGCWCGSAFl
  18. AwQCATBGMEQWH1pYU0dCREJrTDgyVEZHSHVFNFZPWXRKUC1FNC5jcmwDIQCzTdC3GsuONsRq
  19. RFnYf8+AJ2NnCIgmnc3O8PyfGvn18aCCBO4wggTqMIID0qADAgECAgIK5zANBgkqhkiG9w0B
  20. AQsFADATMREwDwYDVQQDEwhBOTE5OTg4NTAeFw0xMjEwMjMyMjI2MDNaFw0xMjEwMjUyMjI2
  21. MDNaMBgxFjAUBgNVBAMTDTUwODcxOTdjLTIwZjcwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
  22. ggEKAoIBAQDEl4R4LiCs6zyR/IAeaRCfz0O0mXXAUKt8bmG6DXzaDYNG8dnBjbrsM1L05sb4
  23. 2Ti4TyE1UXtwFFEwatsFQ2uRBn9gsKmDGOjW8TH1AYObmZW+hZlEN7OLSz2bmPLtxIMwiCq/
  24. vqmBJlMWPyCSym4iPnjzwWbJechqHSiTMOYGICF1QSW5xjJDAhRfeZG3nRY7TqfW8R2KJXeN
  25. c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awf4Ttoh
  39. GYakbUZQl7lJaXzbluG5siRSv6AowEWxf99iLhDx+pE1htklRfmmTE9oFpKnITAYZAUjarNC
  40. sYGCZ00vSwRu27OdpSQbZQ7WdyDAhyHS0Sun0pkImVSqPO11gqyKV9ZCwCJUa5U/zsWDMNrj
  41. MSZl1I3VoPs2rx997rLoiQiMqwGeoqfl7snpsL9OR/CazPmepuq3SyZNWcCrUGcGRhRdGScj
  42. Tm2EHne1GiRHapn46HWQ3am8jumEKv5u0gLT4Mi9CyZwkDyhotGTJZmdAmN7zzGCAaowggGm
  43. AgEDgBRtxs7I0EeRFdcNoyrnWMLu85IcVTALBglghkgBZQMEAgGgazAaBgkqhkiG9w0BCQMx
  44. DQYLKoZIhvcNAQkQARowHAYJKoZIhvcNAQkFMQ8XDTEyMTAyMzIyMjYwNFowLwYJKoZIhvcN
  45. AQkEMSIEIIu2XV8dT+rqQy5Cbpm3Tv5I1dwkLK8n2GesMGOr6/pEMA0GCSqGSIb3DQEBAQUA
  46. BIIBAFsd0zkl4dIHrqZts441T+w/5/ekymDLFwftk6W+Mi35Htjvm2IHOthnKHQsK5h6dnEh
  47. 6DfNfc6tACmzLnM+UG7ve+uAhfpA+CUJIoVhpQvDH7Ntql0cD1X3d9ng484jpkVoHhbUIYNR
  48. TyxvV4DV5EBbLYpx2HYf6wWa8TCobxUXNtw53OVA24ceavS+KvuDa0JQPFpbYUCS0UPMt/Im
  49. mtKrWTmRUr8sYWdIQn+SStUh8iAR5rmSVr+Pe7aFbe2ju2FPf08gnIjH/SdCrJuFK8q7Z5MT
  50. C9ijmXiajracUe+7eCluqgXRE8yRtnscWoA/9fVFz1lPwgEeNHLoaK7Sqew=
  51. """
  52. def testDerCodec(self):
  53. substrate = pem.readBase64fromText(self.manifest_pem_text)
  54. layers = rfc5652.cmsContentTypesMap.copy()
  55. getNextLayer = {
  56. rfc5652.id_ct_contentInfo: lambda x: x['contentType'],
  57. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContentType'],
  58. rfc6486.id_ct_rpkiManifest: lambda x: None
  59. }
  60. getNextSubstrate = {
  61. rfc5652.id_ct_contentInfo: lambda x: x['content'],
  62. rfc5652.id_signedData: lambda x: x['encapContentInfo']['eContent'],
  63. rfc6486.id_ct_rpkiManifest: lambda x: None
  64. }
  65. next_layer = rfc5652.id_ct_contentInfo
  66. while next_layer:
  67. asn1Object, rest = der_decoder(substrate, asn1Spec=layers[next_layer])
  68. self.assertFalse(rest)
  69. self.assertTrue(asn1Object.prettyPrint())
  70. self.assertEqual(substrate, der_encoder(asn1Object))
  71. substrate = getNextSubstrate[next_layer](asn1Object)
  72. next_layer = getNextLayer[next_layer](asn1Object)
  73. self.assertEqual(0, asn1Object['version'])
  74. for f in asn1Object['fileList']:
  75. self.assertEqual('ZXSGBDBkL82TFGHuE4VOYtJP-E4.crl', f['file'])
  76. def testOpenTypes(self):
  77. substrate = pem.readBase64fromText(self.manifest_pem_text)
  78. asn1Object, rest = der_decoder(
  79. substrate, asn1Spec=rfc5652.ContentInfo(), decodeOpenTypes=True)
  80. self.assertFalse(rest)
  81. self.assertTrue(asn1Object.prettyPrint())
  82. self.assertEqual(substrate, der_encoder(asn1Object))
  83. oid = asn1Object['content']['encapContentInfo']['eContentType']
  84. substrate = asn1Object['content']['encapContentInfo']['eContent']
  85. self.assertIn(oid, rfc5652.cmsContentTypesMap)
  86. asn1Object, rest = der_decoder(
  87. substrate, asn1Spec=rfc5652.cmsContentTypesMap[oid],
  88. decodeOpenTypes=True)
  89. self.assertFalse(rest)
  90. self.assertTrue(asn1Object.prettyPrint())
  91. self.assertEqual(substrate, der_encoder(asn1Object))
  92. self.assertEqual(0, asn1Object['version'])
  93. for f in asn1Object['fileList']:
  94. self.assertEqual('ZXSGBDBkL82TFGHuE4VOYtJP-E4.crl', f['file'])
  95. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  96. if __name__ == '__main__':
  97. result = unittest.TextTestRunner(verbosity=2).run(suite)
  98. sys.exit(not result.wasSuccessful())