Hi,

I sent this to openssl-dev before and was advised to file it under rt...

The implementation of d2i_SSL_SESSION() (in ssl_asn1.c) doesn't seem
correct to me.

d2i_SSL_SESSION() decodes an ASN1 encoding of an SSL_SESSION object
previously encoded by i2d_SSL_SESSION(). Various SSL_SESSION fields are
optional, and tags are used to identify which fields are present... so
far, so good. But in two cases when they are not present,
d2i_SSL_SESSION() actually sets values which were not in the original.

Specifically, if 'time' is not present (which means it was 0 when
i2d_SSL_SESSION() looked at it) it is set to the current time(). And if
'timeout' was not present, it is set to 3.

Surely d2i_SSL_SESSION() should return exactly the session data that was
passed into i2d_SSL_SESSION()?

This came to my attention because I am working on an embedded device, and
OpenSSL is used before the device has had its real time clock set, which
means time() is returning 0. This resulted in
ssl3_send_newsession_ticket() getting different asn1 sizes for a session
encoded with i2d_SSL_SESSION, and decoded with d2i_SSL_SESSION, resulting
in an error being returned due to this check:
                if (slen > slen_full) /* shouldn't ever happen */
(because the decoded session now had a 'time' field the original did not
have).

While I know this won't affect big Linux/Unix/BSD users, it may affect
other embedded device users. The inconsistency with the 'timeout' field
could affect other people too though - why change it to 3?

So I have attached a patch for your consideration to resolve the
inconsistency.

Thanks,

Jifl
-- 
------["Si fractum non sit, noli id reficere"]------       Opinions==mine

diff -x CVS -x .svn -x '*~' -x '.#*' -x autom4te.cache -urpN openssl-1.0.1k.bak/ssl/ssl_asn1.c openssl-1.0.1k/ssl/ssl_asn1.c
--- openssl-1.0.1k.bak/ssl/ssl_asn1.c	2015-01-08 14:00:36.000000000 +0000
+++ openssl-1.0.1k/ssl/ssl_asn1.c	2015-01-13 21:37:31.194930304 +0000
@@ -496,7 +496,10 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION
 		OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
 		}
 	else
-		ret->time=(unsigned long)time(NULL);
+		/* i2d_SSL_SESSION() must have been called with time as 0
+		 * (plausible on embedded targets), so we faithfully re-create
+		 * the session exactly as it would have been passed in. */
+		ret->time=0;
 
 	ai.length=0;
 	M_ASN1_D2I_get_EXP_opt(aip,d2i_ASN1_INTEGER,2);
@@ -506,7 +509,10 @@ SSL_SESSION *d2i_SSL_SESSION(SSL_SESSION
 		OPENSSL_free(ai.data); ai.data=NULL; ai.length=0;
 		}
 	else
-		ret->timeout=3;
+		/* i2d_SSL_SESSION() must have been called with timeout as 0,
+		 * so we respect that in order to re-create the session
+		 * faithfully. */
+		ret->timeout=0;
 
 	if (ret->peer != NULL)
 		{
_______________________________________________
openssl-dev mailing list
To unsubscribe: https://mta.openssl.org/mailman/listinfo/openssl-dev

Reply via email to