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


Python HandshakeSettings.cipherNames方法代码示例

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


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

示例1: clientTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]

#.........这里部分代码省略.........
                        address[0], address[1], checker=checker)
                for x in range(3):
                    synchro.recv(1)
                    h.request("GET", "/index.html")
                    r = h.getresponse()
                    assert(r.status == 200)
                    b = bytearray(r.read())
                    assert(b == htmlBody)
                fingerprint = h.tlsSession.serverCertChain.getFingerprint()
                assert(fingerprint)
            break
        except timeoutEx:
            print("timeout, retrying...")
            pass

    address = address[0], address[1]+1

    implementations = []
    if m2cryptoLoaded:
        implementations.append("openssl")
    if pycryptoLoaded:
        implementations.append("pycrypto")
    implementations.append("python")

    print("Test 22 - different ciphers, TLSv1.0")
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "rc4"]:

            print("Test 22:", end=' ')
            synchro.recv(1)
            connection = connect()

            settings = HandshakeSettings()
            settings.cipherNames = [cipher]
            settings.cipherImplementations = [implementation, "python"]
            settings.minVersion = (3,1)
            settings.maxVersion = (3,1)            
            connection.handshakeClientCert(settings=settings)
            testConnClient(connection)
            print("%s %s" % (connection.getCipherName(), connection.getCipherImplementation()))
            connection.close()

    print("Test 23 - throughput test")
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "3des", "rc4"]:
            if cipher == "3des" and implementation not in ("openssl", "pycrypto"):
                continue

            print("Test 23:", end=' ')
            synchro.recv(1)
            connection = connect()

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

            startTime = time.clock()
            connection.write(b"hello"*10000)
            h = connection.read(min=50000, max=50000)
            stopTime = time.clock()
            if stopTime-startTime:
                print("100K exchanged at rate of %d bytes/sec" % int(100000/(stopTime-startTime)))
            else:
                print("100K exchanged very fast")
开发者ID:alex1818,项目名称:tlslite,代码行数:70,代码来源:tlstest.py

示例2: connect

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
    implementations = []
    if m2cryptoLoaded:
        implementations.append("openssl")
    if pycryptoLoaded:
        implementations.append("pycrypto")
    implementations.append("python")

    print "Test 22 - different ciphers, TLSv1.0"
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "rc4"]:

            print "Test 22:",
            connection = connect()

            settings = HandshakeSettings()
            settings.cipherNames = [cipher]
            settings.cipherImplementations = [implementation, "python"]
            settings.minVersion = (3,1)
            settings.maxVersion = (3,1)            
            connection.handshakeClientCert(settings=settings)
            testConnClient(connection)
            print ("%s %s" % (connection.getCipherName(), connection.getCipherImplementation()))
            connection.close()

    print "Test 23 - throughput test"
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "3des", "rc4"]:
            if cipher == "3des" and implementation not in ("openssl", "pycrypto"):
                continue

            print "Test 23:",
开发者ID:eaescob,项目名称:tlslite,代码行数:33,代码来源:tlstest.py

示例3: serverTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
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,代码行数:103,代码来源:tlstest.py

示例4: serverTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
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,代码行数:103,代码来源:tlstest.py

示例5: HandshakeSettings

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
#!/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,代码行数:32,代码来源:httpsclient.py

示例6: clientTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]

#.........这里部分代码省略.........
                for x in range(3):
                    h.request("GET", "/index.html")
                    r = h.getresponse()
                    assert(r.status == 200)
                    b = bytearray(r.read())
                    assert(b == htmlBody)
                fingerprint = h.tlsSession.serverCertChain.getFingerprint()
                assert(fingerprint)
            time.sleep(2)
            break
        except timeoutEx:
            print("timeout, retrying...")
            pass

    address = address[0], address[1]+1

    implementations = []
    if m2cryptoLoaded:
        implementations.append("openssl")
    if tlscryptoLoaded:
        implementations.append("tlscrypto")
    if pycryptoLoaded:
        implementations.append("pycrypto")
    implementations.append("python")

    print("Test 22 - different ciphers, TLSv1.0")
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "rc4"]:

            print("Test 22:", end=' ')
            connection = connect()

            settings = HandshakeSettings()
            settings.cipherNames = [cipher]
            settings.cipherImplementations = [implementation, "python"]
            settings.minVersion = (3,1)
            settings.maxVersion = (3,1)            
            connection.handshakeClientCert(settings=settings)
            testConnClient(connection)
            print("%s %s" % (connection.getCipherName(), connection.getCipherImplementation()))
            connection.close()

    print("Test 23 - throughput test")
    for implementation in implementations:
        for cipher in ["aes128", "aes256", "3des", "rc4"]:
            if cipher == "3des" and implementation not in ("openssl", "pycrypto"):
                continue

            print("Test 23:", end=' ')
            connection = connect()

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

            startTime = time.clock()
            connection.write(b"hello"*10000)
            h = connection.read(min=50000, max=50000)
            stopTime = time.clock()
            if stopTime-startTime:
                print("100K exchanged at rate of %d bytes/sec" % int(100000/(stopTime-startTime)))
            else:
                print("100K exchanged very fast")
开发者ID:dmbaggett,项目名称:tlslite,代码行数:69,代码来源:tlstest.py

示例7: clientTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
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,代码行数:103,代码来源:throughput-tests.py

示例8: serverTestCmd

# 需要导入模块: from tlslite import HandshakeSettings [as 别名]
# 或者: from tlslite.HandshakeSettings import cipherNames [as 别名]
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,代码行数:90,代码来源:throughput-tests.py


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