(iOS) 我正在尝试使用站点 https://login.11st.co.kr 进行 SSL_connect(我正在使用开放 ssl 来提取 PEM 证书链):
这就是我使 Tcp 连接的方式
struct TcpConnectionInfo {
std::string ipAddress;
int socketId;
};
static TcpConnectionInfo TcpConnect(const char *host, int port) {
TcpConnectionInfo resultInfo;
resultInfo.socketId = kInvalidSocketId;
// TODO: gethostbyname is depricated, should replace with another
struct hostent *hp = gethostbyname(host);
if (hp == NULL) {
DLog(@"Couldn't resolve host");
return resultInfo;
}
struct sockaddr_in addr;
memset(&addr, 0, sizeof(addr));
addr.sin_addr = *(struct in_addr*)hp->h_addr_list[0];
addr.sin_family = AF_INET;
addr.sin_port = htons(port);
int socketId = (int)socket(AF_INET,SOCK_STREAM, IPPROTO_TCP);
if (socketId < 0) {
DLog(@"Couldn't create socket");
return resultInfo;
}
int connectResult = connect(socketId, (struct sockaddr *)&addr, sizeof(addr));
if (connectResult < 0) {
DLog(@"Couldn't connect socket");
return resultInfo;
}
resultInfo.socketId = socketId;
resultInfo.ipAddress = inet_ntoa(addr.sin_addr);
return resultInfo;
}
这就是我使用它的方式:
TcpConnectionInfo connectInfo = TcpConnect(url.c_str(), port);
SSL *ssl = SSL_new(ctx);
BIO *sbio = BIO_new_socket(connectInfo.socketId, BIO_NOCLOSE);
SSL_set_bio(ssl, sbio, sbio);
int sslConnectResult = SSL_connect(ssl);
我得到带有代码的错误代码:
const int errorCode = SSL_get_error(ssl, sslConnectResult);
DLog(@"SSL Error Code: %d", errorCode);
DLog(@"errno: %d", errno);
对于网站 https://login.11st.co.kr 它提供
SSL 错误代码:5 错误号:3
对应于
SSL_ERROR_SYSCALL,ESRCH(没有这样的过程)
对于其他 https 网站都很好。会是什么?我无法理解这个错误。我该如何解决这个问题?它如何取决于流程?