2 # PyGOST -- Pure Python GOST cryptographic functions library
3 # Copyright (C) 2015-2021 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, version 3 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 """:rfc:`5280` related structures (**NOT COMPLETE**)
18 They are taken from `PyDERASN <http://www.pyderasn.cypherpunks.ru/`__ tests.
21 from pyderasn import Any
22 from pyderasn import BitString
23 from pyderasn import Boolean
24 from pyderasn import Choice
25 from pyderasn import GeneralizedTime
26 from pyderasn import Integer
27 from pyderasn import ObjectIdentifier
28 from pyderasn import OctetString
29 from pyderasn import PrintableString
30 from pyderasn import Sequence
31 from pyderasn import SequenceOf
32 from pyderasn import SetOf
33 from pyderasn import tag_ctxc
34 from pyderasn import tag_ctxp
35 from pyderasn import TeletexString
36 from pyderasn import UTCTime
38 from pygost.asn1schemas.oids import id_at_commonName
39 from pygost.asn1schemas.oids import id_at_countryName
40 from pygost.asn1schemas.oids import id_at_localityName
41 from pygost.asn1schemas.oids import id_at_organizationName
42 from pygost.asn1schemas.oids import id_at_stateOrProvinceName
45 class Version(Integer):
53 class CertificateSerialNumber(Integer):
57 class AlgorithmIdentifier(Sequence):
59 ("algorithm", ObjectIdentifier()),
60 ("parameters", Any(optional=True)),
64 class AttributeType(ObjectIdentifier):
68 class AttributeValue(Any):
72 class OrganizationName(Choice):
74 ("printableString", PrintableString()),
75 ("teletexString", TeletexString()),
79 class AttributeTypeAndValue(Sequence):
81 ("type", AttributeType(defines=(((".", "value"), {
82 id_at_countryName: PrintableString(),
83 id_at_stateOrProvinceName: PrintableString(),
84 id_at_localityName: PrintableString(),
85 id_at_organizationName: OrganizationName(),
86 id_at_commonName: PrintableString(),
88 ("value", AttributeValue()),
92 class RelativeDistinguishedName(SetOf):
93 schema = AttributeTypeAndValue()
94 bounds = (1, float("+inf"))
97 class RDNSequence(SequenceOf):
98 schema = RelativeDistinguishedName()
103 ("rdnSequence", RDNSequence()),
109 ("utcTime", UTCTime()),
110 ("generalTime", GeneralizedTime()),
114 class Validity(Sequence):
116 ("notBefore", Time()),
117 ("notAfter", Time()),
121 class GostR34102012PublicKeyParameters(Sequence):
123 ("publicKeyParamSet", ObjectIdentifier()),
124 ("digestParamSet", ObjectIdentifier(optional=True)),
128 class SubjectPublicKeyInfo(Sequence):
130 ("algorithm", AlgorithmIdentifier()),
131 ("subjectPublicKey", BitString()),
135 class UniqueIdentifier(BitString):
139 class KeyIdentifier(OctetString):
143 class SubjectKeyIdentifier(KeyIdentifier):
147 class BasicConstraints(Sequence):
149 ("cA", Boolean(default=False)),
150 # ("pathLenConstraint", PathLenConstraint(optional=True)),
154 class Extension(Sequence):
156 ("extnID", ObjectIdentifier()),
157 ("critical", Boolean(default=False)),
158 ("extnValue", OctetString()),
162 class Extensions(SequenceOf):
164 bounds = (1, float("+inf"))
167 class TBSCertificate(Sequence):
169 ("version", Version(expl=tag_ctxc(0), default="v1")),
170 ("serialNumber", CertificateSerialNumber()),
171 ("signature", AlgorithmIdentifier()),
173 ("validity", Validity()),
175 ("subjectPublicKeyInfo", SubjectPublicKeyInfo()),
176 ("issuerUniqueID", UniqueIdentifier(impl=tag_ctxp(1), optional=True)),
177 ("subjectUniqueID", UniqueIdentifier(impl=tag_ctxp(2), optional=True)),
178 ("extensions", Extensions(expl=tag_ctxc(3), optional=True)),
182 class Certificate(Sequence):
184 ("tbsCertificate", TBSCertificate()),
185 ("signatureAlgorithm", AlgorithmIdentifier()),
186 ("signatureValue", BitString()),
190 class RevokedCertificates(SequenceOf):
191 # schema = RevokedCertificate()
192 schema = OctetString() # dummy
195 class TBSCertList(Sequence):
197 ("version", Version(optional=True)),
198 ("signature", AlgorithmIdentifier()),
200 ("thisUpdate", Time()),
201 ("nextUpdate", Time(optional=True)),
202 ("revokedCertificates", RevokedCertificates(optional=True)),
203 ("crlExtensions", Extensions(expl=tag_ctxc(0), optional=True)),
207 class CertificateList(Sequence):
209 ("tbsCertList", TBSCertList()),
210 ("signatureAlgorithm", AlgorithmIdentifier()),
211 ("signatureValue", BitString()),