X-Git-Url: http://www.git.cypherpunks.ru/?a=blobdiff_plain;f=pygost%2Ftest_pfx.py;h=67fe788298a5feb82ce1bb584912f1775d384919;hb=dfa5e690f30f29a44f529f8a9951688b43c6ce3b;hp=fe5b1649cf209012d5691eabf9b46bfdfa2ede6a;hpb=21a30721c31912c296e1faced73e2fd0db191be9;p=pygost.git diff --git a/pygost/test_pfx.py b/pygost/test_pfx.py index fe5b164..67fe788 100644 --- a/pygost/test_pfx.py +++ b/pygost/test_pfx.py @@ -1,11 +1,10 @@ # coding: utf-8 # PyGOST -- Pure Python GOST cryptographic functions library -# Copyright (C) 2015-2019 Sergey Matveev +# Copyright (C) 2015-2020 Sergey Matveev # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# the Free Software Foundation, version 3 of the License. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -23,13 +22,13 @@ from unittest import TestCase from pygost.gost28147 import cfb_decrypt from pygost.gost34112012512 import GOST34112012512 from pygost.gost34112012512 import pbkdf2 as gost34112012_pbkdf2 -from pygost.utils import hexdec try: from pygost.asn1schemas.pfx import OctetStringSafeContents from pygost.asn1schemas.pfx import PFX from pygost.asn1schemas.pfx import PKCS8ShroudedKeyBag + from pygost.asn1schemas.pfx import SafeContents except ImportError: pyderasn_exists = False else: @@ -83,13 +82,12 @@ G2ki9enTqos4KpUU0j9IDpl1UXiaA1YDIwUjlAp+81GkLmyt8Fw6Gt/X5JZySAY= pfx, tail = PFX().decode(self.pfx_raw) self.assertSequenceEqual(tail, b"") - _, octet_string_safe_contents = pfx["authSafe"]["content"].defined - outer_safe_contents = octet_string_safe_contents["safeContents"] - octet_string_safe_contents, tail = OctetStringSafeContents().decode( + _, outer_safe_contents = pfx["authSafe"]["content"].defined + safe_contents, tail = OctetStringSafeContents().decode( bytes(outer_safe_contents[0]["bagValue"]), ) self.assertSequenceEqual(tail, b"") - safe_bag = octet_string_safe_contents["safeContents"][0] + safe_bag = safe_contents[0] shrouded_key_bag, tail = PKCS8ShroudedKeyBag().decode( bytes(safe_bag["bagValue"]), ) @@ -110,7 +108,7 @@ G2ki9enTqos4KpUU0j9IDpl1UXiaA1YDIwUjlAp+81GkLmyt8Fw6Gt/X5JZySAY= key, bytes(shrouded_key_bag["encryptedData"]), iv=bytes(enc_scheme_params["iv"]), - sbox="Gost28147_tc26_ParamZ", + sbox="id-tc26-gost-28147-param-Z", ), private_key_info_expected, ) @@ -136,8 +134,7 @@ ATAMBggqhQMHAQEDAgUAA0EA9oq0Vvk8kkgIwkp0x0J5eKtia4MNTiwKAm7jgnCZIx3O98BThaTX pfx, tail = PFX().decode(self.pfx_raw) self.assertSequenceEqual(tail, b"") - _, octet_string_safe_contents = pfx["authSafe"]["content"].defined - outer_safe_contents = octet_string_safe_contents["safeContents"] + _, outer_safe_contents = pfx["authSafe"]["content"].defined _, encrypted_data = outer_safe_contents[1]["bagValue"].defined _, pbes2_params = encrypted_data["encryptedContentInfo"]["contentEncryptionAlgorithm"]["parameters"].defined _, pbkdf2_params = pbes2_params["keyDerivationFunc"]["parameters"].defined @@ -154,7 +151,7 @@ ATAMBggqhQMHAQEDAgUAA0EA9oq0Vvk8kkgIwkp0x0J5eKtia4MNTiwKAm7jgnCZIx3O98BThaTX key, bytes(encrypted_data["encryptedContentInfo"]["encryptedContent"]), iv=bytes(enc_scheme_params["iv"]), - sbox="Gost28147_tc26_ParamZ", + sbox="id-tc26-gost-28147-param-Z", ), cert_bag_expected, ) @@ -162,8 +159,7 @@ ATAMBggqhQMHAQEDAgUAA0EA9oq0Vvk8kkgIwkp0x0J5eKtia4MNTiwKAm7jgnCZIx3O98BThaTX def test_mac(self): pfx, tail = PFX().decode(self.pfx_raw) self.assertSequenceEqual(tail, b"") - _, octet_string_safe_contents = pfx["authSafe"]["content"].defined - outer_safe_contents = octet_string_safe_contents["safeContents"] + _, outer_safe_contents = pfx["authSafe"]["content"].defined mac_data = pfx["macData"] mac_key = gost34112012_pbkdf2( password=self.password.encode('utf-8'), @@ -175,7 +171,7 @@ ATAMBggqhQMHAQEDAgUAA0EA9oq0Vvk8kkgIwkp0x0J5eKtia4MNTiwKAm7jgnCZIx3O98BThaTX self.assertSequenceEqual( hmac_new( key=mac_key, - msg=outer_safe_contents.encode(), + msg=SafeContents(outer_safe_contents).encode(), digestmod=GOST34112012512, ).digest(), bytes(mac_data["mac"]["digest"]),