make JPAKE work again, fix memory leaks
authorDr. Stephen Henson <steve@openssl.org>
Sat, 29 Dec 2012 23:58:44 +0000 (23:58 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Sat, 29 Dec 2012 23:58:44 +0000 (23:58 +0000)
apps/apps.c
apps/s_apps.h
apps/s_cb.c
apps/s_client.c
apps/s_server.c

index 761a8c7f279baa5fe7a813023a6b329697e526ac..bd5c71eac8976d83f6e217df70afd7ceb6517ce3 100644 (file)
@@ -2726,6 +2726,9 @@ void jpake_client_auth(BIO *out, BIO *conn, const char *secret)
 
        BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
 
+       if (psk_key)
+               OPENSSL_free(psk_key);
+
        psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
 
        BIO_pop(bconn);
@@ -2755,6 +2758,9 @@ void jpake_server_auth(BIO *out, BIO *conn, const char *secret)
 
        BIO_puts(out, "JPAKE authentication succeeded, setting PSK\n");
 
+       if (psk_key)
+               OPENSSL_free(psk_key);
+
        psk_key = BN_bn2hex(JPAKE_get_shared_key(ctx));
 
        BIO_pop(bconn);
index 4b06d189a3bf96aad4cbd3548c0ef6623512913e..74e5a2f872f56d6710de1d14d0a2d0e3779b6381 100644 (file)
@@ -195,5 +195,5 @@ int load_excert(SSL_EXCERT **pexc, BIO *err);
 int args_ssl(char ***pargs, int *pargc, SSL_CONF_CTX *cctx,
                        int *badarg, BIO *err, STACK_OF(OPENSSL_STRING) **pstr);
 int args_ssl_call(SSL_CTX *ctx, BIO *err, SSL_CONF_CTX *cctx,
-                               STACK_OF(OPENSSL_STRING) *str, int no_ecdhe);
+               STACK_OF(OPENSSL_STRING) *str, int no_ecdhe, int no_jpake);
 #endif
index 45d4aab3338dd85380969a33a1cde77ff2bb4d87..e760289f9df8596ef07e32aaf4a41eff985ca189 100644 (file)
@@ -1545,7 +1545,7 @@ int args_ssl(char ***pargs, int *pargc, SSL_CONF_CTX *cctx,
        }
 
 int args_ssl_call(SSL_CTX *ctx, BIO *err, SSL_CONF_CTX *cctx,
-                               STACK_OF(OPENSSL_STRING) *str, int no_ecdhe)
+               STACK_OF(OPENSSL_STRING) *str, int no_ecdhe, int no_jpake)
        {
        int i;
        SSL_CONF_CTX_set_ssl_ctx(cctx, ctx);
@@ -1558,6 +1558,13 @@ int args_ssl_call(SSL_CTX *ctx, BIO *err, SSL_CONF_CTX *cctx,
                 */
                if (!no_ecdhe && !strcmp(param, "-named_curve"))
                        no_ecdhe = 1;
+#ifndef OPENSSL_NO_JPAKE
+               if (!no_jpake && !strcmp(param, "-cipher"))
+                       {
+                       BIO_puts(err, "JPAKE sets cipher to PSK\n");
+                       return 0;
+                       }
+#endif
                if (SSL_CONF_cmd(cctx, param, value) <= 0)
                        {
                        BIO_printf(err, "Error with command: \"%s %s\"\n",
@@ -1579,5 +1586,16 @@ int args_ssl_call(SSL_CTX *ctx, BIO *err, SSL_CONF_CTX *cctx,
                        return 0;
                        }
                }
+#ifndef OPENSSL_NO_JPAKE
+       if (!no_jpake)
+               {
+               if (SSL_CONF_cmd(cctx, "-cipher", "PSK") <= 0)
+                       {
+                       BIO_puts(err, "Error setting cipher to PSK\n");
+                       ERR_print_errors(err);
+                       return 0;
+                       }
+               }
+#endif
        return 1;
        }
index 4a987206917634bab6a20c640574a939e118c599..6f16d066172a55b07993c705604327caebc039a8 100644 (file)
@@ -618,7 +618,10 @@ int MAIN(int argc, char **argv)
        int enable_timeouts = 0 ;
        long socket_mtu = 0;
 #ifndef OPENSSL_NO_JPAKE
-       char *jpake_secret = NULL;
+static char *jpake_secret = NULL;
+#define no_jpake !jpake_secret
+#else
+#define no_jpake 1
 #endif
 #ifndef OPENSSL_NO_SRP
        char * srppass = NULL;
@@ -997,12 +1000,6 @@ bad:
                        goto end;
                        }
                psk_identity = "JPAKE";
-               if (cipher)
-                       {
-                       BIO_printf(bio_err, "JPAKE sets cipher to PSK\n");
-                       goto end;
-                       }
-               cipher = "PSK";
                }
 #endif
 
@@ -1120,7 +1117,7 @@ bad:
        if (vpm)
                SSL_CTX_set1_param(ctx, vpm);
 
-       if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1))
+       if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, 1, no_jpake))
                {
                ERR_print_errors(bio_err);
                goto end;
@@ -1932,6 +1929,10 @@ end:
                sk_OPENSSL_STRING_free(ssl_args);
        if (cctx)
                SSL_CONF_CTX_free(cctx);
+#ifndef OPENSSL_NO_JPAKE
+       if (jpake_secret && psk_key)
+               OPENSSL_free(psk_key);
+#endif
        if (cbuf != NULL) { OPENSSL_cleanse(cbuf,BUFSIZZ); OPENSSL_free(cbuf); }
        if (sbuf != NULL) { OPENSSL_cleanse(sbuf,BUFSIZZ); OPENSSL_free(sbuf); }
        if (mbuf != NULL) { OPENSSL_cleanse(mbuf,BUFSIZZ); OPENSSL_free(mbuf); }
index 139005ab462d2d801580aaf78c3557b8a849148e..9abeec93b3dc973355db2e449eb956c93253ece9 100644 (file)
@@ -930,6 +930,9 @@ int MAIN(int, char **);
 
 #ifndef OPENSSL_NO_JPAKE
 static char *jpake_secret = NULL;
+#define no_jpake !jpake_secret
+#else
+#define no_jpake 1
 #endif
 #ifndef OPENSSL_NO_SRP
        static srpsrvparm srp_callback_parm;
@@ -1417,14 +1420,7 @@ bad:
                        goto end;
                        }
                psk_identity = "JPAKE";
-               if (cipher)
-                       {
-                       BIO_printf(bio_err, "JPAKE sets cipher to PSK\n");
-                       goto end;
-                       }
-               cipher = "PSK";
                }
-
 #endif
 
        SSL_load_error_strings();
@@ -1648,7 +1644,7 @@ bad:
        if (vpm)
                SSL_CTX_set1_param(ctx, vpm);
 
-       if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, no_ecdhe))
+       if (!args_ssl_call(ctx, bio_err, cctx, ssl_args, no_ecdhe, no_jpake))
                goto end;
 
        if (!ssl_load_stores(ctx, vfyCApath, vfyCAfile, chCApath, chCAfile))
@@ -1712,7 +1708,7 @@ bad:
                if (vpm)
                        SSL_CTX_set1_param(ctx2, vpm);
 
-               if (!args_ssl_call(ctx2, bio_err, cctx, ssl_args, no_ecdhe))
+               if (!args_ssl_call(ctx2, bio_err, cctx, ssl_args, no_ecdhe, no_jpake))
                        goto end;
                }
 
@@ -2011,6 +2007,10 @@ end:
                sk_OPENSSL_STRING_free(ssl_args);
        if (cctx)
                SSL_CONF_CTX_free(cctx);
+#ifndef OPENSSL_NO_JPAKE
+       if (jpake_secret && psk_key)
+               OPENSSL_free(psk_key);
+#endif
        if (bio_s_out != NULL)
                {
                BIO_free(bio_s_out);