/** * 鑾峰彇SSL鎻℃墜榪囩▼涓湇鍔″櫒涓庡鎴風鍙屾柟鐨勭郴緇熸椂闂? */ void getSSLHandleShakeTimeInfo(int write_p, int version, int content_type, const unsigned char* buf, size_t len, SSL *ssl, TimeInfo *ti) { if(content_type !=22) //require handshake message return; if(len <42) return; if(buf[0] ==1) //ClientHello Message send from client to server ti->client = htonl(*((u_long*)(buf +6))); elseif(buf[0] ==2) //ServerHello Message send from server to client ti->server = htonl(*((u_long*)(buf +6))); else return; }
int main() { BIO * bio; SSL * ssl; SSL_CTX * ctx; TimeInfo timeInfo = {-1, -1}; BOOL timeSynced = FALSE; long result;
/* Set up the library */ SSL_library_init(); ERR_load_BIO_strings(); SSL_load_error_strings();
/* Set up the SSL context */ ctx = SSL_CTX_new(SSLv3_client_method()); if(ctx == NULL) { fprintf(stderr, "Error new SSL_CTX\n"); ERR_print_errors_fp(stderr); SSL_CTX_free(ctx); return0; }
/* Get Server and Client system time via SSL Handshake */ SSL_CTX_set_msg_callback(ctx, getSSLHandleShakeTimeInfo); SSL_CTX_set_msg_callback_arg(ctx, &timeInfo);
/* Load the trust store */ if(! SSL_CTX_load_verify_locations(ctx, ".\\certs\\cacert.pem", NULL)) { fprintf(stderr, "Error loading trust store\n"); ERR_print_errors_fp(stderr); SSL_CTX_free(ctx); return0; }
/* Setup the connection */ bio = BIO_new_ssl_connect(ctx);
/* Set the SSL_MODE_AUTO_RETRY flag */ BIO_get_ssl(bio, & ssl); SSL_set_mode(ssl, SSL_MODE_AUTO_RETRY);
/* Create and setup the connection */ BIO_set_conn_hostname(bio, "192.168.1.5:5555"); if(BIO_do_connect(bio) <=0) { fprintf(stderr, "Error attempting to connect\n"); ERR_print_errors_fp(stderr); BIO_free_all(bio); SSL_CTX_free(ctx); return0; }
/* Check the certificate */ switch(SSL_get_verify_result(ssl)) { case X509_V_OK: break; case X509_V_ERR_CERT_NOT_YET_VALID: case X509_V_ERR_CERT_HAS_EXPIRED: if(timeInfo.server !=-1&& timeInfo.client !=-1) { printf("褰撳墠瀹㈡埛绔椂闂? %s", ctime(&timeInfo.client)); printf("褰撳墠鏈嶅姟鍣ㄦ椂闂? %s", ctime(&timeInfo.server)); printf("灝濊瘯涓庢湇鍔″櫒鏃墮棿鍚屾");
]]>emacs鐢ㄤ簬鍦╟/c++澶存枃浠朵腑鐢熸垚鍖呭惈淇濇姢澶達紙include guard錛夌殑lisp鍑芥暟http://www.shnenglu.com/tangxinfa/archive/2008/05/21/50705.html鍞愭柊鍙?/dc:creator>鍞愭柊鍙?/author>Wed, 21 May 2008 15:40:00 GMThttp://www.shnenglu.com/tangxinfa/archive/2008/05/21/50705.htmlhttp://www.shnenglu.com/tangxinfa/comments/50705.htmlhttp://www.shnenglu.com/tangxinfa/archive/2008/05/21/50705.html#Feedback4http://www.shnenglu.com/tangxinfa/comments/commentRss/50705.htmlhttp://www.shnenglu.com/tangxinfa/services/trackbacks/50705.html;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; c/c++ header include guard (defun insert-include-guard () "insert include guard for c and c++ header file. for file filename.ext will generate: #ifndef FILENAME_EXT_ #define FILENAME_EXT_