c++ - 库函数所需的标准输入未阻止调试控制台
问题描述
每个代码都可以正常工作。使用 Visual Studio 进行调试是有问题的。
我正在使用带有 c++11 的 openSSL 库制作 Linux 服务器。
服务器在 VMware 的 CentOS 上运行。(完成后将移至 Azure)
我在 Visual Studio 2017 上工作,交叉编译与该 CentOS 链接。
当我打电话时
int SSL_CTX_use_PrivateKey_file(SSL_CTX *ctx, const char *file, int type);
ssl 库中的这个函数,它打开私钥文件,要求我在标准输入上输入密码,在标准输出上显示消息并等待我的输入。
但如果我在 Visual Studio 调试模式下运行,它就会消失。
当我在 CentOS 上使用 .out 文件时它工作正常,并且该 '.out' 文件由 Visual Studio 编译以进行调试。
这不是路径问题。“.crt”文件可以很好地打开,只有同一文件夹中的“.key”文件不能很好地打开。
这些是发生问题的代码。SslUtil,ExceptionSslUtil 类在我自己的代码中。但此代码中的其他所有函数和结构都在 ssl 库中。
void SslUtil::InitAsServer(const char* pathCert, const char* pathKey) {
amIServer = true;
SSL_load_error_strings();
SSLeay_add_ssl_algorithms();
meth = SSLv23_server_method();
ctx = SSL_CTX_new(meth);
if (!ctx)
throw ExceptionSslUtil("ctx create error");
if (SSL_CTX_use_certificate_file(ctx, pathCert, SSL_FILETYPE_PEM) <= 0)
throw ExceptionSslUtil("cert file open error");
if (SSL_CTX_use_PrivateKey_file( ctx, pathKey, SSL_FILETYPE_PEM) <= 0)// here's the problem.
throw ExceptionSslUtil("private key file open error");
if (!SSL_CTX_check_private_key(ctx))
throw ExceptionSslUtil("Private key does not match the certificate public keyn");
return;
}
SSL_CTX_use_PrivateKey_file 函数未阻止输入,仅返回负值。它必须等待输入,但不是。
我不知道那里发生了什么。它以前工作过,
但是当我将原始 main(argc, argv) 函数更改为 mainSslEpoll(argc, argv) 并使其由其他主函数调用时,会发生此问题...为什么?以下是我的新主要功能。
int main(int argc, char** argv) {
string str;
while (true) {
cout << "select mode" << endl;
cout << "\t" << "0:SSL + Epoll server" << endl;
cout << "\t" << "1:SSL server" << endl;
cout << "\t" << "2:SSL client" << endl;
cin >> str;
if (str[0] == '0') return mainSslEpoll(argc, argv);
if (str[0] == '1') return mainSslServer(argc, argv);
if (str[0] == '2') return mainSslClient(argc, argv);
}
}
解决方案
推荐阅读
- java - 无法使用 Java 连接到 Azure 上的 Postgres 数据库
- sql - 如何在 Hive 中打印毫秒而不忽略零
- javascript - 在 Plotly.js 中动态切换形状的可见性
- php - 在容器中连接 nginx 和 php-fpm
- java - 无法从数据库中检索任何数据
- c# - c# Entity Framework - 查询 2 个链接列
- node.js - express-hHandlebars partials,我们如何将子文件夹放入部分?
- ruby-on-rails - 将轨道对象或变量传递给液体
- javascript - How to compare currentDate with ExpirationDate?
- xcode11 - iOS 14 启动屏幕故事板在 iOS 14 设备上不显示图像