forked from particle-iot/tinydtls
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge commit '982cbf5ffcc0266c4a50f31bcf1377e1ab9610c8' into ecdh-merge
Conflicts: Makefile.in dtls.c dtls.h
- Loading branch information
Showing
6 changed files
with
326 additions
and
135 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
/* dtls -- a very basic DTLS implementation | ||
* | ||
* Copyright (C) 2011--2012 Olaf Bergmann <[email protected]> | ||
* Copyright (C) 2011--2013 Olaf Bergmann <[email protected]> | ||
* Copyright (C) 2013 Hauke Mehrtens <[email protected]> | ||
* | ||
* Permission is hereby granted, free of charge, to any person | ||
|
@@ -33,7 +33,10 @@ | |
#define _DTLS_H_ | ||
|
||
#include <stdint.h> | ||
#include "config.h" | ||
|
||
#include "t_list.h" | ||
#include "state.h" | ||
#include "peer.h" | ||
|
||
#ifndef WITH_CONTIKI | ||
#include "uthash.h" | ||
|
@@ -51,55 +54,6 @@ | |
#define DTLS_VERSION 0xfefd /* DTLS v1.2 */ | ||
#endif | ||
|
||
typedef enum { | ||
DTLS_STATE_INIT = 0, DTLS_STATE_WAIT_CLIENTHELLO, DTLS_STATE_WAIT_CLIENTCERTIFICATE, | ||
DTLS_STATE_WAIT_CLIENTKEYEXCHANGE, DTLS_STATE_WAIT_CERTIFICATEVERIFY, | ||
DTLS_STATE_WAIT_CLIENTCHANGECIPHERSPEC, | ||
DTLS_STATE_WAIT_FINISHED, DTLS_STATE_FINISHED, | ||
/* client states */ | ||
DTLS_STATE_CLIENTHELLO, DTLS_STATE_WAIT_SERVERCERTIFICATE, DTLS_STATE_WAIT_SERVERKEYEXCHANGE, | ||
DTLS_STATE_WAIT_SERVERHELLODONE, DTLS_STATE_WAIT_SERVERFINISHED, | ||
|
||
DTLS_STATE_CONNECTED, | ||
DTLS_STATE_CLOSING, | ||
DTLS_STATE_CLOSED, | ||
} dtls_state_t; | ||
|
||
typedef struct { | ||
uint24 mseq; /**< handshake message sequence number counter */ | ||
|
||
/** pending config that is updated during handshake */ | ||
/* FIXME: dtls_security_parameters_t pending_config; */ | ||
|
||
/* temporary storage for the final handshake hash */ | ||
dtls_hash_ctx hs_hash; | ||
} dtls_hs_state_t; | ||
|
||
typedef enum { DTLS_CLIENT=0, DTLS_SERVER } dtls_peer_type; | ||
|
||
/** | ||
* Holds security parameters, local state and the transport address | ||
* for each peer. */ | ||
typedef struct dtls_peer_t { | ||
#ifndef WITH_CONTIKI | ||
UT_hash_handle hh; | ||
#else /* WITH_CONTIKI */ | ||
struct dtls_peer_t *next; | ||
#endif /* WITH_CONTIKI */ | ||
|
||
session_t session; /**< peer address and local interface */ | ||
|
||
dtls_peer_type role; /**< denotes if this host is DTLS_CLIENT or DTLS_SERVER */ | ||
dtls_state_t state; /**< DTLS engine state */ | ||
uint16 epoch; /**< counter for cipher state changes*/ | ||
uint48 rseq; /**< sequence number of last record sent */ | ||
|
||
dtls_hs_state_t hs_state; /**< handshake protocol status */ | ||
|
||
dtls_security_parameters_t security_params; | ||
dtls_handshake_parameters_t handshake_params; | ||
} dtls_peer_t; | ||
|
||
typedef struct dtls_psk_key_t { | ||
unsigned char *id; /**< psk identity */ | ||
size_t id_length; /**< length of psk identity */ | ||
|
@@ -311,6 +265,18 @@ static inline void dtls_set_handler(dtls_context_t *ctx, dtls_handler_t *h) { | |
*/ | ||
int dtls_connect(dtls_context_t *ctx, const session_t *dst); | ||
|
||
/** | ||
* Establishes a DTLS channel with the specified remote peer. | ||
* This function returns @c 0 if that channel already exists, a value | ||
* greater than zero when a new ClientHello message was sent, and | ||
* a value less than zero on error. | ||
* | ||
* @param ctx The DTLS context to use. | ||
* @param peer The peer object that describes the session. | ||
* @return A value less than zero on error, greater or equal otherwise. | ||
*/ | ||
int dtls_connect_peer(dtls_context_t *ctx, dtls_peer_t *peer); | ||
|
||
/** | ||
* Closes the DTLS connection associated with @p remote. This function | ||
* returns zero on success, and a value less than zero on error. | ||
|
@@ -416,6 +382,19 @@ int dtls_record_read(dtls_state_t *state, uint8 *msg, int msglen); | |
int dtls_handle_message(dtls_context_t *ctx, session_t *session, | ||
uint8 *msg, int msglen); | ||
|
||
/** | ||
* Check if @p session is associated with a peer object in @p context. | ||
* This function returns a pointer to the peer if found, NULL otherwise. | ||
* | ||
* @param context The DTLS context to search. | ||
* @param session The remote address and local interface | ||
* @return A pointer to the peer associated with @p session or NULL if | ||
* none exists. | ||
*/ | ||
dtls_peer_t *dtls_get_peer(const dtls_context_t *context, | ||
const session_t *session); | ||
|
||
|
||
#endif /* _DTLS_H_ */ | ||
|
||
/** | ||
|
Oops, something went wrong.