forked from twisted/twisted
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Author: glyph Reviewer: habnabit, radix, rwall, reaperhulk, hynek Fixes: twisted#7098 Refactor client TLS hostname verification support into a new, better API (`optionsForClientTLS`), with new interfaces that will facilitate addressing twisted#4888. git-svn-id: svn:https://svn.twistedmatrix.com/svn/Twisted/trunk@42511 bbbe8e31-12d6-0310-92fd-ac37d47ddeeb
- Loading branch information
Showing
17 changed files
with
1,090 additions
and
468 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIICjzCCAfgCAQEwDQYJKoZIhvcNAQEEBQAwgY8xEDAOBgNVBAsTB2V4YW1wbGUx | ||
EDAOBgNVBAoTB2V4YW1wbGUxFDASBgNVBAMTC2V4YW1wbGUuY29tMRAwDgYDVQQI | ||
EwdleGFtcGxlMQswCQYDVQQGEwJVUzEiMCAGCSqGSIb3DQEJARYTZXhhbXBsZUBl | ||
eGFtcGxlLmNvbTEQMA4GA1UEBxMHZXhhbXBsZTAeFw0xNDAyMTIwMDMxMzlaFw0x | ||
NTAyMTIwMDMxMzlaMIGPMRAwDgYDVQQLEwdleGFtcGxlMRAwDgYDVQQKEwdleGFt | ||
cGxlMRQwEgYDVQQDEwtleGFtcGxlLmNvbTEQMA4GA1UECBMHZXhhbXBsZTELMAkG | ||
A1UEBhMCVVMxIjAgBgkqhkiG9w0BCQEWE2V4YW1wbGVAZXhhbXBsZS5jb20xEDAO | ||
BgNVBAcTB2V4YW1wbGUwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBAKkRahIc | ||
Fp0V44QYpO9ue7mjZNbZYPAC8caoQC1jUgL42CT40PcoOiZWLgRk+Qw6P7PoJzO/ | ||
T4ufK0qoPUJm1jErDRWy9eWlGLE0grPECM+jxFfLXxJLKdPtuwMA8Ip72JMirFN5 | ||
Y/JTBZOR3j5a/mbY5tcRqgffKxm4QQegnhiBAgMBAAEwDQYJKoZIhvcNAQEEBQAD | ||
gYEAWANPpp985nXMoIwHlsSMm8ijkk7XQU3oioCYDcM6pLT+mvBDe1mZc8mUlrWy | ||
Zo/lT6HF44SHIZ0zCgPYwTpWV6C0K+/kKlYBERZ3ajrzGf5ACfUTNyk5P81C68mc | ||
9fQ7lhq1iuNKzVh8b746Z4ufn6iI1VygnyOQ1hZ/lOX56TA= | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) Twisted Matrix Laboratories. | ||
# See LICENSE for details. | ||
|
||
from twisted.internet import ssl, task, protocol, endpoints, defer | ||
from twisted.python.modules import getModule | ||
|
||
import echoclient | ||
|
||
@defer.inlineCallbacks | ||
def main(reactor): | ||
factory = protocol.Factory.forProtocol(echoclient.EchoClient) | ||
certData = getModule(__name__).filePath.sibling('public.pem').getContent() | ||
authData = getModule(__name__).filePath.sibling('server.pem').getContent() | ||
clientCertificate = ssl.PrivateCertificate.loadPEM(authData) | ||
authority = ssl.Certificate.loadPEM(certData) | ||
options = ssl.optionsForClientTLS(u'example.com', authority, | ||
clientCertificate) | ||
endpoint = endpoints.SSL4ClientEndpoint(reactor, 'localhost', 8000, | ||
options) | ||
echoClient = yield endpoint.connect(factory) | ||
|
||
done = defer.Deferred() | ||
echoClient.connectionLost = lambda reason: done.callback(None) | ||
yield done | ||
|
||
if __name__ == '__main__': | ||
import ssl_clientauth_client | ||
task.react(ssl_clientauth_client.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env python | ||
# Copyright (c) Twisted Matrix Laboratories. | ||
# See LICENSE for details. | ||
|
||
import sys | ||
|
||
from twisted.internet import ssl, protocol, task, defer | ||
from twisted.python import log | ||
from twisted.python.modules import getModule | ||
|
||
import echoserv | ||
|
||
def main(reactor): | ||
log.startLogging(sys.stdout) | ||
certData = getModule(__name__).filePath.sibling('public.pem').getContent() | ||
authData = getModule(__name__).filePath.sibling('server.pem').getContent() | ||
authority = ssl.Certificate.loadPEM(certData) | ||
certificate = ssl.PrivateCertificate.loadPEM(authData) | ||
factory = protocol.Factory.forProtocol(echoserv.Echo) | ||
reactor.listenSSL(8000, factory, certificate.options(authority)) | ||
return defer.Deferred() | ||
|
||
if __name__ == '__main__': | ||
import ssl_clientauth_server | ||
task.react(ssl_clientauth_server.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from twisted.internet import ssl, endpoints, task, protocol, defer | ||
from twisted.protocols.basic import LineReceiver | ||
from twisted.python.modules import getModule | ||
|
||
class StartTLSClient(LineReceiver): | ||
def connectionMade(self): | ||
self.sendLine("plain text") | ||
self.sendLine("STARTTLS") | ||
|
||
def lineReceived(self, line): | ||
print("received: " + line) | ||
if line == "READY": | ||
self.transport.startTLS(self.factory.options) | ||
self.sendLine("secure text") | ||
self.transport.loseConnection() | ||
|
||
@defer.inlineCallbacks | ||
def main(reactor): | ||
factory = protocol.Factory.forProtocol(StartTLSClient) | ||
certData = getModule(__name__).filePath.sibling('server.pem').getContent() | ||
factory.options = ssl.optionsForClientTLS( | ||
u"example.com", ssl.PrivateCertificate.loadPEM(certData) | ||
) | ||
endpoint = endpoints.HostnameEndpoint(reactor, 'localhost', 8000) | ||
startTLSClient = yield endpoint.connect(factory) | ||
|
||
done = defer.Deferred() | ||
startTLSClient.connectionLost = lambda reason: done.callback(None) | ||
yield done | ||
|
||
if __name__ == "__main__": | ||
import starttls_client | ||
task.react(starttls_client.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
from twisted.internet import ssl, protocol, defer, task, endpoints | ||
from twisted.protocols.basic import LineReceiver | ||
from twisted.python.modules import getModule | ||
|
||
class TLSServer(LineReceiver): | ||
def lineReceived(self, line): | ||
print("received: " + line) | ||
if line == "STARTTLS": | ||
print("-- Switching to TLS") | ||
self.sendLine('READY') | ||
self.transport.startTLS(self.factory.options) | ||
|
||
def main(reactor): | ||
certData = getModule(__name__).filePath.sibling('server.pem').getContent() | ||
cert = ssl.PrivateCertificate.loadPEM(certData) | ||
factory = protocol.Factory.forProtocol(TLSServer) | ||
factory.options = cert.options() | ||
endpoint = endpoints.TCP4ServerEndpoint(reactor, 8000) | ||
endpoint.listen(factory) | ||
return defer.Deferred() | ||
|
||
if __name__ == '__main__': | ||
import starttls_server | ||
task.react(starttls_server.main) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.