Ejemplo n.º 1
0
def i_update_user_after_ssi_auth_success(user, res_obj, remember_passwd):
    """ get and set SSI cookie, uri, user ID, mobile No. """
    body_dom = minidom.parseString(res_obj.body)

    headers = res_obj.getheader('Set-Cookie')
    ssi_cookie = strip2(headers, "ssic=", ";")
    user.set_ssi_cookie(ssi_cookie)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.uri = user_node.getAttribute("uri")

    user.sid = get_sid_from_uri(user.uri)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.mobile_no = user_node.getAttribute("mobile-no")
    user.user_id = user_node.getAttribute("user-id")

    user.set_user_path(user.sid)
    user.set_portrait_save_path()


    set_last_login_sid(user.sid)
    if remember_passwd:
        hashed_passwd = user.get_hashed_passwd()
    else:
        hashed_passwd = None

    data = {
        "sid" : user.sid,
        "mobile_no" : user.mobile_no,
        "hashed_passwd" : "%s%s" % (HASHED_PREFIX, hashed_passwd),
        "last_presence" : user.get_presence()
    }
    save_data_to_local_json(data, "account.json")
Ejemplo n.º 2
0
def i_update_user_after_ssi_auth_success(user, res_obj, remember_passwd):
    """ get and set SSI cookie, uri, user ID, mobile No. """
    body_dom = minidom.parseString(res_obj.body)

    headers = res_obj.getheader("Set-Cookie")
    ssi_cookie = strip2(headers, "ssic=", ";")
    user.set_ssi_cookie(ssi_cookie)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.uri = user_node.getAttribute("uri")

    user.sid = get_sid_from_uri(user.uri)

    user_node = body_dom.getElementsByTagName("user")[0]
    user.mobile_no = user_node.getAttribute("mobile-no")
    user.user_id = user_node.getAttribute("user-id")

    user.set_user_path(user.sid)
    user.set_portrait_save_path()

    set_last_login_sid(user.sid)
    if remember_passwd:
        hashed_passwd = user.get_hashed_passwd()
    else:
        hashed_passwd = None

    data = {
        "sid": user.sid,
        "mobile_no": user.mobile_no,
        "hashed_passwd": "%s%s" % (HASHED_PREFIX, hashed_passwd),
        "last_presence": user.get_presence(),
    }
    save_data_to_local_json(data, "account.json")
Ejemplo n.º 3
0
def _generate_sipc_auth_response(user, res_obj):
    digest = res_obj.headers.get_field_value("W")
#    print "digest:", digest
    nonce = strip2(digest, 'nonce="', '"')
    key = strip2(digest, 'key="', '"')
    user_id = user.user_id

    p1 = user.get_hashed_passwd()
#    print "p1:", p1
    aes_key = "e146a9e31efb41f2d7ab58ba7ccd1f2958ec944a5cffdc514873986923c64567"
    p2 = hashlib.sha1(struct.pack("i", int(user_id)) + binascii.a2b_hex(p1)).hexdigest()
    plain = nonce + binascii.a2b_hex(p2) + binascii.a2b_hex(aes_key)

    rsa_n = key[:-6]
    rsa_e = key[-6:]

    response = binascii.b2a_hex(rsa(plain, rsa_e, rsa_n[:256], False))
    assert len(response) == 256
    return response
Ejemplo n.º 4
0
def _get_ip_port_credential_from_auth_field(auth):
    splits = strip2(auth, 'CS ').split(',')
    ip = strip2(splits[0], 'address="', ':')
    port = int(strip2(splits[0], ":", ";"))
    credential = strip2(splits[1], 'credential="', '"')
    return ip, port, credential
Ejemplo n.º 5
0
def get_sid_from_uri(uri):
    if uri.find("sip:") != STR_NOT_FOUND:
        return strip2(uri, "sip:", "@")
    elif uri.find("tel:") != STR_NOT_FOUND:
        return strip2(uri, "tel:")
Ejemplo n.º 6
0
def get_sid_from_uri(uri):
    if uri.find("sip:") != STR_NOT_FOUND:
        return strip2(uri, "sip:", "@")
    elif uri.find("tel:") != STR_NOT_FOUND:
        return strip2(uri, "tel:")
Ejemplo n.º 7
0
def i_generate_verification_pic(user, res_obj, debug=False):
    """ There two types response, HTTP status 421 or SIPResponse code 421,
        the former response body contains verification node, the latter contains reason note only. """

    body_dom = minidom.parseString(res_obj.body)
    veri_nodes = body_dom.getElementsByTagName("verification")
    if veri_nodes:
        veri_node = veri_nodes[0]
        attr = veri_node.getAttribute

        algorithm = attr("algorithm")
        _type = attr("type")
        text = attr("text")
        tips = attr("tips")
    else:
        reason_node = body_dom.getElementsByTagName("reason")[0]
        w_val = res_obj.headers.get_field_value("W")

        algorithm = strip2(w_val, 'algorithm="', '",')
        _type = strip2(w_val, 'type="', '"')
        text = reason_node.getAttribute("text")
        tips = ""
    veri = Verification(algorithm=algorithm, _type=_type, text=text, tips=tips)

    ssi_cookie = user.get_ssi_cookie() or ""
    host = "nav.fetion.com.cn"

    headers = dict({
        'Cookie': 'ssic=%s' % ssi_cookie,
        "Connection": "close",
        "User-Agent": "IIC2.0/PC %s" % PROTOCOL_VERSION,
    })

    httplib.HTTPConnection.response_class = HTTPResponse
    conn = httplib.HTTPConnection(host)

    if debug:
        debuglevel = 1
    else:
        debuglevel = 0
    conn.set_debuglevel(debuglevel)

    if veri.algorithm:
        algorithm = veri.algorithm
    else:
        algorithm = ""
    url = '/nav/GetPicCodeV4.aspx?algorithm=%s' % algorithm
    conn.request("GET", url, headers=headers)
    res_obj = conn.getresponse()

    assert httplib.OK == res_obj.status

    body_dom = minidom.parseString(res_obj.body)
    conn.close()

    pic_cert_node = body_dom.getElementsByTagName("pic-certificate")[0]
    attr = pic_cert_node.getAttribute
    veri.pid = attr("id")

    pic_base64 = attr("pic")
    pic_save_path = os.path.join(get_user_config_path(), "%s" % user.sid,
                                 "verify_code.jpeg")
    with open(pic_save_path, "wb") as f:
        f.write(base64.decodestring(pic_base64))
    veri.picture_path = pic_save_path

    return veri
Ejemplo n.º 8
0
def i_generate_verification_pic(user, res_obj, debug = False):
    """ There two types response, HTTP status 421 or SIPResponse code 421,
        the former response body contains verification node, the latter contains reason note only. """

    body_dom = minidom.parseString(res_obj.body)
    veri_nodes = body_dom.getElementsByTagName("verification")
    if veri_nodes:
        veri_node = veri_nodes[0]
        attr = veri_node.getAttribute

        algorithm = attr("algorithm")
        _type = attr("type")
        text = attr("text")
        tips = attr("tips")
    else:
        reason_node = body_dom.getElementsByTagName("reason")[0]
        w_val = res_obj.headers.get_field_value("W")

        algorithm = strip2(w_val, 'algorithm="', '",')
        _type = strip2(w_val, 'type="', '"')
        text = reason_node.getAttribute("text")
        tips = ""
    veri = Verification(algorithm = algorithm, _type = _type, text = text, tips = tips)

    ssi_cookie = user.get_ssi_cookie() or ""
    host = "nav.fetion.com.cn"

    headers = dict({
        'Cookie' : 'ssic=%s' % ssi_cookie,
        "Connection" : "close",
        "User-Agent" : "IIC2.0/PC %s" % PROTOCOL_VERSION,
        })

    httplib.HTTPConnection.response_class = HTTPResponse
    conn = httplib.HTTPConnection(host)

    if debug:
        debuglevel = 1
    else:
        debuglevel = 0
    conn.set_debuglevel(debuglevel)

    if veri.algorithm:
        algorithm = veri.algorithm
    else:
        algorithm = ""
    url = '/nav/GetPicCodeV4.aspx?algorithm=%s' % algorithm
    conn.request("GET", url, headers = headers)
    res_obj = conn.getresponse()

    assert httplib.OK == res_obj.status

    body_dom = minidom.parseString(res_obj.body)
    conn.close()

    pic_cert_node = body_dom.getElementsByTagName("pic-certificate")[0]
    attr = pic_cert_node.getAttribute
    veri.pid = attr("id")

    pic_base64 = attr("pic")
    pic_save_path = os.path.join(get_user_config_path(), "%s" % user.sid, "verify_code.jpeg")
    with open(pic_save_path, "wb") as f:
        f.write(base64.decodestring(pic_base64))
    veri.picture_path = pic_save_path

    return veri