Skip to content

Commit

Permalink
added debugging for cookie calculation and verification code
Browse files Browse the repository at this point in the history
  • Loading branch information
mcr committed Jan 22, 2018
1 parent 87bf899 commit 65b5c86
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions ext/openssl/ossl_dtls.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,23 @@ static void cookie_secret_setup(void)
}
}

#define DTLS_COOKIE_DEBUG 1

#ifdef DTLS_COOKIE_DEBUG
static void print_cookie(const char *label, const unsigned char cookie[], const unsigned int cookie_len)
{
unsigned int i;
printf("%s cookie: ", label);
for(i=0; i<cookie_len; i++) {
printf("%02x ", cookie[i]);
}
printf("\n");
}
#define PRINT_COOKIE(label, cookie, len) print_cookie(label, cookie,len)
#else
#define PRINT_COOKIE(label, cookie, len) {} while(0)
#endif

static void cookie_calculate(unsigned char cookie[],
unsigned int *cookie_len,
const unsigned short peerport,
Expand All @@ -71,6 +88,8 @@ static void cookie_calculate(unsigned char cookie[],
cookie_secret, sizeof(cookie_secret),
things_to_crunch, things_len,
cookie, cookie_len);

PRINT_COOKIE("calculated ", cookie, *cookie_len);
}

static int cookie_gen(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)
Expand Down Expand Up @@ -99,12 +118,14 @@ static int cookie_gen(SSL *ssl, unsigned char *cookie, unsigned int *cookie_len)
BIO_ADDR_sockaddr_size(peer),
tv.tv_sec);

for (i = 0; i < *cookie_len && i<cookie1_len; i++, cookie++) {
*cookie = cookie1[i];
for (i = 0; i<DTLS1_COOKIE_LENGTH && i<cookie1_len; i++) {
cookie[i] = cookie1[i];
}
*cookie_len = i;
ret = 1;

PRINT_COOKIE("generated ", cookie, *cookie_len);

err:
if(peer) BIO_ADDR_free(peer);
return ret;
Expand All @@ -120,6 +141,8 @@ static int cookie_verify(SSL *ssl, const unsigned char *peer_cookie,
BIO *rbio;
int ret;

PRINT_COOKIE("peer cookie", peer_cookie, peer_cookie_len);

cookie_secret_setup();
gettimeofday(&tv, NULL);

Expand Down

0 comments on commit 65b5c86

Please sign in to comment.