OPENSSL服务 - 安全信息传输(5)

**加载证书:

** 第一个参数同上,参数二是证书文件的名称,参数三是证书文件的路径;

int SSL_CTX_use_certificate_file(SSL_CTX *ctx, const char *file, int type);

加载本地的证书;type 指明证书文件的结构类型;失败返回-1

int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);

加载自己的私钥;type 参数指明私钥文件的结构类型;失败返回-1

加载了证书和文件之后,就可以验证私钥和证书是否相符:

BOOl SSL_CTX_check_private_key (SSL_CTX*);

3.既然SSL 使用TCP 协议,当然需要把SSL attach 到已经连接的套接字上了:

SSL* SSL_new (SSL_CTX*); 申请一个SSL 套节字;
int SSL_set_rfd (SSL*); 绑定只读套接字
int SSL_set_wfd (SSL*); 绑定只写套接字
int SSL_set_fd ( SSL*); 绑定读写套接字
绑定成功返回 1, 失败返回0;

Published At
Categories with 服务器类
Tagged with
comments powered by Disqus