aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/libcharon/encoding/payloads/nonce_payload.c21
-rw-r--r--src/libcharon/sa/tasks/main_mode.c8
2 files changed, 22 insertions, 7 deletions
diff --git a/src/libcharon/encoding/payloads/nonce_payload.c b/src/libcharon/encoding/payloads/nonce_payload.c
index 58ef70a0e..3c5eeb535 100644
--- a/src/libcharon/encoding/payloads/nonce_payload.c
+++ b/src/libcharon/encoding/payloads/nonce_payload.c
@@ -19,6 +19,7 @@
#include "nonce_payload.h"
+#include <daemon.h>
#include <encoding/payloads/encodings.h>
typedef struct private_nonce_payload_t private_nonce_payload_t;
@@ -103,8 +104,26 @@ static encoding_rule_t encodings[] = {
METHOD(payload_t, verify, status_t,
private_nonce_payload_t *this)
{
- if (this->nonce.len < 16 || this->nonce.len > 256)
+ bool bad_length = FALSE;
+
+ if (this->nonce.len > 256)
+ {
+ bad_length = TRUE;
+ }
+ if (this->type == NONCE &&
+ this->nonce.len < 16)
+ {
+ bad_length = TRUE;
+ }
+ if (this->type == NONCE_V1 &&
+ this->nonce.len < 8)
+ {
+ bad_length = TRUE;
+ }
+ if (bad_length)
{
+ DBG1(DBG_ENC, "%N payload has invalid length (%d bytes)",
+ payload_type_names, this->type, this->nonce.len);
return FAILED;
}
return SUCCESS;
diff --git a/src/libcharon/sa/tasks/main_mode.c b/src/libcharon/sa/tasks/main_mode.c
index 4468482af..2de9c0e9f 100644
--- a/src/libcharon/sa/tasks/main_mode.c
+++ b/src/libcharon/sa/tasks/main_mode.c
@@ -171,8 +171,7 @@ METHOD(task_t, build_i, status_t,
DBG1(DBG_IKE, "no RNG found to create nonce");
return FAILED;
}
- /* TODO-IKEv1: nonce size? */
- rng->allocate_bytes(rng, 20, &this->nonce_i);
+ rng->allocate_bytes(rng, NONCE_SIZE, &this->nonce_i);
rng->destroy(rng);
nonce_payload = nonce_payload_create(NONCE_V1);
@@ -297,7 +296,6 @@ METHOD(task_t, process_r, status_t,
return FAILED;
}
this->nonce_i = nonce_payload->get_nonce(nonce_payload);
- /* TODO-IKEv1: verify nonce length */
this->state = MM_KE;
return NEED_MORE;
@@ -386,8 +384,7 @@ METHOD(task_t, build_r, status_t,
DBG1(DBG_IKE, "no RNG found to create nonce");
return FAILED;
}
- /* TODO-IKEv1: nonce size? */
- rng->allocate_bytes(rng, 20, &this->nonce_r);
+ rng->allocate_bytes(rng, NONCE_SIZE, &this->nonce_r);
rng->destroy(rng);
nonce_payload = nonce_payload_create(NONCE_V1);
@@ -483,7 +480,6 @@ METHOD(task_t, process_i, status_t,
return FAILED;
}
this->nonce_r = nonce_payload->get_nonce(nonce_payload);
- /* TODO-IKEv1: verify nonce length */
return NEED_MORE;
}