<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:base="https://jbeekman.nl/">
  <id>https://jbeekman.nl/</id>
  <title>SSH – Technology &amp; Policy</title>
  <updated>2015-05-20T12:00:00Z</updated>
  <link rel="alternate" href="https://jbeekman.nl/"/>
  <link rel="self" href="https://jbeekman.nl/blog/ssh/"/>
  <author>
    <name>Jethro Beekman</name>
    <uri>https://jbeekman.nl/blog</uri>
  </author>
  <icon>https://jbeekman.nl/favicon.ico</icon>
  <entry>
    <id>tag:jbeekman.nl,2015-05-20:/blog/2015/05/ssh-logjam/</id>
    <title type="html">On OpenSSH and Logjam – Technology &amp; Policy</title>
    <published>2015-05-20T12:00:00Z</published>
    <updated>2015-05-20T12:00:00Z</updated>
    <link rel="alternate" href="https://jbeekman.nl/blog/2015/05/ssh-logjam/"/>
    <content type="html">&lt;p&gt;&lt;a href="https://weakdh.org/"&gt;Recent work&lt;/a&gt; showing the feasibility of calculating 
discrete logarithms on large integers has put the Diffie-Hellman key exchange 
parameters we use every day in the spotlight. I have looked at what this means
for SSH key exchange. In short, on your &lt;strong&gt;SSH server&lt;/strong&gt;, do the following:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;awk '{ if ($5 &amp;lt;= 2000) printf "#"; print }' /etc/ssh/moduli &amp;gt; /tmp/large_moduli
mv /tmp/large_moduli /etc/ssh/moduli
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;And put the following in your &lt;code&gt;sshd_config&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,
              ecdh-sha2-nistp384,ecdh-sha2-nistp521,
              diffie-hellman-group14-sha1,
              diffie-hellman-group-exchange-sha1,
              diffie-hellman-group-exchange-sha256
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Note that &lt;code&gt;curve25519-sha256@libssh.org&lt;/code&gt; is only supported in &lt;a href="http://www.openssh.com/txt/release-6.5"&gt;OpenSSH 
6.5&lt;/a&gt; and up, and only works reliably in 
&lt;a href="http://www.openssh.com/txt/release-6.7"&gt;OpenSSH 6.7&lt;/a&gt; and up. On your &lt;strong&gt;SSH 
client&lt;/strong&gt;, put the following in your &lt;code&gt;ssh_config&lt;/code&gt;:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;KexAlgorithms curve25519-sha256@libssh.org,ecdh-sha2-nistp256,
              ecdh-sha2-nistp384,ecdh-sha2-nistp521,
              diffie-hellman-group14-sha1
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;If with this configuration you are unable to connect to some SSH servers, and 
you need to add &lt;code&gt;diffie-hellman-group-exchange-sha1&lt;/code&gt; or 
&lt;code&gt;diffie-hellman-group-exchange-sha256&lt;/code&gt; to the supported list of algorithms, you 
should recompile your SSH client with a &lt;code&gt;DH_GRP_MIN&lt;/code&gt; of 2048, so that a server 
can’t force your client to use a weak group.&lt;/p&gt;

&lt;h3 id="technical-details"&gt;Technical details&lt;/h3&gt;

&lt;p&gt;Now follows a detailed explanation of these recommendations. The following key 
exchange mechanisms are supported in the current version (6.8) of OpenSSH:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code&gt;curve25519-sha256@libssh.org&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;ecdh-sha2-nistp256&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;ecdh-sha2-nistp384&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;ecdh-sha2-nistp521&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;diffie-hellman-group1-sha1&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;diffie-hellman-group14-sha1&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;diffie-hellman-group-exchange-sha1&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code&gt;diffie-hellman-group-exchange-sha256&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The first four mechanisms, &lt;code&gt;curve25519-sha256@libssh.org&lt;/code&gt;, 
&lt;code&gt;ecdh-sha2-nistp256&lt;/code&gt;, &lt;code&gt;ecdh-sha2-nistp384&lt;/code&gt;, &lt;code&gt;ecdh-sha2-nistp521&lt;/code&gt;, do not use 
prime-field Diffie-Hellman and are not affected. &lt;a href="http://nmav.gnutls.org/2011/12/price-to-pay-for-perfect-forward.html"&gt;Previous 
work&lt;/a&gt; 
shows that these mechanisms are much faster when used at the same security 
level, so you should use them!&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;diffie-hellman-group1-sha1&lt;/code&gt; mechanism uses the fixed 1024-bit &lt;a href="https://www.ietf.org/rfc/rfc2409.txt"&gt;Oakley 
Group 2&lt;/a&gt; (not the 768-bit group 1, as the 
name of the mechanism might suggest). This group is within the range of being a 
viable target for nation-state attackers, and should not be used.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;diffie-hellman-group14-sha1&lt;/code&gt; mechanism uses the fixed 2048-bit &lt;a href="https://www.ietf.org/rfc/rfc3526.txt"&gt;Oakley 
Group 14&lt;/a&gt;, which should be secure enough 
for now.&lt;/p&gt;

&lt;p&gt;The &lt;code&gt;diffie-hellman-group-exchange-sha1&lt;/code&gt; and 
&lt;code&gt;diffie-hellman-group-exchange-sha256&lt;/code&gt; mechanisms let the client and server 
negotiate a custom DH group. The client sends a tuple «min, n, max» to the 
server, indicating the client’s minimum, preferred and maximum group size. 
&lt;a href="https://www.ietf.org/rfc/rfc4419.txt"&gt;According to the RFC&lt;/a&gt;,&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Servers and clients SHOULD support groups with a modulus length of k
bits, where 1024 &amp;lt;= k &amp;lt;= 8192.  The recommended values for min and
max are 1024 and 8192, respectively.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The OpenSSH server selects a suitable group from a pre-generated set of groups, 
installed system-wide in &lt;code&gt;/etc/ssh/moduli&lt;/code&gt; (falling back to &lt;code&gt;/etc/ssh/primes&lt;/code&gt;), 
using the &lt;code&gt;choose_dh&lt;/code&gt; function in 
&lt;a href="https://github.com/openssh/openssh-portable/blob/master/dh.c"&gt;&lt;code&gt;dh.c&lt;/code&gt;&lt;/a&gt;. In case 
no suitable group is found, the code defaults to Oakley Group 14, which is 
safe. A pre-generated set is &lt;a href="https://github.com/openssh/openssh-portable/blob/master/moduli"&gt;distributed with the OpenSSH 
source&lt;/a&gt; and 
many binary distributions and is infrequently changed. The group sizes 
distributed with OpenSSH are 1024, 1536, 2048, 3072, 4096, 6144, and 8192 bits, 
with about 30 groups per size. The OpenSSH-distributed 1024-bit groups are 
well-known and within the range of being a viable target for nation-state 
attackers, and as such should not be used.&lt;/p&gt;

&lt;p&gt;It is possible to generate your own set of groups, in which case it would be 
safer to use a 1024-bit group, but you might as well go for larger groups. The 
&lt;code&gt;ssh-keygen&lt;/code&gt; man page mentions that “It is important that … both ends of a 
connection share common moduli.” That statement should not be interpreted as 
“both server and client need to have the same moduli configured”, as the server 
sends the chosen modulus to the client. As a case-in-point, the OpenSSH client 
does not access the system-wide moduli file at all during connection setup.&lt;/p&gt;

&lt;p&gt;Speaking about the client, it usually offers the RFC-specified minimum of 1024 
bits. There is nothing preventing a server from using that value and offering a 
well-known (and thus weak) group. So, a standard client shouldn’t use the 
custom group key exchange mechanisms, unless there is a way to change the 
minimum group size.&lt;/p&gt;
</content>
    <summary type="html">&lt;p&gt;&lt;a href="https://weakdh.org/"&gt;Recent work&lt;/a&gt; showing the feasibility of calculating 
discrete logarithms on large integers has put the Diffie-Hellman key exchange 
parameters we use every day in the spotlight. I have looked at what this means
for SSH key exchange. In short, on your &lt;strong&gt;SSH server&lt;/strong&gt;, do the following:&lt;/p&gt;</summary>
  </entry>
</feed>

