Avoid including cryptlib.h, it's not really needed.
[openssl.git] / ssl / ssl_sess.c
index 2a4a90897e4589d53aa0917c8c50404c3065e7b2..85581d43ca40ba11fb75aac1ffb7abb23f0258e9 100644 (file)
@@ -60,7 +60,6 @@
 #include <openssl/lhash.h>
 #include <openssl/rand.h>
 #include "ssl_locl.h"
-#include "cryptlib.h"
 
 static void SSL_SESSION_list_remove(SSL_CTX *ctx, SSL_SESSION *s);
 static void SSL_SESSION_list_add(SSL_CTX *ctx,SSL_SESSION *s);
@@ -79,11 +78,11 @@ SSL_SESSION *SSL_get1_session(SSL *ssl)
        /* Need to lock this all up rather than just use CRYPTO_add so that
         * somebody doesn't free ssl->session between when we check it's
         * non-null and when we up the reference count. */
-       CRYPTO_r_lock(CRYPTO_LOCK_SSL_SESSION);
+       CRYPTO_w_lock(CRYPTO_LOCK_SSL_SESSION);
        sess = ssl->session;
        if(sess)
                sess->references++;
-       CRYPTO_r_unlock(CRYPTO_LOCK_SSL_SESSION);
+       CRYPTO_w_unlock(CRYPTO_LOCK_SSL_SESSION);
        return(sess);
        }
 
@@ -127,6 +126,13 @@ SSL_SESSION *SSL_SESSION_new(void)
        return(ss);
        }
 
+const unsigned char *SSL_SESSION_get_id(const SSL_SESSION *s, unsigned int *len)
+       {
+       if(len)
+               *len = s->session_id_length;
+       return s->session_id;
+       }
+
 /* Even with SSLv2, we have 16 bytes (128 bits) of session ID space. SSLv3/TLSv1
  * has 32 bytes (256 bits). As such, filling the ID with random gunk repeatedly
  * until we have no conflict is going to complete in one iteration pretty much
@@ -528,13 +534,13 @@ void SSL_SESSION_free(SSL_SESSION *ss)
 
        CRYPTO_free_ex_data(CRYPTO_EX_INDEX_SSL_SESSION, ss, &ss->ex_data);
 
-       memset(ss->key_arg,0,SSL_MAX_KEY_ARG_LENGTH);
-       memset(ss->master_key,0,SSL_MAX_MASTER_KEY_LENGTH);
-       memset(ss->session_id,0,SSL_MAX_SSL_SESSION_ID_LENGTH);
+       OPENSSL_cleanse(ss->key_arg,sizeof ss->key_arg);
+       OPENSSL_cleanse(ss->master_key,sizeof ss->master_key);
+       OPENSSL_cleanse(ss->session_id,sizeof ss->session_id);
        if (ss->sess_cert != NULL) ssl_sess_cert_free(ss->sess_cert);
        if (ss->peer != NULL) X509_free(ss->peer);
        if (ss->ciphers != NULL) sk_SSL_CIPHER_free(ss->ciphers);
-       memset(ss,0,sizeof(*ss));
+       OPENSSL_cleanse(ss,sizeof(*ss));
        OPENSSL_free(ss);
        }