aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/cryptography/x509/extensions.py11
-rw-r--r--tests/test_x509.py30
-rw-r--r--tests/test_x509_ext.py13
3 files changed, 43 insertions, 11 deletions
diff --git a/src/cryptography/x509/extensions.py b/src/cryptography/x509/extensions.py
index 46ba5a28..71ce8a15 100644
--- a/src/cryptography/x509/extensions.py
+++ b/src/cryptography/x509/extensions.py
@@ -18,9 +18,7 @@ from cryptography import utils
from cryptography.hazmat.primitives import constant_time, serialization
from cryptography.x509.general_name import GeneralName, IPAddress, OtherName
from cryptography.x509.name import Name
-from cryptography.x509.oid import (
- AuthorityInformationAccessOID, ExtensionOID, ObjectIdentifier
-)
+from cryptography.x509.oid import ExtensionOID, ObjectIdentifier
class _SubjectPublicKeyInfo(univ.Sequence):
@@ -238,11 +236,8 @@ class AuthorityInformationAccess(object):
class AccessDescription(object):
def __init__(self, access_method, access_location):
- if not (access_method == AuthorityInformationAccessOID.OCSP or
- access_method == AuthorityInformationAccessOID.CA_ISSUERS):
- raise ValueError(
- "access_method must be OID_OCSP or OID_CA_ISSUERS"
- )
+ if not isinstance(access_method, ObjectIdentifier):
+ raise TypeError("access_method must be an ObjectIdentifier")
if not isinstance(access_location, GeneralName):
raise TypeError("access_location must be a GeneralName")
diff --git a/tests/test_x509.py b/tests/test_x509.py
index 5e5944a4..511aac6b 100644
--- a/tests/test_x509.py
+++ b/tests/test_x509.py
@@ -1303,6 +1303,36 @@ class TestCertificateBuilder(object):
@pytest.mark.requires_backend_interface(interface=RSABackend)
@pytest.mark.requires_backend_interface(interface=X509Backend)
+ def test_encode_nonstandard_aia(self, backend):
+ private_key = RSA_KEY_2048.private_key(backend)
+
+ aia = x509.AuthorityInformationAccess([
+ x509.AccessDescription(
+ x509.ObjectIdentifier("2.999.7"),
+ x509.UniformResourceIdentifier(u"http://example.com")
+ ),
+ ])
+
+ builder = x509.CertificateBuilder().subject_name(x509.Name([
+ x509.NameAttribute(NameOID.COUNTRY_NAME, u'US'),
+ ])).issuer_name(x509.Name([
+ x509.NameAttribute(NameOID.COUNTRY_NAME, u'US'),
+ ])).public_key(
+ private_key.public_key()
+ ).serial_number(
+ 777
+ ).not_valid_before(
+ datetime.datetime(1999, 1, 1)
+ ).not_valid_after(
+ datetime.datetime(2020, 1, 1)
+ ).add_extension(
+ aia, False
+ )
+
+ builder.sign(private_key, hashes.SHA256(), backend)
+
+ @pytest.mark.requires_backend_interface(interface=RSABackend)
+ @pytest.mark.requires_backend_interface(interface=X509Backend)
def test_no_subject_name(self, backend):
subject_private_key = RSA_KEY_2048.private_key(backend)
builder = x509.CertificateBuilder().serial_number(
diff --git a/tests/test_x509_ext.py b/tests/test_x509_ext.py
index 751de08d..83145cd0 100644
--- a/tests/test_x509_ext.py
+++ b/tests/test_x509_ext.py
@@ -18,8 +18,8 @@ from cryptography.hazmat.backends.interfaces import (
)
from cryptography.hazmat.primitives.asymmetric import ec
from cryptography.x509.oid import (
- AuthorityInformationAccessOID, ExtendedKeyUsageOID,
- ExtensionOID, NameOID
+ AuthorityInformationAccessOID, ExtendedKeyUsageOID, ExtensionOID,
+ NameOID, ObjectIdentifier
)
from .hazmat.primitives.test_ec import _skip_curve_unsupported
@@ -1861,7 +1861,7 @@ class TestExtendedKeyUsageExtension(object):
class TestAccessDescription(object):
def test_invalid_access_method(self):
- with pytest.raises(ValueError):
+ with pytest.raises(TypeError):
x509.AccessDescription("notanoid", x509.DNSName(u"test"))
def test_invalid_access_location(self):
@@ -1870,6 +1870,13 @@ class TestAccessDescription(object):
AuthorityInformationAccessOID.CA_ISSUERS, "invalid"
)
+ def test_valid_nonstandard_method(self):
+ ad = x509.AccessDescription(
+ ObjectIdentifier("2.999.1"),
+ x509.UniformResourceIdentifier(u"http://example.com")
+ )
+ assert ad is not None
+
def test_repr(self):
ad = x509.AccessDescription(
AuthorityInformationAccessOID.OCSP,
a> 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474