php/php-src — pull request #493 by rdlowrey (2013-10-14 13:35:22+00:00)
Title: Honor cipher order

#### Mitigating the BEAST TLS Vulnerability

The [BEAST][context] TLS attack vector was [first publicized in 2011][wiki-beast]. Mitigating this attack is relatively simple: servers have only to [prioritize ciphers][qualys-mitigation] that aren't susceptible to the attack. However, unless instructed otherwise, OpenSSL uses the client's preferences when negotiating the cipher. To prevent nefarious clients from prioritizing susceptible ciphers servers must configure SSL sessions using OpenSSL's `SSL_OP_CIPHER_SERVER_PREFERENCE` context option.

##### Proposed Solution

This patch adds a new boolean ssl context option, `"honor_cipher_order"`, to mitigate BEAST vulnerabilities in encrypted stream servers.

##### Suggested Usage

```php
[
'local_cert' => '/path/to/cert.pem',
'max_handshake_rate' => 0,
'disable_compression' => TRUE,
'ciphers' => '',
'honor_server_ciphers' => TRUE
]]);
$server = stream_socket_server($bindTo, $errNo, $errStr, $flags, $ctx);
```

##### How Problematic Is This Really?

> The 2011 BEAST attack8 targets a 2004 vulnerability in TLS 1.0 and earlier protocol versions, previously thought to be impractical to exploit. For a period of time, server-side mitigation of the BEAST attack was considered appropriate, even though the weakness is on the client side. Unfortunately, to mitigate server-side requires RC4, which we now recommend to disable. Because of that, and because the BEAST attack is by now largely mitigated client-side, we no longer recommend server-side mitigation.
>
> The impact of a successful BEAST attack is similar to that of session hijacking.

-- [SSL Labs Best Practices Report][ssl-labs] (September 2013)

##### Other Considerations

It's not really possible to include tests for this functionality without adding new functions to retrieve the negotiated cipher from an encrypted socket stream. I don't generally feel like creating functions solely for use in testing things is a good idea, so there are no .phpt tests included. I may PR a new function to get meta information about the SSL session in the future, though. In such a case I'll go ahead and add tests for this scenario.

[context]: http://contextis.com/research/blog/server-technologies-https-beast-attack/
[wiki-beast]: http://en.wikipedia.org/wiki/Transport_Layer_Security#BEAST_attack
[qualys-mitigation]: https://community.qualys.com/blogs/securitylabs/2011/10/17/mitigating-the-beast-attack-on-tls
[ssl-labs]: https://www.ssllabs.com/downloads/SSL_TLS_Deployment_Best_Practices_1.3.pdf