2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2018 Sergey Matveev <stargrave@stargrave.org>
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
17 """PKCS #12 related structures (**NOT COMPLETE**)
20 from pyderasn import Any
21 from pyderasn import Choice
22 from pyderasn import Integer
23 from pyderasn import ObjectIdentifier
24 from pyderasn import OctetString
25 from pyderasn import Sequence
26 from pyderasn import SequenceOf
27 from pyderasn import SetOf
28 from pyderasn import tag_ctxc
29 from pyderasn import tag_ctxp
31 from pygost.asn1schemas.cms import CMSVersion
32 from pygost.asn1schemas.cms import ContentType
33 from pygost.asn1schemas.x509 import AlgorithmIdentifier
36 class EncryptionAlgorithmIdentifier(AlgorithmIdentifier):
38 ("algorithm", ObjectIdentifier()),
39 ("parameters", Any(optional=True)),
43 class ContentEncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier):
47 class PBES2KDFs(AlgorithmIdentifier):
49 ("algorithm", ObjectIdentifier()),
50 ("parameters", Any(optional=True)),
54 class PBES2Encs(AlgorithmIdentifier):
56 ("algorithm", ObjectIdentifier()),
57 ("parameters", Any(optional=True)),
61 class PBES2Params(Sequence):
63 ("keyDerivationFunc", PBES2KDFs()),
64 ("encryptionScheme", PBES2Encs()),
68 class EncryptedContent(OctetString):
72 class EncryptedContentInfo(Sequence):
74 ("contentType", ContentType()),
75 ("contentEncryptionAlgorithm", ContentEncryptionAlgorithmIdentifier()),
76 ("encryptedContent", EncryptedContent(impl=tag_ctxp(0), optional=True)),
80 class EncryptedData(Sequence):
82 ("version", CMSVersion()),
83 ("encryptedContentInfo", EncryptedContentInfo()),
84 # ("unprotectedAttrs", UnprotectedAttributes(impl=tag_ctxc(1), optional=True)),
88 class PKCS12BagSet(Any):
92 class AttrValue(SetOf):
96 class PKCS12Attribute(Sequence):
98 ("attrId", ObjectIdentifier()),
99 ("attrValue", AttrValue()),
103 class PKCS12Attributes(SetOf):
104 schema = PKCS12Attribute()
107 class SafeBag(Sequence):
109 ("bagId", ObjectIdentifier()),
110 ("bagValue", PKCS12BagSet(expl=tag_ctxc(0))),
111 ("bagAttributes", PKCS12Attributes(optional=True)),
115 class SafeContents(SequenceOf):
119 class OctetStringSafeContents(Sequence):
120 tag_default = OctetString.tag_default
121 schema = (("safeContents", SafeContents()),)
124 class AuthSafe(Sequence):
126 ("contentType", ContentType()),
127 ("content", Any(expl=tag_ctxc(0))),
131 class DigestInfo(Sequence):
133 ("digestAlgorithm", AlgorithmIdentifier()),
134 ("digest", OctetString()),
138 class MacData(Sequence):
140 ("mac", DigestInfo()),
141 ("macSalt", OctetString()),
142 ("iterations", Integer(default=1)),
148 ("version", Integer(default=1)),
149 ("authSafe", AuthSafe()),
150 ("macData", MacData(optional=True)),
154 class EncryptedPrivateKeyInfo(Sequence):
156 ("encryptionAlgorithm", EncryptionAlgorithmIdentifier()),
157 ("encryptedData", OctetString()),
161 class PKCS8ShroudedKeyBag(EncryptedPrivateKeyInfo):
165 class PBKDF2Salt(Choice):
167 ("specified", OctetString()),
168 # ("otherSource", PBKDF2SaltSources()),
172 id_hmacWithSHA1 = ObjectIdentifier("1.2.840.113549.2.7")
175 class PBKDF2PRFs(AlgorithmIdentifier):
177 ("algorithm", ObjectIdentifier(default=id_hmacWithSHA1)),
178 ("parameters", Any(optional=True)),
182 class IterationCount(Integer):
183 bounds = (1, float("+inf"))
186 class KeyLength(Integer):
187 bounds = (1, float("+inf"))
190 class PBKDF2Params(Sequence):
192 ("salt", PBKDF2Salt()),
193 ("iterationCount", IterationCount(optional=True)),
194 ("keyLength", KeyLength(optional=True)),
195 ("prf", PBKDF2PRFs()),