Import Upstream version 4.12.4
This commit is contained in:
@@ -26,6 +26,7 @@ from binascii import hexlify
|
||||
from configparser import RawConfigParser
|
||||
import datetime
|
||||
from io import StringIO
|
||||
import os
|
||||
import pickle
|
||||
|
||||
import pytest
|
||||
@@ -164,6 +165,26 @@ QUs1Hx1wL7mL4U8fKCFDKA+ds2B2xWgoZg==
|
||||
-----END CERTIFICATE-----
|
||||
'''
|
||||
|
||||
v1_cert = b'''\
|
||||
-----BEGIN CERTIFICATE-----
|
||||
MIICwTCCAakCFG3lgHmtal7cilKoevNM/kD4gIToMA0GCSqGSIb3DQEBCwUAMB8x
|
||||
HTAbBgNVBAMMFEV4YW1wbGUtVGVzdC1DQS0xMTg4MB4XDTIxMDYxMTE5NTgwNVoX
|
||||
DTIxMDYxMjE5NTgwNVowGzEZMBcGA1UEAwwQaXBhLmV4YW1wbGUudGVzdDCCASIw
|
||||
DQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBALsi+qZj7MB/okR4QFUYBHgLyFXr
|
||||
TVd4ENDYERPhHddMkShWsAD6jG7bo/fvrWdaVKdoawghQZymI0o7VVwwuu5+EVA+
|
||||
gp/vKQM+QiF2fnbprLKVdZHexqdCyo0lMSGDeSobg3iH8iHiq4StYkGyXuUzcbgf
|
||||
6avajlASGC7b4W7RahTION+GJFrP/eW392Oceu6idY6rl3Joyo9SY+zX+pAR0tDC
|
||||
+ixaYWkk9UxVuh4ObRToNLlHsnBWs3D6eZUiwBoX5QALWxwtdmsofwEOg3D+a2/h
|
||||
RihBnZzghQUOf9pjcu/jdgUzd0fsH9FpZVad3HjQmGq2Vgy/rT6STG9ojecCAwEA
|
||||
ATANBgkqhkiG9w0BAQsFAAOCAQEAMdB8pCPqEsJY5bnJNdr6EXdEIHk/l2P8tWJs
|
||||
wlpdAcOm5NfeZkOkGVYC4HTPNkMQ+K7K7VqHNT7hDjdNS0Gp/LVoHxBrQPAgsM7I
|
||||
RTZteGkCqIEBUxXvX2hKnMtuuAe9ljYlVF1P+WsV7qXP/M7RsWb2d+9ubA28mYD/
|
||||
lhW/TB0/2EzP6QuiMh7bURIoQWw/733cfMIoP7XRVGn5Ux2z+o2hl5oOjHl7KBDa
|
||||
/6PWd4wOMU/cY2fOPPJQ7eSGJh4VCe64au3S6zAtoTE8XXweo/cDD70NZnmwdeGQ
|
||||
bswNlxWfohaW0FzTRfTMbIrwoUCWil/Uw2kBYnld15gwzuLDNQ==
|
||||
-----END CERTIFICATE-----
|
||||
'''
|
||||
|
||||
|
||||
class test_x509:
|
||||
"""
|
||||
@@ -214,8 +235,10 @@ class test_x509:
|
||||
# Verify certificate contents. This exercises python-cryptography
|
||||
# more than anything but confirms our usage of it.
|
||||
|
||||
not_before = datetime.datetime(2010, 6, 25, 13, 0, 42)
|
||||
not_after = datetime.datetime(2015, 6, 25, 13, 0, 42)
|
||||
not_before = datetime.datetime(2010, 6, 25, 13, 0, 42, 0,
|
||||
datetime.timezone.utc)
|
||||
not_after = datetime.datetime(2015, 6, 25, 13, 0, 42, 0,
|
||||
datetime.timezone.utc)
|
||||
cert = x509.load_pem_x509_certificate(goodcert_headers)
|
||||
|
||||
assert DN(cert.subject) == DN(('CN', 'ipa.example.com'), ('O', 'IPA'))
|
||||
@@ -223,6 +246,8 @@ class test_x509:
|
||||
assert cert.serial_number == 1093
|
||||
assert cert.not_valid_before == not_before
|
||||
assert cert.not_valid_after == not_after
|
||||
assert cert.not_valid_before_utc == not_before
|
||||
assert cert.not_valid_after_utc == not_after
|
||||
assert cert.san_general_names == []
|
||||
assert cert.san_a_label_dns_names == []
|
||||
assert cert.extended_key_usage == {'1.3.6.1.5.5.7.3.1'}
|
||||
@@ -231,6 +256,32 @@ class test_x509:
|
||||
b'+\x06\x01\x05\x05\x07\x03\x01'
|
||||
)
|
||||
|
||||
def test_cert_with_timezone(self):
|
||||
"""
|
||||
Test the not_before and not_after values in a diffent timezone
|
||||
|
||||
Test for https://pagure.io/freeipa/issue/9462
|
||||
"""
|
||||
# Store initial timezone, then set to New York
|
||||
tz = os.environ.get('TZ', None)
|
||||
os.environ['TZ'] = 'America/New_York'
|
||||
# Load the cert, extract not before and not after
|
||||
cert = x509.load_pem_x509_certificate(goodcert_headers)
|
||||
not_before = datetime.datetime(2010, 6, 25, 13, 0, 42, 0,
|
||||
datetime.timezone.utc)
|
||||
not_after = datetime.datetime(2015, 6, 25, 13, 0, 42, 0,
|
||||
datetime.timezone.utc)
|
||||
# Reset timezone to previous value
|
||||
if tz:
|
||||
os.environ['TZ'] = tz
|
||||
else:
|
||||
del os.environ['TZ']
|
||||
# ensure the timezone doesn't mess with not_before and not_after
|
||||
assert cert.not_valid_before == not_before
|
||||
assert cert.not_valid_after == not_after
|
||||
assert cert.not_valid_before_utc == not_before
|
||||
assert cert.not_valid_after_utc == not_after
|
||||
|
||||
def test_load_pkcs7_pem(self):
|
||||
certlist = x509.pkcs7_to_certs(good_pkcs7, datatype=x509.PEM)
|
||||
assert len(certlist) == 1
|
||||
@@ -259,10 +310,14 @@ class test_x509:
|
||||
assert DN(cert.issuer) == DN(
|
||||
"CN=Let's Encrypt Authority X3,O=Let's Encrypt,C=US")
|
||||
assert cert.serial_number == 0x03ad42a2a5ada59a131327cb0979623cb605
|
||||
not_before = datetime.datetime(2018, 7, 25, 5, 36, 59)
|
||||
not_after = datetime.datetime(2018, 10, 23, 5, 36, 59)
|
||||
not_before = datetime.datetime(2018, 7, 25, 5, 36, 59, 0,
|
||||
datetime.timezone.utc)
|
||||
not_after = datetime.datetime(2018, 10, 23, 5, 36, 59, 0,
|
||||
datetime.timezone.utc)
|
||||
assert cert.not_valid_before == not_before
|
||||
assert cert.not_valid_after == not_after
|
||||
assert cert.not_valid_before_utc == not_before
|
||||
assert cert.not_valid_after_utc == not_after
|
||||
assert cert.san_general_names == [DNSName('ipa.demo1.freeipa.org')]
|
||||
assert cert.san_a_label_dns_names == ['ipa.demo1.freeipa.org']
|
||||
assert cert.extended_key_usage == {
|
||||
@@ -273,6 +328,10 @@ class test_x509:
|
||||
b'\x05\x05\x07\x03\x01\x06\x08+\x06\x01\x05\x05\x07\x03\x02'
|
||||
)
|
||||
|
||||
def test_x509_v1_cert(self):
|
||||
with pytest.raises(ValueError):
|
||||
x509.load_pem_x509_certificate(v1_cert)
|
||||
|
||||
|
||||
class test_ExternalCAProfile:
|
||||
def test_MSCSTemplateV1_good(self):
|
||||
|
||||
Reference in New Issue
Block a user