我有以下 Apple Security API 初始化代码:
OSStatus status = noErr;
sslContext = SSLCreateContext(kCFAllocatorDefault, kSSLClientSide, kSSLStreamType);
if (sslContext == nullptr)
{
throw std::runtime_error("cannot create ssl context");
}
status = SSLSetIOFuncs(sslContext, socketRead, socketWrite);
if (status != noErr)
{
throw std::runtime_error("cannot set ssl io functions");
}
status = SSLSetConnection(sslContext, reinterpret_cast<void*>(&handle));
if (status != noErr)
{
throw std::runtime_error("cannot set ssl connections");
}
status = SSLSetPeerDomainName(sslContext, address.c_str(), address.length());
if (status != noErr)
{
throw std::runtime_error("cannot set ssl peer domain name");
}
status = SSLSetSessionOption(sslContext, kSSLSessionOptionBreakOnServerAuth, true);
if (status != noErr)
{
throw std::runtime_error("cannot set ssl options");
}
status = SSLHandshake(sslContext);
if (status != noErr)
{
throw std::runtime_error("cannot perform ssl handshake");
}
在这条线上:
status = SSLHandshake(sslContext);
我的 SSLWriteFunc 回调被调用。它试图通过 SSLWrite 发送 174 个字节(我不是故意发送它),但它还是失败了。但是在有关 SSLHandshake 的文档中,它写道“成功返回时,会话已准备好使用 SSLRead( : : :)和 SSLWrite( : : :)函数进行正常的安全通信。”。所以在我的情况下,这个方法没有返回,然后我的 SSLWriteFunc 突然尝试通过 SSLWrite 发送数据。我只是不明白我做错了什么。请大家帮帮我。