test_rfc8708.py 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #
  2. # This file is part of pyasn1-modules software.
  3. #
  4. # Created by Russ Housley
  5. # Copyright (c) 2020, Vigil Security, LLC
  6. # License: http://snmplabs.com/pyasn1/license.html
  7. #
  8. import sys
  9. import unittest
  10. from pyasn1.codec.der.decoder import decode as der_decoder
  11. from pyasn1.codec.der.encoder import encode as der_encoder
  12. from pyasn1_modules import pem
  13. from pyasn1_modules import rfc5280
  14. from pyasn1_modules import rfc5652
  15. from pyasn1_modules import rfc8708
  16. class HashSigPublicKeyTestCase(unittest.TestCase):
  17. public_key_pem_text = """\
  18. MFAwDQYLKoZIhvcNAQkQAxEDPwAEPAAAAAIAAAAGAAAAA9CPq9SiCR/wqMtO2DTn
  19. RTQypYiFzZugQxI1Rmv/llHGySEkQE1F+lPPFhwo8a1ajg==
  20. """
  21. def setUp(self):
  22. self.asn1Spec = rfc5280.SubjectPublicKeyInfo()
  23. def testDerCodec(self):
  24. substrate = pem.readBase64fromText(self.public_key_pem_text)
  25. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  26. self.assertFalse(rest)
  27. self.assertTrue(asn1Object.prettyPrint())
  28. self.assertEqual(substrate, der_encoder(asn1Object))
  29. self.assertEqual(
  30. asn1Object['algorithm']['algorithm'],
  31. rfc8708.id_alg_hss_lms_hashsig)
  32. class HashSigSignedDataTestCase(unittest.TestCase):
  33. signed_data_pem_text = """\
  34. MIIKfQYJKoZIhvcNAQcCoIIKbjCCCmoCAQMxADAtBgkqhkiG9w0BBwGgIAQe
  35. VGhpcyBpcyBzb21lIHNhbXBsZSBjb250ZW50Lg0KMYIKMjCCCi4CAQOABkhp
  36. TW9tITALBglghkgBZQMEAgGgMTAvBgkqhkiG9w0BCQQxIgQgF6DPgklChkQZ
  37. NfFTIwED50Du7vSlr2SKRDkhJIYWL8gwDQYLKoZIhvcNAQkQAxEEggnQAAAA
  38. AAAAAAEAAAADkSkd52zm4k0eKptgJmUZvIzoifgU3rD8AO3TEp3jq5v2DGW6
  39. SNGcy3dtMFWLhS9DutlHr2Iphd6AGwaL7RGA004g3b+BnpErvDqnGIPy5CZl
  40. u0Q1UlL2U9DEp6LaPrhZSv7LVR5odGEu9h8TvI/HCXs8IeaDW3S+mtaGOr+V
  41. sRLCwWpCOYQXBfErxfRJqCgJEtJjQ/KPdROB3u4yTRcFh8qyfHBJCN5Cphx7
  42. g/NkceH36hXJP/L7f2oFFMP9bloY7Tqyt9etZUKdlDiyrxZGCmdcmCJoj9SL
  43. hrkz+nIisCMKy3MjjZ+pT1XUOuv6QOCJcTezCDucuspflxyqJADXIbXnMn6B
  44. 7H/vYfxuXCBWyRXLulOe00xNY2XaIAdJRGdm1oLuLWsNuv+v9stWiZGQT3j6
  45. AQlC0CV1PFno/TpAeTFUcKo+fxHOmDOfV7wGExWhOoh1+1c0eQjJujefNJMB
  46. 9lgSFMCYcLcsOXN+xMRqlhmbZsrSmQvL5bsav96ZEHx/g7OkEenXupLA0RsG
  47. UrggIMHshcISeZAH6sYKPSVNYFx8ub9UVNgUvAxSygUei9UnDvTCUGAhs/1U
  48. ZZZnzwRwWh7BgyAb35mzl79jCRXgsZ84GFcZi9WtiWsQWoRN8/YM0d13o4NS
  49. 6gtsCqOKdo21mAyQ7D9UnTZBWhlhRX1M9M14hblDGtkI02pvioJiVtKqNPiq
  50. BzGjV8Bg246A/v1hsRDOID+toMvgnneS8tBc279QGYessKBUWFvKjkzJFrui
  51. yv1WgFyyc+YxujldI+hqz26uYxgaWv4fCjYcu9X+/rcxwapgvSUgcdaJydnM
  52. Ht/oqgI1xlT3WPyJNlFa40QcO/BTuC7bzrX6j9H0tlSlbxJfakZwGuNL19o1
  53. tYSAnBhTkcz4OTVCTJAL1pgqK4zljUO/R+iPgvWavMKIh1HxXJB4EER4FF/L
  54. hFZMCqPdDN0EN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Pm2boffTln9wnN3TXcd9YDVvDD
  88. aAiQC0kctOy7q+wSjnyBpG5ipntXZAoKeL4cv33Z1BmhDNhobRZiGoCBa/21
  89. vcViEdcspwuB8RF9EpUpp1cM95z1KnAopIU47N07ONPV1i0mJGWVxPtzpSWl
  90. 7SwwUk67HYzILgwZvEl3xomP+V/T0xCwuucWls75PGpVJFa/lunQdeODu3VD
  91. xnWEK6+/x824hIOzJ2wp1PCjQcLUBuQNRlO35NBFhRrPagoOqccQuAXM7UY1
  92. 7owQc2Lw/I2AwU0KxJxRZwPSbRR1LzTBwNLEJHWBwYws9N5I6c6Um+fIiOnK
  93. 6+SkFeKR/RB9IdwfCEsRWCCCSfKPT3x+kxuns70NgkpFcA==
  94. """
  95. def setUp(self):
  96. self.asn1Spec = rfc5652.ContentInfo()
  97. def testDerCodec(self):
  98. substrate = pem.readBase64fromText(self.signed_data_pem_text)
  99. asn1Object, rest = der_decoder(substrate, asn1Spec=self.asn1Spec)
  100. self.assertFalse(rest)
  101. self.assertTrue(asn1Object.prettyPrint())
  102. self.assertEqual(substrate, der_encoder(asn1Object))
  103. self.assertEqual(asn1Object['contentType'], rfc5652.id_signedData)
  104. sd, rest = der_decoder(
  105. asn1Object['content'], asn1Spec=rfc5652.SignedData())
  106. oid = sd['signerInfos'][0]['signatureAlgorithm']['algorithm']
  107. self.assertEqual(rfc8708.id_alg_hss_lms_hashsig, oid)
  108. suite = unittest.TestLoader().loadTestsFromModule(sys.modules[__name__])
  109. if __name__ == '__main__':
  110. unittest.TextTestRunner(verbosity=2).run(suite)