Government launches login.gov to simplify access to public services
Login Spec Here: <a href="https:&#x2F;&#x2F;github.com&#x2F;18F&#x2F;identity-idp&#x2F;blob&#x2F;master&#x2F;docs&#x2F;encryption-and-key-rotation.md" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;18F&#x2F;identity-idp&#x2F;blob&#x2F;master&#x2F;docs&#x2F;encrypt...</a><p>Many aspects of this make no sense to me... so <i>IF</i> this is actually what they are doing...<p><pre><code>  hash(user, password) {
    salt = CS-PRNG(160bit)
    s = scrypt(salt, password)
    z1 = s[0:32]
    z2 = s[32:64]

    R = CS-PRNG(256bit)
    d = HSM(R) XOR (pad_right(z1, 0x00, 32 bytes))
    cek = SHA256(z2 || d)
    hash = SHA256(cek)
    save_record(user, d, salt, hash)
  }
</code></pre>
First and foremost, if the HSM operation is to have any <i>meaning</i>, it needs to be in the critical path for encrypting &#x2F; decrypting data and possibly also calculating the password hash. If you don&#x27;t need to go through the HSM to perform a decrypt or a hash validation, then obviously the HSM isn&#x27;t actually securing anything! All it becomes is a source of entropy into the key derivation, but that&#x27;s more likely to harm than help.<p>From their own specification;<p>&quot;It is important to note that the HSM factor strengthens the model in a way different than the other two factors, which rely on keeping them secret. Because the HSM is tied to a physical object, brute force attacks on our database would need to happen in proximity to the HSM, i.e., within our AWS environment, which greatly reduces the attack surface. A bad actor with a copy of the database cannot apply their own computing power to brute force cracking of passwords.&quot;<p>But to be clear, if you have &#x27;d&#x27;, &#x27;salt&#x27;, and &#x27;hash&#x27;, you can brute force attack passwords as;<p><pre><code>  s = scrypt(salt, password)
  h = SHA256(SHA256(s[32:64] || d))
  h =? hash
</code></pre>
Now, if they were <i>not</i> storing &#x27;d&#x27; in the user record, you might think to store what they call &#x27;R&#x27; in the user record. Then you would have to go through the HSM as part of each login to <i>derive</i> the correct &#x27;d&#x27; and &#x27;cek&#x27; which is how it&#x27;s <i>supposed to work</i>.<p>But even that design is still not good enough. You don&#x27;t want to allow an attacker to pull &#x27;R&#x27; from your database, send it through the HSM just once, and <i>then</i> be able to start brute forcing the password forever from there on out. If you&#x27;re going to pay for an HSM, and your going to call it for each password verification, then you better make sure an <i>attacker</i> is also required to call the HSM for <i>each attempt</i> at verifying a password. Which means you send your password hash (or something derived from it) through the HSM, not just a random &#x27;R&#x27;!<p>Next, besides all of that, the design is horrific for end users. PII is encrypted with &#x27;cek&#x27; above. That means if you lose your password, you lose your PII. Which means starting basically a new account from scratch! I can&#x27;t endorse the idea that a password reset from an end user will effectively <i>wipe out</i> their account information and make them start over.<p>The vast majority of users will be logging into this service <i>infrequently</i>. Combine this with a typically user hostile password policy, and the result is that a large percentage of users will be resetting their password every time they need to login. With this design, that means they have to <i>start over</i> with validation through a third party... and guess who that third party is? Companies like <i>Equifax</i> now responsible for the single largest PII breach in American history.<p>Now they&#x27;ve also added something like a recovery key which the user is supposed to <i>print out and save</i> at the moment they create their account, and that key is used to separately encrypt all the PII. So if the user forgets their password but can find this magic piece of paper, they can enter this key (that&#x27;ll be fun) as part of the password reset process and reset their password without effectively wiping their account. To think &quot;Average Users&quot; will succeed in doing this belies reality.<p>But wait... where is this magic key being saved on login.gov servers? If it was a private key they give to the user and they just keep the public key on their side that could work, but it&#x27;s actually an uppercase 16 character alphanumeric token... 5.17 * 16 = 82 bits. Let&#x27;s hope that&#x27;s not literally the encryption key, but the alternative -- it&#x27;s a token used to lookup the key in their database -- would completely defeat the purpose of encrypting the PII with a PBK in the first place?! And, even if it was the literal encryption key, when you change or update your PII, if they don&#x27;t also keep it on their side, how would they update their secondary encrypted PII record?