Port "use_tunneled_reply" fix for MS-CHAP from branch_1_1
[freeradius.git] / src / modules / rlm_eap / types / rlm_eap_psk / eap_psk.h
1 /* $Id$ */
2
3 /*
4  * eap_psk.h
5  *
6  * Implementation of the EAP-PSK packet management
7  *
8  * 
9  * Copyright (C) France Télécom R&D (DR&D/MAPS/NSS)
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  * 
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24  *
25  * Copyright 2006 The FreeRADIUS server project
26  *
27  */
28
29
30
31 #ifndef _EAP_PSK_H
32 #define _EAP_PSK_H
33
34 #include <freeradius-devel/ident.h>
35 RCSIDH(eap_psk_h, "$Id$")
36
37 #include "eap.h"
38
39 #if defined(__cplusplus)
40 extern "C"
41 {
42 #endif
43
44 // EAP-PSK Type
45 #define EAPPSK_TYPE 255
46
47 // EXT_Payload maximum length in bytes
48 #define EXT_PAYLOAD_MAX_LEN 977
49
50 #define PSK_PCHANNEL_REPLAY_COUNTER_SIZE sizeof(unsigned long int) // size in octets
51 #define PSK_KEY_SIZE (PSK_AK_SIZE+PSK_KDK_SIZE)                    // size in octets
52 #define PSK_AK_SIZE 16                                             // size in octets
53 #define PSK_KDK_SIZE 16                                            // size in octets
54 #define PSK_TEK_SIZE 16                                            // size in octets
55 #define PSK_MSK_SIZE 64                                            // size in octets
56 #define PSK_EMSK_SIZE 64                                           // size in octets
57 #define PSK_RANDOM_NUMBER_SIZE 16                                  // size in octets
58 #define PSK_MAC_SIZE 16                                            // size in octets
59 #define EAP_HEADER_SIZE 5                                          // size in octets
60 #define PSK_SIZE 16
61
62
63
64 // EAP-PSK attribute flags
65 #define PSK_STATUS_CONT            0x40
66 #define PSK_STATUS_DONE_FAILURE    0xC0
67 #define PSK_STATUS_DONE_SUCCESS    0x80
68
69 #define PSK_IS_EXT                 0x20
70
71
72 // the EAP-PSK configuration parameters
73 typedef struct eap_psk_conf {
74   unsigned char *privateKey;           // the server private key
75   unsigned char *id_s;                 // the server name
76   unsigned int  ldapSupport;           // if an LDAP directory is used
77   unsigned char *peerNaiAttribute;     // the LDAP attribute name which corresponds to the peer NAI
78   unsigned char *peerKeyAttribute;     // the LDAP attribute name which corresponds to the peer Key = AK || KDK
79   unsigned char  *usersFilePath;       // the EAP-PSK users file path
80   unsigned int   nbRetry;              // the number of bad authorized responses while the EAP-PSK authentication
81   unsigned int   maxDelay;                 // the maximum interval in seconds between two correct responses
82 } PSK_CONF;
83
84   
85 // data format of the first EAP-PSK message
86 typedef struct psk_message_1 {
87   unsigned char rand_s[PSK_RANDOM_NUMBER_SIZE];
88 }psk_message_1;
89
90 // data format of the second EAP-PSK message
91 typedef struct psk_message_2 {
92   unsigned char rand_p[PSK_RANDOM_NUMBER_SIZE];
93   unsigned char mac_p[16];
94   unsigned char *id_p;
95 }psk_message_2;
96
97 // data format of the third EAP-PSK message
98 typedef struct psk_message_3 {
99   unsigned char mac_s[16];
100   unsigned long int nonce;
101   unsigned char tag[16];
102   unsigned char flags;
103   unsigned char ext_type;
104   unsigned char *extPayload;
105 }psk_message_3;
106
107 // data format of the fourth EAP-PSK message
108 typedef struct psk_message_4 {
109   unsigned long int nonce;
110   unsigned char tag[16];
111   unsigned char flags;
112   unsigned char ext_type;
113   unsigned char *ext_payload;
114 }psk_message_4;
115
116
117 /** 
118  *@memo         this function converts a string into hexa
119  *@param    inbytes, pointer to a string
120  *@param    outstr, pointer to the hexa conversion
121  *@param    numbytes, number of bytes to convert
122  *@return       0 if an error has occured
123  */
124 int pskConvertHex(char *inbytes, char *outstr, int numbytes);
125
126
127 /**
128  *@memo         this function converts a string which contains hexa characters into hexa
129  *@param    inbytes, the string to convert
130  *@param        outstr, the conversion in hexa
131  *@param        numbytes, the number of bytes to convert
132  *@return       0 if an error has occured
133  */
134 int pskHex2Bin(const char *hex, unsigned char *bin, int numbytes);
135
136
137 /** 
138  *@memo         this function delivers random bytes
139  *@param    buf, pointer to the buffer to fill
140  *@param    nbytes, number of bytes to generate
141  *@return   0 if an error has occured
142  */
143 int pskGetRandomBytes(void *buf, int nbytes);
144   
145
146 #if defined(__cplusplus)
147 }
148 #endif
149
150 #endif /*_EAP_PSK_H*/