Beispiel #1
0
    def test_ssl_cert_subject_alt_name_wildcard(self):
        """
        Test certificate: wildcard SAN match
        """
        cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-san-certificate.crt')
        cert = crypto.load_certificate(crypto.FILETYPE_PEM,
                                       open(cert_file).read())
        # The expected cert should have CN=0.0.0.0
        self.assertEqual('0.0.0.0', cert.get_subject().commonName)
        try:
            conn = https.VerifiedHTTPSConnection('alt1.example.com', 0)
            https.do_verify_callback(None, cert, 0, 0, 1, host=conn.host)
        except Exception:
            self.fail('Unexpected exception.')

        try:
            conn = https.VerifiedHTTPSConnection('alt2.example.com', 0)
            https.do_verify_callback(None, cert, 0, 0, 1, host=conn.host)
        except Exception:
            self.fail('Unexpected exception.')

        try:
            conn = https.VerifiedHTTPSConnection('alt3.example.net', 0)
            https.do_verify_callback(None, cert, 0, 0, 1, host=conn.host)
            self.fail('Failed to raise assertion.')
        except exc.SSLCertificateError:
            pass
Beispiel #2
0
    def test_ssl_cert_subject_alt_name(self):
        """
        Test certificate: SAN match
        """
        cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
        cert = crypto.load_certificate(crypto.FILETYPE_PEM,
                                       open(cert_file).read())
        # The expected cert should have CN=0.0.0.0
        self.assertEqual('0.0.0.0', cert.get_subject().commonName)
        try:
            conn = https.VerifiedHTTPSConnection('alt1.example.com', 0)
            conn.verify_callback(None, cert, 0, 0, 1)
        except Exception:
            self.fail('Unexpected exception.')

        try:
            conn = https.VerifiedHTTPSConnection('alt2.example.com', 0)
            conn.verify_callback(None, cert, 0, 0, 1)
        except Exception:
            self.fail('Unexpected exception.')
Beispiel #3
0
 def test_ssl_init_cert_no_key(self):
     """
     Test VerifiedHTTPSConnection: absence of SSL key file.
     """
     cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
     cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
     try:
         https.VerifiedHTTPSConnection('127.0.0.1', 0,
                                       cert_file=cert_file,
                                       cacert=cacert)
         self.fail('Failed to raise assertion.')
     except exc.SSLConfigurationError:
         pass
Beispiel #4
0
 def test_ssl_init_bad_cert(self):
     """
     Test VerifiedHTTPSConnection: bad cert.
     """
     cert_file = os.path.join(TEST_VAR_DIR, 'badcert.crt')
     cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
     try:
         https.VerifiedHTTPSConnection('127.0.0.1', 0,
                                       cert_file=cert_file,
                                       cacert=cacert)
         self.fail('Failed to raise assertion.')
     except exc.SSLConfigurationError:
         pass
Beispiel #5
0
 def test_ssl_cert_cname_wildcard(self):
     """
     Test certificate: wildcard CN match
     """
     cert_file = os.path.join(TEST_VAR_DIR, 'wildcard-certificate.crt')
     cert = crypto.load_certificate(crypto.FILETYPE_PEM,
                                    open(cert_file).read())
     # The expected cert should have CN=*.pong.example.com
     self.assertEqual('*.pong.example.com', cert.get_subject().commonName)
     try:
         conn = https.VerifiedHTTPSConnection('ping.pong.example.com', 0)
         https.do_verify_callback(None, cert, 0, 0, 1, host=conn.host)
     except Exception:
         self.fail('Unexpected exception.')
Beispiel #6
0
 def test_ssl_init_key_no_cert(self):
     """
     Test VerifiedHTTPSConnection: absence of SSL cert file.
     """
     key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
     cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
     try:
         https.VerifiedHTTPSConnection('127.0.0.1', 0,
                                       key_file=key_file,
                                       cacert=cacert)
     except exc.SSLConfigurationError:
         pass
     except Exception:
         self.fail('Failed to init VerifiedHTTPSConnection.')
Beispiel #7
0
 def test_ssl_init_ok(self):
     """
     Test VerifiedHTTPSConnection class init
     """
     key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
     cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
     cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
     try:
         https.VerifiedHTTPSConnection('127.0.0.1', 0,
                                       key_file=key_file,
                                       cert_file=cert_file,
                                       cacert=cacert)
     except exc.SSLConfigurationError:
         self.fail('Failed to init VerifiedHTTPSConnection.')
Beispiel #8
0
 def test_ssl_expired_cert(self):
     """
     Test certificate: out of date cert
     """
     cert_file = os.path.join(TEST_VAR_DIR, 'expired-cert.crt')
     cert = crypto.load_certificate(crypto.FILETYPE_PEM,
                                    open(cert_file).read())
     # The expected expired cert has CN=openstack.example.com
     self.assertEqual('openstack.example.com',
                      cert.get_subject().commonName)
     try:
         conn = https.VerifiedHTTPSConnection('openstack.example.com', 0)
     except Exception:
         self.fail('Failed to init VerifiedHTTPSConnection.')
     self.assertRaises(exc.SSLCertificateError, conn.verify_callback, None,
                       cert, 0, 0, 1)
Beispiel #9
0
    def test_ssl_cert_mismatch(self):
        """
        Test certificate: bogus host
        """
        cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
        cert = crypto.load_certificate(crypto.FILETYPE_PEM,
                                       open(cert_file).read())
        # The expected cert should have CN=0.0.0.0
        self.assertEqual('0.0.0.0', cert.get_subject().commonName)
        try:
            conn = https.VerifiedHTTPSConnection('mismatch.example.com', 0)
        except Exception:
            self.fail('Failed to init VerifiedHTTPSConnection.')

        self.assertRaises(exc.SSLCertificateError, conn.verify_callback, None,
                          cert, 0, 0, 1)
Beispiel #10
0
    def test_ssl_init_non_byte_string(self):
        """
        Test VerifiedHTTPSConnection class non byte string

        Reproduces bug #1301849
        """
        key_file = os.path.join(TEST_VAR_DIR, 'privatekey.key')
        cert_file = os.path.join(TEST_VAR_DIR, 'certificate.crt')
        cacert = os.path.join(TEST_VAR_DIR, 'ca.crt')
        # Note: we reproduce on python 2.6/2.7, on 3.3 the bug doesn't occur.
        key_file = key_file.encode('ascii', 'strict').decode('utf-8')
        cert_file = cert_file.encode('ascii', 'strict').decode('utf-8')
        cacert = cacert.encode('ascii', 'strict').decode('utf-8')
        try:
            https.VerifiedHTTPSConnection('127.0.0.1', 0,
                                          key_file=key_file,
                                          cert_file=cert_file,
                                          cacert=cacert)
        except exc.SSLConfigurationError:
            self.fail('Failed to init VerifiedHTTPSConnection.')