将OpenSSL与pthreads结合使用的教程 [英] Tutorial on Using OpenSSL with pthreads

查看:238
本文介绍了将OpenSSL与pthreads结合使用的教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

OpenSSL文档指出可以安全地在多线程应用程序中使用它只要设置了至少两个回调函数,即locking_function和threadid_func....

OpenSSL documents state that it can safely be used in multi-threaded applications provided that at least two callback functions are set, locking_function and threadid_func....

我编写了使用OpenSSL API的程序.而且,我知道如何使用pthreads.但是,OpenSSL文档是以手册的形式编写的,在多线程应用程序中使用OpenSSL时,我看不到逐步指南.

I've written programs which use OpenSSL API. Moreover, I know how to use pthreads. However, the OpenSSL documents are written in the form of a manual, and I can't see a step-by-step guide on what I have to do when using OpenSSL in a multi-threaded app.

是否有关于将OpenSSL与pthreads一起使用的教程? (我在网上搜索,但未出现令人满意的结果.)

Is there a tutorial on using OpenSSL with pthreads? (I searched the web, but no satisfactory result appeared.)

PS::我在Debian Lenny& Ubuntu Lucid/Maverick.

PS: I'm working in Debian Lenny & Ubuntu Lucid/Maverick.

PS2: OpenSSL包含一个示例,但是起步太复杂了.

PS2: OpenSSL includes a sample, but it's far too complicated to start with.

推荐答案

本书的第10章

Chapter 10 of the book The Definitive Guide to Linux Network Programming includes a section Thread-safe Programming with OpenSSL (on pages 255-259). This section details how OpenSSL and the pthreads library work. Specially, it tells how to setup the callback functions both in static allocation (where the number of threads are known a priori) and dynamic allocation (where threads are created and destroyed on the fly).

另一个好的来源是该书的第4.1节网络安全OpenSSL (标题为多线程支持).它分别在4.1.1和4.1.2小节中提供了静态/动态分配机制.

Another good source is Section 4.1 of the book Network Security with OpenSSL, titled Multithread Support. It provides static/dynamic allocation mechanisms in subsections 4.1.1 and 4.1.2, respectively.

最后,有一本书 Unix-Netzwerkprogrammierung mit Threads,套接字和SSL ,这是迄今为止最全面的主题.不幸的是,这本德语书的英语翻译不可用.

Finally, there's the book Unix-Netzwerkprogrammierung mit Threads, Sockets und SSL, which is by far the most comprehensive one on the subject. Unfortunately, the English translation of this German book is not available.

上述参考现已被视为过时,因为OpenSSL 1.1.0

The above references are now considered obsolete, as OpenSSL 1.1.0 changelog explains:

OpenSSL现在使用新的线程API. 不再需要设置锁定回调以在多线程环境中使用OpenSSL.有两种受支持的线程模型:pthreads和Windows线程.也可以在编译时为无线程"配置OpenSSL.不再使用旧的线程API.这些功能已被无操作"兼容性宏替换.

OpenSSL now uses a new threading API. It is no longer necessary to set locking callbacks to use OpenSSL in a multi-threaded environment. There are two supported threading models: pthreads and windows threads. It is also possible to configure OpenSSL at compile time for "no-threads". The old threading API should no longer be used. The functions have been replaced with "no-op" compatibility macros.

[亚历山德罗·格迪尼(Alessandro Ghedini),马特·卡斯威尔(Matt Caswell)

[Alessandro Ghedini, Matt Caswell]

OpenSSL博客文章 OpenSSL和线程.

This is further elaborated in OpenSSL blog post OpenSSL and Threads.

另请参见 OpenSSL GitHub存储库上的此问题,该问题自2017年开始开放.

See also this issue on OpenSSL GitHub repository, which is open since 2017.

这篇关于将OpenSSL与pthreads结合使用的教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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