| 74 | }; |
| 75 | |
| 76 | int SrpClient::authenticate(CheckStatusWrapper* status, IClientBlock* cb) |
| 77 | { |
| 78 | try |
| 79 | { |
| 80 | if (sessionKey.hasData()) |
| 81 | { |
| 82 | // Why are we called when auth is completed? |
| 83 | (Arg::Gds(isc_random) << "Auth sync failure - SRP's authenticate called more times than supported").raise(); |
| 84 | } |
| 85 | |
| 86 | if (!client) |
| 87 | { |
| 88 | HANDSHAKE_DEBUG(fprintf(stderr, "Cli: SRP phase1: login=%s password=%s\n", |
| 89 | cb->getLogin(), cb->getPassword())); |
| 90 | if (!(cb->getLogin() && cb->getPassword())) |
| 91 | { |
| 92 | return AUTH_CONTINUE; |
| 93 | } |
| 94 | |
| 95 | client = remotePasswordFactory(); |
| 96 | client->genClientKey(data); |
| 97 | dumpIt("Clnt: clientPubKey", data); |
| 98 | cb->putData(status, data.length(), data.begin()); |
| 99 | |
| 100 | if (status->getState() & IStatus::STATE_ERRORS) |
| 101 | return AUTH_FAILED; |
| 102 | |
| 103 | return AUTH_MORE_DATA; |
| 104 | } |
| 105 | |
| 106 | HANDSHAKE_DEBUG(fprintf(stderr, "Cli: SRP phase2\n")); |
| 107 | unsigned length; |
| 108 | const unsigned char* saltAndKey = cb->getData(&length); |
| 109 | if (!saltAndKey || length == 0) |
| 110 | { |
| 111 | Arg::Gds(isc_auth_data).raise(); |
| 112 | } |
| 113 | const unsigned expectedLength = |
| 114 | (RemotePassword::SRP_SALT_SIZE + RemotePassword::SRP_KEY_SIZE + 2) * 2; |
| 115 | if (length > expectedLength) |
| 116 | { |
| 117 | (Arg::Gds(isc_auth_datalength) << Arg::Num(length) << |
| 118 | Arg::Num(expectedLength) << "data").raise(); |
| 119 | } |
| 120 | |
| 121 | string salt, key; |
| 122 | unsigned charSize = *saltAndKey++; |
| 123 | charSize += ((unsigned) *saltAndKey++) << 8; |
| 124 | if (charSize > RemotePassword::SRP_SALT_SIZE * 2) |
| 125 | { |
| 126 | (Arg::Gds(isc_auth_datalength) << Arg::Num(charSize) << |
| 127 | Arg::Num(RemotePassword::SRP_SALT_SIZE * 2) << "salt").raise(); |
| 128 | } |
| 129 | salt.assign(saltAndKey, charSize); |
| 130 | dumpIt("Clnt: salt", salt); |
| 131 | saltAndKey += charSize; |
| 132 | length -= (charSize + 2); |
| 133 |
nothing calls this directly
no test coverage detected