+ if(RSA_private_decrypt(len, buffer, cl->mychallenge, myself->rsa_key, RSA_NO_PADDING) != len) /* See challenge() */
+ {
+ syslog(LOG_ERR, _("Error during encryption of challenge for %s (%s)"), cl->name, cl->hostname);
+ return -1;
+ }
+
+ if(debug_lvl >= DEBUG_SCARY_THINGS)
+ {
+ bin2hex(cl->mychallenge, buffer, len);
+ buffer[len*2] = '\0';
+ syslog(LOG_DEBUG, _("Received random challenge (unencrypted): %s"), buffer);
+ }
+
+ /* Rest is done by send_chal_reply() */
+cp
+ return send_chal_reply(cl);
+}
+
+int send_chal_reply(connection_t *cl)
+{
+ char hash[SHA_DIGEST_LENGTH*2+1];
+cp
+ if(!cl->mychallenge)
+ {
+ syslog(LOG_ERR, _("Trying to send CHAL_REPLY to %s (%s) without a valid CHALLENGE"), cl->name, cl->hostname);
+ return -1;
+ }
+
+ /* Calculate the hash from the challenge we received */
+
+ SHA1(cl->mychallenge, RSA_size(myself->rsa_key), hash);