OpenSSL的:如何接受一个进程SSL连接,并在另一个进程中重复使用相同的SSL上下文 [英] OpenSSL: How to accept SSL connection in one process and reuse the same SSL context in another process

查看:1039
本文介绍了OpenSSL的:如何接受一个进程SSL连接,并在另一个进程中重复使用相同的SSL上下文的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我花了相当长的一段时间做我的研究如何解决这个问题,但一直没找到工作的解决方案呢。

I have spent quite some time doing my research on how to tackle this problem but could not find a working solution yet.

问题:
我使用OpenSSL库和Linux操作系统。
我有一个服务器进程P1接受来自SSL客户端的SSL连接。 P1确实tcp_accept(),然后SSL_accept()和一些交换协议数据与SSL_read / SSL_write客户端()。一切都很好,直到这一点。现在,通过设计P1需要fork一个子进程C1从这一点服务客户端开始。 C1采用的execve调用重新图像本身并生成一个不同的二进制。 C1仍然需要在这在P1使用相同的SSL连接来SSL客户端。现在的问题是,因为C1是一个完全不同的过程,现在怎么可以重新使用该客户端的现有SSL连接?我能够从P1通过底层TCP套接字描述符C1,因为它是保持在内核中,但因为它的维护OpenSSL库中我无法通过SSL上下文。

Problem: I am using OpenSSL library and linux. I have a server process P1 accepting SSL connection from SSL client. P1 does tcp_accept() and then SSL_accept() and exchanges some protocol data with client with SSL_read/SSL_write(). Everything is fine till this point. Now by design P1 needs to fork a child process C1 to serve the client from this point onwards. C1 uses execve call to re-image itself and spawn a different binary. C1 still needs to talk to the SSL client over the same SSL connection that was used in P1. The problem is since C1 is a completely different process now how it can re-use the existing SSL connection for that client? I am able to pass the underlying TCP socket descriptor from P1 to C1 as it is maintained in kernel but I can not pass the SSL context since it's maintained in the Openssl Library.

我看到这个计算器胎面但遗憾的是没有解决方案被提及。
<一href=\"http://stackoverflow.com/questions/12426246/openssl-accept-tls-connection-and-then-transfer-to-another-process?\">OpenSSL:接受TLS连接,然后转移到另一个进程

I saw this tread on stackoverflow but unfortunately no solution is mentioned. OpenSSL: accept TLS connection and then transfer to another process

可能的解决方案:
我不知道是否有人已经解决了这样的问题,但我尝试以下。

Possible Solution: I am not sure if anybody has already solved this kind of problem but I tried following.


  1. 我想我可以只创建一个新的SSL conctext做SSL重新协商新的子进程。因此,在C1我创造了相同的底层TCP套接字fd一个新的SSL上下文并做SSL重新协商。这里是我做过什么(Omiting的SSL_CTX初始化部分)

  1. I thought I can just create a new SSL conctext and do SSL renegotiation in the new child process. So in C1 I created a new SSL context over the same underlying tcp socket fd and tried to do SSL renegotiation. Here is what I did (Omiting the SSL_ctx initialization part)

SSL = SSL_new(CTX)//因为它是在P1服务器完成CTX初始化相同的结果
SSL_set_fd(SSL,FD); // fd被底层TCP套接字fd从P1传递到C1结果
SSL_set_accept_state(SSL);结果
SSL_set_verify(SSL,SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT,0);结果
SSL_renegotiate(SSL);结果
SSL_do_handshake(SSL);结果
SSL->状态= SSL_ST_ACCEPT;结果
SSL_do_handshake(SSL);

ssl = SSL_new(ctx) // ctx is initialized the same as it was done in P1 server
SSL_set_fd(ssl, fd); // fd is the underlying tcp socket fd passed from P1 to C1
SSL_set_accept_state(ssl);
SSL_set_verify(ssl, SSL_VERIFY_PEER | SSL_VERIFY_FAIL_IF_NO_PEER_CERT, 0);
SSL_renegotiate(ssl);
SSL_do_handshake(ssl);
ssl->state=SSL_ST_ACCEPT;
SSL_do_handshake(ssl);

但重新谈判不会成功,并且返回我从第一SSL_do_handshake()调用一个Openssl的内部错误。我甚至不知道这是否能真正做到。我能想到的其他解决方案如下。

But the renegotiation does not succeed and returns me an Openssl Internal error from first SSL_do_handshake() call. I am not even sure if this can really be done. The other solution that I can think of is following.


  1. 不知何故,该客户端传送整个SSL上下文从P1到C1。如何有效地可以做到这一点?我能想到的共享内存为这一点,但真的不知道什么所有的内部状态的OpenSSL认为需要复制到共享内存中。
    这似乎是最合理的解决方案,但我没有太多的洞察OpenSSL的code做到这一点。

有没有人遇到类似的问题,解决它?
我真的会AP preciate对此的任何帮助。

Has anybody faced similar problem and solved it? I will really appreciate any help regarding this.

非常感谢

推荐答案

一个在网上搜索,发现这个讨论:

A search online finds this discussion:

程序之间传递TLS会话

一旦你有了SSL_SESSION,将其转换为ASN1(通过i2d_SSL_SESSION),并将其记录到文件中。阅读该文件与你的第二个程序,并把它转换回从ASN1到SSL_SESSION(通过d2i_SSL_SESSION),并把它添加到SSL_CTX(通过SSL_CTX_add_session)的SSL_SESSION缓存。

Once you have the SSL_SESSION, convert it to ASN1 (via i2d_SSL_SESSION) and dump it to a file. Read that file in with your second program and convert it back from ASN1 to SSL_SESSION(via d2i_SSL_SESSION) and add it to the SSL_SESSION cache of the SSL_CTX (via SSL_CTX_add_session).

我DOC / ssleay.txt发现:结果
  [...]结果
  该PEM_write_SSL_SESSION(FP,x)和PEM_read_SSL_SESSION(FP,X,CB)会
  写在base64编码文件指针。
  你可以用这个做的,是分开之间传递会话信息
  流程。结果
  [...]

I found in doc/ssleay.txt :
[...]
The PEM_write_SSL_SESSION(fp,x) and PEM_read_SSL_SESSION(fp,x,cb) will write to a file pointer in base64 encoding. What you can do with this, is pass session information between separate processes.
[...]

所以,你需要从P1序列化SSL会话数据,并把它传递给C1反序列化,与插座一起描述。然后,您可以在C1创造新的 SSL SSL_CTX 对象并将其与插口关联和反序列化会话数据,以便C1可以接管会话。

So you need to serialize the SSL session data from P1 and pass it to C1 to deserialize, along with the socket descriptor. You can then create new SSL and SSL_CTX objects in C1 and associate them with the socket and deserialized session data so C1 can take over the conversation.

这篇关于OpenSSL的:如何接受一个进程SSL连接,并在另一个进程中重复使用相同的SSL上下文的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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