# License along with this program. If not, see
# <http://www.gnu.org/licenses/>.
+from copy import copy
from datetime import datetime
from unittest import TestCase
+from six.moves.cPickle import dumps as pickle_dumps
+from six.moves.cPickle import HIGHEST_PROTOCOL as pickle_proto
+from six.moves.cPickle import loads as pickle_loads
+
from pyderasn import Any
from pyderasn import BitString
from pyderasn import Boolean
from pyderasn import UTCTime
-some_oids = {
- "1.2.840.113549.1.1.1": "id-rsaEncryption",
- "1.2.840.113549.1.1.5": "id-sha1WithRSAEncryption",
- "1.2.840.113549.1.9.1": "id-emailAddress",
- "2.5.29.14": "id-ce-subjectKeyIdentifier",
- "2.5.29.15": "id-ce-keyUsage",
- "2.5.29.17": "id-ce-subjectAltName",
- "2.5.29.18": "id-ce-issuerAltName",
- "2.5.29.19": "id-ce-basicConstraints",
- "2.5.29.31": "id-ce-cRLDistributionPoints",
- "2.5.29.35": "id-ce-authorityKeyIdentifier",
- "2.5.29.37": "id-ce-extKeyUsage",
- "2.5.4.3": "id-at-commonName",
- "2.5.4.6": "id-at-countryName",
- "2.5.4.7": "id-at-localityName",
- "2.5.4.8": "id-at-stateOrProvinceName",
- "2.5.4.10": "id-at-organizationName",
- "2.5.4.11": "id-at-organizationalUnitName",
+name2oid = {
+ "id-rsaEncryption": ObjectIdentifier("1.2.840.113549.1.1.1"),
+ "id-sha1WithRSAEncryption": ObjectIdentifier("1.2.840.113549.1.1.5"),
+ "id-emailAddress": ObjectIdentifier("1.2.840.113549.1.9.1"),
+ "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-issuerAltName": ObjectIdentifier("2.5.29.18"),
+ "id-ce-basicConstraints": ObjectIdentifier("2.5.29.19"),
+ "id-ce-cRLDistributionPoints": ObjectIdentifier("2.5.29.31"),
+ "id-ce-authorityKeyIdentifier": ObjectIdentifier("2.5.29.35"),
+ "id-ce-extKeyUsage": ObjectIdentifier("2.5.29.37"),
+ "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-at-organizationalUnitName": ObjectIdentifier("2.5.4.11"),
}
+stroid2name = {str(oid): name for name, oid in name2oid.items()}
class Version(Integer):
class AttributeTypeAndValue(Sequence):
schema = (
("type", AttributeType(defines=(((".", "value"), {
- ObjectIdentifier("2.5.4.6"): PrintableString(),
- ObjectIdentifier("2.5.4.8"): PrintableString(),
- ObjectIdentifier("2.5.4.7"): PrintableString(),
- ObjectIdentifier("2.5.4.10"): OrganizationName(),
- ObjectIdentifier("2.5.4.3"): PrintableString(),
+ name2oid["id-at-countryName"]: PrintableString(),
+ name2oid["id-at-localityName"]: PrintableString(),
+ name2oid["id-at-stateOrProvinceName"]: PrintableString(),
+ name2oid["id-at-organizationName"]: OrganizationName(),
+ name2oid["id-at-commonName"]: PrintableString(),
}),))),
("value", AttributeValue()),
)
)
assert_raw_equals(tbs["serialNumber"], Integer(10143011886257155224))
algo_id = AlgorithmIdentifier((
- ("algorithm", ObjectIdentifier("1.2.840.113549.1.1.5")),
+ ("algorithm", name2oid["id-sha1WithRSAEncryption"]),
("parameters", Any(Null())),
))
self.assertEqual(tbs["signature"], algo_id)
self.assertEqual(tbs["subject"], issuer)
assert_raw_equals(tbs["subject"], issuer)
spki = SubjectPublicKeyInfo()
- algo_id["algorithm"] = ObjectIdentifier("1.2.840.113549.1.1.1")
+ algo_id["algorithm"] = name2oid["id-rsaEncryption"]
spki["algorithm"] = algo_id
spki["subjectPublicKey"] = BitString(hexdec("".join((
"3048024100cdb7639c3278f006aa277f6eaf42902b592d8cbcbe38a1c92ba4695",
self.assertNotIn("issuerUniqueID", tbs)
self.assertNotIn("subjectUniqueID", tbs)
self.assertNotIn("extensions", tbs)
- algo_id["algorithm"] = ObjectIdentifier("1.2.840.113549.1.1.5")
+ algo_id["algorithm"] = name2oid["id-sha1WithRSAEncryption"]
self.assertEqual(crt["signatureAlgorithm"], algo_id)
self.assertEqual(crt["signatureValue"], BitString(hexdec("".join((
"a67b06ec5ece92772ca413cba3ca12568fdc6c7b4511cd40a7f659980402df2b",
self.assertSequenceEqual(crt.encode(), raw)
pprint(crt)
repr(crt)
+ pickle_loads(pickle_dumps(crt, pickle_proto))
tbs = TBSCertificate()
tbs["serialNumber"] = CertificateSerialNumber(10143011886257155224)
sign_algo_id = AlgorithmIdentifier((
- ("algorithm", ObjectIdentifier("1.2.840.113549.1.1.5")),
+ ("algorithm", name2oid["id-sha1WithRSAEncryption"]),
("parameters", Any(Null())),
))
tbs["signature"] = sign_algo_id
tbs["validity"] = validity
spki = SubjectPublicKeyInfo()
- spki_algo_id = sign_algo_id.copy()
- spki_algo_id["algorithm"] = ObjectIdentifier("1.2.840.113549.1.1.1")
+ spki_algo_id = copy(sign_algo_id)
+ spki_algo_id["algorithm"] = name2oid["id-rsaEncryption"]
spki["algorithm"] = spki_algo_id
spki["subjectPublicKey"] = BitString(hexdec("".join((
"3048024100cdb7639c3278f006aa277f6eaf42902b592d8cbcbe38a1c92ba4695",
self.assertSequenceEqual(crt.encode(), raw)
pprint(crt)
repr(crt)
+ pickle_loads(pickle_dumps(crt, pickle_proto))