Linux下SSL_CTX_use_PrivateKey_file失败 [英] SSL_CTX_use_PrivateKey_file fail under Linux

查看:2187
本文介绍了Linux下SSL_CTX_use_PrivateKey_file失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在Linux下的OpenSSL中使用SSL_CTX_use_PrivateKey_file函数,但是它返回false.周围的代码已从Windows移植,一切正常.视系统而定,必须做些不同的事情吗?

I'm trying to use the SSL_CTX_use_PrivateKey_file function in OpenSSL under Linux, but it returns false. The surrounding code has been ported from Windows, where everything runs fine. Is there something that must be done differently depending on system?

我已经在Ubuntu下自己编译了OpenSSL库(默认配置等),并且正在使用Windows的预编译二进制文件(从OpenSSL站点链接).

I've compiled the OpenSSL library myself (default config etc) under Ubuntu and am using pre-compiled binaries for Windows (linked from the OpenSSL site).

证书和密钥都在.pem文件中.另外,还建立了密码.

The certificates are in .pem files as well as the key. Also, there's a password established.

以下基本上是完成的事情;

The following is basically what's done;

SSL_CTX_set_default_passwd_cb( pContext, passwdCallback );
SSL_CTX_set_default_passwd_cb_userdata( pContext, (void*)this );
SSL_CTX_use_certificate_file( pContext, strCertificateFile, SSL_FILETYPE_PEM );
SSL_CTX_use_Privatekey_file( pContext, strPrivateKeyFile, SSL_FILETYPE_PEM ); // fail in Linux but work fine in Windows

有人有主意吗?

推荐答案

为简单起见,我从密码回调中删除了所有代码,并使用了简单的pBuf = "mypass"; return 6;这是回调函数的最低要求.这很好.

To keep things simple, I removed all code from my password callback, and had simple pBuf = "mypass"; return 6; This would be the bare-minimum of the callback function. This worked fine.

那么Windows代码和Linux代码之间有什么区别?好吧,分别调用strcpy_sstrcpy是代码中的唯一区别.这两个之间有什么区别(附加的验证参数除外)?

So what was different between the Windows code and the Linux code? Well, a call to strcpy_s and strcpy, respectively, was the only difference in the code. What's different between those two (except additonal validation parameters)?

为验证字符串复制操作的成功,该代码仅检查是否等于0.但是,两个复制函数对其返回值的规范不同.微软将"strcpy"的返回行为从"0表示错误"更改为"0表示成功".感叹...

To validate the string copy operation's success, the code simply checked for equality to 0. However, the two copy functions have different specifications for their return values. Microsoft changed "strcpy"'s return behaviour from "0 means error" to "0 means success". Sigh...

这篇关于Linux下SSL_CTX_use_PrivateKey_file失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆