mirror of
https://github.com/certbot/certbot.git
synced 2026-08-01 02:44:21 +02:00
Merge pull request #2962 from chrismarget/master
Randomize serial numbers of DVSNI challenge certificates.
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
"""Crypto utilities."""
|
"""Crypto utilities."""
|
||||||
|
import binascii
|
||||||
import contextlib
|
import contextlib
|
||||||
import logging
|
import logging
|
||||||
import re
|
import re
|
||||||
@@ -203,7 +204,7 @@ def gen_ss_cert(key, domains, not_before=None,
|
|||||||
"""
|
"""
|
||||||
assert domains, "Must provide one or more hostnames for the cert."
|
assert domains, "Must provide one or more hostnames for the cert."
|
||||||
cert = OpenSSL.crypto.X509()
|
cert = OpenSSL.crypto.X509()
|
||||||
cert.set_serial_number(1337)
|
cert.set_serial_number(int(binascii.hexlify(OpenSSL.rand.bytes(16)), 16))
|
||||||
cert.set_version(2)
|
cert.set_version(2)
|
||||||
|
|
||||||
extensions = [
|
extensions = [
|
||||||
|
|||||||
@@ -8,6 +8,8 @@ import unittest
|
|||||||
import six
|
import six
|
||||||
from six.moves import socketserver # pylint: disable=import-error
|
from six.moves import socketserver # pylint: disable=import-error
|
||||||
|
|
||||||
|
import OpenSSL
|
||||||
|
|
||||||
from acme import errors
|
from acme import errors
|
||||||
from acme import jose
|
from acme import jose
|
||||||
from acme import test_util
|
from acme import test_util
|
||||||
@@ -126,5 +128,23 @@ class PyOpenSSLCertOrReqSANTest(unittest.TestCase):
|
|||||||
self._get_idn_names())
|
self._get_idn_names())
|
||||||
|
|
||||||
|
|
||||||
|
class RandomSnTest(unittest.TestCase):
|
||||||
|
"""Test for random certificate serial numbers."""
|
||||||
|
|
||||||
|
def setUp(self):
|
||||||
|
self.cert_count = 5
|
||||||
|
self.serial_num = []
|
||||||
|
self.key = OpenSSL.crypto.PKey()
|
||||||
|
self.key.generate_key(OpenSSL.crypto.TYPE_RSA, 2048)
|
||||||
|
|
||||||
|
def test_sn_collisions(self):
|
||||||
|
from acme.crypto_util import gen_ss_cert
|
||||||
|
|
||||||
|
for _ in range(self.cert_count):
|
||||||
|
cert = gen_ss_cert(self.key, ['dummy'], force_san=True)
|
||||||
|
self.serial_num.append(cert.get_serial_number())
|
||||||
|
self.assertTrue(len(set(self.serial_num)) > 1)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
unittest.main() # pragma: no cover
|
unittest.main() # pragma: no cover
|
||||||
|
|||||||
Reference in New Issue
Block a user