def i_ssi_auth(user, verification=None, debug=False): """ NOTICE: Don't use httplib.HTTPSConnection, it gets wrong size response body sometimes! """ digest = user.get_hashed_passwd() # hard-code enable login with SID or mobile No. only SID_OR_MOBILE_NO = 1 digest_type = SID_OR_MOBILE_NO params = dict() params.update({"domains": HOME_DOMAIN, "v4digest-type": str(digest_type), "v4digest": digest}) if verification is not None: veri_d = {"pid": verification.pid, "pic": verification.chars, "algorithm": verification.algorithm} params.update(veri_d) if user.get_login_with() == user.LOGIN_WITH_MOBILE_NO: login_with = {"mobileno": user.mobile_no} else: login_with = {"sid": user.sid} params.update(login_with) query = urllib.urlencode(params) path = "/ssiportal/SSIAppSignInV4.aspx" req = "GET %s?%s %s" % (path, query, CRLF) # headers = { # "User-Agent" : "IIC2.0/pc %s" % PROTOCOL_VERSION, # "Host" : "uid.fetion.com.cn", # "Cache-Control" : "private", # "Connection" : "Keep-Alive", # } # # head_obj = HTTPHeaders(headers = headers) # req += str(head_obj) + CRLF SSI_AUTH_HOST = "uid.fetion.com.cn" ip = socket.gethostbyname(SSI_AUTH_HOST) port = 443 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ssl_sock = ssl.wrap_socket(sock, cert_reqs=ssl.CERT_NONE, ssl_version=ssl.PROTOCOL_SSLv23) ssl_sock.connect((ip, port)) ssl_sock.write(req) if debug: logger.debug(req) if debug: debuglevel = 1 else: debuglevel = 0 res_obj = HTTPResponse(ssl_sock, debuglevel=debuglevel, read_body=True) ssl_sock.close() return res_obj
def sock_send_debug_msg_filter(sock, buf, debug): res_obj = SIPResponse(buf) ip, port = sock.getpeername() attr = res_obj.headers.get_field_value q_val = attr("Q") x_val = attr("X") l_val = attr("L") IS_KEEP_ALIVE_ACK = q_val == "2 R" and x_val == "600" and l_val == "481" prefix = "%s:%d send:" % (ip, port) if IS_KEEP_ALIVE_ACK: msg = "%s %s" % (prefix, "a {keep alive,keep connection busy}") else: msg = "%s\n%s" % (prefix, buf) if debug: logger.debug(msg)
def sock_recv_debug_msg_filter(sock, buf, debug): res_obj = SIPResponse(buf) ip, port = sock.getpeername() sip_type = res_obj.get_sip_method() attr = res_obj.headers.get_field_value q_val = attr("Q") x_val = attr("X") l_val = attr("L") IS_KEEP_ALIVE_ACK = q_val == "2 R" and x_val == "600" and l_val == "481" IS_KEEP_CONN_BUSY = q_val == "1 O" and sip_type == SIP.SIPC_4_0 prefix = "%s:%d recv:" % (ip, port) if IS_KEEP_ALIVE_ACK: msg = "%s %s" % (prefix, "a keep alive ack") elif IS_KEEP_CONN_BUSY: msg = "%s %s" % (prefix, "a keep connection busy ack") else: msg = "%s\n%s" % (prefix, buf) if debug: logger.debug(msg)
def over(self): if self.keep_conn_busy_thread: logger.debug("cancel keep_conn_busy_thread ...") self.keep_conn_busy_thread.cancel() self.sock.close()
def i_ssi_auth(user, verification = None, debug = False): ''' NOTICE: Don't use httplib.HTTPSConnection, it gets wrong size response body sometimes! ''' digest = user.get_hashed_passwd() # hard-code enable login with SID or mobile No. only SID_OR_MOBILE_NO = 1 digest_type = SID_OR_MOBILE_NO params = dict() params.update({ "domains" : HOME_DOMAIN, "v4digest-type" : str(digest_type), "v4digest" : digest, }) if verification is not None: veri_d = { "pid" : verification.pid, "pic" : verification.chars, "algorithm" : verification.algorithm } params.update(veri_d) if user.get_login_with() == user.LOGIN_WITH_MOBILE_NO: login_with = {"mobileno" : user.mobile_no} else: login_with = {"sid" : user.sid} params.update(login_with) query = urllib.urlencode(params) path = "/ssiportal/SSIAppSignInV4.aspx" req = "GET %s?%s %s" % (path, query, CRLF) # headers = { # "User-Agent" : "IIC2.0/pc %s" % PROTOCOL_VERSION, # "Host" : "uid.fetion.com.cn", # "Cache-Control" : "private", # "Connection" : "Keep-Alive", # } # # head_obj = HTTPHeaders(headers = headers) # req += str(head_obj) + CRLF SSI_AUTH_HOST = "uid.fetion.com.cn" ip = socket.gethostbyname(SSI_AUTH_HOST) port = 443 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) ssl_sock = ssl.wrap_socket(sock, cert_reqs = ssl.CERT_NONE, ssl_version = ssl.PROTOCOL_SSLv23) ssl_sock.connect((ip, port)) ssl_sock.write(req) if debug: logger.debug(req) if debug: debuglevel = 1 else: debuglevel = 0 res_obj = HTTPResponse(ssl_sock, debuglevel = debuglevel, read_body = True) ssl_sock.close() return res_obj