Hi

I implemented the points 1 and 2 and my test are very positive. I attach the
corresponding patch for the ssl_engine_kernel.c file.

For the point 3 I made a test implementation in my old shared-ssl-session-cache.
But the official exported functions and structures are NOT sufficient. That 
means there is really a change of OpenSSL necessary. Either 'i2d_SSL_SESSION'
and 'd2i_SSL_SESSION' have to be expanded by the cert_chain or there must be
a funtion to set the cert_chain (which should alloc the 'sess_cert' struct
if necessary. 

But after inclusion of ssl_locl.h everything works perfect.

Matthias Loepfe wrote:
> 
> Hi Ralf
> 
> I'm testing the optimized dynamic renegotiations and found some points I would
> like to discuss.
> 
> 1. If for example mod_ssl tries to make a quick renegotiation and fails, now
>    mod_ssl returns a 'FORBIDDEN' reply which is a dead end from which you cannot
>    escape. I think it would be better to force a full renegotiation in such
> cases.
> 
> 2. In the function ssl_hook_Access in the 'optimized' case you call
>    'SSL_get_peer_cert_chain(ssl)' to get the cert chain for re-verification.
>    From what I can see (in the debugger) this chain does NOT contain the
>    leaf and root certificates. The leaf gets shiftet from the chain in the
>    function 'ssl3_get_client_certificate()' on the line ~1630
>    's->session->peer=sk_X509_shift(sk);'. The root cert seems not to be sent
>    by the client.
>    That leads to two things. First if the real chain lengt is more than 2
>    the code seems to work, but it does nor verify the leaf cert but the
>    first intermediate ca-cert. Secornd if the real chain length is 2 the
>    SSL_get_peer_cert_chain(ssl) returns an empty stack and the check fails
>    and returns 'FORBIDDEN'.
>    To fix it we have to push the peer cert on the stack (copy).
> 
> 3. This cert chain is only held in the 'local' cache. That means as soon as
>    the SSL-Session gets reused in a new process out of the shared cache there
>    is no such chain.
>    There are two possible solutions.
>    1. Change the functions 'i2d_SSL_SESSION' and 'i2d_SSL_SESSION' to also
>       contain the cert chain or
>    2. Change the cache to separately cache this chain
> 
> ...

regards

Matthias

-------------------------------------------------------------------------------
Matthias Loepfe, AdNovum Informatik AG, Roentgenstr. 22, CH-8005 Zurich
Email: [EMAIL PROTECTED]   Voice: +41 1 272 6111   Fax: +41 1 272 6312
*** apache_1.3.6/src/modules/ssl/ssl_engine_kernel.c    Wed Jun 30 00:18:56 1999
--- mod_ssl-2.3.5-1.3.6/pkg.sslmod/ssl_engine_kernel.c  Tue Jun 22 14:20:33 1999
***************
*** 951,984 ****
              certstore = SSL_CTX_get_cert_store(ctx);
              if (certstore == NULL) {
                  ssl_log(r->server, SSL_LOG_ERROR, "Cannot find certificate storage");
!                 /* do a full renegotiation */
!                 renegotiate_quick = 0;
              }
!             else {
!                 certstack = SSL_get_peer_cert_chain(ssl);
!                 if (certstack == NULL /* || sk_X509_num(certstack) == 0*/) {
!                     ssl_log(r->server, SSL_LOG_ERROR, "Cannot find peer certificate 
chain");
!                     /* do a full renegotiation */
!                     renegotiate_quick = 0;
!                 }
!                 else {
!                     cert = SSL_get_peer_certificate(ssl);
!                     X509_STORE_CTX_init(&certstorectx, certstore, cert, certstack);
!                     depth = SSL_get_verify_depth(ssl);
!                     if (depth >= 0)
!                         X509_STORE_CTX_set_depth(&certstorectx, depth);
!                     X509_STORE_CTX_set_ex_data(&certstorectx,
!                         SSL_get_ex_data_X509_STORE_CTX_idx(), (char *)ssl);
!                     if (!X509_verify_cert(&certstorectx))
!                         ssl_log(r->server, SSL_LOG_ERROR|SSL_ADD_SSLERR, 
!                                 "Re-negotiation verification step failed");
!                     SSL_set_verify_result(ssl, certstorectx.error);
!                     X509_STORE_CTX_cleanup(&certstorectx);
!                 }
              }
          }
!         
!         if (!renegotiate_quick) {
              /* do a full renegotiation */
              ssl_log(r->server, SSL_LOG_TRACE,
                      "Performing full renegotiation: complete handshake protocol");
--- 951,977 ----
              certstore = SSL_CTX_get_cert_store(ctx);
              if (certstore == NULL) {
                  ssl_log(r->server, SSL_LOG_ERROR, "Cannot find certificate storage");
!                 return FORBIDDEN;
              }
!             certstack = SSL_get_peer_cert_chain(ssl);
!             if (certstack == NULL || sk_X509_num(certstack) == 0) {
!                 ssl_log(r->server, SSL_LOG_ERROR, "Cannot find peer certificate 
chain");
!                 return FORBIDDEN;
              }
+             cert = sk_X509_value(certstack, 0);
+             X509_STORE_CTX_init(&certstorectx, certstore, cert, certstack);
+             depth = SSL_get_verify_depth(ssl);
+             if (depth >= 0)
+                 X509_STORE_CTX_set_depth(&certstorectx, depth);
+             X509_STORE_CTX_set_ex_data(&certstorectx,
+                 SSL_get_ex_data_X509_STORE_CTX_idx(), (char *)ssl);
+             if (!X509_verify_cert(&certstorectx))
+                 ssl_log(r->server, SSL_LOG_ERROR|SSL_ADD_SSLERR, 
+                         "Re-negotiation verification step failed");
+             SSL_set_verify_result(ssl, certstorectx.error);
+             X509_STORE_CTX_cleanup(&certstorectx);
          }
!         else {
              /* do a full renegotiation */
              ssl_log(r->server, SSL_LOG_TRACE,
                      "Performing full renegotiation: complete handshake protocol");

Reply via email to