The FreeRADIUS server  $Id: 15bac2a4c627c01d1aa2047687b3418955ac7f00 $
eap_pwd.h
Go to the documentation of this file.
1 #pragma once
2 /**
3  * copyright holder grants permission for redistribution and use in source
4  * and binary forms, with or without modification, provided that the
5  * following conditions are met:
6  * 1. Redistribution of source code must retain the above copyright
7  * notice, this list of conditions, and the following disclaimer
8  * in all source files.
9  * 2. Redistribution in binary form must retain the above copyright
10  * notice, this list of conditions, and the following disclaimer
11  * in the documentation and/or other materials provided with the
12  * distribution.
13  *
14  * "DISCLAIMER OF LIABILITY
15  *
16  * THIS SOFTWARE IS PROVIDED BY DAN HARKINS ``AS IS'' AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE INDUSTRIAL LOUNGE BE LIABLE
20  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26  * SUCH DAMAGE."
27  *
28  * This license and distribution terms cannot be changed. In other words,
29  * this code cannot simply be copied and put under a different distribution
30  * license (including the GNU public license).
31  *
32  * @copyright (c) Dan Harkins, 2012
33  */
34 RCSIDH(eap_pwd_h, "$Id: 47e41f63c49a6a24d0081a9174ae08db4e3e98b1 $")
35 
36 #include <freeradius-devel/eap/base.h>
37 #include <freeradius-devel/tls/openssl_user_macros.h>
38 #include <openssl/bn.h>
39 #include <openssl/sha.h>
40 #include <openssl/ec.h>
41 #include <openssl/evp.h>
42 #include <openssl/hmac.h>
43 
44 #if OPENSSL_VERSION_NUMBER < 0x10101000L
45 # define EC_POINT_get_affine_coordinates EC_POINT_get_affine_coordinates_GFp
46 # define EC_POINT_set_affine_coordinates EC_POINT_set_affine_coordinates_GFp
47 #endif
48 
49 typedef struct {
51 #define EAP_PWD_EXCH_ID 1
52 #define EAP_PWD_EXCH_COMMIT 2
53 #define EAP_PWD_EXCH_CONFIRM 3
54 // uint16_t total_length; /* there if the L-bit is set */
56 } CC_HINT(packed) pwd_hdr;
57 
58 #define EAP_PWD_GET_LENGTH_BIT(x) ((x)->lm_exchange & 0x80)
59 #define EAP_PWD_SET_LENGTH_BIT(x) ((x)->lm_exchange |= 0x80)
60 #define EAP_PWD_GET_MORE_BIT(x) ((x)->lm_exchange & 0x40)
61 #define EAP_PWD_SET_MORE_BIT(x) ((x)->lm_exchange |= 0x40)
62 #define EAP_PWD_GET_EXCHANGE(x) ((x)->lm_exchange & 0x3f)
63 #define EAP_PWD_SET_EXCHANGE(x,y) ((x)->lm_exchange |= (y))
64 
65 typedef struct {
68 #define EAP_PWD_DEF_RAND_FUN 1
70 #define EAP_PWD_DEF_PRF 1
71  uint8_t token[4];
73 #define EAP_PWD_PREP_NONE 0
74 #define EAP_PWD_PREP_MS 1
75 #define EAP_PWD_PREP_SASL 2
76  char identity[];
77 } CC_HINT(packed) pwd_id_packet_t;
78 
79 typedef struct {
81 #define PWD_STATE_ID_REQ 1
82 #define PWD_STATE_COMMIT 2
83 #define PWD_STATE_CONFIRM 3
87  char peer_id[FR_MAX_STRING_LEN];
88  size_t peer_id_len;
89  size_t mtu;
90  uint8_t *in; /* reassembled fragments */
91  size_t in_pos;
92  size_t in_len;
93  uint8_t *out; /* message to fragment */
94  size_t out_pos;
95  size_t out_len;
96  EC_GROUP *group;
97  EC_POINT *pwe;
98  BIGNUM *order;
99  BIGNUM *prime;
100  BIGNUM *k;
101  BIGNUM *private_value;
102  BIGNUM *peer_scalar;
103  BIGNUM *my_scalar;
104  EC_POINT *my_element;
105  EC_POINT *peer_element;
106  uint8_t my_confirm[SHA256_DIGEST_LENGTH];
107 } pwd_session_t;
108 
109 int compute_password_element(request_t *request, pwd_session_t *sess, uint16_t grp_num,
110  char const *password, int password_len,
111  char const *id_server, int id_server_len,
112  char const *id_peer, int id_peer_len,
113  uint32_t *token, BN_CTX *bnctx);
114 int compute_scalar_element(request_t *request, pwd_session_t *sess, BN_CTX *bnctx);
115 int process_peer_commit(request_t *request, pwd_session_t *sess, uint8_t *in, size_t in_len, BN_CTX *bnctx);
116 int compute_server_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx);
117 int compute_peer_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx);
118 int compute_keys(request_t *request, pwd_session_t *sess, uint8_t *peer_confirm,
119  uint8_t *msk, uint8_t *emsk);
120 #ifdef PRINTBUF
121 void print_buf(char *str, uint8_t *buf, int len);
122 #endif /* PRINTBUF */
#define RCSIDH(h, id)
Definition: build.h:445
static fr_slen_t in
Definition: dict.h:645
BIGNUM * private_value
Definition: eap_pwd.h:101
int compute_server_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:684
uint16_t group_num
Definition: eap_pwd.h:84
int compute_password_element(request_t *request, pwd_session_t *sess, uint16_t grp_num, char const *password, int password_len, char const *id_server, int id_server_len, char const *id_peer, int id_peer_len, uint32_t *token, BN_CTX *bnctx)
Definition: eap_pwd.c:253
size_t in_pos
Definition: eap_pwd.h:91
uint8_t lm_exchange
Definition: eap_pwd.h:50
BIGNUM * my_scalar
Definition: eap_pwd.h:103
uint32_t token
Definition: eap_pwd.h:86
int process_peer_commit(request_t *request, pwd_session_t *sess, uint8_t *in, size_t in_len, BN_CTX *bnctx)
Definition: eap_pwd.c:558
uint16_t state
Definition: eap_pwd.h:80
uint16_t group_num
Definition: eap_pwd.h:66
size_t out_len
Definition: eap_pwd.h:95
int compute_scalar_element(request_t *request, pwd_session_t *sess, BN_CTX *bnctx)
Definition: eap_pwd.c:518
size_t peer_id_len
Definition: eap_pwd.h:88
BIGNUM * prime
Definition: eap_pwd.h:99
int compute_peer_confirm(request_t *request, pwd_session_t *sess, uint8_t *out, BN_CTX *bnctx)
Definition: eap_pwd.c:787
uint8_t prf
Definition: eap_pwd.h:69
uint8_t prep
Definition: eap_pwd.h:72
size_t out_pos
Definition: eap_pwd.h:94
EC_GROUP * group
Definition: eap_pwd.h:96
size_t in_len
Definition: eap_pwd.h:92
BIGNUM * peer_scalar
Definition: eap_pwd.h:102
int compute_keys(request_t *request, pwd_session_t *sess, uint8_t *peer_confirm, uint8_t *msk, uint8_t *emsk)
EC_POINT * pwe
Definition: eap_pwd.h:97
BIGNUM * k
Definition: eap_pwd.h:100
size_t mtu
Definition: eap_pwd.h:89
uint8_t * out
Definition: eap_pwd.h:93
uint8_t random_function
Definition: eap_pwd.h:67
uint8_t * in
Definition: eap_pwd.h:90
uint32_t ciphersuite
Definition: eap_pwd.h:85
BIGNUM * order
Definition: eap_pwd.h:98
EC_POINT * peer_element
Definition: eap_pwd.h:105
EC_POINT * my_element
Definition: eap_pwd.h:104
unsigned short uint16_t
Definition: merged_model.c:31
unsigned int uint32_t
Definition: merged_model.c:33
unsigned char uint8_t
Definition: merged_model.c:30
static fr_slen_t data
Definition: value.h:1259
#define FR_MAX_STRING_LEN
Definition: value.h:30
static size_t char ** out
Definition: value.h:984