我正在尝试用 C 编写程序,其中连接到远程 SSL 服务器的 HTTPS 客户端发送加密的 HTTP 请求并打印出服务器的响应(网页)。
我正在尝试运行 some examples from here
但它没有显示我期望的结果。
我通过以下命令检查我的笔记本电脑中是否有 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/