added EAP PEAP and MSTLV protocols
[strongswan.git] / src / libstrongswan / eap / eap.c
1 /*
2 * Copyright (C) 2006 Martin Willi
3 * Hochschule fuer Technik Rapperswil
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 */
15
16 #include "eap.h"
17
18 ENUM(eap_code_names, EAP_REQUEST, EAP_FAILURE,
19 "EAP_REQUEST",
20 "EAP_RESPONSE",
21 "EAP_SUCCESS",
22 "EAP_FAILURE",
23 );
24
25 ENUM(eap_code_short_names, EAP_REQUEST, EAP_FAILURE,
26 "REQ",
27 "RES",
28 "SUCC",
29 "FAIL",
30 );
31
32 ENUM_BEGIN(eap_type_names, EAP_IDENTITY, EAP_GTC,
33 "EAP_IDENTITY",
34 "EAP_NOTIFICATION",
35 "EAP_NAK",
36 "EAP_MD5",
37 "EAP_OTP",
38 "EAP_GTC");
39 ENUM_NEXT(eap_type_names, EAP_TLS, EAP_TLS, EAP_GTC,
40 "EAP_TLS");
41 ENUM_NEXT(eap_type_names, EAP_SIM, EAP_SIM, EAP_TLS,
42 "EAP_SIM");
43 ENUM_NEXT(eap_type_names, EAP_TTLS, EAP_TTLS, EAP_SIM,
44 "EAP_TTLS");
45 ENUM_NEXT(eap_type_names, EAP_AKA, EAP_AKA, EAP_TTLS,
46 "EAP_AKA");
47 ENUM_NEXT(eap_type_names, EAP_PEAP, EAP_MSCHAPV2, EAP_AKA,
48 "EAP_PEAP",
49 "EAP_MSCHAPV2");
50 ENUM_NEXT(eap_type_names, EAP_MSTLV, EAP_MSTLV, EAP_MSCHAPV2,
51 "EAP_MSTLV");
52 ENUM_NEXT(eap_type_names, EAP_TNC, EAP_TNC, EAP_MSTLV,
53 "EAP_TNC");
54 ENUM_NEXT(eap_type_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
55 "EAP_DYNAMIC",
56 "EAP_RADIUS",
57 "EAP_EXPANDED",
58 "EAP_EXPERIMENTAL");
59 ENUM_END(eap_type_names, EAP_EXPERIMENTAL);
60
61 ENUM_BEGIN(eap_type_short_names, EAP_IDENTITY, EAP_GTC,
62 "ID",
63 "NTF",
64 "NAK",
65 "MD5",
66 "OTP",
67 "GTC");
68 ENUM_NEXT(eap_type_short_names, EAP_TLS, EAP_TLS, EAP_GTC,
69 "TLS");
70 ENUM_NEXT(eap_type_short_names, EAP_SIM, EAP_SIM, EAP_TLS,
71 "SIM");
72 ENUM_NEXT(eap_type_short_names, EAP_TTLS, EAP_TTLS, EAP_SIM,
73 "TTLS");
74 ENUM_NEXT(eap_type_short_names, EAP_AKA, EAP_AKA, EAP_TTLS,
75 "AKA");
76 ENUM_NEXT(eap_type_short_names, EAP_PEAP, EAP_MSCHAPV2, EAP_AKA,
77 "PEAP",
78 "MSCHAPV2");
79 ENUM_NEXT(eap_type_short_names, EAP_MSTLV, EAP_MSTLV, EAP_MSCHAPV2,
80 "MSTLV");
81 ENUM_NEXT(eap_type_short_names, EAP_TNC, EAP_TNC, EAP_MSTLV,
82 "TNC");
83 ENUM_NEXT(eap_type_short_names, EAP_DYNAMIC, EAP_EXPERIMENTAL, EAP_TNC,
84 "DYN",
85 "RAD",
86 "EXP",
87 "XP");
88 ENUM_END(eap_type_short_names, EAP_EXPERIMENTAL);
89
90 ENUM(auth_rule_names, AUTH_RULE_IDENTITY, AUTH_HELPER_SUBJECT_HASH_URL,
91 "RULE_IDENTITY",
92 "RULE_AUTH_CLASS",
93 "RULE_EAP_IDENTITY",
94 "RULE_EAP_TYPE",
95 "RULE_EAP_VENDOR",
96 "RULE_CA_CERT",
97 "RULE_IM_CERT",
98 "RULE_SUBJECT_CERT",
99 "RULE_CRL_VALIDATION",
100 "RULE_OCSP_VALIDATION",
101 "RULE_GROUP",
102 "HELPER_IM_CERT",
103 "HELPER_SUBJECT_CERT",
104 "HELPER_IM_HASH_URL",
105 "HELPER_SUBJECT_HASH_URL",
106 );
107
108 /*
109 * See header
110 */
111 eap_type_t eap_type_from_string(char *name)
112 {
113 int i;
114 static struct {
115 char *name;
116 eap_type_t type;
117 } types[] = {
118 {"identity", EAP_IDENTITY},
119 {"md5", EAP_MD5},
120 {"otp", EAP_OTP},
121 {"gtc", EAP_GTC},
122 {"tls", EAP_TLS},
123 {"ttls", EAP_TTLS},
124 {"sim", EAP_SIM},
125 {"aka", EAP_AKA},
126 {"peap", EAP_PEAP},
127 {"mschapv2", EAP_MSCHAPV2},
128 {"tnc", EAP_TNC},
129 {"radius", EAP_RADIUS},
130 };
131
132 for (i = 0; i < countof(types); i++)
133 {
134 if (strcaseeq(name, types[i].name))
135 {
136 return types[i].type;
137 }
138 }
139 return 0;
140 }