|
|
|
|
@@ -1,3 +1,4 @@
|
|
|
|
|
# Lint as: python2, python3
|
|
|
|
|
################################################################################
|
|
|
|
|
# Copyright 2016 Google LLC.
|
|
|
|
|
#
|
|
|
|
|
@@ -10,7 +11,7 @@ import base64
|
|
|
|
|
import datetime
|
|
|
|
|
import os
|
|
|
|
|
import shutil
|
|
|
|
|
import StringIO
|
|
|
|
|
import sys
|
|
|
|
|
import tempfile
|
|
|
|
|
import textwrap
|
|
|
|
|
import unittest
|
|
|
|
|
@@ -20,6 +21,7 @@ from cryptography.hazmat import backends
|
|
|
|
|
from cryptography.hazmat.primitives import serialization
|
|
|
|
|
from cryptography.hazmat.primitives.asymmetric import padding
|
|
|
|
|
from cryptography.x509 import oid
|
|
|
|
|
import six
|
|
|
|
|
|
|
|
|
|
import oem_certificate
|
|
|
|
|
import oem_certificate_test_helper as oem_cert_test_helper
|
|
|
|
|
@@ -49,8 +51,9 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.COUNTRY_NAME)[0].value,
|
|
|
|
|
args.country_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.STATE_OR_PROVINCE_NAME)[0]
|
|
|
|
|
.value, args.state_or_province_name)
|
|
|
|
|
subject.get_attributes_for_oid(
|
|
|
|
|
oid.NameOID.STATE_OR_PROVINCE_NAME)[0].value,
|
|
|
|
|
args.state_or_province_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.LOCALITY_NAME)[0].value,
|
|
|
|
|
args.locality_name)
|
|
|
|
|
@@ -58,8 +61,9 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.ORGANIZATION_NAME)[0].value,
|
|
|
|
|
args.organization_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.ORGANIZATIONAL_UNIT_NAME)[0]
|
|
|
|
|
.value, args.organizational_unit_name)
|
|
|
|
|
subject.get_attributes_for_oid(
|
|
|
|
|
oid.NameOID.ORGANIZATIONAL_UNIT_NAME)[0].value,
|
|
|
|
|
args.organizational_unit_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
len(subject.get_attributes_for_oid(oid.NameOID.COMMON_NAME)), 0)
|
|
|
|
|
|
|
|
|
|
@@ -84,8 +88,9 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.COUNTRY_NAME)[0].value,
|
|
|
|
|
args.country_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.STATE_OR_PROVINCE_NAME)[0]
|
|
|
|
|
.value, args.state_or_province_name)
|
|
|
|
|
subject.get_attributes_for_oid(
|
|
|
|
|
oid.NameOID.STATE_OR_PROVINCE_NAME)[0].value,
|
|
|
|
|
args.state_or_province_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.LOCALITY_NAME)[0].value,
|
|
|
|
|
args.locality_name)
|
|
|
|
|
@@ -93,11 +98,12 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.ORGANIZATION_NAME)[0].value,
|
|
|
|
|
args.organization_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.ORGANIZATIONAL_UNIT_NAME)[0]
|
|
|
|
|
.value, args.organizational_unit_name)
|
|
|
|
|
subject.get_attributes_for_oid(
|
|
|
|
|
oid.NameOID.ORGANIZATIONAL_UNIT_NAME)[0].value,
|
|
|
|
|
args.organizational_unit_name)
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.COMMON_NAME)[0]
|
|
|
|
|
.value, args.common_name)
|
|
|
|
|
subject.get_attributes_for_oid(oid.NameOID.COMMON_NAME)[0].value,
|
|
|
|
|
args.common_name)
|
|
|
|
|
|
|
|
|
|
private_key = serialization.load_der_private_key(
|
|
|
|
|
args.output_private_key_file.getvalue(),
|
|
|
|
|
@@ -111,11 +117,11 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def test_generate_csr_with_keysize4096_and_passphrase(self):
|
|
|
|
|
args = oem_cert_test_helper.setup_csr_args(
|
|
|
|
|
key_size=4096, passphrase='passphrase_4096')
|
|
|
|
|
key_size=4096, passphrase=b'passphrase_4096')
|
|
|
|
|
oem_certificate.generate_csr(args)
|
|
|
|
|
private_key = serialization.load_der_private_key(
|
|
|
|
|
args.output_private_key_file.getvalue(),
|
|
|
|
|
'passphrase_4096',
|
|
|
|
|
b'passphrase_4096',
|
|
|
|
|
backend=backends.default_backend())
|
|
|
|
|
csr = x509.load_pem_x509_csr(args.output_csr_file.getvalue(),
|
|
|
|
|
backends.default_backend())
|
|
|
|
|
@@ -156,15 +162,14 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
cert.signature_hash_algorithm)
|
|
|
|
|
|
|
|
|
|
def test_generate_intermediate_with_cert_mismatch_root_cert_and_key(self):
|
|
|
|
|
root_key1, _ = (
|
|
|
|
|
oem_cert_test_helper.create_root_certificate_and_key())
|
|
|
|
|
root_key1, _ = (oem_cert_test_helper.create_root_certificate_and_key())
|
|
|
|
|
_, root_certificate2 = oem_cert_test_helper.create_root_certificate_and_key(
|
|
|
|
|
)
|
|
|
|
|
args = oem_cert_test_helper.setup_intermediate_cert_args(
|
|
|
|
|
'some csr data', root_key1, root_certificate2)
|
|
|
|
|
b'some csr data', root_key1, root_certificate2)
|
|
|
|
|
with self.assertRaises(ValueError) as context:
|
|
|
|
|
oem_certificate.generate_intermediate_certificate(args)
|
|
|
|
|
self.assertTrue('certificate does not match' in str(context.exception))
|
|
|
|
|
self.assertIn('certificate does not match', str(context.exception))
|
|
|
|
|
|
|
|
|
|
def test_generate_leaf_certificate_from_pem_intermediate_cert(self):
|
|
|
|
|
intermediate_key_bytes, intermediate_certificate_bytes = (
|
|
|
|
|
@@ -195,8 +200,7 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
system_id_raw_bytes = leaf_cert.extensions.get_extension_for_oid(
|
|
|
|
|
oem_certificate.WidevineSystemId.oid).value.value
|
|
|
|
|
self.assertEqual(
|
|
|
|
|
oem_certificate.WidevineSystemId(system_id_raw_bytes).int_value(),
|
|
|
|
|
2001)
|
|
|
|
|
oem_certificate.WidevineSystemId(system_id_raw_bytes).int_value(), 2001)
|
|
|
|
|
|
|
|
|
|
leaf_key = serialization.load_der_private_key(
|
|
|
|
|
args.output_private_key_file.getvalue(),
|
|
|
|
|
@@ -238,75 +242,81 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
intermediate_key_bytes,
|
|
|
|
|
intermediate_certificate_bytes,
|
|
|
|
|
key_size=4096,
|
|
|
|
|
passphrase='leaf passphrase')
|
|
|
|
|
passphrase=b'leaf passphrase')
|
|
|
|
|
oem_certificate.generate_leaf_certificate(args)
|
|
|
|
|
leaf_key = serialization.load_der_private_key(
|
|
|
|
|
args.output_private_key_file.getvalue(),
|
|
|
|
|
'leaf passphrase',
|
|
|
|
|
b'leaf passphrase',
|
|
|
|
|
backend=backends.default_backend())
|
|
|
|
|
self.assertEqual(4096, leaf_key.key_size)
|
|
|
|
|
|
|
|
|
|
def test_get_csr_info(self):
|
|
|
|
|
args = oem_cert_test_helper.setup_csr_args()
|
|
|
|
|
oem_certificate.generate_csr(args)
|
|
|
|
|
args.file = StringIO.StringIO(args.output_csr_file.getvalue())
|
|
|
|
|
output = StringIO.StringIO()
|
|
|
|
|
args.file = six.BytesIO(args.output_csr_file.getvalue())
|
|
|
|
|
output = six.StringIO()
|
|
|
|
|
oem_certificate.get_info(args, output)
|
|
|
|
|
expected_info = """\
|
|
|
|
|
CSR Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Key Size: 4096"""
|
|
|
|
|
self.assertEqual(output.getvalue(), textwrap.dedent(expected_info))
|
|
|
|
|
# Remove unicode marker for Python2 backwards compatibility.
|
|
|
|
|
output_value = output.getvalue().replace("u'", "'")
|
|
|
|
|
self.assertEqual(output_value, textwrap.dedent(expected_info))
|
|
|
|
|
|
|
|
|
|
def test_get_pem_certificate_info(self):
|
|
|
|
|
_, intermediate_certificate_bytes = (
|
|
|
|
|
oem_cert_test_helper.create_intermediate_certificate_and_key_bytes(
|
|
|
|
|
pem_format=True))
|
|
|
|
|
args = ArgParseObject()
|
|
|
|
|
args.file = StringIO.StringIO(intermediate_certificate_bytes)
|
|
|
|
|
output = StringIO.StringIO()
|
|
|
|
|
args.file = six.BytesIO(intermediate_certificate_bytes)
|
|
|
|
|
output = six.StringIO()
|
|
|
|
|
oem_certificate.get_info(args, output)
|
|
|
|
|
expected_info = """\
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'root_cert')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='root_cert')>
|
|
|
|
|
Key Size: 4096
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2001-11-17 00:00:00"""
|
|
|
|
|
self.assertEqual(output.getvalue(), textwrap.dedent(expected_info))
|
|
|
|
|
# Remove unicode marker for Python2 backwards compatibility.
|
|
|
|
|
output_value = output.getvalue().replace("u'", "'")
|
|
|
|
|
self.assertEqual(output_value, textwrap.dedent(expected_info))
|
|
|
|
|
|
|
|
|
|
def test_get_der_certificate_info(self):
|
|
|
|
|
_, intermediate_certificate_bytes = (
|
|
|
|
|
oem_cert_test_helper.create_intermediate_certificate_and_key_bytes(
|
|
|
|
|
pem_format=False))
|
|
|
|
|
args = ArgParseObject()
|
|
|
|
|
args.file = StringIO.StringIO(intermediate_certificate_bytes)
|
|
|
|
|
output = StringIO.StringIO()
|
|
|
|
|
args.file = six.BytesIO(intermediate_certificate_bytes)
|
|
|
|
|
output = six.StringIO()
|
|
|
|
|
oem_certificate.get_info(args, output)
|
|
|
|
|
expected_info = """\
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'root_cert')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='root_cert')>
|
|
|
|
|
Key Size: 4096
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2001-11-17 00:00:00"""
|
|
|
|
|
self.assertEqual(output.getvalue(), textwrap.dedent(expected_info))
|
|
|
|
|
# Remove unicode marker for Python2 backwards compatibility.
|
|
|
|
|
output_value = output.getvalue().replace("u'", "'")
|
|
|
|
|
self.assertEqual(output_value, textwrap.dedent(expected_info))
|
|
|
|
|
|
|
|
|
|
def test_get_certificate_chain_info(self):
|
|
|
|
|
intermediate_key_bytes, intermediate_certificate_bytes = (
|
|
|
|
|
@@ -314,41 +324,43 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
args = oem_cert_test_helper.setup_leaf_cert_args(
|
|
|
|
|
intermediate_key_bytes, intermediate_certificate_bytes)
|
|
|
|
|
oem_certificate.generate_leaf_certificate(args)
|
|
|
|
|
args.file = StringIO.StringIO(args.output_certificate_file.getvalue())
|
|
|
|
|
output = StringIO.StringIO()
|
|
|
|
|
args.file = six.BytesIO(args.output_certificate_file.getvalue())
|
|
|
|
|
output = six.StringIO()
|
|
|
|
|
oem_certificate.get_info(args, output)
|
|
|
|
|
expected_info = """\
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'2001-leaf')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='2001-leaf')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Key Size: 1024
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2023-07-05 00:00:00
|
|
|
|
|
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'root_cert')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='root_cert')>
|
|
|
|
|
Key Size: 4096
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2001-11-17 00:00:00"""
|
|
|
|
|
self.assertEqual(output.getvalue(), textwrap.dedent(expected_info))
|
|
|
|
|
# Remove unicode marker for Python2 backwards compatibility.
|
|
|
|
|
output_value = output.getvalue().replace("u'", "'")
|
|
|
|
|
self.assertEqual(output_value, textwrap.dedent(expected_info))
|
|
|
|
|
|
|
|
|
|
def test_get_certificate_chain_info_fixed_input(self):
|
|
|
|
|
# This was generated from args.output_certificate_file in the test above.
|
|
|
|
|
@@ -400,41 +412,43 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
'nm0mTbNTgcC673L5YA8qpQkAzk9vLg4UaslMbPfeKM8rqduJFcjTyVY3C4jBC0qxf6z6'
|
|
|
|
|
'vpWbEO7UpHHdfvWe9DEBODFbyXMxAA==')
|
|
|
|
|
args = oem_cert_test_helper.ArgParseObject()
|
|
|
|
|
args.file = StringIO.StringIO(base64.b64decode(data_b64))
|
|
|
|
|
output = StringIO.StringIO()
|
|
|
|
|
args.file = six.BytesIO(base64.b64decode(data_b64))
|
|
|
|
|
output = six.StringIO()
|
|
|
|
|
oem_certificate.get_info(args, output)
|
|
|
|
|
expected_info = """\
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'2001-leaf')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='2001-leaf')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Key Size: 1024
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2023-07-05 00:00:00
|
|
|
|
|
|
|
|
|
|
Certificate Subject Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value=u'US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value=u'WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value=u'Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value=u'CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value=u'ContentProtection')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.6, name=countryName)>, value='US')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.8, name=stateOrProvinceName)>, value='WA')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.7, name=localityName)>, value='Kirkland')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.10, name=organizationName)>, value='CompanyXYZ')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.11, name=organizationalUnitName)>, value='ContentProtection')>
|
|
|
|
|
Issuer Name:
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value=u'root_cert')>
|
|
|
|
|
<NameAttribute(oid=<ObjectIdentifier(oid=2.5.4.3, name=commonName)>, value='root_cert')>
|
|
|
|
|
Key Size: 4096
|
|
|
|
|
Widevine System Id: 2001
|
|
|
|
|
Not valid before: 2001-08-09 00:00:00
|
|
|
|
|
Not valid after: 2001-11-17 00:00:00"""
|
|
|
|
|
self.assertEqual(output.getvalue(), textwrap.dedent(expected_info))
|
|
|
|
|
# Remove unicode marker for Python2 backwards compatibility.
|
|
|
|
|
output_value = output.getvalue().replace("u'", "'")
|
|
|
|
|
self.assertEqual(output_value, textwrap.dedent(expected_info))
|
|
|
|
|
|
|
|
|
|
def test_secure_erase(self):
|
|
|
|
|
args = ArgParseObject()
|
|
|
|
|
@@ -448,10 +462,12 @@ class OemCertificateTest(unittest.TestCase):
|
|
|
|
|
class OemCertificateArgParseTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
|
super(OemCertificateArgParseTest, self).setUp()
|
|
|
|
|
self.parser = oem_certificate.create_parser()
|
|
|
|
|
self.test_dir = tempfile.mkdtemp()
|
|
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
|
super(OemCertificateArgParseTest, self).tearDown()
|
|
|
|
|
shutil.rmtree(self.test_dir)
|
|
|
|
|
|
|
|
|
|
def test_generate_csr(self):
|
|
|
|
|
@@ -506,7 +522,7 @@ class OemCertificateArgParseTest(unittest.TestCase):
|
|
|
|
|
|
|
|
|
|
def _fill_file_with_dummy_contents(self, file_name):
|
|
|
|
|
with open(file_name, 'wb') as f:
|
|
|
|
|
f.write('dummy')
|
|
|
|
|
f.write(b'dummy')
|
|
|
|
|
|
|
|
|
|
def test_generate_csr_invalid_key_size(self):
|
|
|
|
|
cmds = ('generate_csr --key_size unknown -C USA -ST WA '
|
|
|
|
|
@@ -601,7 +617,7 @@ class OemCertificateArgParseTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(args.func, oem_certificate.generate_leaf_certificate)
|
|
|
|
|
|
|
|
|
|
def test_generate_leaf_cert_invalid_date(self):
|
|
|
|
|
cmds = ('generate_leaf_certificate --not_valid_before invaid-date '
|
|
|
|
|
cmds = ('generate_leaf_certificate --not_valid_before invalid-date '
|
|
|
|
|
'--valid_duration 10').split()
|
|
|
|
|
|
|
|
|
|
intermediate_certificate_file = os.path.join(self.test_dir,
|
|
|
|
|
@@ -651,9 +667,12 @@ class OemCertificateArgParseTest(unittest.TestCase):
|
|
|
|
|
self.assertEqual(context.exception.code, 2)
|
|
|
|
|
|
|
|
|
|
def test_no_argument(self):
|
|
|
|
|
with self.assertRaises(SystemExit) as context:
|
|
|
|
|
self.parser.parse_args([])
|
|
|
|
|
self.assertEqual(context.exception.code, 2)
|
|
|
|
|
# Only valid for python2.
|
|
|
|
|
# Python3 does not throw error when missing required
|
|
|
|
|
if sys.version_info[0] == 2:
|
|
|
|
|
with self.assertRaises(SystemExit) as context:
|
|
|
|
|
self.parser.parse_args([])
|
|
|
|
|
self.assertEqual(context.exception.code, 2)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
|
|