if (fr_type_is_null(user_password->type)) RETURN_MODULE_NOOP;
if (user_password->vb_length == 0) {
- RDEBUG("TOTP.From-User is empty");
+ RWARN("TOTP.From-User is empty");
RETURN_MODULE_FAIL;
}
if ((user_password->vb_length != 6) && (user_password->vb_length != 8)) {
- RDEBUG("TOTP.From-User has incorrect length. Expected 6 or 8, got %zu", user_password->vb_length);
+ RWARN("TOTP.From-User has incorrect length. Expected 6 or 8, got %zu", user_password->vb_length);
RETURN_MODULE_FAIL;
}
} else {
ssize_t len;
- if (!fr_type_is_null(secret->type)) RETURN_MODULE_NOOP;
+ if (fr_type_is_null(secret->type)) RETURN_MODULE_NOOP;
len = fr_base32_decode(&FR_DBUFF_TMP((uint8_t *) buffer, sizeof(buffer)), &FR_SBUFF_IN(secret->vb_strvalue, secret->vb_length), true, true);
if (len < 0) {
- RDEBUG("TOTP.Secret cannot be decoded");
+ RERROR("TOTP.Secret cannot be decoded");
RETURN_MODULE_FAIL;
}
our_keylen = len;
}
- if (fr_totp_cmp(&inst->totp, request, fr_time_to_sec(request->packet->timestamp), our_key, our_keylen, user_password->vb_strvalue) != 0) RETURN_MODULE_FAIL;
+ switch (fr_totp_cmp(&inst->totp, request, fr_time_to_sec(request->packet->timestamp), our_key, our_keylen, user_password->vb_strvalue)) {
+ case 0:
+ RETURN_MODULE_OK;
- RETURN_MODULE_OK;
+ case -2:
+ RETURN_MODULE_FAIL;
+
+ default:
+ RETURN_MODULE_REJECT;
+ }
}
/*
* @param[in] cfg Instance of fr_totp_t
* @param[in] request The current request
* @param[in] now The current time
- * @param[in] key Key to decrypt.
+ * @param[in] key Key to encrypt.
* @param[in] keylen Length of key field.
* @param[in] totp TOTP password entered by the user.
* @return
* - 0 On Success
* - -1 On Failure
+ * - -2 On incorrect arguments
*/
int fr_totp_cmp(fr_totp_t const *cfg, request_t *request, time_t now, uint8_t const *key, size_t keylen, char const *totp)
{
if (cfg->otp_length != 6 && cfg->otp_length != 8) {
fr_strerror_const("The 'opt_length' has incorrect length. Expected 6 or 8.");
- return -1;
+ return -2;
}
if (keylen < 1) {
fr_strerror_const("Invalid 'keylen' parameter value.");
- return -1;
+ return -2;
}
if (!*totp) {
fr_strerror_const("Invalid 'totp' parameter value.");
- return -1;
+ return -2;
}
/*