Advertisement
Guest User

Ramsey

a guest
Feb 13th, 2010
498
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.59 KB | None | 0 0
  1.     ctx_client = SSL_CTX_new(SSLv3_client_method());
  2.     SSL_CTX_set_verify(ctx_client, SSL_VERIFY_NONE, my_verify_callback);
  3.     SSL_CTX_set_verify_depth(ctx_client, 0);
  4.    
  5.     bio_client = BIO_new_connect(SERVER ":" PORT);
  6.     if(!bio_client) {
  7.         printf("Error creating connection BIO");
  8.         return false;
  9.     }
  10.        
  11.     if (BIO_do_connect(bio_client) <= 0) {
  12.         printf("Error connecting to remote machine");
  13.         return false;
  14.     }
  15.    
  16.     ssl_client = SSL_new(ctx_client);
  17.     SSL_set_bio(ssl_client, bio_client, bio_client);
  18.     SSL_set_verify(ssl_client, SSL_VERIFY_NONE, my_verify_callback);
  19.     SSL_set_verify_depth(ssl_client, 0);
  20.     if (SSL_connect(ssl_client) <= 0) {
  21.         printf("Error connecting SSL object\n");
  22.         return false;
  23.     }
  24.     printf("SSL Connection opened\n");
  25.  
  26. static int my_verify_callback(int ok, X509_STORE_CTX *store)
  27. {
  28.     char data[256];
  29.     int err = 0;
  30.  
  31.     if (!ok)
  32.     {
  33.         X509 *cert = X509_STORE_CTX_get_current_cert(store);
  34.         int  depth = X509_STORE_CTX_get_error_depth(store);
  35.         err = X509_STORE_CTX_get_error(store);
  36.  
  37.         fprintf(stderr, "-Error with certificate at depth: %i\n", depth);
  38.         X509_NAME_oneline(X509_get_issuer_name(cert), data, 256);
  39.         fprintf(stderr, "  issuer   = %s\n", data);
  40.         X509_NAME_oneline(X509_get_subject_name(cert), data, 256);
  41.         fprintf(stderr, "  subject  = %s\n", data);
  42.         fprintf(stderr, "  err %i:%s\n", err, X509_verify_cert_error_string(err));
  43.     }
  44.    
  45.     //return ok;
  46.    
  47.     // Always continue:
  48.     return 1;
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement