You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@httpd.apache.org by Paul Querna <pa...@querna.org> on 2011/09/30 08:08:17 UTC

[PATCH] Support for TLS Session Tickets

Hiya,

Attached is a patch
<http://people.apache.org/~pquerna/tls_session_ticket_support.patch>
 to add support for setting SSL_CTX_set_tlsext_ticket_keys.

I have two questions:

1) What is the right ifdef to look for support of this feature?  I was
just using ifdef SSL_CTX_set_tlsext_ticket_keys and it seemed to work
for me......

2) What is the right way to set/generate the keys -- openssl requires
that the key is 48 bytes exactly. (16 bytes for
tlsext_tick_key_nametlsext_tick_hmac_key (unused?), 16 for hmac of
session, 16 for aes key).  Right now I take the user provided key
value and use it as an HMAC key with the SHA1(Certificate) for that
vhost as the SHA256 HMAC'ed value.  I don't know what is best. I just
made this shit up, but I couldn't find any examples of
SSL_CTX_set_tlsext_ticket_keys being used, so any suggestions would be
helpful.

The other option is to require the user to provide 48 bytes of random
data (base64'ed?) rather than trying to be nice by generating it from
ascii for them.

Happy to fix/iterate or just commit to trunk,

Thanks,

Paul

Re: [PATCH] Support for TLS Session Tickets

Posted by Paul Querna <pa...@querna.org>.
On Sun, Oct 2, 2011 at 12:20 AM, Kaspar Brand <ht...@velox.ch> wrote:
> On 30.09.2011 08:08, Paul Querna wrote:
>> Attached is a patch
>> <http://people.apache.org/~pquerna/tls_session_ticket_support.patch>
>>  to add support for setting SSL_CTX_set_tlsext_ticket_keys.
>>
>> I have two questions:
>>
>> 1) What is the right ifdef to look for support of this feature?  I was
>> just using ifdef SSL_CTX_set_tlsext_ticket_keys and it seemed to work
>> for me......
>
> SSL_CTRL_SET_TLSEXT_TICKET_KEYS and #ifndef OPENSSL_NO_TLSEXT,
> respectively - I would suggest wrapping it in the same way as
> SSL_CTX_set_tlsext_servername_callback/SSL_CTX_set_tlsext_servername_arg.
>
> Generally speaking, I agree with Stefan that such keys shouldn't be
> stored in config files as (static) plain-text strings. RFC 5077 section
> 5.5 lists some recommendations for the management of ticket protection
> keys, although it hastens to add that "A full description [...] is
> beyond the scope of this document".

I've committed an updated patch that stores the key id, hmac secret,
and aes key into a file:
<https://svn.apache.org/viewvc?view=revision&revision=1200040>

Feedback welcome!

Thanks,

Paul

Re: [PATCH] Support for TLS Session Tickets

Posted by Kaspar Brand <ht...@velox.ch>.
On 30.09.2011 08:08, Paul Querna wrote:
> Attached is a patch
> <http://people.apache.org/~pquerna/tls_session_ticket_support.patch>
>  to add support for setting SSL_CTX_set_tlsext_ticket_keys.
> 
> I have two questions:
> 
> 1) What is the right ifdef to look for support of this feature?  I was
> just using ifdef SSL_CTX_set_tlsext_ticket_keys and it seemed to work
> for me......

SSL_CTRL_SET_TLSEXT_TICKET_KEYS and #ifndef OPENSSL_NO_TLSEXT,
respectively - I would suggest wrapping it in the same way as
SSL_CTX_set_tlsext_servername_callback/SSL_CTX_set_tlsext_servername_arg.

Generally speaking, I agree with Stefan that such keys shouldn't be
stored in config files as (static) plain-text strings. RFC 5077 section
5.5 lists some recommendations for the management of ticket protection
keys, although it hastens to add that "A full description [...] is
beyond the scope of this document".

Kaspar

Re: [PATCH] Support for TLS Session Tickets

Posted by Paul Querna <pa...@querna.org>.
On Sat, Oct 1, 2011 at 9:48 AM, Stefan Fritsch <sf...@sfritsch.de> wrote:
> On Fri, 30 Sep 2011, Rainer Jung wrote:
>>
>> Thanks for the info. That would definitely be a nice feature. Would it
>> be safe to use a statically defined key? Only as long as the config file
>> is safe?
>
> As I understand it, knowledge of the session ticket key allows to
> decrypt all connections that use session tickets with this key. I
> think this is true even if the tls cipher itself guarantees forward
> security (like DHE). If this is correct, the option certainly needs
> some warnings in the documentation.
>
> Also, I think the config file is the wrong place for the key. Just think of
> mod_info, which would display the key in the configuration. And I am also
> against generating the key from some ASCII password that likely has less
> entropy than the 48 bytes used for the key.
>
> What about specifying a file that contains the base64 encoded key? If
> the file does not exist, httpd could create it with a random value and
> the correct permissions. The admin would then just need to start httpd on
> one server and copy the created file to the other servers.
>
> Or we could just document how to create it. Under Unix, it's a one-
> liner:
>
> (umask 077; dd if=/dev/random bs=48 count=1|
> openssl base64 > filename.key)

How about using the private key for the certificate as a signing key
as one way to get more (deterministic) data?

Re: [PATCH] Support for TLS Session Tickets

Posted by Stefan Fritsch <sf...@sfritsch.de>.
On Fri, 30 Sep 2011, Rainer Jung wrote:
> Thanks for the info. That would definitely be a nice feature. Would it
> be safe to use a statically defined key? Only as long as the config file
> is safe?

As I understand it, knowledge of the session ticket key allows to
decrypt all connections that use session tickets with this key. I
think this is true even if the tls cipher itself guarantees forward
security (like DHE). If this is correct, the option certainly needs
some warnings in the documentation.

Also, I think the config file is the wrong place for the key. Just think 
of mod_info, which would display the key in the configuration. And I am 
also against generating the key from some ASCII password that likely has 
less entropy than the 48 bytes used for the key.

What about specifying a file that contains the base64 encoded key? If
the file does not exist, httpd could create it with a random value and
the correct permissions. The admin would then just need to start httpd on 
one server and copy the created file to the other servers.

Or we could just document how to create it. Under Unix, it's a one-
liner:

(umask 077; dd if=/dev/random bs=48 count=1|
openssl base64 > filename.key)


Other nice to have things may be:

Support for storing the ticket key in encrypted form and querying the 
passphrase with SSLPassPhraseDialog.

Automatic key rollover. The first idea for this I could come up with would 
be would be the following: Store the key together with a timestamp and 
replace the key with some hash of the key at fixed intervals (like every 
day). Then the key could be used to decrypt ssl sessions of the current 
day and of the future, but it would not allow to decrypt sessions that 
used an older ticket key. Well, at least if the old key is overwritten on 
disk, too.

Re: [PATCH] Support for TLS Session Tickets

Posted by Rainer Jung <ra...@kippdata.de>.
On 30.09.2011 14:33, Paul Querna wrote:
> On Fri, Sep 30, 2011 at 12:38 AM, Rainer Jung <ra...@kippdata.de> wrote:
>> On 30.09.2011 08:08, Paul Querna wrote:
>>> Hiya,

>> So do we actually need to worry about the keys?
> 
> If you don't set anything, OpenSSL randomly generates a key
> per-SSL_CTX.  This is useful in a single server environment, as it
> generally "just works", and should be less load than using the normal
> ssl session cache.
> 
> The reason you would want to set the keys is so that you can have
> multiple Apache instances terminating SSL.  If they all use the same
> certificate and ticket key, then you can essentially share SSL
> Sessions between nodes without using a cache like memcached, by
> relying upon the client to share state with the other SSL terminator.

Ahh, right, I was actually thinking about a non SSL-sticky balanced
farm, but didn't know how it would behave and forgot to write about it.

Thanks for the info. That would definitely be a nice feature. Would it
be safe to use a statically defined key? Only as long as the config file
is safe?

Regards,

Rainer


Re: [PATCH] Support for TLS Session Tickets

Posted by Paul Querna <pa...@querna.org>.
On Fri, Sep 30, 2011 at 12:38 AM, Rainer Jung <ra...@kippdata.de> wrote:
> Hi Paul,
>
> On 30.09.2011 08:08, Paul Querna wrote:
>> Hiya,
>>
>> Attached is a patch
>> <http://people.apache.org/~pquerna/tls_session_ticket_support.patch>
>>  to add support for setting SSL_CTX_set_tlsext_ticket_keys.
>
> Unfortunately I don't have answers to your questions, but I'm a bit
> curious about the patch. As far as I understand we already support RFC
> 5077 (even with 2.2.x). So am I right, that the patch is about improving
> key handling?
>
> The Changelog for OpenSSL 0.9.8f says:
>
> *) Add RFC4507 support to OpenSSL. This includes the corrections in
>     RFC4507bis. The encrypted ticket format is an encrypted encoded
>     SSL_SESSION structure, that way new session features are automatically
>     supported.
>
> ...
>
>     The SSL_CTX structure automatically generates keys for ticket
>     protection in servers so again support should be possible
>     with no application modification.
>
> So do we actually need to worry about the keys?

If you don't set anything, OpenSSL randomly generates a key
per-SSL_CTX.  This is useful in a single server environment, as it
generally "just works", and should be less load than using the normal
ssl session cache.

The reason you would want to set the keys is so that you can have
multiple Apache instances terminating SSL.  If they all use the same
certificate and ticket key, then you can essentially share SSL
Sessions between nodes without using a cache like memcached, by
relying upon the client to share state with the other SSL terminator.

> Then for 0.9.8g there is the following change:
>
>  *) Add TLS session ticket callback. This allows an application to set
>     TLS ticket cipher and HMAC keys rather than relying on hardcoded fixed
>     values. This is useful for key rollover for example where several key
>     sets may exist with different names.

This actually more fully exposes the feature.   Built into RFC 5077 is
the ability to have multiple key names.  So, you could have multiple
private AES keys active at once, all with different names.

The patch as written does not support this use case.  I thought about
making a apr_table_t for this purpose, but it looked far more
complicated.   The callback is given an HMAC and EVP Digest objects
and is responsible for initializing them based on the server key.  I'm
open to doing it if people are interested in this feature, but for a
v0 it seemed like supporting setting the keys at all was a good start,
over building a fairly complicated callback/table of keys.

> There was some discussion about improving session ticket support in 2009:
>
> http://www.mail-archive.com/dev@httpd.apache.org/msg46095.html
>
> The thread contains some interesting remark by Stephen concerning the
> keys. The proposed code IMHO was never applied (nor was there consensus).
>
> Finally there is a Bugzilla about session tickets not respecting the
> defined session timeout:
>
> https://issues.apache.org/bugzilla/show_bug.cgi?id=50869
>

AFAIK there is no way of 'fixing' this without digging into the
internals of OpenSSL, they don't expose an API for controlling the
timeout settings for the Session tickets.  You can set
SSL_CTX_set_timeout, which effects both session tickets normal
sessions.

Re: [PATCH] Support for TLS Session Tickets

Posted by Rainer Jung <ra...@kippdata.de>.
Hi Paul,

On 30.09.2011 08:08, Paul Querna wrote:
> Hiya,
> 
> Attached is a patch
> <http://people.apache.org/~pquerna/tls_session_ticket_support.patch>
>  to add support for setting SSL_CTX_set_tlsext_ticket_keys.

Unfortunately I don't have answers to your questions, but I'm a bit
curious about the patch. As far as I understand we already support RFC
5077 (even with 2.2.x). So am I right, that the patch is about improving
key handling?

The Changelog for OpenSSL 0.9.8f says:

*) Add RFC4507 support to OpenSSL. This includes the corrections in
     RFC4507bis. The encrypted ticket format is an encrypted encoded
     SSL_SESSION structure, that way new session features are automatically
     supported.

...

     The SSL_CTX structure automatically generates keys for ticket
     protection in servers so again support should be possible
     with no application modification.

So do we actually need to worry about the keys?

Then for 0.9.8g there is the following change:

 *) Add TLS session ticket callback. This allows an application to set
     TLS ticket cipher and HMAC keys rather than relying on hardcoded fixed
     values. This is useful for key rollover for example where several key
     sets may exist with different names.


There was some discussion about improving session ticket support in 2009:

http://www.mail-archive.com/dev@httpd.apache.org/msg46095.html

The thread contains some interesting remark by Stephen concerning the
keys. The proposed code IMHO was never applied (nor was there consensus).

Finally there is a Bugzilla about session tickets not respecting the
defined session timeout:

https://issues.apache.org/bugzilla/show_bug.cgi?id=50869

Regards,

Rainer