【问题标题】:OpenSSL with gcc on OS X 10.7在 OS X 10.7 上使用 gcc 的 OpenSSL
【发布时间】:2014-01-09 04:42:07
【问题描述】:

我在 OS X 10.7 上使用 TextEdit 和 gcc 来制作小型终端程序。我正在尝试学习如何编写 OpenSSL,但我正在编译戏剧(由于已弃用的问题 - 更多信息见下文)。我已经在 SO 上进行了谷歌搜索和搜索,但我阅读的所有内容要么是 2011 年之前(问题似乎出现时),特定于 iOS(我正在为 OS X 编程,但试图独立于平台)或谈论使用 XCode(我不喜欢 - 我更喜欢 TextEdit)。

谁能指出如何使用 gcc 在 OS X 上安装 OpenSSL 程序的简单分步过程的正确方向?

为了记录,这是我采取的确切步骤:

  • 通过 macports 安装 OpenSSL

  • “openssl 版本”返回“OpenSSL 1.0.1e 2013 年 2 月 11 日”

  • 我正在尝试编译这个文件:http://saju.net.in/code/misc/openssl_aes.c.txt

  • 我已重命名为“aes.c”,并且正在使用“gcc -o aes aes.c”

  • 我尝试了以下标志(没有结果):-lcrypto、lssl、-Wno-error=deprecated-declarations

我从 gcc 得到的具体输出如下:

Brads-MacBook-Air:Desktop brad$ gcc -o aes aes.c -lssl -lcrypto -Wno-error=deprecated-declarations
aes.c: In function ‘aes_init’:
aes.c:30: warning: ‘EVP_BytesToKey’ is deprecated (declared at /usr/include/openssl/evp.h:572)
aes.c:30: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:30: warning: ‘EVP_sha1’ is deprecated (declared at /usr/include/openssl/evp.h:666)
aes.c:36: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:37: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:37: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c:38: warning: ‘EVP_CIPHER_CTX_init’ is deprecated (declared at /usr/include/openssl/evp.h:636)
aes.c:39: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:39: warning: ‘EVP_aes_256_cbc’ is deprecated (declared at /usr/include/openssl/evp.h:786)
aes.c: In function ‘aes_encrypt’:
aes.c:51: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:51: error: (Each undeclared identifier is reported only once
aes.c:51: error: for each function it appears in.)
aes.c:55: warning: ‘EVP_EncryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:581)
aes.c:59: warning: ‘EVP_EncryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:583)
aes.c:62: warning: ‘EVP_EncryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:584)
aes.c: In function ‘aes_decrypt’:
aes.c:75: error: ‘AES_BLOCK_SIZE’ undeclared (first use in this function)
aes.c:77: warning: ‘EVP_DecryptInit_ex’ is deprecated (declared at /usr/include/openssl/evp.h:590)
aes.c:78: warning: ‘EVP_DecryptUpdate’ is deprecated (declared at /usr/include/openssl/evp.h:592)
aes.c:79: warning: ‘EVP_DecryptFinal_ex’ is deprecated (declared at /usr/include/openssl/evp.h:594)
aes.c: In function ‘main’:
aes.c:136: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)
aes.c:137: warning: ‘EVP_CIPHER_CTX_cleanup’ is deprecated (declared at /usr/include/openssl/evp.h:637)

【问题讨论】:

  • 通常,您避免使用 Apple 的 0.9.8 版本的 OpenSSL。它缺少 TLS 1.1 和 1.2,缺少对 EC 等的完全支持。要在 OS X 上构建 OpenSSL,请参阅 OpenSSL wiki 上的 Compilation and Installation。我编写了 OS X 说明,所以我知道它们可以工作。

标签: c macos gcc openssl


【解决方案1】:

弃用警告只是警告,可以忽略。真正的问题是编译器看不到AES_BLOCK_SIZE 宏的声明,该宏定义为aes.h。所以你需要在你的源代码中添加一个#include <openssl/aes.h>

您还需要包含 -lcrypto 链接器标志以链接到 OpenSSL 运行时库;否则,你会得到一堆“未定义的引用”错误。

【讨论】:

  • 感谢 Adam - 我添加了额外的包含,现在程序可以编译了。当我运行它时,虽然我遇到了分段错误...但至少它可以编译... :) 再次感谢!
  • 使用该编译行,它使用 ssl 库的 macports 版本,但操作系统提供了一个。操作系统提供的一个是弃用警告的来源
  • 嗨Petesh - 你能详细说明一下吗?如何让它使用最新的?谢谢!
猜你喜欢
  • 2017-02-11
  • 2013-09-15
  • 1970-01-01
  • 1970-01-01
  • 2013-12-10
  • 2012-03-24
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多