SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|SSL_VERIFY_FAIL_IF_NO_PEER_CERT, NULL); // 设置信任根证书 if (SSL_CTX_load_verify_locations(ctx, "ca.crt",NULL)<=0){ ERR_print_errors_fp(stdout); exit(1); } /* 载入用户的数字证书, 此证书用来发送给客户端。 证书里包含有公钥 */ if (S...
1.客户端 /* 客户端不验证服务器证书, 但是服务器必须提供证书*/ SSL_CTX_set_verify(ctx, SSL_VERIFY_NONE, NULL); /* 客户端验证服务器证书 */ SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER|, NULL); 2.服务器 /* 服务器不验证客户端证书, 客户端可以不提供证书*/ SSL_CTX_set_verify(ctx, SSL_...
}#ifOPENSSL_VERSION_NUMBER >= 0x10000000/* Disable compression */SSL_CTX_set_options(mosq->ssl_ctx, SSL_OP_NO_COMPRESSION);#endif#ifdefSSL_MODE_RELEASE_BUFFERS/* Use even less memory per SSL connection. */SSL_CTX_set_mode(mosq->ssl_ctx, SSL_MODE_RELEASE_BUFFERS);#endifif(mosq->tls_...
ctx = SSL_CTX_new(meth); if (NULL == ctx) exit(1); //设置会话的握手方式并加载CA证书 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); SSL_CTX_load_verify_locations(ctx, CACERT, NULL); //加载服务器端的证书 if (0 >= SSL_CTX_use_certificate_file(ctx, SVRCERTF, SSL_FILETYPE_PE...
LIBS := CSSL #include <openssl/ssl.h> void SSL_CTX_set_verify(SSL_CTX *ctx, int mode, int (*cb) (int, X509_STORE_CTX*)) ctx A pointer to a token returned on the SSL_CTX_new call or the SSL_CTX_new_shared call. mode One or more of the following verify options: SSL_VERI...
ctx = SSL_CTX_new(meth); if (NULL == ctx) exit(1); //设置会话的握手方式并加载CA证书 SSL_CTX_set_verify(ctx, SSL_VERIFY_PEER, NULL); SSL_CTX_load_verify_locations(ctx, CACERT, NULL); //加载自己的证书 if (0 >= SSL_CTX_use_certificate_file(ctx, MYCERTF, SSL_FILETYPE_PEM))...
ctx = SSL_CTX_new (meth); ssl = SSL_new(ctx); /*下面是正常的socket过程*/ fd = socket(); bind(); listen(); accept(); /*把建立好的socket和SSL结构联系起来*/ SSL_set_fd(ssl,fd); /*SSL的握手过程*/ SSL_connect(ssl);
另一方面,SSL_CTX_set_verify()指定当默认验证器检查每个证书时调用的函数,其中preverify_ok设置为0...
static method (or function) ctx->setVerify(SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT...
所以要实现客户端认证,在服务器端加上如下: SSL_CTX_load_verify_locations(ctx, RSA_SERVER_CA_CERT/*客户证书的根CA*/, NULL); SSL_CTX_set_verify(ctx,SSL_VERIFY_PEER,NULL); SSL_CTX_set_verify_depth(ctx,1);