If there isn't enough data, then the client reading the hash will fall
down and try to read the subtype instead, which isn't correct.
Invert the logic so we get a more consistent way through where we only
break out when there is insufficient data.
Do the same for the server code, for consistency.
{
switch (state) {
case ReadPublicKey:
- if (readPublicKey()) {
- verifyServer();
- writePublicKey();
- writeRandom();
- state = ReadRandom;
- }
- return false;
+ if (!readPublicKey())
+ return false;
+ verifyServer();
+ writePublicKey();
+ writeRandom();
+ state = ReadRandom;
case ReadRandom:
- if (readRandom()) {
- setCipher();
- writeHash();
- state = ReadHash;
- }
- return false;
+ if (!readRandom())
+ return false;
+ setCipher();
+ writeHash();
+ state = ReadHash;
case ReadHash:
- if (readHash()) {
- clearSecrets();
- state = ReadSubtype;
- }
+ if (!readHash())
+ return false;
+ clearSecrets();
+ state = ReadSubtype;
case ReadSubtype:
- if (readSubtype()) {
- writeCredentials();
- return true;
- }
- return false;
+ if (!readSubtype())
+ return false;
+ writeCredentials();
+ return true;
}
assert(!"unreachable");
return false;
loadPrivateKey();
writePublicKey();
state = ReadPublicKey;
- // fall through
+ /* fall through */
case ReadPublicKey:
- if (readPublicKey()) {
- writeRandom();
- state = ReadRandom;
- }
- return false;
+ if (!readPublicKey())
+ return false;
+ writeRandom();
+ state = ReadRandom;
+ /* fall through */
case ReadRandom:
- if (readRandom()) {
- setCipher();
- writeHash();
- state = ReadHash;
- }
- return false;
+ if (!readRandom())
+ return false;
+ setCipher();
+ writeHash();
+ state = ReadHash;
+ /* fall through */
case ReadHash:
- if (readHash()) {
- clearSecrets();
- writeSubtype();
- state = ReadCredentials;
- }
- return false;
+ if (!readHash())
+ return false;
+ clearSecrets();
+ writeSubtype();
+ state = ReadCredentials;
+ /* fall through */
case ReadCredentials:
- if (readCredentials()) {
- if (requireUsername)
- verifyUserPass();
- else
- verifyPass();
- return true;
- }
- return false;
+ if (!readCredentials())
+ return false;
+ if (requireUsername)
+ verifyUserPass();
+ else
+ verifyPass();
+ return true;
}
assert(!"unreachable");
return false;