eapol_test.c 31 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217
  1. /*
  2. * WPA Supplicant - test code
  3. * Copyright (c) 2003-2007, Jouni Malinen <j@w1.fi>
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License version 2 as
  7. * published by the Free Software Foundation.
  8. *
  9. * Alternatively, this software may be distributed under the terms of BSD
  10. * license.
  11. *
  12. * See README and COPYING for more details.
  13. *
  14. * IEEE 802.1X Supplicant test code (to be used in place of wpa_supplicant.c.
  15. * Not used in production version.
  16. */
  17. #include "includes.h"
  18. #include <assert.h>
  19. #include "common.h"
  20. #include "config.h"
  21. #include "eapol_supp/eapol_supp_sm.h"
  22. #include "eap_peer/eap.h"
  23. #include "eloop.h"
  24. #include "wpa.h"
  25. #include "eap_peer/eap_i.h"
  26. #include "wpa_supplicant_i.h"
  27. #include "radius/radius.h"
  28. #include "radius/radius_client.h"
  29. #include "ctrl_iface.h"
  30. #include "pcsc_funcs.h"
  31. extern int wpa_debug_level;
  32. extern int wpa_debug_show_keys;
  33. struct wpa_driver_ops *wpa_drivers[] = { NULL };
  34. struct extra_radius_attr {
  35. u8 type;
  36. char syntax;
  37. char *data;
  38. struct extra_radius_attr *next;
  39. };
  40. struct eapol_test_data {
  41. struct wpa_supplicant *wpa_s;
  42. int eapol_test_num_reauths;
  43. int no_mppe_keys;
  44. int num_mppe_ok, num_mppe_mismatch;
  45. u8 radius_identifier;
  46. struct radius_msg *last_recv_radius;
  47. struct in_addr own_ip_addr;
  48. struct radius_client_data *radius;
  49. struct hostapd_radius_servers *radius_conf;
  50. u8 *last_eap_radius; /* last received EAP Response from Authentication
  51. * Server */
  52. size_t last_eap_radius_len;
  53. u8 authenticator_pmk[PMK_LEN];
  54. size_t authenticator_pmk_len;
  55. int radius_access_accept_received;
  56. int radius_access_reject_received;
  57. int auth_timed_out;
  58. u8 *eap_identity;
  59. size_t eap_identity_len;
  60. char *connect_info;
  61. u8 own_addr[ETH_ALEN];
  62. struct extra_radius_attr *extra_attrs;
  63. };
  64. static struct eapol_test_data eapol_test;
  65. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx);
  66. static void hostapd_logger_cb(void *ctx, const u8 *addr, unsigned int module,
  67. int level, const char *txt, size_t len)
  68. {
  69. if (addr)
  70. wpa_printf(MSG_DEBUG, "STA " MACSTR ": %s\n",
  71. MAC2STR(addr), txt);
  72. else
  73. wpa_printf(MSG_DEBUG, "%s", txt);
  74. }
  75. static int add_extra_attr(struct radius_msg *msg,
  76. struct extra_radius_attr *attr)
  77. {
  78. size_t len;
  79. char *pos;
  80. u32 val;
  81. char buf[128];
  82. switch (attr->syntax) {
  83. case 's':
  84. os_snprintf(buf, sizeof(buf), "%s", attr->data);
  85. len = os_strlen(buf);
  86. break;
  87. case 'n':
  88. buf[0] = '\0';
  89. len = 1;
  90. break;
  91. case 'x':
  92. pos = attr->data;
  93. if (pos[0] == '0' && pos[1] == 'x')
  94. pos += 2;
  95. len = os_strlen(pos);
  96. if ((len & 1) || (len / 2) > sizeof(buf)) {
  97. printf("Invalid extra attribute hexstring\n");
  98. return -1;
  99. }
  100. len /= 2;
  101. if (hexstr2bin(pos, (u8 *) buf, len) < 0) {
  102. printf("Invalid extra attribute hexstring\n");
  103. return -1;
  104. }
  105. break;
  106. case 'd':
  107. val = htonl(atoi(attr->data));
  108. os_memcpy(buf, &val, 4);
  109. len = 4;
  110. break;
  111. default:
  112. printf("Incorrect extra attribute syntax specification\n");
  113. return -1;
  114. }
  115. if (!radius_msg_add_attr(msg, attr->type, (u8 *) buf, len)) {
  116. printf("Could not add attribute %d\n", attr->type);
  117. return -1;
  118. }
  119. return 0;
  120. }
  121. static int add_extra_attrs(struct radius_msg *msg,
  122. struct extra_radius_attr *attrs)
  123. {
  124. struct extra_radius_attr *p;
  125. for (p = attrs; p; p = p->next) {
  126. if (add_extra_attr(msg, p) < 0)
  127. return -1;
  128. }
  129. return 0;
  130. }
  131. static struct extra_radius_attr *
  132. find_extra_attr(struct extra_radius_attr *attrs, u8 type)
  133. {
  134. struct extra_radius_attr *p;
  135. for (p = attrs; p; p = p->next) {
  136. if (p->type == type)
  137. return p;
  138. }
  139. return NULL;
  140. }
  141. static void ieee802_1x_encapsulate_radius(struct eapol_test_data *e,
  142. const u8 *eap, size_t len)
  143. {
  144. struct radius_msg *msg;
  145. char buf[128];
  146. const struct eap_hdr *hdr;
  147. const u8 *pos;
  148. wpa_printf(MSG_DEBUG, "Encapsulating EAP message into a RADIUS "
  149. "packet");
  150. e->radius_identifier = radius_client_get_id(e->radius);
  151. msg = radius_msg_new(RADIUS_CODE_ACCESS_REQUEST,
  152. e->radius_identifier);
  153. if (msg == NULL) {
  154. printf("Could not create net RADIUS packet\n");
  155. return;
  156. }
  157. radius_msg_make_authenticator(msg, (u8 *) e, sizeof(*e));
  158. hdr = (const struct eap_hdr *) eap;
  159. pos = (const u8 *) (hdr + 1);
  160. if (len > sizeof(*hdr) && hdr->code == EAP_CODE_RESPONSE &&
  161. pos[0] == EAP_TYPE_IDENTITY) {
  162. pos++;
  163. os_free(e->eap_identity);
  164. e->eap_identity_len = len - sizeof(*hdr) - 1;
  165. e->eap_identity = os_malloc(e->eap_identity_len);
  166. if (e->eap_identity) {
  167. os_memcpy(e->eap_identity, pos, e->eap_identity_len);
  168. wpa_hexdump(MSG_DEBUG, "Learned identity from "
  169. "EAP-Response-Identity",
  170. e->eap_identity, e->eap_identity_len);
  171. }
  172. }
  173. if (e->eap_identity &&
  174. !radius_msg_add_attr(msg, RADIUS_ATTR_USER_NAME,
  175. e->eap_identity, e->eap_identity_len)) {
  176. printf("Could not add User-Name\n");
  177. goto fail;
  178. }
  179. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_IP_ADDRESS) &&
  180. !radius_msg_add_attr(msg, RADIUS_ATTR_NAS_IP_ADDRESS,
  181. (u8 *) &e->own_ip_addr, 4)) {
  182. printf("Could not add NAS-IP-Address\n");
  183. goto fail;
  184. }
  185. os_snprintf(buf, sizeof(buf), RADIUS_802_1X_ADDR_FORMAT,
  186. MAC2STR(e->wpa_s->own_addr));
  187. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CALLING_STATION_ID)
  188. &&
  189. !radius_msg_add_attr(msg, RADIUS_ATTR_CALLING_STATION_ID,
  190. (u8 *) buf, os_strlen(buf))) {
  191. printf("Could not add Calling-Station-Id\n");
  192. goto fail;
  193. }
  194. /* TODO: should probably check MTU from driver config; 2304 is max for
  195. * IEEE 802.11, but use 1400 to avoid problems with too large packets
  196. */
  197. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_FRAMED_MTU) &&
  198. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_FRAMED_MTU, 1400)) {
  199. printf("Could not add Framed-MTU\n");
  200. goto fail;
  201. }
  202. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_NAS_PORT_TYPE) &&
  203. !radius_msg_add_attr_int32(msg, RADIUS_ATTR_NAS_PORT_TYPE,
  204. RADIUS_NAS_PORT_TYPE_IEEE_802_11)) {
  205. printf("Could not add NAS-Port-Type\n");
  206. goto fail;
  207. }
  208. os_snprintf(buf, sizeof(buf), "%s", e->connect_info);
  209. if (!find_extra_attr(e->extra_attrs, RADIUS_ATTR_CONNECT_INFO) &&
  210. !radius_msg_add_attr(msg, RADIUS_ATTR_CONNECT_INFO,
  211. (u8 *) buf, os_strlen(buf))) {
  212. printf("Could not add Connect-Info\n");
  213. goto fail;
  214. }
  215. if (add_extra_attrs(msg, e->extra_attrs) < 0)
  216. goto fail;
  217. if (eap && !radius_msg_add_eap(msg, eap, len)) {
  218. printf("Could not add EAP-Message\n");
  219. goto fail;
  220. }
  221. /* State attribute must be copied if and only if this packet is
  222. * Access-Request reply to the previous Access-Challenge */
  223. if (e->last_recv_radius && e->last_recv_radius->hdr->code ==
  224. RADIUS_CODE_ACCESS_CHALLENGE) {
  225. int res = radius_msg_copy_attr(msg, e->last_recv_radius,
  226. RADIUS_ATTR_STATE);
  227. if (res < 0) {
  228. printf("Could not copy State attribute from previous "
  229. "Access-Challenge\n");
  230. goto fail;
  231. }
  232. if (res > 0) {
  233. wpa_printf(MSG_DEBUG, " Copied RADIUS State "
  234. "Attribute");
  235. }
  236. }
  237. radius_client_send(e->radius, msg, RADIUS_AUTH, e->wpa_s->own_addr);
  238. return;
  239. fail:
  240. radius_msg_free(msg);
  241. os_free(msg);
  242. }
  243. static int eapol_test_eapol_send(void *ctx, int type, const u8 *buf,
  244. size_t len)
  245. {
  246. /* struct wpa_supplicant *wpa_s = ctx; */
  247. printf("WPA: eapol_test_eapol_send(type=%d len=%lu)\n",
  248. type, (unsigned long) len);
  249. if (type == IEEE802_1X_TYPE_EAP_PACKET) {
  250. wpa_hexdump(MSG_DEBUG, "TX EAP -> RADIUS", buf, len);
  251. ieee802_1x_encapsulate_radius(&eapol_test, buf, len);
  252. }
  253. return 0;
  254. }
  255. static void eapol_test_set_config_blob(void *ctx,
  256. struct wpa_config_blob *blob)
  257. {
  258. struct wpa_supplicant *wpa_s = ctx;
  259. wpa_config_set_blob(wpa_s->conf, blob);
  260. }
  261. static const struct wpa_config_blob *
  262. eapol_test_get_config_blob(void *ctx, const char *name)
  263. {
  264. struct wpa_supplicant *wpa_s = ctx;
  265. return wpa_config_get_blob(wpa_s->conf, name);
  266. }
  267. static void eapol_test_eapol_done_cb(void *ctx)
  268. {
  269. printf("WPA: EAPOL processing complete\n");
  270. }
  271. static void eapol_sm_reauth(void *eloop_ctx, void *timeout_ctx)
  272. {
  273. struct eapol_test_data *e = eloop_ctx;
  274. printf("\n\n\n\n\neapol_test: Triggering EAP reauthentication\n\n");
  275. e->radius_access_accept_received = 0;
  276. send_eap_request_identity(e->wpa_s, NULL);
  277. }
  278. static int eapol_test_compare_pmk(struct eapol_test_data *e)
  279. {
  280. u8 pmk[PMK_LEN];
  281. int ret = 1;
  282. if (eapol_sm_get_key(e->wpa_s->eapol, pmk, PMK_LEN) == 0) {
  283. wpa_hexdump(MSG_DEBUG, "PMK from EAPOL", pmk, PMK_LEN);
  284. if (os_memcmp(pmk, e->authenticator_pmk, PMK_LEN) != 0) {
  285. printf("WARNING: PMK mismatch\n");
  286. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  287. e->authenticator_pmk, PMK_LEN);
  288. } else if (e->radius_access_accept_received)
  289. ret = 0;
  290. } else if (e->authenticator_pmk_len == 16 &&
  291. eapol_sm_get_key(e->wpa_s->eapol, pmk, 16) == 0) {
  292. wpa_hexdump(MSG_DEBUG, "LEAP PMK from EAPOL", pmk, 16);
  293. if (os_memcmp(pmk, e->authenticator_pmk, 16) != 0) {
  294. printf("WARNING: PMK mismatch\n");
  295. wpa_hexdump(MSG_DEBUG, "PMK from AS",
  296. e->authenticator_pmk, 16);
  297. } else if (e->radius_access_accept_received)
  298. ret = 0;
  299. } else if (e->radius_access_accept_received && e->no_mppe_keys) {
  300. /* No keying material expected */
  301. ret = 0;
  302. }
  303. if (ret && !e->no_mppe_keys)
  304. e->num_mppe_mismatch++;
  305. else if (!e->no_mppe_keys)
  306. e->num_mppe_ok++;
  307. return ret;
  308. }
  309. static void eapol_sm_cb(struct eapol_sm *eapol, int success, void *ctx)
  310. {
  311. struct eapol_test_data *e = ctx;
  312. printf("eapol_sm_cb: success=%d\n", success);
  313. e->eapol_test_num_reauths--;
  314. if (e->eapol_test_num_reauths < 0)
  315. eloop_terminate();
  316. else {
  317. eapol_test_compare_pmk(e);
  318. eloop_register_timeout(0, 100000, eapol_sm_reauth, e, NULL);
  319. }
  320. }
  321. static int test_eapol(struct eapol_test_data *e, struct wpa_supplicant *wpa_s,
  322. struct wpa_ssid *ssid)
  323. {
  324. struct eapol_config eapol_conf;
  325. struct eapol_ctx *ctx;
  326. ctx = os_zalloc(sizeof(*ctx));
  327. if (ctx == NULL) {
  328. printf("Failed to allocate EAPOL context.\n");
  329. return -1;
  330. }
  331. ctx->ctx = wpa_s;
  332. ctx->msg_ctx = wpa_s;
  333. ctx->scard_ctx = wpa_s->scard;
  334. ctx->cb = eapol_sm_cb;
  335. ctx->cb_ctx = e;
  336. ctx->eapol_send_ctx = wpa_s;
  337. ctx->preauth = 0;
  338. ctx->eapol_done_cb = eapol_test_eapol_done_cb;
  339. ctx->eapol_send = eapol_test_eapol_send;
  340. ctx->set_config_blob = eapol_test_set_config_blob;
  341. ctx->get_config_blob = eapol_test_get_config_blob;
  342. #ifdef EAP_TLS_OPENSSL
  343. ctx->opensc_engine_path = wpa_s->conf->opensc_engine_path;
  344. ctx->pkcs11_engine_path = wpa_s->conf->pkcs11_engine_path;
  345. ctx->pkcs11_module_path = wpa_s->conf->pkcs11_module_path;
  346. #endif /* EAP_TLS_OPENSSL */
  347. wpa_s->eapol = eapol_sm_init(ctx);
  348. if (wpa_s->eapol == NULL) {
  349. os_free(ctx);
  350. printf("Failed to initialize EAPOL state machines.\n");
  351. return -1;
  352. }
  353. wpa_s->current_ssid = ssid;
  354. os_memset(&eapol_conf, 0, sizeof(eapol_conf));
  355. eapol_conf.accept_802_1x_keys = 1;
  356. eapol_conf.required_keys = 0;
  357. eapol_conf.fast_reauth = wpa_s->conf->fast_reauth;
  358. eapol_conf.workaround = ssid->eap_workaround;
  359. eapol_sm_notify_config(wpa_s->eapol, &ssid->eap, &eapol_conf);
  360. eapol_sm_register_scard_ctx(wpa_s->eapol, wpa_s->scard);
  361. eapol_sm_notify_portValid(wpa_s->eapol, FALSE);
  362. /* 802.1X::portControl = Auto */
  363. eapol_sm_notify_portEnabled(wpa_s->eapol, TRUE);
  364. return 0;
  365. }
  366. static void test_eapol_clean(struct eapol_test_data *e,
  367. struct wpa_supplicant *wpa_s)
  368. {
  369. struct extra_radius_attr *p, *prev;
  370. radius_client_deinit(e->radius);
  371. os_free(e->last_eap_radius);
  372. if (e->last_recv_radius) {
  373. radius_msg_free(e->last_recv_radius);
  374. os_free(e->last_recv_radius);
  375. }
  376. os_free(e->eap_identity);
  377. e->eap_identity = NULL;
  378. eapol_sm_deinit(wpa_s->eapol);
  379. wpa_s->eapol = NULL;
  380. if (e->radius_conf && e->radius_conf->auth_server) {
  381. os_free(e->radius_conf->auth_server->shared_secret);
  382. os_free(e->radius_conf->auth_server);
  383. }
  384. os_free(e->radius_conf);
  385. e->radius_conf = NULL;
  386. scard_deinit(wpa_s->scard);
  387. if (wpa_s->ctrl_iface) {
  388. wpa_supplicant_ctrl_iface_deinit(wpa_s->ctrl_iface);
  389. wpa_s->ctrl_iface = NULL;
  390. }
  391. wpa_config_free(wpa_s->conf);
  392. p = e->extra_attrs;
  393. while (p) {
  394. prev = p;
  395. p = p->next;
  396. os_free(prev);
  397. }
  398. }
  399. static void send_eap_request_identity(void *eloop_ctx, void *timeout_ctx)
  400. {
  401. struct wpa_supplicant *wpa_s = eloop_ctx;
  402. u8 buf[100], *pos;
  403. struct ieee802_1x_hdr *hdr;
  404. struct eap_hdr *eap;
  405. hdr = (struct ieee802_1x_hdr *) buf;
  406. hdr->version = EAPOL_VERSION;
  407. hdr->type = IEEE802_1X_TYPE_EAP_PACKET;
  408. hdr->length = htons(5);
  409. eap = (struct eap_hdr *) (hdr + 1);
  410. eap->code = EAP_CODE_REQUEST;
  411. eap->identifier = 0;
  412. eap->length = htons(5);
  413. pos = (u8 *) (eap + 1);
  414. *pos = EAP_TYPE_IDENTITY;
  415. printf("Sending fake EAP-Request-Identity\n");
  416. eapol_sm_rx_eapol(wpa_s->eapol, wpa_s->bssid, buf,
  417. sizeof(*hdr) + 5);
  418. }
  419. static void eapol_test_timeout(void *eloop_ctx, void *timeout_ctx)
  420. {
  421. struct eapol_test_data *e = eloop_ctx;
  422. printf("EAPOL test timed out\n");
  423. e->auth_timed_out = 1;
  424. eloop_terminate();
  425. }
  426. static char *eap_type_text(u8 type)
  427. {
  428. switch (type) {
  429. case EAP_TYPE_IDENTITY: return "Identity";
  430. case EAP_TYPE_NOTIFICATION: return "Notification";
  431. case EAP_TYPE_NAK: return "Nak";
  432. case EAP_TYPE_TLS: return "TLS";
  433. case EAP_TYPE_TTLS: return "TTLS";
  434. case EAP_TYPE_PEAP: return "PEAP";
  435. case EAP_TYPE_SIM: return "SIM";
  436. case EAP_TYPE_GTC: return "GTC";
  437. case EAP_TYPE_MD5: return "MD5";
  438. case EAP_TYPE_OTP: return "OTP";
  439. case EAP_TYPE_FAST: return "FAST";
  440. case EAP_TYPE_SAKE: return "SAKE";
  441. case EAP_TYPE_PSK: return "PSK";
  442. default: return "Unknown";
  443. }
  444. }
  445. static void ieee802_1x_decapsulate_radius(struct eapol_test_data *e)
  446. {
  447. u8 *eap;
  448. size_t len;
  449. struct eap_hdr *hdr;
  450. int eap_type = -1;
  451. char buf[64];
  452. struct radius_msg *msg;
  453. if (e->last_recv_radius == NULL)
  454. return;
  455. msg = e->last_recv_radius;
  456. eap = radius_msg_get_eap(msg, &len);
  457. if (eap == NULL) {
  458. /* draft-aboba-radius-rfc2869bis-20.txt, Chap. 2.6.3:
  459. * RADIUS server SHOULD NOT send Access-Reject/no EAP-Message
  460. * attribute */
  461. wpa_printf(MSG_DEBUG, "could not extract "
  462. "EAP-Message from RADIUS message");
  463. os_free(e->last_eap_radius);
  464. e->last_eap_radius = NULL;
  465. e->last_eap_radius_len = 0;
  466. return;
  467. }
  468. if (len < sizeof(*hdr)) {
  469. wpa_printf(MSG_DEBUG, "too short EAP packet "
  470. "received from authentication server");
  471. os_free(eap);
  472. return;
  473. }
  474. if (len > sizeof(*hdr))
  475. eap_type = eap[sizeof(*hdr)];
  476. hdr = (struct eap_hdr *) eap;
  477. switch (hdr->code) {
  478. case EAP_CODE_REQUEST:
  479. os_snprintf(buf, sizeof(buf), "EAP-Request-%s (%d)",
  480. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  481. eap_type);
  482. break;
  483. case EAP_CODE_RESPONSE:
  484. os_snprintf(buf, sizeof(buf), "EAP Response-%s (%d)",
  485. eap_type >= 0 ? eap_type_text(eap_type) : "??",
  486. eap_type);
  487. break;
  488. case EAP_CODE_SUCCESS:
  489. os_strlcpy(buf, "EAP Success", sizeof(buf));
  490. /* LEAP uses EAP Success within an authentication, so must not
  491. * stop here with eloop_terminate(); */
  492. break;
  493. case EAP_CODE_FAILURE:
  494. os_strlcpy(buf, "EAP Failure", sizeof(buf));
  495. eloop_terminate();
  496. break;
  497. default:
  498. os_strlcpy(buf, "unknown EAP code", sizeof(buf));
  499. wpa_hexdump(MSG_DEBUG, "Decapsulated EAP packet", eap, len);
  500. break;
  501. }
  502. wpa_printf(MSG_DEBUG, "decapsulated EAP packet (code=%d "
  503. "id=%d len=%d) from RADIUS server: %s",
  504. hdr->code, hdr->identifier, ntohs(hdr->length), buf);
  505. /* sta->eapol_sm->be_auth.idFromServer = hdr->identifier; */
  506. os_free(e->last_eap_radius);
  507. e->last_eap_radius = eap;
  508. e->last_eap_radius_len = len;
  509. {
  510. struct ieee802_1x_hdr *dot1x;
  511. dot1x = os_malloc(sizeof(*dot1x) + len);
  512. assert(dot1x != NULL);
  513. dot1x->version = EAPOL_VERSION;
  514. dot1x->type = IEEE802_1X_TYPE_EAP_PACKET;
  515. dot1x->length = htons(len);
  516. os_memcpy((u8 *) (dot1x + 1), eap, len);
  517. eapol_sm_rx_eapol(e->wpa_s->eapol, e->wpa_s->bssid,
  518. (u8 *) dot1x, sizeof(*dot1x) + len);
  519. os_free(dot1x);
  520. }
  521. }
  522. static void ieee802_1x_get_keys(struct eapol_test_data *e,
  523. struct radius_msg *msg, struct radius_msg *req,
  524. const u8 *shared_secret,
  525. size_t shared_secret_len)
  526. {
  527. struct radius_ms_mppe_keys *keys;
  528. keys = radius_msg_get_ms_keys(msg, req, shared_secret,
  529. shared_secret_len);
  530. if (keys && keys->send == NULL && keys->recv == NULL) {
  531. os_free(keys);
  532. keys = radius_msg_get_cisco_keys(msg, req, shared_secret,
  533. shared_secret_len);
  534. }
  535. if (keys) {
  536. if (keys->send) {
  537. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Send-Key (sign)",
  538. keys->send, keys->send_len);
  539. }
  540. if (keys->recv) {
  541. wpa_hexdump(MSG_DEBUG, "MS-MPPE-Recv-Key (crypt)",
  542. keys->recv, keys->recv_len);
  543. e->authenticator_pmk_len =
  544. keys->recv_len > PMK_LEN ? PMK_LEN :
  545. keys->recv_len;
  546. os_memcpy(e->authenticator_pmk, keys->recv,
  547. e->authenticator_pmk_len);
  548. if (e->authenticator_pmk_len == 16 && keys->send &&
  549. keys->send_len == 16) {
  550. /* MS-CHAP-v2 derives 16 octet keys */
  551. wpa_printf(MSG_DEBUG, "Use MS-MPPE-Send-Key "
  552. "to extend PMK to 32 octets");
  553. os_memcpy(e->authenticator_pmk +
  554. e->authenticator_pmk_len,
  555. keys->send, keys->send_len);
  556. e->authenticator_pmk_len += keys->send_len;
  557. }
  558. }
  559. os_free(keys->send);
  560. os_free(keys->recv);
  561. os_free(keys);
  562. }
  563. }
  564. /* Process the RADIUS frames from Authentication Server */
  565. static RadiusRxResult
  566. ieee802_1x_receive_auth(struct radius_msg *msg, struct radius_msg *req,
  567. const u8 *shared_secret, size_t shared_secret_len,
  568. void *data)
  569. {
  570. struct eapol_test_data *e = data;
  571. /* RFC 2869, Ch. 5.13: valid Message-Authenticator attribute MUST be
  572. * present when packet contains an EAP-Message attribute */
  573. if (msg->hdr->code == RADIUS_CODE_ACCESS_REJECT &&
  574. radius_msg_get_attr(msg, RADIUS_ATTR_MESSAGE_AUTHENTICATOR, NULL,
  575. 0) < 0 &&
  576. radius_msg_get_attr(msg, RADIUS_ATTR_EAP_MESSAGE, NULL, 0) < 0) {
  577. wpa_printf(MSG_DEBUG, "Allowing RADIUS "
  578. "Access-Reject without Message-Authenticator "
  579. "since it does not include EAP-Message\n");
  580. } else if (radius_msg_verify(msg, shared_secret, shared_secret_len,
  581. req, 1)) {
  582. printf("Incoming RADIUS packet did not have correct "
  583. "Message-Authenticator - dropped\n");
  584. return RADIUS_RX_UNKNOWN;
  585. }
  586. if (msg->hdr->code != RADIUS_CODE_ACCESS_ACCEPT &&
  587. msg->hdr->code != RADIUS_CODE_ACCESS_REJECT &&
  588. msg->hdr->code != RADIUS_CODE_ACCESS_CHALLENGE) {
  589. printf("Unknown RADIUS message code\n");
  590. return RADIUS_RX_UNKNOWN;
  591. }
  592. e->radius_identifier = -1;
  593. wpa_printf(MSG_DEBUG, "RADIUS packet matching with station");
  594. if (e->last_recv_radius) {
  595. radius_msg_free(e->last_recv_radius);
  596. os_free(e->last_recv_radius);
  597. }
  598. e->last_recv_radius = msg;
  599. switch (msg->hdr->code) {
  600. case RADIUS_CODE_ACCESS_ACCEPT:
  601. e->radius_access_accept_received = 1;
  602. ieee802_1x_get_keys(e, msg, req, shared_secret,
  603. shared_secret_len);
  604. break;
  605. case RADIUS_CODE_ACCESS_REJECT:
  606. e->radius_access_reject_received = 1;
  607. break;
  608. }
  609. ieee802_1x_decapsulate_radius(e);
  610. if ((msg->hdr->code == RADIUS_CODE_ACCESS_ACCEPT &&
  611. e->eapol_test_num_reauths < 0) ||
  612. msg->hdr->code == RADIUS_CODE_ACCESS_REJECT) {
  613. eloop_terminate();
  614. }
  615. return RADIUS_RX_QUEUED;
  616. }
  617. static void wpa_init_conf(struct eapol_test_data *e,
  618. struct wpa_supplicant *wpa_s, const char *authsrv,
  619. int port, const char *secret,
  620. const char *cli_addr)
  621. {
  622. struct hostapd_radius_server *as;
  623. int res;
  624. wpa_s->bssid[5] = 1;
  625. os_memcpy(wpa_s->own_addr, e->own_addr, ETH_ALEN);
  626. e->own_ip_addr.s_addr = htonl((127 << 24) | 1);
  627. os_strlcpy(wpa_s->ifname, "test", sizeof(wpa_s->ifname));
  628. e->radius_conf = os_zalloc(sizeof(struct hostapd_radius_servers));
  629. assert(e->radius_conf != NULL);
  630. e->radius_conf->num_auth_servers = 1;
  631. as = os_zalloc(sizeof(struct hostapd_radius_server));
  632. assert(as != NULL);
  633. #if defined(CONFIG_NATIVE_WINDOWS) || defined(CONFIG_ANSI_C_EXTRA)
  634. {
  635. int a[4];
  636. u8 *pos;
  637. sscanf(authsrv, "%d.%d.%d.%d", &a[0], &a[1], &a[2], &a[3]);
  638. pos = (u8 *) &as->addr.u.v4;
  639. *pos++ = a[0];
  640. *pos++ = a[1];
  641. *pos++ = a[2];
  642. *pos++ = a[3];
  643. }
  644. #else /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  645. inet_aton(authsrv, &as->addr.u.v4);
  646. #endif /* CONFIG_NATIVE_WINDOWS or CONFIG_ANSI_C_EXTRA */
  647. as->addr.af = AF_INET;
  648. as->port = port;
  649. as->shared_secret = (u8 *) os_strdup(secret);
  650. as->shared_secret_len = os_strlen(secret);
  651. e->radius_conf->auth_server = as;
  652. e->radius_conf->auth_servers = as;
  653. e->radius_conf->msg_dumps = 1;
  654. if (cli_addr) {
  655. if (hostapd_parse_ip_addr(cli_addr,
  656. &e->radius_conf->client_addr) == 0)
  657. e->radius_conf->force_client_addr = 1;
  658. else {
  659. wpa_printf(MSG_ERROR, "Invalid IP address '%s'",
  660. cli_addr);
  661. assert(0);
  662. }
  663. }
  664. e->radius = radius_client_init(wpa_s, e->radius_conf);
  665. assert(e->radius != NULL);
  666. res = radius_client_register(e->radius, RADIUS_AUTH,
  667. ieee802_1x_receive_auth, e);
  668. assert(res == 0);
  669. }
  670. static int scard_test(void)
  671. {
  672. struct scard_data *scard;
  673. size_t len;
  674. char imsi[20];
  675. unsigned char _rand[16];
  676. #ifdef PCSC_FUNCS
  677. unsigned char sres[4];
  678. unsigned char kc[8];
  679. #endif /* PCSC_FUNCS */
  680. #define num_triplets 5
  681. unsigned char rand_[num_triplets][16];
  682. unsigned char sres_[num_triplets][4];
  683. unsigned char kc_[num_triplets][8];
  684. int i, res;
  685. size_t j;
  686. #define AKA_RAND_LEN 16
  687. #define AKA_AUTN_LEN 16
  688. #define AKA_AUTS_LEN 14
  689. #define RES_MAX_LEN 16
  690. #define IK_LEN 16
  691. #define CK_LEN 16
  692. unsigned char aka_rand[AKA_RAND_LEN];
  693. unsigned char aka_autn[AKA_AUTN_LEN];
  694. unsigned char aka_auts[AKA_AUTS_LEN];
  695. unsigned char aka_res[RES_MAX_LEN];
  696. size_t aka_res_len;
  697. unsigned char aka_ik[IK_LEN];
  698. unsigned char aka_ck[CK_LEN];
  699. scard = scard_init(SCARD_TRY_BOTH);
  700. if (scard == NULL)
  701. return -1;
  702. if (scard_set_pin(scard, "1234")) {
  703. wpa_printf(MSG_WARNING, "PIN validation failed");
  704. scard_deinit(scard);
  705. return -1;
  706. }
  707. len = sizeof(imsi);
  708. if (scard_get_imsi(scard, imsi, &len))
  709. goto failed;
  710. wpa_hexdump_ascii(MSG_DEBUG, "SCARD: IMSI", (u8 *) imsi, len);
  711. /* NOTE: Permanent Username: 1 | IMSI */
  712. os_memset(_rand, 0, sizeof(_rand));
  713. if (scard_gsm_auth(scard, _rand, sres, kc))
  714. goto failed;
  715. os_memset(_rand, 0xff, sizeof(_rand));
  716. if (scard_gsm_auth(scard, _rand, sres, kc))
  717. goto failed;
  718. for (i = 0; i < num_triplets; i++) {
  719. os_memset(rand_[i], i, sizeof(rand_[i]));
  720. if (scard_gsm_auth(scard, rand_[i], sres_[i], kc_[i]))
  721. goto failed;
  722. }
  723. for (i = 0; i < num_triplets; i++) {
  724. printf("1");
  725. for (j = 0; j < len; j++)
  726. printf("%c", imsi[j]);
  727. printf(",");
  728. for (j = 0; j < 16; j++)
  729. printf("%02X", rand_[i][j]);
  730. printf(",");
  731. for (j = 0; j < 4; j++)
  732. printf("%02X", sres_[i][j]);
  733. printf(",");
  734. for (j = 0; j < 8; j++)
  735. printf("%02X", kc_[i][j]);
  736. printf("\n");
  737. }
  738. wpa_printf(MSG_DEBUG, "Trying to use UMTS authentication");
  739. /* seq 39 (0x28) */
  740. os_memset(aka_rand, 0xaa, 16);
  741. os_memcpy(aka_autn, "\x86\x71\x31\xcb\xa2\xfc\x61\xdf"
  742. "\xa3\xb3\x97\x9d\x07\x32\xa2\x12", 16);
  743. res = scard_umts_auth(scard, aka_rand, aka_autn, aka_res, &aka_res_len,
  744. aka_ik, aka_ck, aka_auts);
  745. if (res == 0) {
  746. wpa_printf(MSG_DEBUG, "UMTS auth completed successfully");
  747. wpa_hexdump(MSG_DEBUG, "RES", aka_res, aka_res_len);
  748. wpa_hexdump(MSG_DEBUG, "IK", aka_ik, IK_LEN);
  749. wpa_hexdump(MSG_DEBUG, "CK", aka_ck, CK_LEN);
  750. } else if (res == -2) {
  751. wpa_printf(MSG_DEBUG, "UMTS auth resulted in synchronization "
  752. "failure");
  753. wpa_hexdump(MSG_DEBUG, "AUTS", aka_auts, AKA_AUTS_LEN);
  754. } else {
  755. wpa_printf(MSG_DEBUG, "UMTS auth failed");
  756. }
  757. failed:
  758. scard_deinit(scard);
  759. return 0;
  760. #undef num_triplets
  761. }
  762. static int scard_get_triplets(int argc, char *argv[])
  763. {
  764. struct scard_data *scard;
  765. size_t len;
  766. char imsi[20];
  767. unsigned char _rand[16];
  768. unsigned char sres[4];
  769. unsigned char kc[8];
  770. int num_triplets;
  771. int i;
  772. size_t j;
  773. if (argc < 2 || ((num_triplets = atoi(argv[1])) <= 0)) {
  774. printf("invalid parameters for sim command\n");
  775. return -1;
  776. }
  777. if (argc <= 2 || os_strcmp(argv[2], "debug") != 0) {
  778. /* disable debug output */
  779. wpa_debug_level = 99;
  780. }
  781. scard = scard_init(SCARD_GSM_SIM_ONLY);
  782. if (scard == NULL) {
  783. printf("Failed to open smartcard connection\n");
  784. return -1;
  785. }
  786. if (scard_set_pin(scard, argv[0])) {
  787. wpa_printf(MSG_WARNING, "PIN validation failed");
  788. scard_deinit(scard);
  789. return -1;
  790. }
  791. len = sizeof(imsi);
  792. if (scard_get_imsi(scard, imsi, &len)) {
  793. scard_deinit(scard);
  794. return -1;
  795. }
  796. for (i = 0; i < num_triplets; i++) {
  797. os_memset(_rand, i, sizeof(_rand));
  798. if (scard_gsm_auth(scard, _rand, sres, kc))
  799. break;
  800. /* IMSI:Kc:SRES:RAND */
  801. for (j = 0; j < len; j++)
  802. printf("%c", imsi[j]);
  803. printf(":");
  804. for (j = 0; j < 8; j++)
  805. printf("%02X", kc[j]);
  806. printf(":");
  807. for (j = 0; j < 4; j++)
  808. printf("%02X", sres[j]);
  809. printf(":");
  810. for (j = 0; j < 16; j++)
  811. printf("%02X", _rand[j]);
  812. printf("\n");
  813. }
  814. scard_deinit(scard);
  815. return 0;
  816. }
  817. static void eapol_test_terminate(int sig, void *eloop_ctx,
  818. void *signal_ctx)
  819. {
  820. struct wpa_supplicant *wpa_s = eloop_ctx;
  821. wpa_msg(wpa_s, MSG_INFO, "Signal %d received - terminating", sig);
  822. eloop_terminate();
  823. }
  824. static void usage(void)
  825. {
  826. printf("usage:\n"
  827. "eapol_test [-nWS] -c<conf> [-a<AS IP>] [-p<AS port>] "
  828. "[-s<AS secret>]\\\n"
  829. " [-r<count>] [-t<timeout>] [-C<Connect-Info>] \\\n"
  830. " [-M<client MAC address>] \\\n"
  831. " [-N<attr spec>] \\\n"
  832. " [-A<client IP>]\n"
  833. "eapol_test scard\n"
  834. "eapol_test sim <PIN> <num triplets> [debug]\n"
  835. "\n");
  836. printf("options:\n"
  837. " -c<conf> = configuration file\n"
  838. " -a<AS IP> = IP address of the authentication server, "
  839. "default 127.0.0.1\n"
  840. " -p<AS port> = UDP port of the authentication server, "
  841. "default 1812\n"
  842. " -s<AS secret> = shared secret with the authentication "
  843. "server, default 'radius'\n"
  844. " -A<client IP> = IP address of the client, default: select "
  845. "automatically\n"
  846. " -r<count> = number of re-authentications\n"
  847. " -W = wait for a control interface monitor before starting\n"
  848. " -S = save configuration after authentication\n"
  849. " -n = no MPPE keys expected\n"
  850. " -t<timeout> = sets timeout in seconds (default: 30 s)\n"
  851. " -C<Connect-Info> = RADIUS Connect-Info (default: "
  852. "CONNECT 11Mbps 802.11b)\n"
  853. " -M<client MAC address> = Set own MAC address "
  854. "(Calling-Station-Id,\n"
  855. " default: 02:00:00:00:00:01)\n"
  856. " -N<attr spec> = send arbitrary attribute specified by:\n"
  857. " attr_id:syntax:value or attr_id\n"
  858. " attr_id - number id of the attribute\n"
  859. " syntax - one of: s, d, x\n"
  860. " s = string\n"
  861. " d = integer\n"
  862. " x = octet string\n"
  863. " value - attribute value.\n"
  864. " When only attr_id is specified, NULL will be used as "
  865. "value.\n"
  866. " Multiple attributes can be specified by using the "
  867. "option several times.\n");
  868. }
  869. int main(int argc, char *argv[])
  870. {
  871. struct wpa_supplicant wpa_s;
  872. int c, ret = 1, wait_for_monitor = 0, save_config = 0;
  873. char *as_addr = "127.0.0.1";
  874. int as_port = 1812;
  875. char *as_secret = "radius";
  876. char *cli_addr = NULL;
  877. char *conf = NULL;
  878. int timeout = 30;
  879. char *pos;
  880. struct extra_radius_attr *p = NULL, *p1;
  881. if (os_program_init())
  882. return -1;
  883. hostapd_logger_register_cb(hostapd_logger_cb);
  884. os_memset(&eapol_test, 0, sizeof(eapol_test));
  885. eapol_test.connect_info = "CONNECT 11Mbps 802.11b";
  886. os_memcpy(eapol_test.own_addr, "\x02\x00\x00\x00\x00\x01", ETH_ALEN);
  887. wpa_debug_level = 0;
  888. wpa_debug_show_keys = 1;
  889. for (;;) {
  890. c = getopt(argc, argv, "a:A:c:C:M:nN:p:r:s:St:W");
  891. if (c < 0)
  892. break;
  893. switch (c) {
  894. case 'a':
  895. as_addr = optarg;
  896. break;
  897. case 'A':
  898. cli_addr = optarg;
  899. break;
  900. case 'c':
  901. conf = optarg;
  902. break;
  903. case 'C':
  904. eapol_test.connect_info = optarg;
  905. break;
  906. case 'M':
  907. if (hwaddr_aton(optarg, eapol_test.own_addr)) {
  908. usage();
  909. return -1;
  910. }
  911. break;
  912. case 'n':
  913. eapol_test.no_mppe_keys++;
  914. break;
  915. case 'p':
  916. as_port = atoi(optarg);
  917. break;
  918. case 'r':
  919. eapol_test.eapol_test_num_reauths = atoi(optarg);
  920. break;
  921. case 's':
  922. as_secret = optarg;
  923. break;
  924. case 'S':
  925. save_config++;
  926. break;
  927. case 't':
  928. timeout = atoi(optarg);
  929. break;
  930. case 'W':
  931. wait_for_monitor++;
  932. break;
  933. case 'N':
  934. p1 = os_zalloc(sizeof(p1));
  935. if (p1 == NULL)
  936. break;
  937. if (!p)
  938. eapol_test.extra_attrs = p1;
  939. else
  940. p->next = p1;
  941. p = p1;
  942. p->type = atoi(optarg);
  943. pos = os_strchr(optarg, ':');
  944. if (pos == NULL) {
  945. p->syntax = 'n';
  946. p->data = NULL;
  947. break;
  948. }
  949. pos++;
  950. if (pos[0] == '\0' || pos[1] != ':') {
  951. printf("Incorrect format of attribute "
  952. "specification\n");
  953. break;
  954. }
  955. p->syntax = pos[0];
  956. p->data = pos + 2;
  957. break;
  958. default:
  959. usage();
  960. return -1;
  961. }
  962. }
  963. if (argc > optind && os_strcmp(argv[optind], "scard") == 0) {
  964. return scard_test();
  965. }
  966. if (argc > optind && os_strcmp(argv[optind], "sim") == 0) {
  967. return scard_get_triplets(argc - optind - 1,
  968. &argv[optind + 1]);
  969. }
  970. if (conf == NULL) {
  971. usage();
  972. printf("Configuration file is required.\n");
  973. return -1;
  974. }
  975. if (eap_peer_register_methods()) {
  976. wpa_printf(MSG_ERROR, "Failed to register EAP methods");
  977. return -1;
  978. }
  979. if (eloop_init(&wpa_s)) {
  980. wpa_printf(MSG_ERROR, "Failed to initialize event loop");
  981. return -1;
  982. }
  983. os_memset(&wpa_s, 0, sizeof(wpa_s));
  984. eapol_test.wpa_s = &wpa_s;
  985. wpa_s.conf = wpa_config_read(conf);
  986. if (wpa_s.conf == NULL) {
  987. printf("Failed to parse configuration file '%s'.\n", conf);
  988. return -1;
  989. }
  990. if (wpa_s.conf->ssid == NULL) {
  991. printf("No networks defined.\n");
  992. return -1;
  993. }
  994. wpa_init_conf(&eapol_test, &wpa_s, as_addr, as_port, as_secret,
  995. cli_addr);
  996. wpa_s.ctrl_iface = wpa_supplicant_ctrl_iface_init(&wpa_s);
  997. if (wpa_s.ctrl_iface == NULL) {
  998. printf("Failed to initialize control interface '%s'.\n"
  999. "You may have another eapol_test process already "
  1000. "running or the file was\n"
  1001. "left by an unclean termination of eapol_test in "
  1002. "which case you will need\n"
  1003. "to manually remove this file before starting "
  1004. "eapol_test again.\n",
  1005. wpa_s.conf->ctrl_interface);
  1006. return -1;
  1007. }
  1008. if (wpa_supplicant_scard_init(&wpa_s, wpa_s.conf->ssid))
  1009. return -1;
  1010. if (test_eapol(&eapol_test, &wpa_s, wpa_s.conf->ssid))
  1011. return -1;
  1012. if (wait_for_monitor)
  1013. wpa_supplicant_ctrl_iface_wait(wpa_s.ctrl_iface);
  1014. eloop_register_timeout(timeout, 0, eapol_test_timeout, &eapol_test,
  1015. NULL);
  1016. eloop_register_timeout(0, 0, send_eap_request_identity, &wpa_s, NULL);
  1017. eloop_register_signal_terminate(eapol_test_terminate, NULL);
  1018. eloop_register_signal_reconfig(eapol_test_terminate, NULL);
  1019. eloop_run();
  1020. eloop_cancel_timeout(eapol_test_timeout, &eapol_test, NULL);
  1021. eloop_cancel_timeout(eapol_sm_reauth, &eapol_test, NULL);
  1022. if (eapol_test_compare_pmk(&eapol_test) == 0 ||
  1023. eapol_test.no_mppe_keys)
  1024. ret = 0;
  1025. if (eapol_test.auth_timed_out)
  1026. ret = -2;
  1027. if (eapol_test.radius_access_reject_received)
  1028. ret = -3;
  1029. if (save_config)
  1030. wpa_config_write(conf, wpa_s.conf);
  1031. test_eapol_clean(&eapol_test, &wpa_s);
  1032. eap_peer_unregister_methods();
  1033. eloop_destroy();
  1034. printf("MPPE keys OK: %d mismatch: %d\n",
  1035. eapol_test.num_mppe_ok, eapol_test.num_mppe_mismatch);
  1036. if (eapol_test.num_mppe_mismatch)
  1037. ret = -4;
  1038. if (ret)
  1039. printf("FAILURE\n");
  1040. else
  1041. printf("SUCCESS\n");
  1042. os_program_deinit();
  1043. return ret;
  1044. }