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


Python Context.set_timeout方法代码示例

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


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

示例1: __init__

# 需要导入模块: from OpenSSL.SSL import Context [as 别名]
# 或者: from OpenSSL.SSL.Context import set_timeout [as 别名]
    def __init__(self, HOST='130.236.216.131', PORT = 443):
        s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
        context = Context(TLSv1_METHOD)
        context.use_certificate_file((self.certpath))
        context.use_privatekey_file(self.keypath)
        context.set_timeout(2)
        conn = Connection(context,s)
        conn.bind((HOST,PORT))

        print 'Server is listening...'
        conn.listen(5)
        # self.client_table is a dictionary of clients
        # where key = unique id and value = socket
        self.client_table = {} 
        self.id_counter = 0
        self.in_q = Queue.Queue()
        self.out_q = Queue.Queue()
        threading.Thread(target=self.sendinput).start()
        threading.Thread(target=self.in_processor).start()
        threading.Thread(target=self.out_processor).start()
        try:
            while True:
        # Waiting for new client to accept, sslsocket is the socket that will be used for communication with this client after a client sets up a connection with the server
                sslsocket, addr = conn.accept()
                self.client_table[self.id_counter] = sslsocket
                self.id_counter = self.id_counter + 1
                threading.Thread(target=self.client_handler,args=(self.id_counter-1,)).start()
        except KeyboardInterrupt:
            for key, value in self.client_table.iteritems():
                value.shutdown()
                value.close()
            sys.exit(0)
开发者ID:dreamwave,项目名称:rad,代码行数:34,代码来源:socketserver.py

示例2: connect

# 需要导入模块: from OpenSSL.SSL import Context [as 别名]
# 或者: from OpenSSL.SSL.Context import set_timeout [as 别名]
 def connect(self):
     print "You are trying to connect..."
     for x in range(7):
         if not self.connected:
             try:
                 s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
                 context = Context(TLSv1_METHOD)
                 context.use_certificate_file(self.cacertpath)
                 context.set_timeout(2)
                 self.sslsocket = Connection(context,s)
                 self.sslsocket.connect((self.host_addr,self.host_port))
                 #starting a thread that listen to what server sends which the clients need to be able to send and recive data at the same time
                 t = threading.Thread(target=self.receive)
                 t.daemon = True
                 t.start()
                 if self.sslsocket:
                     self.connected = True
                 print "connection established"
                 #self.authentication("Kalle", "te")
                 t = threading.Thread(target=self.sendinput)
                 t.start()
             except socket.error:
                 print "You failed to connect, retrying......."
                 time.sleep(5)
开发者ID:dreamwave,项目名称:rad,代码行数:26,代码来源:socketclient.py

示例3: Context

# 需要导入模块: from OpenSSL.SSL import Context [as 别名]
# 或者: from OpenSSL.SSL.Context import set_timeout [as 别名]
Create Date:        2016/12/1
Create Time:        13:58
 """
import datetime
import time
from socket import socket

from OpenSSL.SSL import Connection, Context, SSLv3_METHOD, TLSv1_2_METHOD

host = 'www.baidu.com'

try:
    ssl_connection_setting = Context(SSLv3_METHOD)
except ValueError:
    ssl_connection_setting = Context(TLSv1_2_METHOD)
ssl_connection_setting.set_timeout(30)

s = socket()
s.connect((host, 443))
c = Connection(ssl_connection_setting, s)
c.set_connect_state()
c.do_handshake()
cert = c.get_peer_certificate()
print "Issuer: ", cert.get_issuer()
print "Subject: ", cert.get_subject().get_components()
subject_list = cert.get_subject().get_components()
print "Common Name:", dict(subject_list).get("CN")
print "notAfter(UTC time): ", cert.get_notAfter()
UTC_FORMAT = "%Y%m%d%H%M%SZ"
utc_to_local_offset = datetime.datetime.fromtimestamp(time.time()) - datetime.datetime.utcfromtimestamp(time.time())
utc_time = time.mktime(time.strptime(cert.get_notAfter(), UTC_FORMAT))
开发者ID:DingGuodong,项目名称:LinuxBashShellScriptForOps,代码行数:33,代码来源:pyGetCertsInfo.py


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