一些神秘地不起作用的OpenSSL源代码
Some OpenSSL source that mysteriously doesn't work
这让我爬上了墙。我找不出这个源为什么不打开套接字。这很简单,但不起作用。有人能帮我做这个吗?感谢您的考虑!BTW:我在屏幕上没有得到任何文本,它用BIO_do_accept()函数阻塞。
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/ssl.h>
#include <openssl/x509v3.h>
#include <iostream>
#include <process.h>
using namespace std;
int main() {
SSL_load_error_strings();
SSL_library_init();
OpenSSL_add_all_algorithms();
BIO *abio, *cbio, *cbio2;
ERR_load_crypto_strings();
abio = BIO_new_accept("4444");
/* First call to BIO_accept() sets up accept BIO */
if(BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error setting up acceptn");
ERR_print_errors_fp(stderr);
exit(0);
}
/* Wait for incoming connection */
if(BIO_do_accept(abio) <= 0) {
fprintf(stderr, "Error accepting connectionn");
ERR_print_errors_fp(stderr);
exit(0);
}
fprintf(stderr, "Connection 1 establishedn");
/* Retrieve BIO for connection */
cbio = BIO_pop(abio);
BIO_puts(cbio, "Connection 1: Sending out Data on initial connectionn");
fprintf(stderr, "Sent out data on connection 1n");
}
我刚刚测试了这个(在cygwin上,安装了gcc 4.5.3和openssl-devel 1.0.1)
您在聊天中发布的代码使用编译
g++ -std=c++0x ./test.cpp -lssl -lcrypto -o test
生成的代码显然不起作用,因为该代码引用了server.crt
和server.key
:
openssl genrsa -out server.key 1024
openssl req -new -key server.key -out server.csr
openssl x509 -req -days 365 -in server.csr -signkey server.key -out server.crt
使用未受保护的密钥创建自签名证书(您可以使用genrsa -des3
向密钥添加密码短语)。
现在,我可以正确地测试它:
test& # in the background
openssl s_client -connect localhost:12120
这使您能够使用一种支持SSL的telnet
客户端,并且工作得很好。
相关文章:
- Openssl 1.1.1d无效使用不完整的类型"struct dsa_st"
- 在Linux中哪里可以找到互斥、未来等的源代码
- 如何在openssl-ecc中获取十六进制格式的私钥
- LINK 尝试使用 OpenSSL evp aes 256 c++ 时出错
- 如果编译的源代码是特定于它编译的硬件的,我们如何分发它
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 如何在OpenSSL中从configuration.h.in获取configuration.h
- 难以理解某些人解决IOI问题的源代码
- 使用g++编译hdf5源代码
- OpenSSL TLS服务器-使用客户端证书白名单
- 通过 Openssl 命令行加密,通过 c++ 解密
- 使用已使用 java 编码的 openssl 解码数据
- 如何使用C++读取另一个程序中的源代码输出
- Poco FindMySql.cmake 无法找到 MySQL 源代码
- 更改命令行 qt5 源代码构建配置的正确/快速方法
- C++出现控制台错误.我无法识别源代码的问题
- 从源代码构建Qt静态,启用OpenSSL支持
- OpenSSL使用Cmake从源代码进行编译
- 一些神秘地不起作用的OpenSSL源代码
- 正在构建用于编译boost的Openssl源代码