openssl 支持 DTLS v1.2

openssl support for DTLS v1.2

我在 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(); 它只显示与 cast

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

代码片段如下:

#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 1.0.1 不支持 DTLSv1.2。为此你需要 1.0.2。

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

编译:

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