c - C 中的 OpenSSL 编程

标签 c ssl cryptography websocket openssl

我正在尝试用 C 编写程序,其中连接到远程 SSL 服务器的 HTTPS 客户端发送加密的 HTTP 请求并打印出服务器的响应(网页)。

我正在尝试运行 some examples from here

特别是 test-port-client.c

但它没有显示我期望的结果。

我通过以下命令检查我的笔记本电脑中是否有 openssl

apt-cache search libssl | grep SSL

得到的结果如下。

libssl-dev - SSL development libraries, header files and documentation
libssl-doc - SSL development documentation documentation
libssl1.0.0 - SSL shared libraries
libssl-ocaml - OCaml bindings for OpenSSL (runtime)
libssl-ocaml-dev - OCaml bindings for OpenSSL
libssl0.9.8 - SSL shared libraries
libsslcommon2 - enterprise messaging system - common SSL libraries
libsslcommon2-dev - enterprise messaging system - common SSL development files

我正在用 C 编译程序如下:

gcc test-port-client.c -o test-port-client

然后按如下方式运行:

./test-port-client google.com 80 abc

但我不知道如何根据我的要求调整代码。

我的要求是这样的

"HTTPS client which connects to a remote SSL server, sends an encrypted HTTP request and >prints out the server's response (the web page). In addition, your program verifies that >the X.509 certificate provided by the server is valid and chains to a root certificate you >trust."

任何指导将不胜感激。请帮助我。

最佳答案

我有点困惑。您尝试运行的代码与 SSL 无关。它看起来就像一个简单的 TCP 数据包发送器。你看到了什么,你期待看到什么?

要快速掌握网络编程,请查看 Beej 的指南: http://www.beej.us/guide/bgnet/

对于 OpenSSL,这可能是一个很好的起点: http://savetheions.com/2010/01/16/quickly-using-openssl-in-c/

不过,上面的示例没有进行证书验证。但这将是一个很好的测试来验证您的库安装,并且您可以针对适当的库进行编译。

关于c - C 中的 OpenSSL 编程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19972703/

相关文章:

c - 函数返回一个没有相关参数的条件函数

android - 如何将 android 应用程序流量转换为代理和解密 TLS 流量?

c# - 解密前如何保护加密文件不被破坏

encryption - TLS 握手 - 对称方案

Python矩阵乘法索引交换内存使用示例

C 管道无法进行大量写入

c - 在 c 中显示文件夹内容 - 运行时错误

java - 无法生成 DH key 对 - 在 IBM Domino 中使用 Java 代理发送帖子

node.js - 从 nodejs 通过 https 连接到远程服务器时出错?

cryptography - 如何使用椭圆曲线上的雅可比坐标系计算点加法