コード例 #1
0
    def test_getHostnameFromURL(self):
        """``getHostnameFromURL()`` should return a hostname from a URI."""
        if _twistedversion >= Version('twisted', 14, 0, 0):
            raise unittest.SkipTest(
                ("The SSLVerifyingContextFactory is no longer necessary in "
                 "Twisted>=14.0.0, because the way in which TLS certificates "
                 "are checked now includes certificate pinning, and the "
                 "SSLVerifyingContextFactory only implemented strict hostname "
                 "checking."))

        agent = txrecaptcha._getAgent(self.reactor, self.url)
        contextFactory = agent._contextFactory
        self.assertRegexpMatches(contextFactory.hostname,
                                 '.*www\.example\.com')
コード例 #2
0
ファイル: test_crypto.py プロジェクト: isislovecruft/bridgedb
    def test_getHostnameFromURL(self):
        """``getHostnameFromURL()`` should return a hostname from a URI."""
        if _twistedversion >= Version('twisted', 14, 0, 0):
            raise unittest.SkipTest(
                ("The SSLVerifyingContextFactory is no longer necessary in "
                 "Twisted>=14.0.0, because the way in which TLS certificates "
                 "are checked now includes certificate pinning, and the "
                 "SSLVerifyingContextFactory only implemented strict hostname "
                 "checking."))

        agent = txrecaptcha._getAgent(self.reactor, self.url)
        contextFactory = agent._contextFactory
        self.assertRegexpMatches(contextFactory.hostname,
                                 '.*www\.example\.com')
コード例 #3
0
    def test_verifyHostname_mismatching(self):
        """Check that ``verifyHostname()`` returns ``False`` when the
        ``SSLVerifyingContextFactory.hostname`` does not match the one found
        in the level 0 certificate subject CN.
        """
        if _twistedversion >= Version('twisted', 14, 0, 0):
            raise unittest.SkipTest(
                ("The SSLVerifyingContextFactory is no longer necessary in "
                 "Twisted>=14.0.0, because the way in which TLS certificates "
                 "are checked now includes certificate pinning, and the "
                 "SSLVerifyingContextFactory only implemented strict hostname "
                 "checking."))

        agent = txrecaptcha._getAgent(self.reactor, self.url)
        contextFactory = agent._contextFactory
        x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                               self._certificateText)
        conn = DummyEndpoint()
        result = contextFactory.verifyHostname(conn, x509, 0, 0, True)
        self.assertIs(result, False)
コード例 #4
0
ファイル: test_crypto.py プロジェクト: isislovecruft/bridgedb
    def test_verifyHostname_mismatching(self):
        """Check that ``verifyHostname()`` returns ``False`` when the
        ``SSLVerifyingContextFactory.hostname`` does not match the one found
        in the level 0 certificate subject CN.
        """
        if _twistedversion >= Version('twisted', 14, 0, 0):
            raise unittest.SkipTest(
                ("The SSLVerifyingContextFactory is no longer necessary in "
                 "Twisted>=14.0.0, because the way in which TLS certificates "
                 "are checked now includes certificate pinning, and the "
                 "SSLVerifyingContextFactory only implemented strict hostname "
                 "checking."))

        agent = txrecaptcha._getAgent(self.reactor, self.url)
        contextFactory = agent._contextFactory
        x509 = OpenSSL.crypto.load_certificate(OpenSSL.crypto.FILETYPE_PEM,
                                               self._certificateText)
        conn = DummyEndpoint()
        result = contextFactory.verifyHostname(conn, x509, 0, 0, True)
        self.assertIs(result, False)