当前位置: 首页>>代码示例>>Python>>正文


Python tlslite.HandshakeSettings类代码示例

本文整理汇总了Python中tlslite.HandshakeSettings的典型用法代码示例。如果您正苦于以下问题:Python HandshakeSettings类的具体用法?Python HandshakeSettings怎么用?Python HandshakeSettings使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了HandshakeSettings类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: clientTestCmd

def clientTestCmd(argv):
    
    address = argv[0]
    dir = argv[1]    

    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #open synchronisation FIFO
    synchro = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    synchro.settimeout(5)
    synchro.connect((address[0], address[1]-1))

    def connect():
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(sock, 'settimeout'): #It's a python 2.3 feature
            sock.settimeout(5)
        sock.connect(address)
        c = TLSConnection(sock)
        return c

    test = 0

    badFault = False

    print("Test 0 - anonymous handshake")
    synchro.recv(1)
    connection = connect()
    connection.handshakeClientAnonymous()
    testConnClient(connection)
    connection.close()
        
    print("Test 1 - good X509 (plus SNI)")
    synchro.recv(1)
    connection = connect()
    connection.handshakeClientCert(serverName=address[0])
    testConnClient(connection)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    assert(connection.session.serverName == address[0])
    connection.close()

    print("Test 1.a - good X509, SSLv3")
    synchro.recv(1)
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeClientCert(settings=settings)
    testConnClient(connection)    
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    connection.close()    

    print("Test 1.b - good X509, RC4-MD5")
    synchro.recv(1)
    connection = connect()
    settings = HandshakeSettings()
    settings.macNames = ["md5"]
    connection.handshakeClientCert(settings=settings)
    testConnClient(connection)    
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    assert(connection.session.cipherSuite == constants.CipherSuite.TLS_RSA_WITH_RC4_128_MD5)
    connection.close()

    if tackpyLoaded:
                    
        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        print("Test 2.a - good X.509, TACK")
        synchro.recv(1)
        connection = connect()
        connection.handshakeClientCert(settings=settings)
        assert(connection.session.tackExt.tacks[0].getTackId() == "5lcbe.eyweo.yxuan.rw6xd.jtoz7")
        assert(connection.session.tackExt.activation_flags == 1)        
        testConnClient(connection)    
        connection.close()    

        print("Test 2.b - good X.509, TACK unrelated to cert chain")
        synchro.recv(1)
        connection = connect()
        try:
            connection.handshakeClientCert(settings=settings)
            assert(False)
        except TLSLocalAlert as alert:
            if alert.description != AlertDescription.illegal_parameter:
                raise        
        connection.close()

    print("Test 3 - good SRP")
    synchro.recv(1)
    connection = connect()
    connection.handshakeClientSRP("test", "password")
    testConnClient(connection)
    connection.close()

    print("Test 4 - SRP faults")
    for fault in Fault.clientSrpFaults + Fault.genericFaults:
        synchro.recv(1)
        connection = connect()
#.........这里部分代码省略.........
开发者ID:alex1818,项目名称:tlslite,代码行数:101,代码来源:tlstest.py

示例2: clientTestCmd

def clientTestCmd(argv):
    
    address = argv[0]
    dir = argv[1]    

    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    def connect():
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(sock, 'settimeout'): #It's a python 2.3 feature
            sock.settimeout(5)
        sock.connect(address)
        c = TLSConnection(sock)
        return c

    test = 0

    badFault = False
    
    print "Test 0 - anonymous handshake"
    connection = connect()
    connection.handshakeClientAnonymous()
    testConnClient(connection)
    connection.close()
        
    print "Test 1 - good X509 (plus SNI)"
    connection = connect()
    connection.handshakeClientCert(serverName=address[0])
    testConnClient(connection)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    assert(connection.session.serverName == address[0])
    connection.close()

    print "Test 1.a - good X509, SSLv3"
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeClientCert(settings=settings)
    testConnClient(connection)    
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    connection.close()    
    
    if tackpyLoaded:
                    
        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        print "Test 2.a - good X.509, TACK"
        connection = connect()
        connection.handshakeClientCert(settings=settings)
        assert(connection.session.tackExt.tacks[0].getTackId() == "rrted.ptvtl.d2uiq.ox2xe.w4ss3")
        assert(connection.session.tackExt.activation_flags == 1)        
        testConnClient(connection)    
        connection.close()    

        print "Test 2.b - good X.509, TACK unrelated to cert chain"
        connection = connect()
        try:
            connection.handshakeClientCert(settings=settings)
            assert(False)
        except TLSLocalAlert, alert:
            if alert.description != AlertDescription.illegal_parameter:
                raise        
        connection.close()
开发者ID:eaescob,项目名称:tlslite,代码行数:67,代码来源:tlstest.py

示例3: serverTestCmd

def serverTestCmd(argv):

    address = argv[0]
    dir = argv[1]
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #Create synchronisation FIFO
    synchroSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    synchroSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    synchroSocket.bind((address[0], address[1]-1))
    synchroSocket.listen(2)

    #Connect to server
    lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    lsock.bind(address)
    lsock.listen(5)

    # following is blocking until the other side doesn't open
    synchro = synchroSocket.accept()[0]

    def connect():
        return TLSConnection(lsock.accept()[0])

    x509Cert = X509().parse(open(os.path.join(dir, "serverX509Cert.pem")).read())
    x509Chain = X509CertChain([x509Cert])
    s = open(os.path.join(dir, "serverX509Key.pem")).read()
    x509Key = parsePEMKey(s, private=True)

    print("Test 0 - Anonymous server handshake")
    synchro.send(b'R')
    connection = connect()
    connection.handshakeServer(anon=True)
    testConnServer(connection)    
    connection.close() 
    
    print("Test 1 - good X.509")
    synchro.send(b'R')
    connection = connect()
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key)
    assert(connection.session.serverName == address[0])    
    testConnServer(connection)    
    connection.close()

    print("Test 1.a - good X.509, SSL v3")
    synchro.send(b'R')
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    testConnServer(connection)
    connection.close()            

    print("Test 1.b - good X.509, RC4-MD5")
    synchro.send(b'R')
    connection = connect()
    settings = HandshakeSettings()
    settings.macNames = ["sha", "md5"]
    settings.cipherNames = ["rc4"]
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    testConnServer(connection)
    connection.close()            
    
    if tackpyLoaded:
        tack = Tack.createFromPem(open("./TACK1.pem", "rU").read())
        tackUnrelated = Tack.createFromPem(open("./TACKunrelated.pem", "rU").read())    
            
        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        print("Test 2.a - good X.509, TACK")
        synchro.send(b'R')
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tacks=[tack], activationFlags=1, settings=settings)
        testConnServer(connection)    
        connection.close()        

        print("Test 2.b - good X.509, TACK unrelated to cert chain")
        synchro.send(b'R')
        connection = connect()
        try:
            connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
                tacks=[tackUnrelated], settings=settings)
            assert(False)
        except TLSRemoteAlert as alert:
            if alert.description != AlertDescription.illegal_parameter:
                raise        
    
    print("Test 3 - good SRP")
    verifierDB = VerifierDB()
    verifierDB.create()
    entry = VerifierDB.makeVerifier("test", "password", 1536)
    verifierDB["test"] = entry

    synchro.send(b'R')
#.........这里部分代码省略.........
开发者ID:alex1818,项目名称:tlslite,代码行数:101,代码来源:tlstest.py

示例4: testConnClient

    testConnClient(connection)
    connection.close()

    print "Test 4 - SRP faults"
    for fault in Fault.clientSrpFaults + Fault.genericFaults:
        connection = connect()
        connection.fault = fault
        try:
            connection.handshakeClientSRP("test", "password")
            print "  Good Fault %s" % (Fault.faultNames[fault])
        except TLSFaultError, e:
            print "  BAD FAULT %s: %s" % (Fault.faultNames[fault], str(e))
            badFault = True

    print "Test 6 - good SRP: with X.509 certificate, TLSv1.0"
    settings = HandshakeSettings()
    settings.minVersion = (3,1)
    settings.maxVersion = (3,1)    
    connection = connect()
    connection.handshakeClientSRP("test", "password", settings=settings)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    testConnClient(connection)
    connection.close()

    print "Test 7 - X.509 with SRP faults"
    for fault in Fault.clientSrpFaults + Fault.genericFaults:
        connection = connect()
        connection.fault = fault
        try:
            connection.handshakeClientSRP("test", "password")
            print "  Good Fault %s" % (Fault.faultNames[fault])
开发者ID:eaescob,项目名称:tlslite,代码行数:31,代码来源:tlstest.py

示例5: serverTestCmd

def serverTestCmd(argv):

    address = argv[0]
    dir = argv[1]
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #Connect to server
    lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsock.bind(address)
    lsock.listen(5)

    def connect():
        return TLSConnection(lsock.accept()[0])

    print "Test 0 - Anonymous server handshake"
    connection = connect()
    connection.handshakeServer(anon=True)
    testConnServer(connection)    
    connection.close() 
    
    print "Test 1 - good X.509"
    x509Cert = X509().parse(open(os.path.join(dir, "serverX509Cert.pem")).read())
    x509Chain = X509CertChain([x509Cert])
    s = open(os.path.join(dir, "serverX509Key.pem")).read()
    x509Key = parsePEMKey(s, private=True)

    connection = connect()
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key)
    assert(connection.session.serverName == address[0])    
    testConnServer(connection)    
    connection.close()

    print "Test 1.a - good X.509, SSL v3"
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    testConnServer(connection)
    connection.close()        
    
    if tackpyLoaded:
        tack = Tack.createFromPem(open("./TACK1.pem", "rU").read())
        tackUnrelated = Tack.createFromPem(open("./TACKunrelated.pem", "rU").read())    
            
        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        print "Test 2.a - good X.509, TACK"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tacks=[tack], activationFlags=1, settings=settings)
        testConnServer(connection)    
        connection.close()        

        print "Test 2.b - good X.509, TACK unrelated to cert chain"
        connection = connect()
        try:
            connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
                tacks=[tackUnrelated], settings=settings)
            assert(False)
        except TLSRemoteAlert, alert:
            if alert.description != AlertDescription.illegal_parameter:
                raise        
开发者ID:eaescob,项目名称:tlslite,代码行数:67,代码来源:tlstest.py

示例6: HandshakeSettings

#!/usr/bin/env python
from __future__ import print_function
from tlslite import HTTPTLSConnection, HandshakeSettings

settings = HandshakeSettings()
settings.useExperimentalTackExtension = True

h = HTTPTLSConnection("localhost", 4443, settings=settings)    
h.request("GET", "/index.html")
r = h.getresponse()
print(r.read())
开发者ID:4b1d,项目名称:tlslite,代码行数:11,代码来源:httpsclient.py

示例7: serverTestCmd

def serverTestCmd(argv):

    address = argv[0]
    dir = argv[1]
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #Create synchronisation FIFO
    synchroSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    synchroSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    synchroSocket.bind((address[0], address[1]-1))
    synchroSocket.listen(2)

    #Connect to server
    lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    lsock.bind(address)
    lsock.listen(5)

    # following is blocking until the other side doesn't open
    synchro = synchroSocket.accept()[0]

    def connect():
        return TLSConnection(lsock.accept()[0])

    x509Cert = X509().parse(open(os.path.join(dir, "serverX509Cert.pem")).read())
    x509Chain = X509CertChain([x509Cert])
    s = open(os.path.join(dir, "serverX509Key.pem")).read()
    x509Key = parsePEMKey(s, private=True)

    test_no = 0

    print("Test {0} - Anonymous server handshake".format(test_no))
    synchro.send(b'R')
    connection = connect()
    connection.handshakeServer(anon=True)
    testConnServer(connection)    
    connection.close()

    test_no += 1

    print("Test {0} - good X.509".format(test_no))
    synchro.send(b'R')
    connection = connect()
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key)
    assert(connection.session.serverName == address[0])    
    assert(connection.extendedMasterSecret)
    testConnServer(connection)    
    connection.close()

    test_no += 1

    print("Test {0} - good X.509, SSL v3".format(test_no))
    synchro.send(b'R')
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    assert(not connection.extendedMasterSecret)
    testConnServer(connection)
    connection.close()

    test_no += 1

    print("Test {0} - good X.509, RC4-MD5".format(test_no))
    synchro.send(b'R')
    connection = connect()
    settings = HandshakeSettings()
    settings.macNames = ["sha", "md5"]
    settings.cipherNames = ["rc4"]
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    testConnServer(connection)
    connection.close()

    if tackpyLoaded:
        tack = Tack.createFromPem(open("./TACK1.pem", "rU").read())
        tackUnrelated = Tack.createFromPem(open("./TACKunrelated.pem", "rU").read())    

        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        test_no += 1

        print("Test {0} - good X.509, TACK".format(test_no))
        synchro.send(b'R')
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tacks=[tack], activationFlags=1, settings=settings)
        testConnServer(connection)
        connection.close()

        test_no += 1

        print("Test {0} - good X.509, TACK unrelated to cert chain".\
              format(test_no))
        synchro.send(b'R')
        connection = connect()
#.........这里部分代码省略.........
开发者ID:ffilipus,项目名称:tlslite-ng,代码行数:101,代码来源:tlstest.py

示例8: clientTestCmd

def clientTestCmd(argv):
    
    address = argv[0]
    dir = argv[1]    

    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    def connect():
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(sock, 'settimeout'): #It's a python 2.3 feature
            sock.settimeout(5)
        sock.connect(address)
        c = TLSConnection(sock)
        return c

    test = 0

    badFault = False
    
    print "Test 0 - anonymous handshake"
    connection = connect()
    connection.handshakeClientAnonymous()
    testConnClient(connection)
    connection.close()
        
    print "Test 1 - good X509"
    connection = connect()
    connection.handshakeClientCert()
    testConnClient(connection)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    connection.close()

    print "Test 1.a - good X509, SSLv3"
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeClientCert(settings=settings)
    testConnClient(connection)    
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    connection.close()    
    
    if tackpyLoaded:
        print "Test 2.a - good X.509, good TACK"
        connection = connect()
        connection.handshakeClientCert(reqTack=True, 
         checker=Checker(tackID="BE1W1.AHUDE.GQIUT.TF9YC.3XVME", hardTack=True))
        testConnClient(connection)    
        connection.close()    

        try:
            print "Test 2.b - good X.509, \"wrong\" TACK"
            connection = connect()
            connection.handshakeClientCert(reqTack=True, 
             checker=Checker(tackID="B4444.EQ61B.F34EL.9KKLN.3WEW5", hardTack=True))
            assert(False)
        except TLSTackMismatchError:
            pass

        print "Test 2.c - good X.509, \"wrong\" TACK but break signature (hardTack)"
        connection = connect()
        try:
            connection.handshakeClientCert(reqTack=True, 
                checker=Checker(tackID="BE1W1.AHUDE.GQIUT.TF9YC.3XVME", hardTack=True))
            assert(False)
        except TLSTackBreakError:
            pass

        print "Test 2.d - good X.509, \"wrong\" TACK but break signature (not hardTack)"
        connection = connect()
        connection.handshakeClientCert(reqTack=True, 
            checker=Checker(tackID="BE1W1.AHUDE.GQIUT.TF9YC.3XVME", hardTack=False))
        testConnClient(connection)    
        connection.close()    

        print "Test 2.e - good X.509, TACK unrelated to cert chain"
        connection = connect()
        try:
            connection.handshakeClientCert(reqTack=True)
            assert(False)
        except TLSLocalAlert as alert:
            assert(alert.description == AlertDescription.handshake_failure)
        connection.close()

        try:
            print "Test 2.f - good X.509, no TACK but expected"
            connection = connect()
            connection.handshakeClientCert(reqTack=True, 
                checker=Checker(tackID="B4444.EQ61B.F34EL.9KKLN.3WEW5", hardTack=False))
            assert(False)
        except TLSTackMissingError:
            pass

    print "Test 3 - good SRP"
    connection = connect()
    connection.handshakeClientSRP("test", "password")
    testConnClient(connection)
    connection.close()
#.........这里部分代码省略.........
开发者ID:d-mo,项目名称:tlslite,代码行数:101,代码来源:tlstest.py

示例9: HandshakeSettings

#!/usr/bin/env python
from __future__ import print_function
from tlslite import HTTPTLSConnection, HandshakeSettings
from optparse import OptionParser


settings = HandshakeSettings()
settings.cipherNames = ['aes128gcm']
settings.keyExchangeNames = ['ecdhe_rsa']
settings.cipherImplementations = ["python"]
#settings.macNames = ['sha256']

settings.minVersion = (3,3)
settings.maxVersion = (3,3)   


settings.useExperimentalTackExtension = True

def main():

    parser = OptionParser(usage='%prog host filename [options]', description='A Simple https client used with tlslite-ng') 
    parser.add_option("--port", dest="port", help="port", default = 4443, type="int", metavar="4443")
    parser.add_option("--algo", dest="algo", help="algo", default = "speck128")
    parser.add_option("--keyEx", dest="keyEx", help="Key Exchange", default="ecdhe_rsa")
    
    (options, arguments) = parser.parse_args()
    
    if len(arguments) < 1:
        parser.print_help()
        exit(1)
        
开发者ID:ioef,项目名称:tlslite-ng,代码行数:30,代码来源:httpsclient.py

示例10: serverTestCmd

def serverTestCmd(argv):

    address = argv[0]
    dir = argv[1]
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #Connect to server
    lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsock.bind(address)
    lsock.listen(5)

    def connect():
        return TLSConnection(lsock.accept()[0])

    print "Test 0 - Anonymous server handshake"
    connection = connect()
    connection.handshakeServer(anon=True)
    testConnServer(connection)    
    connection.close() 
    
    print "Test 1 - good X.509"
    x509Cert = X509().parse(open(os.path.join(dir, "serverX509Cert.pem")).read())
    x509Chain = X509CertChain([x509Cert])
    s = open(os.path.join(dir, "serverX509Key.pem")).read()
    x509Key = parsePEMKey(s, private=True)

    connection = connect()
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key)
    testConnServer(connection)    
    connection.close()

    print "Test 1.a - good X.509, SSL v3"
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeServer(certChain=x509Chain, privateKey=x509Key, settings=settings)
    testConnServer(connection)
    connection.close()        
    
    if tackpyLoaded:
        # TACK1 and TACK2 are both "good" TACKs, one targetting, the key,
        # one the hash
        tack1 = TACK()
        tack1.parsePem(open("./TACK1.pem", "rU").read())
        tack2 = TACK()
        tack2.parsePem(open("./TACK2.pem", "rU").read())
        tackUnrelated = TACK()
        tackUnrelated.parsePem(open("./TACKunrelated.pem", "rU").read())    
        breakSigs = TACK_Break_Sig.parsePemList(
            open("./TACK_Break_Sigs.pem").read())
        breakSigsActual = TACK_Break_Sig.parsePemList(
            open("./TACK_Break_Sigs_TACK1.pem").read())    

        print "Test 2.a - good X.509, good TACK"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tack=tack1, breakSigs=breakSigs)
        testConnServer(connection)    
        connection.close()        

        print "Test 2.b - good X.509, \"wrong\" TACK"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tack=tack1)
        connection.close()        

        print "Test 2.c - good X.509, \"wrong\" TACK but break signature (hardTack)"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tack=tack2, breakSigs=breakSigsActual)

        print "Test 2.d - good X.509, \"wrong\" TACK but break signature (not hardTack)"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
            tack=tack2, breakSigs=breakSigsActual)
        testConnServer(connection)    
        connection.close()

        print "Test 2.e - good X.509, TACK unrelated to cert chain"
        connection = connect()
        try:
            connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
                tack=tackUnrelated)
        except TLSRemoteAlert as alert:
            assert(alert.description == AlertDescription.handshake_failure)

        print "Test 2.f - good X.509, no TACK but expected"
        connection = connect()
        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key)
        connection.close()        

    print "Test 3 - good SRP"
    verifierDB = VerifierDB()
    verifierDB.create()
    entry = VerifierDB.makeVerifier("test", "password", 1536)
    verifierDB["test"] = entry
#.........这里部分代码省略.........
开发者ID:d-mo,项目名称:tlslite,代码行数:101,代码来源:tlstest.py

示例11: clientTestCmd

def clientTestCmd(argv):
    
    address = argv[0]
    dir = argv[1]    

    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    def connect():
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(sock, 'settimeout'): #It's a python 2.3 feature
            sock.settimeout(5)
        sock.connect(address)
        c = TLSConnection(sock)
        return c

    test = 0

    badFault = False
    
    print("Test 0 - anonymous handshake")
    connection = connect()
    connection.handshakeClientAnonymous()
    testConnClient(connection)
    connection.close()
        
    print("Test 1 - good X509 (plus SNI)")
    connection = connect()
    connection.handshakeClientCert(serverName=address[0])
    testConnClient(connection)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    assert(connection.session.serverName == address[0])
    connection.close()

    print("Test 1.a - good X509, SSLv3")
    connection = connect()
    settings = HandshakeSettings()
    settings.minVersion = (3,0)
    settings.maxVersion = (3,0)
    connection.handshakeClientCert(settings=settings)
    testConnClient(connection)    
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    connection.close()    

    if tackpyLoaded:
                    
        settings = HandshakeSettings()
        settings.useExperimentalTackExtension = True

        print("Test 2.a - good X.509, TACK")
        connection = connect()
        connection.handshakeClientCert(settings=settings)
        assert(connection.session.tackExt.tacks[0].getTackId() == "rrted.ptvtl.d2uiq.ox2xe.w4ss3")
        assert(connection.session.tackExt.activation_flags == 1)        
        testConnClient(connection)    
        connection.close()    

        print("Test 2.b - good X.509, TACK unrelated to cert chain")
        connection = connect()
        try:
            connection.handshakeClientCert(settings=settings)
            assert(False)
        except TLSLocalAlert as alert:
            if alert.description != AlertDescription.illegal_parameter:
                raise        
        connection.close()

    print("Test 3 - good SRP")
    connection = connect()
    connection.handshakeClientSRP("test", "password")
    testConnClient(connection)
    connection.close()

    print("Test 4 - SRP faults")
    for fault in Fault.clientSrpFaults + Fault.genericFaults:
        connection = connect()
        connection.fault = fault
        try:
            connection.handshakeClientSRP("test", "password")
            print("  Good Fault %s" % (Fault.faultNames[fault]))
        except TLSFaultError as e:
            print("  BAD FAULT %s: %s" % (Fault.faultNames[fault], str(e)))
            badFault = True

    print("Test 6 - good SRP: with X.509 certificate, TLSv1.0")
    settings = HandshakeSettings()
    settings.minVersion = (3,1)
    settings.maxVersion = (3,1)    
    connection = connect()
    connection.handshakeClientSRP("test", "password", settings=settings)
    assert(isinstance(connection.session.serverCertChain, X509CertChain))
    testConnClient(connection)
    connection.close()

    print("Test 7 - X.509 with SRP faults")
    for fault in Fault.clientSrpFaults + Fault.genericFaults:
        connection = connect()
        connection.fault = fault
        try:
#.........这里部分代码省略.........
开发者ID:dmbaggett,项目名称:tlslite,代码行数:101,代码来源:tlstest.py

示例12: HandshakeSettings

#!/usr/bin/env python

from tlslite import HTTPTLSConnection, HandshakeSettings

settings = HandshakeSettings()
settings.useExperimentalTACKExtension = True

h = HTTPTLSConnection("localhost", 4443, settings=settings)    
h.request("GET", "/index.html")
r = h.getresponse()
print r.read()
开发者ID:tpmanley,项目名称:tlslite,代码行数:11,代码来源:httpsclient.py

示例13: clientTestCmd

def clientTestCmd(argv):
    
    address = argv[0]
    dir = argv[1]    
    datasize = argv[2]
    
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #open synchronisation FIFO
    synchro = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    synchro.settimeout(40)
    synchro.connect((address[0], address[1]-1))

    def connect():
        sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        if hasattr(sock, 'settimeout'): #It's a python 2.3 feature
            sock.settimeout(25)
        sock.connect(address)
        c = TLSConnection(sock)
        return c

    test_no = 0

    badFault = False
 
    message = dataRandomizer(datasize) 
 
    for cipher in [ "aes128gcm","aes128", "aes256",
                       "rc4", "chacha20-poly1305", "speck128", "speck128gcm","speck192gcm"]:                   
        test_no += 1

        t1 = time.time()
        print("Test {0}:".format(test_no), end=' ')
        synchro.recv(1)
        connection = connect()

        t2 = time.time()

        settings = HandshakeSettings()
        settings.cipherNames = [cipher]
        settings.cipherImplementations = ["python"]
        connection.handshakeClientCert(settings=settings)
        t3 = time.time()
        print("%s %s:" % (connection.getCipherName(), connection.getCipherImplementation()), end=' ')


        if datasize == "3MB":
            t3 = time.time()
            connection.write(message)
            h = connection.read(min=1500000, max=1500000)
            t4 = time.time()                
            if t4-t3:
                print("3MB exchanged at rate of %d bytes/sec" % int(3000000/(t4-t3)))
		print ('Raw timers:','t1=', t1,'t2=', t2,'t3=', t3,'t4=', t4)
                print ('Intervals:', t2-t1, t3-t2, t4-t3)
		sizeInBytes = sys.getsizeof(h)*2
                print("Tranmsitted data size:", sizeInBytes)
		print("Throughput is bytes/sec:", round(sizeInBytes / (t4-t3), 3))

            else:
                print("3MB exchanged very fast")
                            
            assert(h == message)            

        elif datasize == "2MB":
            t3 = time.time()
            connection.write(message)
            h = connection.read(min=1000000, max=1000000)
            t4 = time.time()                
            if t4-t3:
                print("2MB exchanged at rate of %d bytes/sec" % int(2000000/(t4-t3)))
		print ('Raw timers:','t1=', t1,'t2=', t2,'t3=', t3,'t4=', t4)
		print ('Intervals:', t2-t1, t3-t2, t4-t3)
		sizeInBytes = sys.getsizeof(h)*2
		print("Tranmsitted data size:", sizeInBytes)
		print("Throughput:", round(sizeInBytes / (t4-t3), 3))		
            else:
                print("2MB exchanged very fast")
                
            assert(h == message)
                
        elif datasize == "1MB": 
            t3 = time.time()
            connection.write(message)
            h = connection.read(min=500000, max=500000)
            t4 = time.time()
            if t4-t3:
                print("1MB exchanged at rate of %d bytes/sec" % int(1000000/(t4-t3)))
                print ('Raw timers:','t1=', t1,'t2=', t2,'t3=', t3,'t4=', t4)
                print ('Intervals:', t2-t1, t3-t2, t4-t3)
		sizeInBytes = sys.getsizeof(h)*2
                print("Tranmsitted data size:", sizeInBytes)
		print("Throughput:", round(sizeInBytes / (t4-t3), 3))
            else:
                print("1MB exchanged very fast")
            
            assert(h == message)                
#.........这里部分代码省略.........
开发者ID:ioef,项目名称:tlslite-ng,代码行数:101,代码来源:throughput-tests.py

示例14: serverTestCmd

def serverTestCmd(argv):

    address = argv[0]
    dir = argv[1]
    datasize = argv[2]
    
    #Split address into hostname/port tuple
    address = address.split(":")
    address = ( address[0], int(address[1]) )

    #Create synchronisation FIFO
    synchroSocket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    synchroSocket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    synchroSocket.bind((address[0], address[1]-1))
    synchroSocket.listen(2)

    #Connect to server
    lsock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
    lsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    lsock.bind(address)
    lsock.listen(5)

    # following is blocking until the other side doesn't open
    synchro = synchroSocket.accept()[0]


    def connect():
        return TLSConnection(lsock.accept()[0])

    x509Cert = X509().parse(open(os.path.join(dir, "serverX509Cert.pem")).read())
    x509Chain = X509CertChain([x509Cert])
    s = open(os.path.join(dir, "serverX509Key.pem")).read()
    x509Key = parsePEMKey(s, private=True)

    test_no = 0
    

    for cipher in ["aes128gcm", "aes128", "aes256", "rc4","chacha20-poly1305","speck128", "speck128gcm", "speck192gcm"]:
       
        test_no += 1

        print("Test {0}:".format(test_no), end=' ')
        synchro.send(b'R')
        connection = connect()

        settings = HandshakeSettings()
        settings.cipherNames = [cipher]
        settings.cipherImplementations = ["python"]

        connection.handshakeServer(certChain=x509Chain, privateKey=x509Key,
                                        settings=settings)
        print(connection.getCipherName(), connection.getCipherImplementation())
            
        if datasize == "3MB":
            h = connection.read(min=1500000, max=1500000)             

        elif datasize == "2MB":
            h = connection.read(min=1000000, max=1000000) 
                
        elif datasize == "1MB":
            h = connection.read(min=500000, max=500000)         

        elif datasize == "500k":
            h = connection.read(min=250000, max=250000)
                
        elif datasize == "100k":
                h = connection.read(min=50000, max=50000)
                
        elif datasize == "2k":
            h = connection.read(min=1000, max=1000)
            
        else:  
                
            print("Datasize not supported or syntax error! Exiting...")
            exit(1)

            
            
        connection.write(h)
        connection.close()




    synchro.close()
    synchroSocket.close()

    print("Test succeeded")
开发者ID:ioef,项目名称:tlslite-ng,代码行数:88,代码来源:throughput-tests.py


注:本文中的tlslite.HandshakeSettings类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。