This commit is contained in:
Ivan Vazhenin
2024-04-25 20:32:28 +03:00
commit 7b8035ff33
101 changed files with 13658 additions and 0 deletions
@@ -0,0 +1,18 @@
#!/usr/bin/env python3
"""DANE's SPKI hash calculator
"""
from base64 import standard_b64decode
from hashlib import sha256
import sys
from pygost.asn1schemas.x509 import Certificate
lines = sys.stdin.read().split("-----")
idx = lines.index("BEGIN CERTIFICATE")
if idx == -1:
raise ValueError("PEM has no CERTIFICATE")
cert_raw = standard_b64decode(lines[idx + 1])
cert = Certificate().decod(cert_raw)
print(sha256(cert["tbsCertificate"]["subjectPublicKeyInfo"].encode()).hexdigest())
@@ -0,0 +1,348 @@
#!/usr/bin/env python3
"""Create example self-signed X.509 certificate
"""
from argparse import ArgumentParser
from base64 import standard_b64decode
from base64 import standard_b64encode
from datetime import datetime
from datetime import timedelta
from os import urandom
from sys import exit as sys_exit
from sys import stdout
from textwrap import fill
from pyderasn import Any
from pyderasn import BitString
from pyderasn import Boolean
from pyderasn import IA5String
from pyderasn import Integer
from pyderasn import OctetString
from pyderasn import PrintableString
from pyderasn import UTCTime
from pygost.asn1schemas.oids import id_at_commonName
from pygost.asn1schemas.oids import id_at_countryName
from pygost.asn1schemas.oids import id_ce_authorityKeyIdentifier
from pygost.asn1schemas.oids import id_ce_basicConstraints
from pygost.asn1schemas.oids import id_ce_keyUsage
from pygost.asn1schemas.oids import id_ce_subjectAltName
from pygost.asn1schemas.oids import id_ce_subjectKeyIdentifier
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256_paramSetA
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256_paramSetB
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256_paramSetC
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256_paramSetD
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512_paramSetA
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512_paramSetB
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512_paramSetC
from pygost.asn1schemas.oids import id_tc26_signwithdigest_gost3410_2012_256
from pygost.asn1schemas.oids import id_tc26_signwithdigest_gost3410_2012_512
from pygost.asn1schemas.prvkey import PrivateKey
from pygost.asn1schemas.prvkey import PrivateKeyAlgorithmIdentifier
from pygost.asn1schemas.prvkey import PrivateKeyInfo
from pygost.asn1schemas.x509 import AlgorithmIdentifier
from pygost.asn1schemas.x509 import AttributeType
from pygost.asn1schemas.x509 import AttributeTypeAndValue
from pygost.asn1schemas.x509 import AttributeValue
from pygost.asn1schemas.x509 import AuthorityKeyIdentifier
from pygost.asn1schemas.x509 import BasicConstraints
from pygost.asn1schemas.x509 import Certificate
from pygost.asn1schemas.x509 import CertificateSerialNumber
from pygost.asn1schemas.x509 import Extension
from pygost.asn1schemas.x509 import Extensions
from pygost.asn1schemas.x509 import GeneralName
from pygost.asn1schemas.x509 import GostR34102012PublicKeyParameters
from pygost.asn1schemas.x509 import KeyIdentifier
from pygost.asn1schemas.x509 import KeyUsage
from pygost.asn1schemas.x509 import Name
from pygost.asn1schemas.x509 import RDNSequence
from pygost.asn1schemas.x509 import RelativeDistinguishedName
from pygost.asn1schemas.x509 import SubjectAltName
from pygost.asn1schemas.x509 import SubjectKeyIdentifier
from pygost.asn1schemas.x509 import SubjectPublicKeyInfo
from pygost.asn1schemas.x509 import TBSCertificate
from pygost.asn1schemas.x509 import Time
from pygost.asn1schemas.x509 import Validity
from pygost.asn1schemas.x509 import Version
from pygost.gost3410 import CURVES
from pygost.gost3410 import prv_unmarshal
from pygost.gost3410 import pub_marshal
from pygost.gost3410 import public_key
from pygost.gost3410 import sign
from pygost.gost34112012256 import GOST34112012256
from pygost.gost34112012512 import GOST34112012512
from pygost.utils import bytes2long
parser = ArgumentParser(description="Self-signed X.509 certificate creator")
parser.add_argument(
"--ca",
action="store_true",
help="Enable BasicConstraints.cA",
)
parser.add_argument(
"--cn",
required=True,
help="Subject's CommonName",
)
parser.add_argument(
"--country",
help="Subject's Country",
)
parser.add_argument(
"--serial",
help="Serial number",
)
parser.add_argument(
"--ai",
required=True,
help="Signing algorithm: {256[ABCD],512[ABC]}",
)
parser.add_argument(
"--issue-with",
help="Path to PEM with CA to issue the child",
)
parser.add_argument(
"--reuse-key",
help="Path to PEM with the key to reuse",
)
parser.add_argument(
"--out-key",
help="Path to PEM with the resulting key",
)
parser.add_argument(
"--only-key",
action="store_true",
help="Only generate the key",
)
parser.add_argument(
"--out-cert",
help="Path to PEM with the resulting certificate",
)
args = parser.parse_args()
AIs = {
"256A": {
"publicKeyParamSet": id_tc26_gost3410_2012_256_paramSetA,
"key_algorithm": id_tc26_gost3410_2012_256,
"prv_len": 32,
"curve": CURVES["id-tc26-gost-3410-2012-256-paramSetA"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_256,
"hasher": GOST34112012256,
},
"256B": {
"publicKeyParamSet": id_tc26_gost3410_2012_256_paramSetB,
"key_algorithm": id_tc26_gost3410_2012_256,
"prv_len": 32,
"curve": CURVES["id-tc26-gost-3410-2012-256-paramSetB"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_256,
"hasher": GOST34112012256,
},
"256C": {
"publicKeyParamSet": id_tc26_gost3410_2012_256_paramSetC,
"key_algorithm": id_tc26_gost3410_2012_256,
"prv_len": 32,
"curve": CURVES["id-tc26-gost-3410-2012-256-paramSetC"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_256,
"hasher": GOST34112012256,
},
"256D": {
"publicKeyParamSet": id_tc26_gost3410_2012_256_paramSetD,
"key_algorithm": id_tc26_gost3410_2012_256,
"prv_len": 32,
"curve": CURVES["id-tc26-gost-3410-2012-256-paramSetD"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_256,
"hasher": GOST34112012256,
},
"512A": {
"publicKeyParamSet": id_tc26_gost3410_2012_512_paramSetA,
"key_algorithm": id_tc26_gost3410_2012_512,
"prv_len": 64,
"curve": CURVES["id-tc26-gost-3410-12-512-paramSetA"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_512,
"hasher": GOST34112012512,
},
"512B": {
"publicKeyParamSet": id_tc26_gost3410_2012_512_paramSetB,
"key_algorithm": id_tc26_gost3410_2012_512,
"prv_len": 64,
"curve": CURVES["id-tc26-gost-3410-12-512-paramSetB"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_512,
"hasher": GOST34112012512,
},
"512C": {
"publicKeyParamSet": id_tc26_gost3410_2012_512_paramSetC,
"key_algorithm": id_tc26_gost3410_2012_512,
"prv_len": 64,
"curve": CURVES["id-tc26-gost-3410-2012-512-paramSetC"],
"sign_algorithm": id_tc26_signwithdigest_gost3410_2012_512,
"hasher": GOST34112012512,
},
}
ai = AIs[args.ai]
ca_prv = None
ca_cert = None
ca_subj = None
ca_ai = None
if args.issue_with is not None:
with open(args.issue_with, "rb") as fd:
lines = fd.read().decode("ascii").split("-----")
idx = lines.index("BEGIN PRIVATE KEY")
if idx == -1:
raise ValueError("PEM has no PRIVATE KEY")
prv_raw = standard_b64decode(lines[idx + 1])
idx = lines.index("BEGIN CERTIFICATE")
if idx == -1:
raise ValueError("PEM has no CERTIFICATE")
cert_raw = standard_b64decode(lines[idx + 1])
pki = PrivateKeyInfo().decod(prv_raw)
ca_prv = prv_unmarshal(bytes(OctetString().decod(bytes(pki["privateKey"]))))
ca_cert = Certificate().decod(cert_raw)
tbs = ca_cert["tbsCertificate"]
ca_subj = tbs["subject"]
curve_oid = GostR34102012PublicKeyParameters().decod(bytes(
tbs["subjectPublicKeyInfo"]["algorithm"]["parameters"]
))["publicKeyParamSet"]
ca_ai = next(iter([
params for params in AIs.values()
if params["publicKeyParamSet"] == curve_oid
]))
key_params = GostR34102012PublicKeyParameters((
("publicKeyParamSet", ai["publicKeyParamSet"]),
))
def pem(obj):
return fill(standard_b64encode(obj.encode()).decode("ascii"), 64)
if args.reuse_key is not None:
with open(args.reuse_key, "rb") as fd:
lines = fd.read().decode("ascii").split("-----")
idx = lines.index("BEGIN PRIVATE KEY")
if idx == -1:
raise ValueError("PEM has no PRIVATE KEY")
prv_raw = standard_b64decode(lines[idx + 1])
pki = PrivateKeyInfo().decod(prv_raw)
prv = prv_unmarshal(bytes(OctetString().decod(bytes(pki["privateKey"]))))
else:
prv_raw = urandom(ai["prv_len"])
out = stdout if args.out_key is None else open(args.out_key, "w")
print("-----BEGIN PRIVATE KEY-----", file=out)
print(pem(PrivateKeyInfo((
("version", Integer(0)),
("privateKeyAlgorithm", PrivateKeyAlgorithmIdentifier((
("algorithm", ai["key_algorithm"]),
("parameters", Any(key_params)),
))),
("privateKey", PrivateKey(OctetString(prv_raw).encode())),
))), file=out)
print("-----END PRIVATE KEY-----", file=out)
if args.only_key:
sys_exit()
prv = prv_unmarshal(prv_raw)
curve = ai["curve"]
pub_raw = pub_marshal(public_key(curve, prv))
rdn = [RelativeDistinguishedName((
AttributeTypeAndValue((
("type", AttributeType(id_at_commonName)),
("value", AttributeValue(PrintableString(args.cn))),
)),
))]
if args.country:
rdn.append(RelativeDistinguishedName((
AttributeTypeAndValue((
("type", AttributeType(id_at_countryName)),
("value", AttributeValue(PrintableString(args.country))),
)),
)))
subj = Name(("rdnSequence", RDNSequence(rdn)))
not_before = datetime.utcnow()
not_after = not_before + timedelta(days=365 * (10 if args.ca else 1))
ai_sign = AlgorithmIdentifier((
("algorithm", (ai if ca_ai is None else ca_ai)["sign_algorithm"]),
))
exts = [
Extension((
("extnID", id_ce_subjectKeyIdentifier),
("extnValue", OctetString(
SubjectKeyIdentifier(GOST34112012256(pub_raw).digest()[:20]).encode()
)),
)),
Extension((
("extnID", id_ce_keyUsage),
("critical", Boolean(True)),
("extnValue", OctetString(KeyUsage(
("keyCertSign" if args.ca else "digitalSignature",),
).encode())),
)),
]
if args.ca:
exts.append(Extension((
("extnID", id_ce_basicConstraints),
("critical", Boolean(True)),
("extnValue", OctetString(BasicConstraints((
("cA", Boolean(True)),
)).encode())),
)))
else:
exts.append(Extension((
("extnID", id_ce_subjectAltName),
("extnValue", OctetString(
SubjectAltName((
GeneralName(("dNSName", IA5String(args.cn))),
)).encode()
)),
)))
if ca_ai is not None:
caKeyId = [
bytes(SubjectKeyIdentifier().decod(bytes(ext["extnValue"])))
for ext in ca_cert["tbsCertificate"]["extensions"]
if ext["extnID"] == id_ce_subjectKeyIdentifier
][0]
exts.append(Extension((
("extnID", id_ce_authorityKeyIdentifier),
("extnValue", OctetString(AuthorityKeyIdentifier((
("keyIdentifier", KeyIdentifier(caKeyId)),
)).encode())),
)))
serial = (
bytes2long(GOST34112012256(urandom(16)).digest()[:20])
if args.serial is None else int(args.serial)
)
tbs = TBSCertificate((
("version", Version("v3")),
("serialNumber", CertificateSerialNumber(serial)),
("signature", ai_sign),
("issuer", subj if ca_ai is None else ca_subj),
("validity", Validity((
("notBefore", Time(("utcTime", UTCTime(not_before)))),
("notAfter", Time(("utcTime", UTCTime(not_after)))),
))),
("subject", subj),
("subjectPublicKeyInfo", SubjectPublicKeyInfo((
("algorithm", AlgorithmIdentifier((
("algorithm", ai["key_algorithm"]),
("parameters", Any(key_params)),
))),
("subjectPublicKey", BitString(OctetString(pub_raw).encode())),
))),
("extensions", Extensions(exts)),
))
cert = Certificate((
("tbsCertificate", tbs),
("signatureAlgorithm", ai_sign),
("signatureValue", BitString(
sign(curve, prv, ai["hasher"](tbs.encode()).digest()[::-1])
if ca_ai is None else
sign(ca_ai["curve"], ca_prv, ca_ai["hasher"](tbs.encode()).digest()[::-1])
)),
))
out = stdout if args.out_cert is None else open(args.out_cert, "w")
print("-----BEGIN CERTIFICATE-----", file=out)
print(pem(cert), file=out)
print("-----END CERTIFICATE-----", file=out)
@@ -0,0 +1,431 @@
# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
# Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
#
# 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, 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""CMS related structures (**NOT COMPLETE**)
"""
from pyderasn import Any
from pyderasn import BitString
from pyderasn import Choice
from pyderasn import Integer
from pyderasn import ObjectIdentifier
from pyderasn import OctetString
from pyderasn import Sequence
from pyderasn import SequenceOf
from pyderasn import SetOf
from pyderasn import tag_ctxc
from pyderasn import tag_ctxp
from pygost.asn1schemas.oids import id_cms_mac_attr
from pygost.asn1schemas.oids import id_contentType
from pygost.asn1schemas.oids import id_digestedData
from pygost.asn1schemas.oids import id_encryptedData
from pygost.asn1schemas.oids import id_envelopedData
from pygost.asn1schemas.oids import id_Gost28147_89
from pygost.asn1schemas.oids import id_gostr3412_2015_kuznyechik_ctracpkm
from pygost.asn1schemas.oids import id_gostr3412_2015_kuznyechik_ctracpkm_omac
from pygost.asn1schemas.oids import id_gostr3412_2015_kuznyechik_wrap_kexp15
from pygost.asn1schemas.oids import id_gostr3412_2015_magma_ctracpkm
from pygost.asn1schemas.oids import id_gostr3412_2015_magma_ctracpkm_omac
from pygost.asn1schemas.oids import id_gostr3412_2015_magma_wrap_kexp15
from pygost.asn1schemas.oids import id_messageDigest
from pygost.asn1schemas.oids import id_signedData
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
from pygost.asn1schemas.x509 import AlgorithmIdentifier
from pygost.asn1schemas.x509 import Certificate
from pygost.asn1schemas.x509 import CertificateSerialNumber
from pygost.asn1schemas.x509 import Name
from pygost.asn1schemas.x509 import SubjectPublicKeyInfo
class CMSVersion(Integer):
pass
class ContentType(ObjectIdentifier):
pass
class IssuerAndSerialNumber(Sequence):
schema = (
("issuer", Name()),
("serialNumber", CertificateSerialNumber()),
)
class KeyIdentifier(OctetString):
pass
class SubjectKeyIdentifier(KeyIdentifier):
pass
class RecipientIdentifier(Choice):
schema = (
("issuerAndSerialNumber", IssuerAndSerialNumber()),
("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
)
class Gost2814789Key(OctetString):
bounds = (32, 32)
class Gost2814789MAC(OctetString):
bounds = (4, 4)
class Gost2814789EncryptedKey(Sequence):
schema = (
("encryptedKey", Gost2814789Key()),
("maskKey", Gost2814789Key(impl=tag_ctxp(0), optional=True)),
("macKey", Gost2814789MAC()),
)
class GostR34102001TransportParameters(Sequence):
schema = (
("encryptionParamSet", ObjectIdentifier()),
("ephemeralPublicKey", SubjectPublicKeyInfo(
impl=tag_ctxc(0),
optional=True,
)),
("ukm", OctetString()),
)
class GostR3410KeyTransport(Sequence):
schema = (
("sessionEncryptedKey", Gost2814789EncryptedKey()),
("transportParameters", GostR34102001TransportParameters(
impl=tag_ctxc(0),
optional=True,
)),
)
class GostR3410KeyTransport2019(Sequence):
schema = (
("encryptedKey", OctetString()),
("ephemeralPublicKey", SubjectPublicKeyInfo()),
("ukm", OctetString()),
)
class GostR341012KEGParameters(Sequence):
schema = (
("algorithm", ObjectIdentifier()),
)
class KeyEncryptionAlgorithmIdentifier(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {
id_gostr3412_2015_magma_wrap_kexp15: GostR341012KEGParameters(),
id_gostr3412_2015_kuznyechik_wrap_kexp15: GostR341012KEGParameters(),
}),
(("..", "encryptedKey"), {
id_tc26_gost3410_2012_256: GostR3410KeyTransport(),
id_tc26_gost3410_2012_512: GostR3410KeyTransport(),
id_gostr3412_2015_magma_wrap_kexp15: GostR3410KeyTransport2019(),
id_gostr3412_2015_kuznyechik_wrap_kexp15: GostR3410KeyTransport2019(),
}),
(("..", "recipientEncryptedKeys", any, "encryptedKey"), {
id_tc26_gost3410_2012_256: Gost2814789EncryptedKey(),
id_tc26_gost3410_2012_512: Gost2814789EncryptedKey(),
}),
))),
("parameters", Any(optional=True)),
)
class EncryptedKey(OctetString):
pass
class KeyTransRecipientInfo(Sequence):
schema = (
("version", CMSVersion()),
("rid", RecipientIdentifier()),
("keyEncryptionAlgorithm", KeyEncryptionAlgorithmIdentifier()),
("encryptedKey", EncryptedKey()),
)
class OriginatorPublicKey(Sequence):
schema = (
("algorithm", AlgorithmIdentifier()),
("publicKey", BitString()),
)
class OriginatorIdentifierOrKey(Choice):
schema = (
("issuerAndSerialNumber", IssuerAndSerialNumber()),
("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
("originatorKey", OriginatorPublicKey(impl=tag_ctxc(1))),
)
class UserKeyingMaterial(OctetString):
pass
class KeyAgreeRecipientIdentifier(Choice):
schema = (
("issuerAndSerialNumber", IssuerAndSerialNumber()),
# ("rKeyId", RecipientKeyIdentifier(impl=tag_ctxc(0))),
)
class RecipientEncryptedKey(Sequence):
schema = (
("rid", KeyAgreeRecipientIdentifier()),
("encryptedKey", EncryptedKey()),
)
class RecipientEncryptedKeys(SequenceOf):
schema = RecipientEncryptedKey()
class KeyAgreeRecipientInfo(Sequence):
schema = (
("version", CMSVersion(3)),
("originator", OriginatorIdentifierOrKey(expl=tag_ctxc(0))),
("ukm", UserKeyingMaterial(expl=tag_ctxc(1), optional=True)),
("keyEncryptionAlgorithm", KeyEncryptionAlgorithmIdentifier()),
("recipientEncryptedKeys", RecipientEncryptedKeys()),
)
class RecipientInfo(Choice):
schema = (
("ktri", KeyTransRecipientInfo()),
("kari", KeyAgreeRecipientInfo(impl=tag_ctxc(1))),
# ("kekri", KEKRecipientInfo(impl=tag_ctxc(2))),
# ("pwri", PasswordRecipientInfo(impl=tag_ctxc(3))),
# ("ori", OtherRecipientInfo(impl=tag_ctxc(4))),
)
class RecipientInfos(SetOf):
schema = RecipientInfo()
bounds = (1, float("+inf"))
class Gost2814789IV(OctetString):
bounds = (8, 8)
class Gost2814789Parameters(Sequence):
schema = (
("iv", Gost2814789IV()),
("encryptionParamSet", ObjectIdentifier()),
)
class Gost341215EncryptionParameters(Sequence):
schema = (
("ukm", OctetString()),
)
class ContentEncryptionAlgorithmIdentifier(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {
id_Gost28147_89: Gost2814789Parameters(),
id_gostr3412_2015_magma_ctracpkm: Gost341215EncryptionParameters(),
id_gostr3412_2015_kuznyechik_ctracpkm: Gost341215EncryptionParameters(),
id_gostr3412_2015_magma_ctracpkm_omac: Gost341215EncryptionParameters(),
id_gostr3412_2015_kuznyechik_ctracpkm_omac: Gost341215EncryptionParameters(),
}),
))),
("parameters", Any(optional=True)),
)
class EncryptedContent(OctetString):
pass
class EncryptedContentInfo(Sequence):
schema = (
("contentType", ContentType()),
("contentEncryptionAlgorithm", ContentEncryptionAlgorithmIdentifier()),
("encryptedContent", EncryptedContent(impl=tag_ctxp(0), optional=True)),
)
class Digest(OctetString):
pass
class AttributeValue(Any):
pass
class AttributeValues(SetOf):
schema = AttributeValue()
class EncryptedMac(OctetString):
pass
class Attribute(Sequence):
schema = (
("attrType", ObjectIdentifier(defines=(
(("attrValues",), {
id_contentType: ObjectIdentifier(),
id_messageDigest: Digest(),
id_cms_mac_attr: EncryptedMac(),
},),
))),
("attrValues", AttributeValues()),
)
class UnprotectedAttributes(SetOf):
schema = Attribute()
bounds = (1, float("+inf"))
class CertificateChoices(Choice):
schema = (
("certificate", Certificate()),
# ("extendedCertificate", OctetString(impl=tag_ctxp(0))),
# ("v1AttrCert", AttributeCertificateV1(impl=tag_ctxc(1))), # V1 is osbolete
# ("v2AttrCert", AttributeCertificateV2(impl=tag_ctxc(2))),
# ("other", OtherCertificateFormat(impl=tag_ctxc(3))),
)
class CertificateSet(SetOf):
schema = CertificateChoices()
class OriginatorInfo(Sequence):
schema = (
("certs", CertificateSet(impl=tag_ctxc(0), optional=True)),
# ("crls", RevocationInfoChoices(impl=tag_ctxc(1), optional=True)),
)
class EnvelopedData(Sequence):
schema = (
("version", CMSVersion()),
("originatorInfo", OriginatorInfo(impl=tag_ctxc(0), optional=True)),
("recipientInfos", RecipientInfos()),
("encryptedContentInfo", EncryptedContentInfo()),
("unprotectedAttrs", UnprotectedAttributes(impl=tag_ctxc(1), optional=True)),
)
class EncapsulatedContentInfo(Sequence):
schema = (
("eContentType", ContentType()),
("eContent", OctetString(expl=tag_ctxc(0), optional=True)),
)
class SignerIdentifier(Choice):
schema = (
("issuerAndSerialNumber", IssuerAndSerialNumber()),
("subjectKeyIdentifier", SubjectKeyIdentifier(impl=tag_ctxp(0))),
)
class DigestAlgorithmIdentifiers(SetOf):
schema = AlgorithmIdentifier()
class DigestAlgorithmIdentifier(AlgorithmIdentifier):
pass
class SignatureAlgorithmIdentifier(AlgorithmIdentifier):
pass
class SignatureValue(OctetString):
pass
class SignedAttributes(SetOf):
schema = Attribute()
bounds = (1, float("+inf"))
class SignerInfo(Sequence):
schema = (
("version", CMSVersion()),
("sid", SignerIdentifier()),
("digestAlgorithm", DigestAlgorithmIdentifier()),
("signedAttrs", SignedAttributes(impl=tag_ctxc(0), optional=True)),
("signatureAlgorithm", SignatureAlgorithmIdentifier()),
("signature", SignatureValue()),
# ("unsignedAttrs", UnsignedAttributes(impl=tag_ctxc(1), optional=True)),
)
class SignerInfos(SetOf):
schema = SignerInfo()
class SignedData(Sequence):
schema = (
("version", CMSVersion()),
("digestAlgorithms", DigestAlgorithmIdentifiers()),
("encapContentInfo", EncapsulatedContentInfo()),
("certificates", CertificateSet(impl=tag_ctxc(0), optional=True)),
# ("crls", RevocationInfoChoices(impl=tag_ctxc(1), optional=True)),
("signerInfos", SignerInfos()),
)
class DigestedData(Sequence):
schema = (
("version", CMSVersion()),
("digestAlgorithm", DigestAlgorithmIdentifier()),
("encapContentInfo", EncapsulatedContentInfo()),
("digest", Digest()),
)
class EncryptedData(Sequence):
schema = (
("version", CMSVersion()),
("encryptedContentInfo", EncryptedContentInfo()),
("unprotectedAttrs", UnprotectedAttributes(impl=tag_ctxc(1), optional=True)),
)
class ContentInfo(Sequence):
schema = (
("contentType", ContentType(defines=(
(("content",), {
id_digestedData: DigestedData(),
id_encryptedData: EncryptedData(),
id_envelopedData: EnvelopedData(),
id_signedData: SignedData(),
}),
))),
("content", Any(expl=tag_ctxc(0))),
)
@@ -0,0 +1,60 @@
from pyderasn import ObjectIdentifier
id_at_commonName = ObjectIdentifier("2.5.4.3")
id_at_countryName = ObjectIdentifier("2.5.4.6")
id_at_localityName = ObjectIdentifier("2.5.4.7")
id_at_stateOrProvinceName = ObjectIdentifier("2.5.4.8")
id_at_organizationName = ObjectIdentifier("2.5.4.10")
id_pkcs7 = ObjectIdentifier("1.2.840.113549.1.7")
id_data = id_pkcs7 + (1,)
id_signedData = id_pkcs7 + (2,)
id_envelopedData = id_pkcs7 + (3,)
id_digestedData = id_pkcs7 + (5,)
id_encryptedData = id_pkcs7 + (6,)
id_pkcs9 = ObjectIdentifier("1.2.840.113549.1.9")
id_contentType = id_pkcs9 + (3,)
id_messageDigest = id_pkcs9 + (4,)
id_pkcs9_certTypes_x509Certificate = ObjectIdentifier("1.2.840.113549.1.9.22.1")
id_pkcs12_bagtypes_keyBag = ObjectIdentifier("1.2.840.113549.1.12.10.1.1")
id_pkcs12_bagtypes_pkcs8ShroudedKeyBag = ObjectIdentifier("1.2.840.113549.1.12.10.1.2")
id_pkcs12_bagtypes_certBag = ObjectIdentifier("1.2.840.113549.1.12.10.1.3")
id_Gost28147_89 = ObjectIdentifier("1.2.643.2.2.21")
id_GostR3410_2001_TestParamSet = ObjectIdentifier("1.2.643.2.2.35.0")
id_cms_mac_attr = ObjectIdentifier("1.2.643.7.1.0.6.1.1")
id_tc26_gost3410_2012_256 = ObjectIdentifier("1.2.643.7.1.1.1.1")
id_tc26_gost3410_2012_512 = ObjectIdentifier("1.2.643.7.1.1.1.2")
id_tc26_gost3411_2012_256 = ObjectIdentifier("1.2.643.7.1.1.2.2")
id_tc26_gost3411_2012_512 = ObjectIdentifier("1.2.643.7.1.1.2.3")
id_tc26_signwithdigest_gost3410_2012_256 = ObjectIdentifier("1.2.643.7.1.1.3.2")
id_tc26_signwithdigest_gost3410_2012_512 = ObjectIdentifier("1.2.643.7.1.1.3.3")
id_gostr3412_2015_magma_ctracpkm = ObjectIdentifier("1.2.643.7.1.1.5.1.1")
id_gostr3412_2015_magma_ctracpkm_omac = ObjectIdentifier("1.2.643.7.1.1.5.1.2")
id_gostr3412_2015_kuznyechik_ctracpkm = ObjectIdentifier("1.2.643.7.1.1.5.2.1")
id_gostr3412_2015_kuznyechik_ctracpkm_omac = ObjectIdentifier("1.2.643.7.1.1.5.2.2")
id_tc26_agreement_gost3410_2012_256 = ObjectIdentifier("1.2.643.7.1.1.6.1")
id_tc26_agreement_gost3410_2012_512 = ObjectIdentifier("1.2.643.7.1.1.6.2")
id_gostr3412_2015_magma_wrap_kexp15 = ObjectIdentifier("1.2.643.7.1.1.7.1.1")
id_gostr3412_2015_kuznyechik_wrap_kexp15 = ObjectIdentifier("1.2.643.7.1.1.7.2.1")
id_tc26_gost3410_2012_256_paramSetA = ObjectIdentifier("1.2.643.7.1.2.1.1.1")
id_tc26_gost3410_2012_256_paramSetB = ObjectIdentifier("1.2.643.7.1.2.1.1.2")
id_tc26_gost3410_2012_256_paramSetC = ObjectIdentifier("1.2.643.7.1.2.1.1.3")
id_tc26_gost3410_2012_256_paramSetD = ObjectIdentifier("1.2.643.7.1.2.1.1.4")
id_tc26_gost3410_2012_512_paramSetTest = ObjectIdentifier("1.2.643.7.1.2.1.2.0")
id_tc26_gost3410_2012_512_paramSetA = ObjectIdentifier("1.2.643.7.1.2.1.2.1")
id_tc26_gost3410_2012_512_paramSetB = ObjectIdentifier("1.2.643.7.1.2.1.2.2")
id_tc26_gost3410_2012_512_paramSetC = ObjectIdentifier("1.2.643.7.1.2.1.2.3")
id_tc26_gost_28147_param_Z = ObjectIdentifier("1.2.643.7.1.2.5.1.1")
id_pbes2 = ObjectIdentifier("1.2.840.113549.1.5.13")
id_pbkdf2 = ObjectIdentifier("1.2.840.113549.1.5.12")
id_at_commonName = ObjectIdentifier("2.5.4.3")
id_ce_basicConstraints = ObjectIdentifier("2.5.29.19")
id_ce_subjectKeyIdentifier = ObjectIdentifier("2.5.29.14")
id_ce_keyUsage = ObjectIdentifier("2.5.29.15")
id_ce_subjectAltName = ObjectIdentifier("2.5.29.17")
id_ce_authorityKeyIdentifier = ObjectIdentifier("2.5.29.35")
@@ -0,0 +1,250 @@
# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
# Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
#
# 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, 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""PKCS #12 related structures (**NOT COMPLETE**)
"""
from pyderasn import Any
from pyderasn import Choice
from pyderasn import Integer
from pyderasn import ObjectIdentifier
from pyderasn import OctetString
from pyderasn import Sequence
from pyderasn import SequenceOf
from pyderasn import SetOf
from pyderasn import tag_ctxc
from pyderasn import tag_ctxp
from pygost.asn1schemas.cms import CMSVersion
from pygost.asn1schemas.cms import ContentType
from pygost.asn1schemas.cms import Gost2814789Parameters
from pygost.asn1schemas.cms import Gost341215EncryptionParameters
from pygost.asn1schemas.oids import id_data
from pygost.asn1schemas.oids import id_encryptedData
from pygost.asn1schemas.oids import id_Gost28147_89
from pygost.asn1schemas.oids import id_gostr3412_2015_kuznyechik_ctracpkm
from pygost.asn1schemas.oids import id_gostr3412_2015_kuznyechik_ctracpkm_omac
from pygost.asn1schemas.oids import id_gostr3412_2015_magma_ctracpkm
from pygost.asn1schemas.oids import id_gostr3412_2015_magma_ctracpkm_omac
from pygost.asn1schemas.oids import id_pbes2
from pygost.asn1schemas.oids import id_pbkdf2
from pygost.asn1schemas.oids import id_pkcs9_certTypes_x509Certificate
from pygost.asn1schemas.prvkey import PrivateKeyInfo
from pygost.asn1schemas.x509 import AlgorithmIdentifier
from pygost.asn1schemas.x509 import Certificate
class PBKDF2Salt(Choice):
schema = (
("specified", OctetString()),
# ("otherSource", PBKDF2SaltSources()),
)
id_hmacWithSHA1 = ObjectIdentifier("1.2.840.113549.2.7")
class PBKDF2PRFs(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(default=id_hmacWithSHA1)),
("parameters", Any(optional=True)),
)
class IterationCount(Integer):
bounds = (1, float("+inf"))
class KeyLength(Integer):
bounds = (1, float("+inf"))
class PBKDF2Params(Sequence):
schema = (
("salt", PBKDF2Salt()),
("iterationCount", IterationCount(optional=True)),
("keyLength", KeyLength(optional=True)),
("prf", PBKDF2PRFs()),
)
class PBES2KDFs(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {id_pbkdf2: PBKDF2Params()}),
))),
("parameters", Any(optional=True)),
)
class PBES2Encs(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {
id_Gost28147_89: Gost2814789Parameters(),
id_gostr3412_2015_magma_ctracpkm: Gost341215EncryptionParameters(),
id_gostr3412_2015_magma_ctracpkm_omac: Gost341215EncryptionParameters(),
id_gostr3412_2015_kuznyechik_ctracpkm: Gost341215EncryptionParameters(),
id_gostr3412_2015_kuznyechik_ctracpkm_omac: Gost341215EncryptionParameters(),
}),
))),
("parameters", Any(optional=True)),
)
class PBES2Params(Sequence):
schema = (
("keyDerivationFunc", PBES2KDFs()),
("encryptionScheme", PBES2Encs()),
)
class EncryptionAlgorithmIdentifier(AlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {id_pbes2: PBES2Params()}),
))),
("parameters", Any(optional=True)),
)
class ContentEncryptionAlgorithmIdentifier(EncryptionAlgorithmIdentifier):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {id_pbes2: PBES2Params()}),
))),
("parameters", Any(optional=True)),
)
class EncryptedContent(OctetString):
pass
class EncryptedContentInfo(Sequence):
schema = (
("contentType", ContentType()),
("contentEncryptionAlgorithm", ContentEncryptionAlgorithmIdentifier()),
("encryptedContent", EncryptedContent(impl=tag_ctxp(0), optional=True)),
)
class EncryptedData(Sequence):
schema = (
("version", CMSVersion()),
("encryptedContentInfo", EncryptedContentInfo()),
# ("unprotectedAttrs", UnprotectedAttributes(impl=tag_ctxc(1), optional=True)),
)
class PKCS12BagSet(Any):
pass
class AttrValue(SetOf):
schema = Any()
class PKCS12Attribute(Sequence):
schema = (
("attrId", ObjectIdentifier()),
("attrValue", AttrValue()),
)
class PKCS12Attributes(SetOf):
schema = PKCS12Attribute()
class SafeBag(Sequence):
schema = (
("bagId", ObjectIdentifier(defines=(
(("bagValue",), {id_encryptedData: EncryptedData()}),
))),
("bagValue", PKCS12BagSet(expl=tag_ctxc(0))),
("bagAttributes", PKCS12Attributes(optional=True)),
)
class SafeContents(SequenceOf):
schema = SafeBag()
OctetStringSafeContents = SafeContents(expl=OctetString.tag_default)
class AuthSafe(Sequence):
schema = (
("contentType", ContentType(defines=(
(("content",), {id_data: OctetStringSafeContents()}),
))),
("content", Any(expl=tag_ctxc(0))),
)
class DigestInfo(Sequence):
schema = (
("digestAlgorithm", AlgorithmIdentifier()),
("digest", OctetString()),
)
class MacData(Sequence):
schema = (
("mac", DigestInfo()),
("macSalt", OctetString()),
("iterations", Integer(default=1)),
)
class PFX(Sequence):
schema = (
("version", Integer(default=1)),
("authSafe", AuthSafe()),
("macData", MacData(optional=True)),
)
class EncryptedPrivateKeyInfo(Sequence):
schema = (
("encryptionAlgorithm", EncryptionAlgorithmIdentifier()),
("encryptedData", OctetString()),
)
class PKCS8ShroudedKeyBag(EncryptedPrivateKeyInfo):
pass
OctetStringX509Certificate = Certificate(expl=OctetString.tag_default)
class CertTypes(Any):
pass
class CertBag(Sequence):
schema = (
("certId", ObjectIdentifier(defines=(
(("certValue",), {
id_pkcs9_certTypes_x509Certificate: OctetStringX509Certificate(),
}),
))),
("certValue", CertTypes(expl=tag_ctxc(0))),
)
class KeyBag(PrivateKeyInfo):
pass
@@ -0,0 +1,49 @@
# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
# Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
#
# 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, 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
"""PKCS #10 related structures (**NOT COMPLETE**)
"""
from pyderasn import BitString
from pyderasn import Integer
from pyderasn import Sequence
from pyderasn import SetOf
from pyderasn import tag_ctxc
from pygost.asn1schemas.cms import Attribute
from pygost.asn1schemas.x509 import AlgorithmIdentifier
from pygost.asn1schemas.x509 import Name
from pygost.asn1schemas.x509 import SubjectPublicKeyInfo
class Attributes(SetOf):
schema = Attribute()
class CertificationRequestInfo(Sequence):
schema = (
("version", Integer(0)),
("subject", Name()),
("subjectPKInfo", SubjectPublicKeyInfo()),
("attributes", Attributes(impl=tag_ctxc(0))),
)
class CertificationRequest(Sequence):
schema = (
("certificationRequestInfo", CertificationRequestInfo()),
("signatureAlgorithm", AlgorithmIdentifier()),
("signature", BitString()),
)
@@ -0,0 +1,100 @@
# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
# Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
#
# 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, 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from pyderasn import Any
from pyderasn import BitString
from pyderasn import Choice
from pyderasn import Integer
from pyderasn import Null
from pyderasn import ObjectIdentifier
from pyderasn import OctetString
from pyderasn import Sequence
from pyderasn import SetOf
from pyderasn import tag_ctxc
from pyderasn import tag_ctxp
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_256
from pygost.asn1schemas.oids import id_tc26_gost3410_2012_512
from pygost.asn1schemas.x509 import GostR34102012PublicKeyParameters
class ECParameters(Choice):
schema = (
("namedCurve", ObjectIdentifier()),
("implicitCurve", Null()),
# ("specifiedCurve", SpecifiedECDomain()),
)
ecPrivkeyVer1 = Integer(1)
class ECPrivateKey(Sequence):
schema = (
("version", Integer(ecPrivkeyVer1)),
("privateKey", OctetString()),
("parameters", ECParameters(expl=tag_ctxc(0), optional=True)),
("publicKey", BitString(expl=tag_ctxc(1), optional=True)),
)
class PrivateKeyAlgorithmIdentifier(Sequence):
schema = (
("algorithm", ObjectIdentifier(defines=(
(("parameters",), {
id_tc26_gost3410_2012_256: GostR34102012PublicKeyParameters(),
id_tc26_gost3410_2012_512: GostR34102012PublicKeyParameters(),
}),
))),
("parameters", Any(optional=True)),
)
class PrivateKey(OctetString):
pass
class AttributeValue(Any):
pass
class AttributeValues(SetOf):
schema = AttributeValue()
class Attribute(Sequence):
schema = (
("attrType", ObjectIdentifier()),
("attrValues", AttributeValues()),
)
class Attributes(SetOf):
schema = Attribute()
class PublicKey(BitString):
pass
class PrivateKeyInfo(Sequence):
schema = (
("version", Integer(0)),
("privateKeyAlgorithm", PrivateKeyAlgorithmIdentifier()),
("privateKey", PrivateKey()),
("attributes", Attributes(impl=tag_ctxc(0), optional=True)),
("publicKey", PublicKey(impl=tag_ctxp(1), optional=True)),
)
@@ -0,0 +1,262 @@
# coding: utf-8
# PyGOST -- Pure Python GOST cryptographic functions library
# Copyright (C) 2015-2023 Sergey Matveev <stargrave@stargrave.org>
#
# 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, 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
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
""":rfc:`5280` related structures (**NOT COMPLETE**)
They are taken from `PyDERASN <http://www.pyderasn.cypherpunks.ru/`__ tests.
"""
from pyderasn import Any
from pyderasn import BitString
from pyderasn import Boolean
from pyderasn import Choice
from pyderasn import GeneralizedTime
from pyderasn import IA5String
from pyderasn import Integer
from pyderasn import ObjectIdentifier
from pyderasn import OctetString
from pyderasn import PrintableString
from pyderasn import Sequence
from pyderasn import SequenceOf
from pyderasn import SetOf
from pyderasn import tag_ctxc
from pyderasn import tag_ctxp
from pyderasn import TeletexString
from pyderasn import UTCTime
from pygost.asn1schemas.oids import id_at_commonName
from pygost.asn1schemas.oids import id_at_countryName
from pygost.asn1schemas.oids import id_at_localityName
from pygost.asn1schemas.oids import id_at_organizationName
from pygost.asn1schemas.oids import id_at_stateOrProvinceName
class Version(Integer):
schema = (
("v1", 0),
("v2", 1),
("v3", 2),
)
class CertificateSerialNumber(Integer):
pass
class AlgorithmIdentifier(Sequence):
schema = (
("algorithm", ObjectIdentifier()),
("parameters", Any(optional=True)),
)
class AttributeType(ObjectIdentifier):
pass
class AttributeValue(Any):
pass
class OrganizationName(Choice):
schema = (
("printableString", PrintableString()),
("teletexString", TeletexString()),
)
class AttributeTypeAndValue(Sequence):
schema = (
("type", AttributeType(defines=(((".", "value"), {
id_at_countryName: PrintableString(),
id_at_stateOrProvinceName: PrintableString(),
id_at_localityName: PrintableString(),
id_at_organizationName: OrganizationName(),
id_at_commonName: PrintableString(),
}),))),
("value", AttributeValue()),
)
class RelativeDistinguishedName(SetOf):
schema = AttributeTypeAndValue()
bounds = (1, float("+inf"))
class RDNSequence(SequenceOf):
schema = RelativeDistinguishedName()
class Name(Choice):
schema = (
("rdnSequence", RDNSequence()),
)
class Time(Choice):
schema = (
("utcTime", UTCTime()),
("generalTime", GeneralizedTime()),
)
class Validity(Sequence):
schema = (
("notBefore", Time()),
("notAfter", Time()),
)
class GostR34102012PublicKeyParameters(Sequence):
schema = (
("publicKeyParamSet", ObjectIdentifier()),
("digestParamSet", ObjectIdentifier(optional=True)),
)
class SubjectPublicKeyInfo(Sequence):
schema = (
("algorithm", AlgorithmIdentifier()),
("subjectPublicKey", BitString()),
)
class UniqueIdentifier(BitString):
pass
class KeyIdentifier(OctetString):
pass
class SubjectKeyIdentifier(KeyIdentifier):
pass
class BasicConstraints(Sequence):
schema = (
("cA", Boolean(default=False)),
# ("pathLenConstraint", PathLenConstraint(optional=True)),
)
class Extension(Sequence):
schema = (
("extnID", ObjectIdentifier()),
("critical", Boolean(default=False)),
("extnValue", OctetString()),
)
class Extensions(SequenceOf):
schema = Extension()
bounds = (1, float("+inf"))
class TBSCertificate(Sequence):
schema = (
("version", Version(expl=tag_ctxc(0), default="v1")),
("serialNumber", CertificateSerialNumber()),
("signature", AlgorithmIdentifier()),
("issuer", Name()),
("validity", Validity()),
("subject", Name()),
("subjectPublicKeyInfo", SubjectPublicKeyInfo()),
("issuerUniqueID", UniqueIdentifier(impl=tag_ctxp(1), optional=True)),
("subjectUniqueID", UniqueIdentifier(impl=tag_ctxp(2), optional=True)),
("extensions", Extensions(expl=tag_ctxc(3), optional=True)),
)
class Certificate(Sequence):
schema = (
("tbsCertificate", TBSCertificate()),
("signatureAlgorithm", AlgorithmIdentifier()),
("signatureValue", BitString()),
)
class RevokedCertificates(SequenceOf):
# schema = RevokedCertificate()
schema = OctetString() # dummy
class TBSCertList(Sequence):
schema = (
("version", Version(optional=True)),
("signature", AlgorithmIdentifier()),
("issuer", Name()),
("thisUpdate", Time()),
("nextUpdate", Time(optional=True)),
("revokedCertificates", RevokedCertificates(optional=True)),
("crlExtensions", Extensions(expl=tag_ctxc(0), optional=True)),
)
class CertificateList(Sequence):
schema = (
("tbsCertList", TBSCertList()),
("signatureAlgorithm", AlgorithmIdentifier()),
("signatureValue", BitString()),
)
class GeneralName(Choice):
schema = (
# ("otherName", AnotherName(impl=tag_ctxc(0))),
# ("rfc822Name", IA5String(impl=tag_ctxp(1))),
("dNSName", IA5String(impl=tag_ctxp(2))),
# ("x400Address", ORAddress(impl=tag_ctxp(3))),
# ("x400Address", OctetString(impl=tag_ctxp(3))),
# ("directoryName", Name(expl=tag_ctxc(4))),
# ("ediPartyName", EDIPartyName(impl=tag_ctxc(5))),
# ("uniformResourceIdentifier", IA5String(impl=tag_ctxp(6))),
# ("iPAddress", OctetString(impl=tag_ctxp(7))),
# ("registeredID", ObjectIdentifier(impl=tag_ctxp(8))),
)
class GeneralNames(SequenceOf):
schema = GeneralName()
bounds = (1, float("+inf"))
class SubjectAltName(GeneralNames):
pass
class AuthorityKeyIdentifier(Sequence):
schema = (
("keyIdentifier", KeyIdentifier(impl=tag_ctxp(0), optional=True)),
# ("authorityCertIssuer", GeneralNames(impl=tag_ctxc(1), optional=True)),
# (
# "authorityCertSerialNumber",
# CertificateSerialNumber(impl=tag_ctxp(2), optional=True),
# ),
)
class KeyUsage(BitString):
schema = (
("digitalSignature", 0),
("nonRepudiation", 1),
("keyEncipherment", 2),
("dataEncipherment", 3),
("keyAgreement", 4),
("keyCertSign", 5),
("cRLSign", 6),
("encipherOnly", 7),
("decipherOnly", 8),
)