In article <[EMAIL PROTECTED]> you wrote:
> Ralf S. Engelschall wrote:
>> In article <[EMAIL PROTECTED]> you wrote:
>> > Ralf S. Engelschall wrote:
>> >> In short, this (the s_server approach) works:
>> >>
>> >>     ctx = SSL_CTX_new();
>> >>     SSL_CTX_set_tmp_rsa_callback(ctx, ...);
>> >>     SSL_CTX_use_certificate(ctx, ...);
>> >>     ssl = SSL_new();
>> >>     /* now ssl->cert contains the callbacks for the RSA temp key */
>> >>
>> >> while this (the mod_ssl approach) fails:
>> >>
>> >>     ctx = SSL_CTX_new();
>> >>     SSL_CTX_set_tmp_rsa_callback(ctx, ...);
>> >>     ssl = SSL_new();
>> >>     SSL_use_certificate(ctx, ...);
>[...]
>> > and there's the point - if you want to use the cert from the context,
>> > then don't set one on the session. If you set one on the session, its
>> > _wrong_ to copy the temp key from the context.
>> 
>> Why? The context's purpose is to provide _defaults_ and so
>> it seems reasonable to me that the temp keys are considered
>> as defaults and preserved.

> The temp key is a property of the cert, not the context. Set a new cert,
> you have to set a new temp key. Perhaps the real problem is that the
> functions should operate on certs and not session or contexts?

Yes, maybe. Then we should at least provide the SSL_set_tmp_rsa() and
SSL_set_tmp_dh() functions which allows one to set the temp keys on a
connection basis when one sets the certificates on a connection basis. At
least one of these two solution is required (either to not loose the defaults
or to allow the setting on a per connection basis).

>[...]
> I don't think we should encourage weakening of security. The temp keys
> are only there to weaken it in the first place, so spreading them around
> more is a Bad Thing, IMO (this is why I decided in the end to not
> pre-generate the temp keys in Apache-SSL - must update that comment).

Ok, then it sounds reasonable that we follow the SSL_set_tmp_xx() idea.
Corresponding patch is appended, Ben. Votes?

                                       Ralf S. Engelschall
                                       [EMAIL PROTECTED]
                                       www.engelschall.com

Index: CHANGES
===================================================================
RCS file: /e/openssl/cvs/openssl/CHANGES,v
retrieving revision 1.96
diff -u -r1.96 CHANGES
--- CHANGES     1999/02/25 08:48:52     1.96
+++ CHANGES     1999/02/25 09:54:57
@@ -5,6 +5,19 @@
 
  Changes between 0.9.1c and 0.9.2
 
+  *) Add a bunch of SSL_xxx() functions for configuring the temporary RSA and
+     DH private keys and callback functions which directly correspond to their
+     SSL_CTX_xxx() functions but work on a per-connection basis. This is
+     needed for applications which have to configure certificates on a
+     per-connection basis (e.g. mod_ssl) instead of a per-context basis (e.g.
+     s_server). For the RSA certificate situation is makes no difference, but
+     for the DSA certificate situation this fixes the "no shared cipher"
+     problem where the cipher selection procedure failed because the
+     temporary keys are not overtaken from the context.  The new functions
+     are in detail: SSL_need_tmp_RSA, SSL_set_tmp_rsa, SSL_set_tmp_dh,
+     SSL_set_tmp_rsa_callback and SSL_set_tmp_dh_callback.
+     [Ralf S. Engelschall]
+
   *) Don't hard-code path to Perl interpreter on shebang line of Configure
      script. Instead use the usual Shell->Perl transition trick.
      [Ralf S. Engelschall]
Index: ssl//s3_lib.c
===================================================================
RCS file: /e/openssl/cvs/openssl/ssl/s3_lib.c,v
retrieving revision 1.12
diff -u -r1.12 s3_lib.c
--- ssl//s3_lib.c       1999/02/22 01:26:38     1.12
+++ ssl//s3_lib.c       1999/02/25 09:47:23
@@ -546,6 +546,31 @@
        {
        int ret=0;
 
+#if !defined(NO_DSA) || !defined(NO_RSA)
+       if (
+#ifndef NO_RSA
+               cmd == SSL_CTRL_SET_TMP_RSA ||
+           cmd == SSL_CTRL_SET_TMP_RSA_CB ||
+#endif
+#ifndef NO_DSA
+           cmd == SSL_CTRL_SET_TMP_DH ||
+           cmd == SSL_CTRL_SET_TMP_DH_CB ||
+#endif
+               0) {
+                       CERT *c;
+                       if ((s->cert == NULL) || (s->cert == s->ctx->default_cert)) {
+                               c = ssl_cert_new();
+                               if (c == NULL) {
+                                       SSLerr(SSL_F_SSL3_CTRL, ERR_R_MALLOC_FAILURE);
+                                       return(0);
+                               }
+                               if (s->cert != NULL) 
+                                       ssl_cert_free(s->cert);
+                               s->cert = c;
+                       }
+               }
+#endif
+
        switch (cmd)
                {
        case SSL_CTRL_GET_SESSION_REUSED:
@@ -566,6 +591,69 @@
        case SSL_CTRL_GET_FLAGS:
                ret=(int)(s->s3->flags);
                break;
+#ifndef NO_RSA
+       case SSL_CTRL_NEED_TMP_RSA:
+               if ((s->cert != NULL) && (s->cert->rsa_tmp == NULL) &&
+                   ((s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey == NULL) ||
+                    (EVP_PKEY_size(s->cert->pkeys[SSL_PKEY_RSA_ENC].privatekey) > 
+(512/8))))
+                       ret = 1;
+               break;
+       case SSL_CTRL_SET_TMP_RSA:
+               {
+                       RSA *rsa = (RSA *)parg;
+                       if (rsa == NULL) {
+                               SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
+                               return(ret);
+                       }
+                       if ((rsa = RSAPrivateKey_dup(rsa)) == NULL) {
+                               SSLerr(SSL_F_SSL3_CTRL, ERR_R_RSA_LIB);
+                               return(ret);
+                       }
+                       if (s->cert->rsa_tmp != NULL)
+                               RSA_free(s->cert->rsa_tmp);
+                       s->cert->rsa_tmp = rsa;
+                       ret = 1;
+               }
+               break;
+       case SSL_CTRL_SET_TMP_RSA_CB:
+#ifndef NOPROTO
+               s->cert->rsa_tmp_cb = (RSA *(*)(SSL *, int, int))parg;
+#else
+               s->cert->rsa_tmp_cb = (RSA *(*)())parg;
+#endif
+               break;
+#endif
+#ifndef NO_DH
+       case SSL_CTRL_SET_TMP_DH:
+               {
+                       DH *dh = (DH *)parg;
+                       if (dh == NULL) {
+                               SSLerr(SSL_F_SSL3_CTRL, ERR_R_PASSED_NULL_PARAMETER);
+                               return(ret);
+                       }
+                       if ((dh = DHparams_dup(dh)) == NULL) {
+                               SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
+                               return(ret);
+                       }
+                       if (!DH_generate_key(dh)) {
+                               DH_free(dh);
+                               SSLerr(SSL_F_SSL3_CTRL, ERR_R_DH_LIB);
+                               return(ret);
+                       }
+                       if (s->cert->dh_tmp != NULL)
+                               DH_free(s->cert->dh_tmp);
+                       s->cert->dh_tmp = dh;
+                       ret = 1;
+               }
+               break;
+       case SSL_CTRL_SET_TMP_DH_CB:
+#ifndef NOPROTO
+               s->cert->dh_tmp_cb = (DH *(*)(SSL *, int, int))parg;
+#else
+               s->cert->dh_tmp_cb = (DH *(*)())parg;
+#endif
+               break;
+#endif
        default:
                break;
                }
Index: ssl//ssl.err
===================================================================
RCS file: /e/openssl/cvs/openssl/ssl/ssl.err,v
retrieving revision 1.3
diff -u -r1.3 ssl.err
--- ssl//ssl.err        1999/02/20 11:50:07     1.3
+++ ssl//ssl.err        1999/02/25 09:49:02
@@ -113,6 +113,7 @@
 #define SSL_F_TLS1_ENC                                  210
 #define SSL_F_TLS1_SETUP_KEY_BLOCK                      211
 #define SSL_F_WRITE_PENDING                             212
+#define SSL_F_SSL3_CTRL                                         213
 
 /* Reason codes. */
 #define SSL_R_APP_DATA_IN_HANDSHAKE                     100
Index: ssl//ssl.h
===================================================================
RCS file: /e/openssl/cvs/openssl/ssl/ssl.h,v
retrieving revision 1.10
diff -u -r1.10 ssl.h
--- ssl//ssl.h  1999/02/21 21:58:59     1.10
+++ ssl//ssl.h  1999/02/25 09:49:04
@@ -784,6 +784,13 @@
 #define SSL_CTX_set_tmp_dh(ctx,dh) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
 
+#define SSL_need_tmp_RSA(ssl) \
+       SSL_ctrl(ssl,SSL_CTRL_NEED_TMP_RSA,0,NULL)
+#define SSL_set_tmp_rsa(ssl,rsa) \
+       SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA,0,(char *)rsa)
+#define SSL_set_tmp_dh(ssl,dh) \
+       SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH,0,(char *)dh)
+
 #define SSL_CTX_add_extra_chain_cert(ctx,x509) \
        SSL_CTX_ctrl(ctx,SSL_CTRL_EXTRA_CHAIN_CERT,0,(char *)x509)
 
@@ -1029,6 +1036,12 @@
 void SSL_CTX_set_tmp_dh_callback(SSL_CTX *ctx,
                                 DH *(*dh)(SSL *ssl,int export,int keylength));
 
+void SSL_set_tmp_rsa_callback(SSL *ssl,
+                                 RSA *(*cb)(SSL *ssl,int export,
+                                            int keylength));
+void SSL_set_tmp_dh_callback(SSL *ssl,
+                                DH *(*dh)(SSL *ssl,int export,int keylength));
+
 #ifdef HEADER_COMP_H
 int SSL_COMP_add_compression_method(int id,COMP_METHOD *cm);
 #else
@@ -1258,6 +1271,9 @@
 void SSL_CTX_set_tmp_rsa_callback();
 void SSL_CTX_set_tmp_dh_callback();
 
+void SSL_set_tmp_rsa_callback();
+void SSL_set_tmp_dh_callback();
+
 /* #endif */
 
 #endif
@@ -1378,6 +1394,7 @@
 #define SSL_F_TLS1_ENC                                  210
 #define SSL_F_TLS1_SETUP_KEY_BLOCK                      211
 #define SSL_F_WRITE_PENDING                             212
+#define SSL_F_SSL3_CTRL                                         213
 
 /* Reason codes. */
 #define SSL_R_APP_DATA_IN_HANDSHAKE                     100
Index: ssl//ssl_err.c
===================================================================
RCS file: /e/openssl/cvs/openssl/ssl/ssl_err.c,v
retrieving revision 1.3
diff -u -r1.3 ssl_err.c
--- ssl//ssl_err.c      1999/02/20 11:50:07     1.3
+++ ssl//ssl_err.c      1999/02/25 09:49:04
@@ -175,6 +175,7 @@
 {ERR_PACK(0,SSL_F_TLS1_ENC,0), "TLS1_ENC"},
 {ERR_PACK(0,SSL_F_TLS1_SETUP_KEY_BLOCK,0),     "TLS1_SETUP_KEY_BLOCK"},
 {ERR_PACK(0,SSL_F_WRITE_PENDING,0),    "WRITE_PENDING"},
+{ERR_PACK(0,SSL_F_SSL3_CTRL,0),        "SSL3_CTRL"},
 {0,NULL},
        };
 
Index: ssl//ssl_lib.c
===================================================================
RCS file: /e/openssl/cvs/openssl/ssl/ssl_lib.c,v
retrieving revision 1.12
diff -u -r1.12 ssl_lib.c
--- ssl//ssl_lib.c      1999/02/21 21:58:59     1.12
+++ ssl//ssl_lib.c      1999/02/25 09:42:48
@@ -1899,6 +1899,14 @@
                                                        int keylength))
     { SSL_CTX_ctrl(ctx,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); }
 
+void SSL_set_tmp_rsa_callback(SSL *ssl,RSA *(*cb)(SSL *ssl,int export,
+                                                         int keylength))
+    { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_RSA_CB,0,(char *)cb); }
+
+void SSL_set_tmp_dh_callback(SSL *ssl,DH *(*dh)(SSL *ssl,int export,
+                                                       int keylength))
+    { SSL_ctrl(ssl,SSL_CTRL_SET_TMP_DH_CB,0,(char *)dh); }
+
 #if defined(_WINDLL) && defined(WIN16)
 #include "../crypto/bio/bss_file.c"
 #endif
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
Development Mailing List                       [EMAIL PROTECTED]
Automated List Manager                           [EMAIL PROTECTED]

Reply via email to