Beispiel #1
0
gboolean
imap_auth_cb(hybrid_imap *imap, const gchar *msg, gpointer user_data)
{
    hybrid_debug_info("imap", "recv:\n%s", msg);

    if (HYBRID_OK == check_resp_ok(msg)) {
        hybrid_account_set_connection_string(imap->account,
                                             _("IMAP OK."));
        hybrid_account_set_connection_status(imap->account,
                                             HYBRID_CONNECTION_CONNECTED);

        hybrid_account_set_state(imap->account, HYBRID_STATE_ONLINE);

        imap->mail_check_source = g_timeout_add_seconds(
                                        imap->mail_check_interval,
                                        check_mail, imap);
        return FALSE;
    }

    hybrid_account_error_reason(imap->account,
                                _("IMAP Authenticate Failed."
                                  " Check your username and password."));

    return FALSE;
}
Beispiel #2
0
/**
 * Ok, TLS handshake success, we will continue the authtication
 * through the established TLS channel.
 */
static gboolean
tls_conn_cb(HybridSslConnection *ssl, XmppStream *stream)
{
    gchar *msg;

    hybrid_account_set_connection_string(stream->account->account,
                                         "TLS connection established.");

    msg = create_initiate_stream(stream);

    /*
     * Reset the stream id, we will start a new stream through 
     * the TLS channel, whether stream id is NULL is the flag 
     * of a new stream.
     */
    xmpp_stream_set_id(stream, NULL);
    xmpp_stream_set_state(stream, XMPP_STATE_TLS_STREAM_STARTING);

    hybrid_debug_info("stream", "send start stream request:\n%s", msg);

    if (hybrid_ssl_write(ssl, msg, strlen(msg)) == -1) {

        hybrid_account_error_reason(stream->account->account,
                "send initial jabber request failed");
        g_free(msg);

        return FALSE;
    }

    g_free(msg);

    return FALSE;
}
Beispiel #3
0
gboolean
ssi_auth_action(HybridSslConnection *isc, gpointer user_data)
{
    gchar *password;
    gchar  no_url[URL_LENGTH];
    gchar  verify_url[URL_LENGTH];
    gchar  ssl_buf[BUF_LENGTH];
    gint   pass_type;

    fetion_account *ac = (fetion_account*)user_data;

    hybrid_account_set_connection_string(ac->account, _("Start SSI authentication..."));

    hybrid_debug_info("fetion", "ssi authencating");
    password = hash_password_v4(ac->userid, ac->password);

    if (ac->mobileno) {
        g_snprintf(no_url, sizeof(no_url) - 1, "mobileno=%s", ac->mobileno);

    } else {
        g_snprintf(no_url, sizeof(no_url) - 1, "sid=%s", ac->sid);
    }

    *verify_url = '\0';
    /**
     * if the verification is not NULL ,it means we need to add the
     * confirm code in the request url.
     */
    if (ac->verification != NULL && ac->verification->code != NULL) {
        g_snprintf(verify_url, sizeof(verify_url) - 1,
                   "&pid=%s&pic=%s&algorithm=%s",
                   ac->verification->guid,
                   ac->verification->code,
                   ac->verification->algorithm);
    }
    fetion_verification_destroy(ac->verification);
    ac->verification = NULL;

    pass_type = (ac->userid == NULL || *(ac->userid) == '\0' ? 1 : 2);

    g_snprintf(ssl_buf, sizeof(ssl_buf) - 1,
               "GET /ssiportal/SSIAppSignInV4.aspx?%s"
               "&domains=fetion.com.cn%s&v4digest-type=%d&v4digest=%s\r\n"
               "User-Agent: IIC2.0/pc "PROTO_VERSION"\r\n"
               "Host: %s\r\n"
               "Cache-Control: private\r\n"
               "Connection: Keep-Alive\r\n\r\n",
               no_url, verify_url, pass_type, password, SSI_SERVER);

    g_free(password);

    hybrid_debug_info("fetion", "send:\n%s", ssl_buf);

    /* write the request to ssl connection, and a callback function
     * to handle the read event. */
    hybrid_ssl_write(isc, ssl_buf, strlen(ssl_buf));
    hybrid_ssl_event_add(isc, ssi_auth_cb, ac);

    return FALSE;
}
Beispiel #4
0
/**
 * Callback function to handle the cfg connect event.
 */
static gboolean
cfg_connect_cb(gint sk, gpointer user_data)
{
    gchar          *http;
    gchar          *body;
    fetion_account *ac = (fetion_account*)user_data;

    hybrid_account_set_connection_string(ac->account, _("Downloading configure file..."));

    body = generate_configuration_body(ac);
    http = g_strdup_printf("POST /nav/getsystemconfig.aspx HTTP/1.1\r\n"
                           "User-Agent: IIC2.0/PC "PROTO_VERSION"\r\n"
                           "Host: %s\r\n"
                           "Connection: Close\r\n"
                           "Content-Length: %lu\r\n\r\n%s",
                           NAV_SERVER, strlen(body), body);

    g_free(body);

    hybrid_debug_info("fetion", "send:\n%s", http);

    if (send(sk, http, strlen(http), 0) == -1) {
        hybrid_account_error_reason(ac->account, _("downloading cfg error"));
        g_free(http);

        return FALSE;
    }

    g_free(http);

    ac->source = hybrid_event_add(sk, HYBRID_EVENT_READ, cfg_read_cb, ac);

    return FALSE;
}
Beispiel #5
0
/**
 * Start the TLS handshake, if success, jump to the 
 * tls_conn_cb() callback function to send the 
 * stream start request through the TLS channel.
 */
static void
xmpp_stream_performtls(XmppStream *stream)
{

    g_return_if_fail(stream != NULL);

    hybrid_account_set_connection_string(stream->account->account,
                                         "Start performing tls");

    if (!(stream->ssl = hybrid_ssl_connect_with_fd(stream->sk,
                    (ssl_callback)tls_conn_cb, stream))) {

        hybrid_account_error_reason(stream->account->account, 
                _("TLS hand-shake failed."));

        return;
    }
}
Beispiel #6
0
/**
 * This function starts to register to the sipc server, since we have
 * got the ip address and port from the cfg string in the last step.
 */
static gboolean
sipc_reg_action(gint sk, gpointer user_data)
{
    gchar          *sipmsg;
    gchar          *cnouce = generate_cnouce();
    fetion_account *ac     = (fetion_account*)user_data;
    fetion_sip     *sip    = ac->sip;

    hybrid_debug_info("fetion", "sipc registeration action");

    hybrid_account_set_connection_string(ac->account,
            _("start registering to the sipc server."));

    /* Now we start to register to the sipc server. */
    fetion_sip_set_type(sip, SIP_REGISTER);

    sip_header *cheader = sip_header_create("CN", cnouce);
    sip_header *client  = sip_header_create("CL", "type=\"pc\""
                                            " ,version=\""PROTO_VERSION"\"");

    fetion_sip_add_header(sip, cheader);
    fetion_sip_add_header(sip, client);

    g_free(cnouce);

    sipmsg = fetion_sip_to_string(sip, NULL);

    hybrid_debug_info("fetion", "start registering to sip server(%s:%d)",
            ac->sipc_proxy_ip, ac->sipc_proxy_port);

    hybrid_debug_info("fetion", "send:\n%s", sipmsg);

    if (send(sk, sipmsg, strlen(sipmsg), 0) == -1) {
        hybrid_account_error_reason(ac->account, _("sipc reg error"));
        g_free(sipmsg);
        return FALSE;
    }

    hybrid_event_add(sk, HYBRID_EVENT_READ, sipc_reg_cb, ac);

    g_free(sipmsg);

    return FALSE;
}
Beispiel #7
0
/**
 * Start sasl authentication.
 */
static void
xmpp_stream_startsasl(XmppStream *stream)
{
    guchar  *auth;
    gchar   *auth_encoded;
    gchar   *xml_string;
    gint     username_len;
    gint     password_len;
    xmlnode *node;

    g_return_if_fail(stream != NULL);

    hybrid_debug_info("xmpp", "start sasl authentication.");

    hybrid_account_set_connection_string(stream->account->account,
                                         "Start sasl authentication.");

    xmpp_stream_set_state(stream, XMPP_STATE_SASL_AUTHENTICATING);
    /*
     * construct the authentication string to be base64 encoded,
     * which is in form of '\0 + username + \0 + password '
     */
    username_len = strlen(stream->account->username);
    password_len = strlen(stream->account->password);

    auth = g_malloc0(username_len + password_len + 2);

    auth[0] = '\0';
    memcpy(auth + 1, stream->account->username, username_len);

    auth[username_len + 1] = '\0';
    memcpy(auth + 2 + username_len, stream->account->password,
            password_len);

    auth_encoded = hybrid_base64_encode(auth, username_len + password_len + 2);

    g_free(auth);

    /* construct the xml string, which is in form of:
     *
     * <auth xmlns="urn:ietf:params:xml:ns:xmpp-sasl" 
     * mechanism="PLAIN">encoded sasl string</auth> 
     */
    node = xmlnode_create("auth");

    xmlnode_new_namespace(node, NULL, NS_XMPP_SASL);
    xmlnode_new_namespace(node, "ga", "http://www.google.com/talk/protocol/auth");
    xmlnode_new_prop(node, "ga:client-uses-full-bind-result", "true");
    xmlnode_new_prop(node, "mechanism", "PLAIN");
    xmlnode_set_content(node, auth_encoded);

    g_free(auth_encoded);
    
    xml_string = xmlnode_to_string(node);
    xmlnode_free(node);

    hybrid_debug_info("xmpp", "sasl send:\n%s", xml_string);

    if (hybrid_ssl_write(stream->ssl, xml_string,
                strlen(xml_string)) == -1) {

        hybrid_account_error_reason(stream->account->account,
                "SASL authentication error.");

        return;
    }

    g_free(xml_string);

}
Beispiel #8
0
/**
 * Start sipc authencation with the response string.
 *
 * @param response It is generated by generate_response().
 */
static gint
sipc_aut_action(gint sk, fetion_account *ac, const gchar *response)
{
    gchar              *sipmsg;
    gchar              *body;
    sip_header         *aheader;
    sip_header         *akheader;
    sip_header         *ackheader;
    fetion_transaction *trans;
    fetion_sip         *sip = ac->sip;

    ac->sk = sk;

    hybrid_debug_info("fetion", "sipc authencation action");

    hybrid_account_set_connection_string(ac->account,
                                         _("start sipc authentication..."));

    body = generate_auth_body(ac);

    fetion_sip_set_type(sip, SIP_REGISTER);

    aheader     = sip_authentication_header_create(response);
    akheader = sip_header_create("AK", "ak-value");

    trans = transaction_create();
    transaction_set_callid(trans, sip->callid);
    transaction_set_callback(trans, sipc_auth_cb);
    transaction_add(ac, trans);

    fetion_sip_add_header(sip, aheader);
    fetion_sip_add_header(sip, akheader);

    if(ac->verification != NULL && ac->verification->algorithm != NULL)    {
        ackheader = sip_ack_header_create(ac->verification->code,
                                          ac->verification->algorithm,
                                          ac->verification->type,
                                          ac->verification->guid);
        fetion_sip_add_header(sip , ackheader);
    }
    fetion_verification_destroy(ac->verification);
    ac->verification = NULL;

    sipmsg = fetion_sip_to_string(sip, body);

    g_free(body);

    hybrid_debug_info("fetion", "Start sipc authentication , with ak-value");
    hybrid_debug_info("fetion", "send:\n%s", sipmsg);

    if(send(sk, sipmsg, strlen(sipmsg), 0) == -1) {
        hybrid_debug_error("fetion", "send sipc auth request:%s\n",
                strerror(errno));
        g_free(sipmsg);

        return HYBRID_ERROR;
    }
    g_free(sipmsg);

    return 0;
}