Example #1
0
void HttpClient::slotProxyAuthenticationRequired( const QNetworkProxy & /* proxy */,
                                                  QAuthenticator *authenticator )
{
  timer->stop();
  getUserPassword( authenticator );
  timer->start();
}
Example #2
0
void HttpClient::slotAuthenticationRequired( QNetworkReply * /* reply */,
                                             QAuthenticator *authenticator )
{
  timer->stop();
  getUserPassword( authenticator );
  timer->start();
}
Example #3
0
int main(int argc, char* argv[]){
    SSL *ssl_connection = NULL;
    const char *host = NULL, *port = NULL;
    const char *username = NULL;
    char *response = NULL;
    char *signed_data_buffer = NULL;
    unsigned int signed_data_buffer_size = 0;
    RSA *my_rsa_key = NULL;
    
    if (argc != 3){
	fprintf(stderr, "Usage: %s host port.\n", argv[0]);
	exit(EXIT_FAILURE);
    }

    w_memory_init();
    openssl_init();
    
    host = argv[1];
    port = argv[2];
    username = getUsername();
    
    if (username == NULL)
	report_error_q("Unable to determine the username of this process.", __FILE__, __LINE__, 0);
 
    if((ssl_connection = ssl_client_connect(host, port)) == NULL)
	report_error_q(ERR_error_string(ERR_get_error(), NULL), __FILE__, __LINE__, 0);
    
    if (haveServerKey(host, username) == 0){
	ssl_write_uint(ssl_connection, REQUEST_KEY_AUTH);
	ssl_write_string(ssl_connection, username);
	my_rsa_key = getServerKey(host, username);
	if (my_rsa_key == NULL)
	    report_error_q("Key file exists, but data is invalid", __FILE__, __LINE__, 0);
    
    
	signed_data_buffer = (char *)w_malloc(key_buffer_size(my_rsa_key));
	signed_data_buffer_size = key_sign_data(my_rsa_key, username, strlen(username), signed_data_buffer, key_buffer_size(my_rsa_key));
	ssl_write_uint(ssl_connection, signed_data_buffer_size);
    
	ssl_write_bytes(ssl_connection, signed_data_buffer, signed_data_buffer_size);
    
	if (ssl_read_uint(ssl_connection) == SERVER_AUTH_SUCCESS){
	    printf("Server responded with SERVER_AUTH_SUCCESS.\n");
	}
	else {
	    printf("Server responded with SERVER_AUTH_SUCCESS.\n");
	}
	w_free(response);
    }
    else {
	ssl_write_uint(ssl_connection, REQUEST_PASS_AUTH);
	ssl_write_string(ssl_connection, username);
	ssl_write_string(ssl_connection, getUserPassword());
	
	if (ssl_read_uint(ssl_connection) == SERVER_AUTH_SUCCESS){
	    printf("Server reponded with SERVER_AUTH_SUCCESS, sending PKI Key.\n");
	    my_rsa_key = key_create_key();
	    if (!my_rsa_key){
		report_error("Error creating RSA key.", __FILE__, __LINE__, 0);
	    }
	    key_net_write_pub(my_rsa_key, ssl_connection);
	    writePrivKey(host, username, my_rsa_key);
	}
	else printf("Server responded with SERVER_AUTH_FAILURE.\n");
    }

    SSL_shutdown(ssl_connection);
    SSL_free(ssl_connection);
    return 0;
}