带有 unicode 路径的 OpenSSL
我通过使用以下函数从客户端实现了 SSL 握手: SSL_CTX_load_verify_locations SSL_CTX_use_certificate_chain_file SSL_CTX_use_PrivateKey_file
所有函数都获取 char* 类型的文件名参数。 如何更改它以支持 unicode 文件位置?
谢谢!
I have an implementation of SSL handshake from the client side, by using these functions:
SSL_CTX_load_verify_locations
SSL_CTX_use_certificate_chain_file
SSL_CTX_use_PrivateKey_file
All functions get char* type for the filename parameter.
How can I change it to support also unicode file locations?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在哪个平台上? Posix 下的 OpenSSL 支持 UTF-8 路径,但在其他平台上不支持。有可能,您必须使用支持 Unicode 路径的标准操作系统文件 I/O 函数自行手动加载证书文件,然后解析原始数据并将其加载到 OpenSSL 中,例如通过
PEM_read_bio_X509
使用sk_X509_NAME_push
、PEM_read_bio_PrivateKey/d2i_PrivateKey_bio
与SSL_CTX_use_PrivateKey
、d2i_X509_bio/PEM_read_bio_X509
与SSL_CTX_use_certificate
等。On which platform? OpenSSL under Posix supports UTF-8 paths, but not on other platforms. Chances are, you will have to manually load the certificate files yourself using standard OS file I/O functions that support Unicode paths, and then parse the raw data and load it into OpenSSL, such as via
PEM_read_bio_X509
withsk_X509_NAME_push
,PEM_read_bio_PrivateKey/d2i_PrivateKey_bio
withSSL_CTX_use_PrivateKey
,d2i_X509_bio/PEM_read_bio_X509
withSSL_CTX_use_certificate
, etc.我想回复上述帖子而不是创建新答案,但是我无法回复它,所以我创建了一个新答案。根据我对 SSL_CTX_load_verify_locations 的测试并查看 openssl 代码,实际上 openssl 在 Windows 上也会使用 utf-8 作为文件路径。在BIO_new_file打开文件的函数中,如果同时定义了_WIN32和CP_UTF8,它将选择utf-8作为文件路径。这些是在 windows 上定义的。然而,如果路径不是有效的 utf-8 字符,openssl 也有代码可以回退到 ANSI 路径。因此,实际上 openssl 将在 Windows 上使用 utf-8 和 ANSI 路径。
I want to reply to the above post instead of creating a new answer, however I was not able to reply it, so I create a new answer. Based on my testing for SSL_CTX_load_verify_locations and looking at openssl code, actually the openssl would use utf-8 for file path as well on Windows. At the function BIO_new_file to open a file, it would choose utf-8 for file path if both _WIN32 and CP_UTF8 are defined. Those are defined at windows. However openssl also has code to fall back to ANSI path if path is not a valid utf-8 characters. So with that, actually openssl will work with both utf-8 and ANSI path on Windows.