-int chal_reply_h(connection_t *c)
-{
- char hishash[MAX_STRING_SIZE];
- char myhash[SHA_DIGEST_LENGTH];
-cp
- if(sscanf(c->buffer, "%*d "MAX_STRING, hishash) != 1)
- {
- syslog(LOG_ERR, _("Got bad %s from %s (%s)"), "CHAL_REPLY", c->name, c->hostname);
- return -1;
- }
-
- /* Check if the length of the hash is all right */
-
- if(strlen(hishash) != SHA_DIGEST_LENGTH*2)
- {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, _("wrong challenge reply length"));
- return -1;
- }
-
- /* Convert the hash to binary format */
-
- hex2bin(hishash, hishash, SHA_DIGEST_LENGTH);
-
- /* Calculate the hash from the challenge we sent */
-
- SHA1(c->hischallenge, RSA_size(c->rsa_key), myhash);
-
- /* Verify the incoming hash with the calculated hash */
-
- if(memcmp(hishash, myhash, SHA_DIGEST_LENGTH))
- {
- syslog(LOG_ERR, _("Possible intruder %s (%s): %s"), c->name, c->hostname, _("wrong challenge reply"));
- if(debug_lvl >= DEBUG_SCARY_THINGS)
- {
- bin2hex(myhash, hishash, SHA_DIGEST_LENGTH);
- hishash[SHA_DIGEST_LENGTH*2] = '\0';
- syslog(LOG_DEBUG, _("Expected challenge reply: %s"), hishash);
- }
- return -1;
- }
-
- /* Identity has now been positively verified.
- Send an acknowledgement with the rest of the information needed.
- */
-
- c->allow_request = ACK;
-cp
- return send_ack(c);
+bool challenge_h(connection_t *c, char *request) {
+ char buffer[MAX_STRING_SIZE];
+ size_t len = rsa_size(&myself->connection->rsa);
+ size_t digestlen = digest_length(&c->outdigest);
+ char digest[digestlen];
+
+ if(sscanf(request, "%*d " MAX_STRING, buffer) != 1) {
+ logger(LOG_ERR, "Got bad %s from %s (%s)", "CHALLENGE", c->name, c->hostname);
+ return false;
+ }
+
+ /* Check if the length of the challenge is all right */
+
+ if(strlen(buffer) != len * 2) {
+ logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge length");
+ return false;
+ }
+
+ /* Convert the challenge from hexadecimal back to binary */
+
+ hex2bin(buffer, buffer, len);
+
+ c->allow_request = CHAL_REPLY;
+
+ /* Calculate the hash from the challenge we received */
+
+ digest_create(&c->indigest, buffer, len, digest);
+
+ /* Convert the hash to a hexadecimal formatted string */
+
+ bin2hex(digest, buffer, digestlen);
+ buffer[digestlen * 2] = '\0';
+
+ /* Send the reply */
+
+ return send_request(c, "%d %s", CHAL_REPLY, buffer);
+}
+
+bool chal_reply_h(connection_t *c, char *request) {
+ char hishash[MAX_STRING_SIZE];
+
+ if(sscanf(request, "%*d " MAX_STRING, hishash) != 1) {
+ logger(LOG_ERR, "Got bad %s from %s (%s)", "CHAL_REPLY", c->name,
+ c->hostname);
+ return false;
+ }
+
+ /* Check if the length of the hash is all right */
+
+ if(strlen(hishash) != digest_length(&c->outdigest) * 2) {
+ logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge reply length");
+ return false;
+ }
+
+ /* Convert the hash to binary format */
+
+ hex2bin(hishash, hishash, digest_length(&c->outdigest));
+
+ /* Verify the hash */
+
+ if(!digest_verify(&c->outdigest, c->hischallenge, rsa_size(&c->rsa), hishash)) {
+ logger(LOG_ERR, "Possible intruder %s (%s): %s", c->name, c->hostname, "wrong challenge reply");
+ return false;
+ }
+
+ /* Identity has now been positively verified.
+ Send an acknowledgement with the rest of the information needed.
+ */
+
+ free(c->hischallenge);
+ c->hischallenge = NULL;
+ c->allow_request = ACK;
+
+ return send_ack(c);