【问题标题】:openssl support for DTLS v1.2openssl 对 DTLS v1.2 的支持
【发布时间】:2016-04-18 16:03:43
【问题描述】:

我在 Ubuntu 14.04 中预装了 openssl 版本

OpenSSL 1.0.1f 6 Jan 2014

这是 Ubuntu 中可用的最新版本。 现在问题出在SSL_library_init(); 之后,我在编译它显示的代码时调用了DTLSv1_2_client_method();

DTLS_test.c:20:12: warning: assignment makes pointer from integer without a cast [enabled by default]
     method = DTLSv1_2_client_method();
            ^
/tmp/ccRUlnEu.o: In function `init_lib':
DTLS_test.c:(.text+0x13): undefined reference to `DTLSv1_2_client_method'
collect2: error: ld returned 1 exit status

但是如果我改成method = DTLSv1_client_method(); 它只显示与演员表相关的警告

DTLS_test.c:20:12: warning: assignment makes pointer from integer without a cast [enabled by default]
     method = DTLSv1_2_client_method();
            ^

代码sn-p如下:

#include <openssl/ssl.h>
#include <openssl/bio.h>
#include <openssl/err.h>
#include <openssl/rand.h>
#include <openssl/dtls1.h>
#include "DTLS_test.h"

void init_lib (void) {

    if(SSL_library_init()) {
        printf("\n[OK] SSL library initialized");
    }
    else {
        printf("\n[ERROR] SSL library initiate FAILED !");
        exit(0);
    }
    SSL_METHOD *method = NULL;
    method = DTLSv1_2_client_method();
    SSL_CTX *ctx = NULL;
    ctx = SSL_CTX_new(method);
    if(ctx != NULL) {
        printf("\n[OK] SSL Method created");
    }
    else {
        printf("\n[ERROR] SSL Method FAILED !");
        exit(0);
    }
}
void main (void) {
    init_lib ();
    printf("\n");
}

我也从 git 下载了 openssl 源代码并安装了,但 openssl 版本没有改变。而且我无法编译。有人建议任何解决方法吗?

【问题讨论】:

    标签: openssl dtls


    【解决方案1】:

    OpenSSL 1.0.1 不支持 DTLSv1.2。为此,您需要 1.0.2。

    您尝试从 git 安装哪个版本?默认情况下,自己安装时,OpenSSL 会安装到“/usr/local/ssl”。它不会替换 OpenSSL 的系统版本,因此您需要确保使用正确的包含/库路径 - 否则您只会选择旧的系统版本。

    编译:

     gcc DTLS_test.c -I/usr/local/ssl/include -L/usr/local/ssl/lib -o DTLS_test -lssl -lcrypto
    

    【讨论】:

    • 我从 openssl 下载了 1.0.2 并安装了它。现在 openssl version 命令向我显示:OpenSSL 1.0.2e 3 Dec 2015 但问题仍然存在。我用 -lssl 和 -lcrypto 编译
    • 我进一步升级到 OpenSSL 1.1.0-pre2-dev xx XXX xxxx 但问题仍然存在 gcc DTLS_test.c -I/usr/local/ssl/ -lssl -lcrypto -o DTLS_test
    • 试试:gcc DTLS_test.c -I/usr/local/ssl/include -L/usr/local/ssl/lib -o DTLS_test -lcrypto -lssl
    • 糟糕。对不起。那应该是: gcc DTLS_test.c -I/usr/local/ssl/include -L/usr/local/ssl/lib -o DTLS_test -lssl -lcrypto
    • @Zim 我已经看到您接受了这个答案,这是否意味着最后一条评论有效?马特,如果可以的话,你能把它整合到你的答案中吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-04-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多