80_all_eaptls-mppe-0.994-gentoo.patch 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899
  1. Taken from http://www.nikhef.nl/~janjust/ppp/ and modified to fit for
  2. ppp-2.4.6
  3. --- ppp-2.4.6/etc.ppp/eaptls-client
  4. +++ ppp-2.4.6/etc.ppp/eaptls-client
  5. @@ -0,0 +1,10 @@
  6. +# Parameters for authentication using EAP-TLS (client)
  7. +
  8. +# client name (can be *)
  9. +# server name (can be *)
  10. +# client certificate file (required)
  11. +# server certificate file (optional, if unused put '-')
  12. +# CA certificate file (required)
  13. +# client private key file (required)
  14. +
  15. +#client server /root/cert/client.crt - /root/cert/ca.crt /root/cert/client.key
  16. --- ppp-2.4.6/etc.ppp/eaptls-server
  17. +++ ppp-2.4.6/etc.ppp/eaptls-server
  18. @@ -0,0 +1,11 @@
  19. +# Parameters for authentication using EAP-TLS (server)
  20. +
  21. +# client name (can be *)
  22. +# server name (can be *)
  23. +# client certificate file (optional, if unused put '-')
  24. +# server certificate file (required)
  25. +# CA certificate file (required)
  26. +# server private key file (required)
  27. +# allowed addresses (required, can be *)
  28. +
  29. +#client server - /root/cert/server.crt /root/cert/ca.crt /root/cert/server.key 192.168.1.0/24
  30. --- ppp-2.4.6/etc.ppp/openssl.cnf
  31. +++ ppp-2.4.6/etc.ppp/openssl.cnf
  32. @@ -0,0 +1,14 @@
  33. +openssl_conf = openssl_def
  34. +
  35. +[ openssl_def ]
  36. +engines = engine_section
  37. +
  38. +[ engine_section ]
  39. +pkcs11 = pkcs11_section
  40. +
  41. +[ pkcs11_section ]
  42. +engine_id = pkcs11
  43. +dynamic_path = /usr/lib64/openssl/engines/engine_pkcs11.so
  44. +MODULE_PATH = /usr/lib64/libeTPkcs11.so
  45. +init = 0
  46. +
  47. --- ppp-2.4.6/linux/Makefile.top
  48. +++ ppp-2.4.6/linux/Makefile.top
  49. @@ -26,7 +26,7 @@
  50. cd pppdump; $(MAKE) $(MFLAGS) install
  51. install-etcppp: $(ETCDIR) $(ETCDIR)/options $(ETCDIR)/pap-secrets \
  52. - $(ETCDIR)/chap-secrets
  53. + $(ETCDIR)/chap-secrets $(ETCDIR)/eaptls-server $(ETCDIR)/eaptls-client
  54. install-devel:
  55. cd pppd; $(MAKE) $(MFLAGS) install-devel
  56. @@ -37,6 +37,10 @@
  57. $(INSTALL) -c -m 600 etc.ppp/pap-secrets $@
  58. $(ETCDIR)/chap-secrets:
  59. $(INSTALL) -c -m 600 etc.ppp/chap-secrets $@
  60. +$(ETCDIR)/eaptls-server:
  61. + $(INSTALL) -c -m 600 etc.ppp/eaptls-server $@
  62. +$(ETCDIR)/eaptls-client:
  63. + $(INSTALL) -c -m 600 etc.ppp/eaptls-client $@
  64. $(BINDIR):
  65. $(INSTALL) -d -m 755 $@
  66. --- ppp-2.4.6/pppd/auth.c
  67. +++ ppp-2.4.6/pppd/auth.c
  68. @@ -109,6 +109,9 @@
  69. #include "upap.h"
  70. #include "chap-new.h"
  71. #include "eap.h"
  72. +#ifdef USE_EAPTLS
  73. +#include "eap-tls.h"
  74. +#endif
  75. #ifdef CBCP_SUPPORT
  76. #include "cbcp.h"
  77. #endif
  78. @@ -183,6 +186,11 @@
  79. /* Hook for a plugin to get the CHAP password for authenticating us */
  80. int (*chap_passwd_hook) __P((char *user, char *passwd)) = NULL;
  81. +#ifdef USE_EAPTLS
  82. +/* Hook for a plugin to get the EAP-TLS password for authenticating us */
  83. +int (*eaptls_passwd_hook) __P((char *user, char *passwd)) = NULL;
  84. +#endif
  85. +
  86. /* Hook for a plugin to say whether it is OK if the peer
  87. refuses to authenticate. */
  88. int (*null_auth_hook) __P((struct wordlist **paddrs,
  89. @@ -238,6 +246,13 @@
  90. bool explicit_user = 0; /* Set if "user" option supplied */
  91. bool explicit_passwd = 0; /* Set if "password" option supplied */
  92. char remote_name[MAXNAMELEN]; /* Peer's name for authentication */
  93. +#ifdef USE_EAPTLS
  94. +char *cacert_file = NULL; /* CA certificate file (pem format) */
  95. +char *cert_file = NULL; /* client certificate file (pem format) */
  96. +char *privkey_file = NULL; /* client private key file (pem format) */
  97. +char *crl_dir = NULL; /* directory containing CRL files */
  98. +bool need_peer_eap = 0; /* Require peer to authenticate us */
  99. +#endif
  100. static char *uafname; /* name of most recent +ua file */
  101. @@ -254,6 +269,19 @@
  102. static int have_chap_secret __P((char *, char *, int, int *));
  103. static int have_srp_secret __P((char *client, char *server, int need_ip,
  104. int *lacks_ipp));
  105. +
  106. +#ifdef USE_EAPTLS
  107. +static int have_eaptls_secret_server
  108. +__P((char *client, char *server, int need_ip, int *lacks_ipp));
  109. +static int have_eaptls_secret_client __P((char *client, char *server));
  110. +static int scan_authfile_eaptls __P((FILE * f, char *client, char *server,
  111. + char *cli_cert, char *serv_cert,
  112. + char *ca_cert, char *pk,
  113. + struct wordlist ** addrs,
  114. + struct wordlist ** opts,
  115. + char *filename, int flags));
  116. +#endif
  117. +
  118. static int ip_addr_check __P((u_int32_t, struct permitted_ip *));
  119. static int scan_authfile __P((FILE *, char *, char *, char *,
  120. struct wordlist **, struct wordlist **,
  121. @@ -401,6 +429,14 @@
  122. "Set telephone number(s) which are allowed to connect",
  123. OPT_PRIV | OPT_A2LIST },
  124. +#ifdef USE_EAPTLS
  125. + { "ca", o_string, &cacert_file, "EAP-TLS CA certificate in PEM format" },
  126. + { "cert", o_string, &cert_file, "EAP-TLS client certificate in PEM format" },
  127. + { "key", o_string, &privkey_file, "EAP-TLS client private key in PEM format" },
  128. + { "crl-dir", o_string, &crl_dir, "Use CRLs in directory" },
  129. + { "need-peer-eap", o_bool, &need_peer_eap,
  130. + "Require the peer to authenticate us", 1 },
  131. +#endif /* USE_EAPTLS */
  132. { NULL }
  133. };
  134. @@ -730,6 +766,9 @@
  135. lcp_options *wo = &lcp_wantoptions[unit];
  136. lcp_options *go = &lcp_gotoptions[unit];
  137. lcp_options *ho = &lcp_hisoptions[unit];
  138. +#ifdef USE_EAPTLS
  139. + lcp_options *ao = &lcp_allowoptions[unit];
  140. +#endif
  141. int i;
  142. struct protent *protp;
  143. @@ -764,6 +803,22 @@
  144. }
  145. }
  146. +#ifdef USE_EAPTLS
  147. + if (need_peer_eap && !ao->neg_eap) {
  148. + warn("eap required to authenticate us but no suitable secrets");
  149. + lcp_close(unit, "couldn't negotiate eap");
  150. + status = EXIT_AUTH_TOPEER_FAILED;
  151. + return;
  152. + }
  153. +
  154. + if (need_peer_eap && !ho->neg_eap) {
  155. + warn("peer doesn't want to authenticate us with eap");
  156. + lcp_close(unit, "couldn't negotiate eap");
  157. + status = EXIT_PEER_AUTH_FAILED;
  158. + return;
  159. + }
  160. +#endif
  161. +
  162. new_phase(PHASE_AUTHENTICATE);
  163. auth = 0;
  164. if (go->neg_eap) {
  165. @@ -1277,6 +1332,15 @@
  166. our_name, 1, &lacks_ip);
  167. }
  168. +#ifdef USE_EAPTLS
  169. + if (!can_auth && wo->neg_eap) {
  170. + can_auth =
  171. + have_eaptls_secret_server((explicit_remote ? remote_name :
  172. + NULL), our_name, 1, &lacks_ip);
  173. +
  174. + }
  175. +#endif
  176. +
  177. if (auth_required && !can_auth && noauth_addrs == NULL) {
  178. if (default_auth) {
  179. option_error(
  180. @@ -1331,7 +1395,11 @@
  181. passwd[0] != 0 ||
  182. (hadchap == 1 || (hadchap == -1 && have_chap_secret(user,
  183. (explicit_remote? remote_name: NULL), 0, NULL))) ||
  184. - have_srp_secret(user, (explicit_remote? remote_name: NULL), 0, NULL));
  185. + have_srp_secret(user, (explicit_remote? remote_name: NULL), 0, NULL)
  186. +#ifdef USE_EAPTLS
  187. + || have_eaptls_secret_client(user, (explicit_remote? remote_name: NULL))
  188. +#endif
  189. + );
  190. hadchap = -1;
  191. if (go->neg_upap && !uselogin && !have_pap_secret(NULL))
  192. @@ -1346,8 +1414,14 @@
  193. !have_chap_secret((explicit_remote? remote_name: NULL), our_name,
  194. 1, NULL))) &&
  195. !have_srp_secret((explicit_remote? remote_name: NULL), our_name, 1,
  196. - NULL))
  197. + NULL)
  198. +#ifdef USE_EAPTLS
  199. + && !have_eaptls_secret_server((explicit_remote? remote_name: NULL),
  200. + our_name, 1, NULL)
  201. +#endif
  202. + )
  203. go->neg_eap = 0;
  204. +
  205. }
  206. @@ -1707,6 +1781,7 @@
  207. }
  208. +
  209. /*
  210. * get_secret - open the CHAP secret file and return the secret
  211. * for authenticating the given client on the given server.
  212. @@ -2359,3 +2434,335 @@
  213. auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0);
  214. }
  215. +
  216. +
  217. +#ifdef USE_EAPTLS
  218. +static int
  219. +have_eaptls_secret_server(client, server, need_ip, lacks_ipp)
  220. + char *client;
  221. + char *server;
  222. + int need_ip;
  223. + int *lacks_ipp;
  224. +{
  225. + FILE *f;
  226. + int ret;
  227. + char *filename;
  228. + struct wordlist *addrs;
  229. + char servcertfile[MAXWORDLEN];
  230. + char clicertfile[MAXWORDLEN];
  231. + char cacertfile[MAXWORDLEN];
  232. + char pkfile[MAXWORDLEN];
  233. +
  234. + filename = _PATH_EAPTLSSERVFILE;
  235. + f = fopen(filename, "r");
  236. + if (f == NULL)
  237. + return 0;
  238. +
  239. + if (client != NULL && client[0] == 0)
  240. + client = NULL;
  241. + else if (server != NULL && server[0] == 0)
  242. + server = NULL;
  243. +
  244. + ret =
  245. + scan_authfile_eaptls(f, client, server, clicertfile, servcertfile,
  246. + cacertfile, pkfile, &addrs, NULL, filename,
  247. + 0);
  248. +
  249. + fclose(f);
  250. +
  251. +/*
  252. + if (ret >= 0 && !eaptls_init_ssl(1, cacertfile, servcertfile,
  253. + clicertfile, pkfile))
  254. + ret = -1;
  255. +*/
  256. +
  257. + if (ret >= 0 && need_ip && !some_ip_ok(addrs)) {
  258. + if (lacks_ipp != 0)
  259. + *lacks_ipp = 1;
  260. + ret = -1;
  261. + }
  262. + if (addrs != 0)
  263. + free_wordlist(addrs);
  264. +
  265. + return ret >= 0;
  266. +}
  267. +
  268. +
  269. +static int
  270. +have_eaptls_secret_client(client, server)
  271. + char *client;
  272. + char *server;
  273. +{
  274. + FILE *f;
  275. + int ret;
  276. + char *filename;
  277. + struct wordlist *addrs = NULL;
  278. + char servcertfile[MAXWORDLEN];
  279. + char clicertfile[MAXWORDLEN];
  280. + char cacertfile[MAXWORDLEN];
  281. + char pkfile[MAXWORDLEN];
  282. +
  283. + if (client != NULL && client[0] == 0)
  284. + client = NULL;
  285. + else if (server != NULL && server[0] == 0)
  286. + server = NULL;
  287. +
  288. + if (cacert_file && cert_file && privkey_file)
  289. + return 1;
  290. +
  291. + filename = _PATH_EAPTLSCLIFILE;
  292. + f = fopen(filename, "r");
  293. + if (f == NULL)
  294. + return 0;
  295. +
  296. + ret =
  297. + scan_authfile_eaptls(f, client, server, clicertfile, servcertfile,
  298. + cacertfile, pkfile, &addrs, NULL, filename,
  299. + 0);
  300. + fclose(f);
  301. +
  302. +/*
  303. + if (ret >= 0 && !eaptls_init_ssl(0, cacertfile, clicertfile,
  304. + servcertfile, pkfile))
  305. + ret = -1;
  306. +*/
  307. +
  308. + if (addrs != 0)
  309. + free_wordlist(addrs);
  310. +
  311. + return ret >= 0;
  312. +}
  313. +
  314. +
  315. +static int
  316. +scan_authfile_eaptls(f, client, server, cli_cert, serv_cert, ca_cert, pk,
  317. + addrs, opts, filename, flags)
  318. + FILE *f;
  319. + char *client;
  320. + char *server;
  321. + char *cli_cert;
  322. + char *serv_cert;
  323. + char *ca_cert;
  324. + char *pk;
  325. + struct wordlist **addrs;
  326. + struct wordlist **opts;
  327. + char *filename;
  328. + int flags;
  329. +{
  330. + int newline;
  331. + int got_flag, best_flag;
  332. + struct wordlist *ap, *addr_list, *alist, **app;
  333. + char word[MAXWORDLEN];
  334. +
  335. + if (addrs != NULL)
  336. + *addrs = NULL;
  337. + if (opts != NULL)
  338. + *opts = NULL;
  339. + addr_list = NULL;
  340. + if (!getword(f, word, &newline, filename))
  341. + return -1; /* file is empty??? */
  342. + newline = 1;
  343. + best_flag = -1;
  344. + for (;;) {
  345. + /*
  346. + * Skip until we find a word at the start of a line.
  347. + */
  348. + while (!newline && getword(f, word, &newline, filename));
  349. + if (!newline)
  350. + break; /* got to end of file */
  351. +
  352. + /*
  353. + * Got a client - check if it's a match or a wildcard.
  354. + */
  355. + got_flag = 0;
  356. + if (client != NULL && strcmp(word, client) != 0 && !ISWILD(word)) {
  357. + newline = 0;
  358. + continue;
  359. + }
  360. + if (!ISWILD(word))
  361. + got_flag = NONWILD_CLIENT;
  362. +
  363. + /*
  364. + * Now get a server and check if it matches.
  365. + */
  366. + if (!getword(f, word, &newline, filename))
  367. + break;
  368. + if (newline)
  369. + continue;
  370. + if (!ISWILD(word)) {
  371. + if (server != NULL && strcmp(word, server) != 0)
  372. + continue;
  373. + got_flag |= NONWILD_SERVER;
  374. + }
  375. +
  376. + /*
  377. + * Got some sort of a match - see if it's better than what
  378. + * we have already.
  379. + */
  380. + if (got_flag <= best_flag)
  381. + continue;
  382. +
  383. + /*
  384. + * Get the cli_cert
  385. + */
  386. + if (!getword(f, word, &newline, filename))
  387. + break;
  388. + if (newline)
  389. + continue;
  390. + if (strcmp(word, "-") != 0) {
  391. + strlcpy(cli_cert, word, MAXWORDLEN);
  392. + } else
  393. + cli_cert[0] = 0;
  394. +
  395. + /*
  396. + * Get serv_cert
  397. + */
  398. + if (!getword(f, word, &newline, filename))
  399. + break;
  400. + if (newline)
  401. + continue;
  402. + if (strcmp(word, "-") != 0) {
  403. + strlcpy(serv_cert, word, MAXWORDLEN);
  404. + } else
  405. + serv_cert[0] = 0;
  406. +
  407. + /*
  408. + * Get ca_cert
  409. + */
  410. + if (!getword(f, word, &newline, filename))
  411. + break;
  412. + if (newline)
  413. + continue;
  414. + strlcpy(ca_cert, word, MAXWORDLEN);
  415. +
  416. + /*
  417. + * Get pk
  418. + */
  419. + if (!getword(f, word, &newline, filename))
  420. + break;
  421. + if (newline)
  422. + continue;
  423. + strlcpy(pk, word, MAXWORDLEN);
  424. +
  425. +
  426. + /*
  427. + * Now read address authorization info and make a wordlist.
  428. + */
  429. + app = &alist;
  430. + for (;;) {
  431. + if (!getword(f, word, &newline, filename) || newline)
  432. + break;
  433. + ap = (struct wordlist *)
  434. + malloc(sizeof(struct wordlist) + strlen(word) + 1);
  435. + if (ap == NULL)
  436. + novm("authorized addresses");
  437. + ap->word = (char *) (ap + 1);
  438. + strcpy(ap->word, word);
  439. + *app = ap;
  440. + app = &ap->next;
  441. + }
  442. + *app = NULL;
  443. + /*
  444. + * This is the best so far; remember it.
  445. + */
  446. + best_flag = got_flag;
  447. + if (addr_list)
  448. + free_wordlist(addr_list);
  449. + addr_list = alist;
  450. +
  451. + if (!newline)
  452. + break;
  453. + }
  454. +
  455. + /* scan for a -- word indicating the start of options */
  456. + for (app = &addr_list; (ap = *app) != NULL; app = &ap->next)
  457. + if (strcmp(ap->word, "--") == 0)
  458. + break;
  459. + /* ap = start of options */
  460. + if (ap != NULL) {
  461. + ap = ap->next; /* first option */
  462. + free(*app); /* free the "--" word */
  463. + *app = NULL; /* terminate addr list */
  464. + }
  465. + if (opts != NULL)
  466. + *opts = ap;
  467. + else if (ap != NULL)
  468. + free_wordlist(ap);
  469. + if (addrs != NULL)
  470. + *addrs = addr_list;
  471. + else if (addr_list != NULL)
  472. + free_wordlist(addr_list);
  473. +
  474. + return best_flag;
  475. +}
  476. +
  477. +
  478. +int
  479. +get_eaptls_secret(unit, client, server, clicertfile, servcertfile,
  480. + cacertfile, pkfile, am_server)
  481. + int unit;
  482. + char *client;
  483. + char *server;
  484. + char *clicertfile;
  485. + char *servcertfile;
  486. + char *cacertfile;
  487. + char *pkfile;
  488. + int am_server;
  489. +{
  490. + FILE *fp;
  491. + int ret;
  492. + char *filename = NULL;
  493. + struct wordlist *addrs = NULL;
  494. + struct wordlist *opts = NULL;
  495. +
  496. + /* in client mode the ca+cert+privkey can also be specified as options */
  497. + if (!am_server && cacert_file && cert_file && privkey_file )
  498. + {
  499. + strlcpy( clicertfile, cert_file, MAXWORDLEN );
  500. + strlcpy( cacertfile, cacert_file, MAXWORDLEN );
  501. + strlcpy( pkfile, privkey_file, MAXWORDLEN );
  502. + servcertfile[0] = '\0';
  503. + }
  504. + else
  505. + {
  506. + filename = (am_server ? _PATH_EAPTLSSERVFILE : _PATH_EAPTLSCLIFILE);
  507. + addrs = NULL;
  508. +
  509. + fp = fopen(filename, "r");
  510. + if (fp == NULL)
  511. + {
  512. + error("Can't open eap-tls secret file %s: %m", filename);
  513. + return 0;
  514. + }
  515. +
  516. + check_access(fp, filename);
  517. +
  518. + ret = scan_authfile_eaptls(fp, client, server, clicertfile, servcertfile,
  519. + cacertfile, pkfile, &addrs, &opts, filename, 0);
  520. +
  521. + fclose(fp);
  522. +
  523. + if (ret < 0) return 0;
  524. + }
  525. +
  526. + if (eaptls_passwd_hook)
  527. + {
  528. + dbglog( "Calling eaptls password hook" );
  529. + if ( (*eaptls_passwd_hook)(pkfile, passwd) < 0)
  530. + {
  531. + error("Unable to obtain EAP-TLS password for %s (%s) from plugin",
  532. + client, pkfile);
  533. + return 0;
  534. + }
  535. + }
  536. + if (am_server)
  537. + set_allowed_addrs(unit, addrs, opts);
  538. + else if (opts != NULL)
  539. + free_wordlist(opts);
  540. + if (addrs != NULL)
  541. + free_wordlist(addrs);
  542. +
  543. + return 1;
  544. +}
  545. +#endif
  546. +
  547. --- ppp-2.4.6/pppd/ccp.c
  548. +++ ppp-2.4.6/pppd/ccp.c
  549. @@ -540,6 +540,9 @@
  550. if (go->mppe) {
  551. ccp_options *ao = &ccp_allowoptions[f->unit];
  552. int auth_mschap_bits = auth_done[f->unit];
  553. +#ifdef USE_EAPTLS
  554. + int auth_eap_bits = auth_done[f->unit];
  555. +#endif
  556. int numbits;
  557. /*
  558. @@ -567,8 +570,23 @@
  559. lcp_close(f->unit, "MPPE required but not available");
  560. return;
  561. }
  562. +
  563. +#ifdef USE_EAPTLS
  564. + /*
  565. + * MPPE is also possible in combination with EAP-TLS.
  566. + * It is not possible to detect if we're doing EAP or EAP-TLS
  567. + * at this stage, hence we accept all forms of EAP. If TLS is
  568. + * not used then the MPPE keys will not be derived anyway.
  569. + */
  570. + /* Leave only the eap auth bits set */
  571. + auth_eap_bits &= (EAP_WITHPEER | EAP_PEER );
  572. +
  573. + if ((numbits == 0) && (auth_eap_bits == 0)) {
  574. + error("MPPE required, but MS-CHAP[v2] nor EAP-TLS auth are performed.");
  575. +#else
  576. if (!numbits) {
  577. - error("MPPE required, but MS-CHAP[v2] auth not performed.");
  578. + error("MPPE required, but MS-CHAP[v2] auth not performed.");
  579. +#endif
  580. lcp_close(f->unit, "MPPE required but not available");
  581. return;
  582. }
  583. --- ppp-2.4.6/pppd/chap-md5.c
  584. +++ ppp-2.4.6/pppd/chap-md5.c
  585. @@ -36,7 +36,11 @@
  586. #include "chap-new.h"
  587. #include "chap-md5.h"
  588. #include "magic.h"
  589. +#ifdef USE_EAPTLS
  590. +#include "eap-tls.h"
  591. +#else
  592. #include "md5.h"
  593. +#endif /* USE_EAPTLS */
  594. #define MD5_HASH_SIZE 16
  595. #define MD5_MIN_CHALLENGE 16
  596. --- ppp-2.4.6/pppd/eap.c
  597. +++ ppp-2.4.6/pppd/eap.c
  598. @@ -43,6 +43,11 @@
  599. * Based on draft-ietf-pppext-eap-srp-03.txt.
  600. */
  601. +/*
  602. + * Modification by Beniamino Galvani, Mar 2005
  603. + * Implemented EAP-TLS authentication
  604. + */
  605. +
  606. #define RCSID "$Id: eap.c,v 1.4 2004/11/09 22:39:25 paulus Exp $"
  607. /*
  608. @@ -62,8 +67,12 @@
  609. #include "pppd.h"
  610. #include "pathnames.h"
  611. -#include "md5.h"
  612. #include "eap.h"
  613. +#ifdef USE_EAPTLS
  614. +#include "eap-tls.h"
  615. +#else
  616. +#include "md5.h"
  617. +#endif /* USE_EAPTLS */
  618. #ifdef USE_SRP
  619. #include <t_pwd.h>
  620. @@ -209,6 +218,9 @@
  621. esp->es_server.ea_id = (u_char)(drand48() * 0x100);
  622. esp->es_client.ea_timeout = EAP_DEFREQTIME;
  623. esp->es_client.ea_maxrequests = EAP_DEFALLOWREQ;
  624. +#ifdef USE_EAPTLS
  625. + esp->es_client.ea_using_eaptls = 0;
  626. +#endif /* USE_EAPTLS */
  627. }
  628. /*
  629. @@ -436,8 +448,16 @@
  630. u_char vals[2];
  631. struct b64state bs;
  632. #endif /* USE_SRP */
  633. +#ifdef USE_EAPTLS
  634. + struct eaptls_session *ets;
  635. + int secret_len;
  636. + char secret[MAXWORDLEN];
  637. +#endif /* USE_EAPTLS */
  638. esp->es_server.ea_timeout = esp->es_savedtime;
  639. +#ifdef USE_EAPTLS
  640. + esp->es_server.ea_prev_state = esp->es_server.ea_state;
  641. +#endif /* USE_EAPTLS */
  642. switch (esp->es_server.ea_state) {
  643. case eapBadAuth:
  644. return;
  645. @@ -562,9 +582,81 @@
  646. break;
  647. }
  648. #endif /* USE_SRP */
  649. +#ifdef USE_EAPTLS
  650. + if (!get_secret(esp->es_unit, esp->es_server.ea_peer,
  651. + esp->es_server.ea_name, secret, &secret_len, 1)) {
  652. +
  653. + esp->es_server.ea_state = eapTlsStart;
  654. + break;
  655. + }
  656. +#endif /* USE_EAPTLS */
  657. +
  658. esp->es_server.ea_state = eapMD5Chall;
  659. break;
  660. +#ifdef USE_EAPTLS
  661. + case eapTlsStart:
  662. + /* Initialize ssl session */
  663. + if(!eaptls_init_ssl_server(esp)) {
  664. + esp->es_server.ea_state = eapBadAuth;
  665. + break;
  666. + }
  667. +
  668. + esp->es_server.ea_state = eapTlsRecv;
  669. + break;
  670. +
  671. + case eapTlsRecv:
  672. + ets = (struct eaptls_session *) esp->es_server.ea_session;
  673. +
  674. + if(ets->alert_sent) {
  675. + esp->es_server.ea_state = eapTlsSendAlert;
  676. + break;
  677. + }
  678. +
  679. + if (status) {
  680. + esp->es_server.ea_state = eapBadAuth;
  681. + break;
  682. + }
  683. + ets = (struct eaptls_session *) esp->es_server.ea_session;
  684. +
  685. + if(ets->frag)
  686. + esp->es_server.ea_state = eapTlsSendAck;
  687. + else
  688. + esp->es_server.ea_state = eapTlsSend;
  689. + break;
  690. +
  691. + case eapTlsSend:
  692. + ets = (struct eaptls_session *) esp->es_server.ea_session;
  693. +
  694. + if(SSL_is_init_finished(ets->ssl)) {
  695. + esp->es_server.ea_state = eapTlsRecvClient;
  696. + break;
  697. + }
  698. +
  699. + if(ets->frag)
  700. + esp->es_server.ea_state = eapTlsRecvAck;
  701. + else
  702. + esp->es_server.ea_state = eapTlsRecv;
  703. + break;
  704. +
  705. + case eapTlsSendAck:
  706. + esp->es_server.ea_state = eapTlsRecv;
  707. + break;
  708. +
  709. + case eapTlsRecvAck:
  710. + if (status) {
  711. + esp->es_server.ea_state = eapBadAuth;
  712. + break;
  713. + }
  714. +
  715. + esp->es_server.ea_state = eapTlsSend;
  716. + break;
  717. +
  718. + case eapTlsSendAlert:
  719. + esp->es_server.ea_state = eapTlsRecvAlertAck;
  720. + break;
  721. +#endif /* USE_EAPTLS */
  722. +
  723. case eapSRP1:
  724. #ifdef USE_SRP
  725. ts = (struct t_server *)esp->es_server.ea_session;
  726. @@ -718,6 +810,30 @@
  727. INCPTR(esp->es_server.ea_namelen, outp);
  728. break;
  729. +#ifdef USE_EAPTLS
  730. + case eapTlsStart:
  731. + PUTCHAR(EAPT_TLS, outp);
  732. + PUTCHAR(EAP_TLS_FLAGS_START, outp);
  733. + eap_figure_next_state(esp, 0);
  734. + break;
  735. +
  736. + case eapTlsSend:
  737. + eaptls_send(esp->es_server.ea_session, &outp);
  738. + eap_figure_next_state(esp, 0);
  739. + break;
  740. +
  741. + case eapTlsSendAck:
  742. + PUTCHAR(EAPT_TLS, outp);
  743. + PUTCHAR(0, outp);
  744. + eap_figure_next_state(esp, 0);
  745. + break;
  746. +
  747. + case eapTlsSendAlert:
  748. + eaptls_send(esp->es_server.ea_session, &outp);
  749. + eap_figure_next_state(esp, 0);
  750. + break;
  751. +#endif /* USE_EAPTLS */
  752. +
  753. #ifdef USE_SRP
  754. case eapSRP1:
  755. PUTCHAR(EAPT_SRP, outp);
  756. @@ -904,11 +1020,57 @@
  757. eap_server_timeout(arg)
  758. void *arg;
  759. {
  760. +#ifdef USE_EAPTLS
  761. + u_char *outp;
  762. + u_char *lenloc;
  763. + int outlen;
  764. +#endif /* USE_EAPTLS */
  765. +
  766. eap_state *esp = (eap_state *) arg;
  767. if (!eap_server_active(esp))
  768. return;
  769. +#ifdef USE_EAPTLS
  770. + switch(esp->es_server.ea_prev_state) {
  771. +
  772. + /*
  773. + * In eap-tls the state changes after a request, so we return to
  774. + * previous state ...
  775. + */
  776. + case(eapTlsStart):
  777. + case(eapTlsSendAck):
  778. + esp->es_server.ea_state = esp->es_server.ea_prev_state;
  779. + break;
  780. +
  781. + /*
  782. + * ... or resend the stored data
  783. + */
  784. + case(eapTlsSend):
  785. + case(eapTlsSendAlert):
  786. + outp = outpacket_buf;
  787. + MAKEHEADER(outp, PPP_EAP);
  788. + PUTCHAR(EAP_REQUEST, outp);
  789. + PUTCHAR(esp->es_server.ea_id, outp);
  790. + lenloc = outp;
  791. + INCPTR(2, outp);
  792. +
  793. + eaptls_retransmit(esp->es_server.ea_session, &outp);
  794. +
  795. + outlen = (outp - outpacket_buf) - PPP_HDRLEN;
  796. + PUTSHORT(outlen, lenloc);
  797. + output(esp->es_unit, outpacket_buf, outlen + PPP_HDRLEN);
  798. + esp->es_server.ea_requests++;
  799. +
  800. + if (esp->es_server.ea_timeout > 0)
  801. + TIMEOUT(eap_server_timeout, esp, esp->es_server.ea_timeout);
  802. +
  803. + return;
  804. + default:
  805. + break;
  806. + }
  807. +#endif /* USE_EAPTLS */
  808. +
  809. /* EAP ID number must not change on timeout. */
  810. eap_send_request(esp);
  811. }
  812. @@ -1166,6 +1328,81 @@
  813. }
  814. #endif /* USE_SRP */
  815. +#ifdef USE_EAPTLS
  816. +/*
  817. + * Send an EAP-TLS response message with tls data
  818. + */
  819. +static void
  820. +eap_tls_response(esp, id)
  821. +eap_state *esp;
  822. +u_char id;
  823. +{
  824. + u_char *outp;
  825. + int outlen;
  826. + u_char *lenloc;
  827. +
  828. + outp = outpacket_buf;
  829. +
  830. + MAKEHEADER(outp, PPP_EAP);
  831. +
  832. + PUTCHAR(EAP_RESPONSE, outp);
  833. + PUTCHAR(id, outp);
  834. +
  835. + lenloc = outp;
  836. + INCPTR(2, outp);
  837. +
  838. + /*
  839. + If the id in the request is unchanged, we must retransmit
  840. + the old data
  841. + */
  842. + if(id == esp->es_client.ea_id)
  843. + eaptls_retransmit(esp->es_client.ea_session, &outp);
  844. + else
  845. + eaptls_send(esp->es_client.ea_session, &outp);
  846. +
  847. + outlen = (outp - outpacket_buf) - PPP_HDRLEN;
  848. + PUTSHORT(outlen, lenloc);
  849. +
  850. + output(esp->es_unit, outpacket_buf, PPP_HDRLEN + outlen);
  851. +
  852. + esp->es_client.ea_id = id;
  853. +
  854. +}
  855. +
  856. +/*
  857. + * Send an EAP-TLS ack
  858. + */
  859. +static void
  860. +eap_tls_sendack(esp, id)
  861. +eap_state *esp;
  862. +u_char id;
  863. +{
  864. + u_char *outp;
  865. + int outlen;
  866. + u_char *lenloc;
  867. +
  868. + outp = outpacket_buf;
  869. +
  870. + MAKEHEADER(outp, PPP_EAP);
  871. +
  872. + PUTCHAR(EAP_RESPONSE, outp);
  873. + PUTCHAR(id, outp);
  874. + esp->es_client.ea_id = id;
  875. +
  876. + lenloc = outp;
  877. + INCPTR(2, outp);
  878. +
  879. + PUTCHAR(EAPT_TLS, outp);
  880. + PUTCHAR(0, outp);
  881. +
  882. + outlen = (outp - outpacket_buf) - PPP_HDRLEN;
  883. + PUTSHORT(outlen, lenloc);
  884. +
  885. + output(esp->es_unit, outpacket_buf, PPP_HDRLEN + outlen);
  886. +
  887. +}
  888. +#endif /* USE_EAPTLS */
  889. +
  890. static void
  891. eap_send_nak(esp, id, type)
  892. eap_state *esp;
  893. @@ -1320,6 +1557,11 @@
  894. char rhostname[256];
  895. MD5_CTX mdContext;
  896. u_char hash[MD5_SIGNATURE_SIZE];
  897. +#ifdef USE_EAPTLS
  898. + u_char flags;
  899. + struct eaptls_session *ets = esp->es_client.ea_session;
  900. +#endif /* USE_EAPTLS */
  901. +
  902. #ifdef USE_SRP
  903. struct t_client *tc;
  904. struct t_num sval, gval, Nval, *Ap, Bval;
  905. @@ -1456,6 +1698,90 @@
  906. esp->es_client.ea_namelen);
  907. break;
  908. +#ifdef USE_EAPTLS
  909. + case EAPT_TLS:
  910. +
  911. + switch(esp->es_client.ea_state) {
  912. +
  913. + case eapListen:
  914. +
  915. + GETCHAR(flags, inp);
  916. + if(flags & EAP_TLS_FLAGS_START){
  917. +
  918. + esp->es_client.ea_using_eaptls = 1;
  919. +
  920. + if (explicit_remote){
  921. + esp->es_client.ea_peer = strdup(remote_name);
  922. + esp->es_client.ea_peerlen = strlen(remote_name);
  923. + } else
  924. + esp->es_client.ea_peer = NULL;
  925. +
  926. + /* Init ssl session */
  927. + if(!eaptls_init_ssl_client(esp)) {
  928. + dbglog("cannot init ssl");
  929. + eap_send_nak(esp, id, EAPT_TLS);
  930. + esp->es_client.ea_using_eaptls = 0;
  931. + break;
  932. + }
  933. +
  934. + ets = esp->es_client.ea_session;
  935. + eap_tls_response(esp, id);
  936. + esp->es_client.ea_state = (ets->frag ? eapTlsRecvAck :
  937. + eapTlsRecv);
  938. + break;
  939. + }
  940. +
  941. + /* The server has sent a bad start packet. */
  942. + eap_send_nak(esp, id, EAPT_TLS);
  943. + break;
  944. +
  945. + case eapTlsRecvAck:
  946. + eap_tls_response(esp, id);
  947. + esp->es_client.ea_state = (ets->frag ? eapTlsRecvAck :
  948. + eapTlsRecv);
  949. + break;
  950. +
  951. + case eapTlsRecv:
  952. + eaptls_receive(ets, inp, len);
  953. +
  954. + if(ets->frag) {
  955. + eap_tls_sendack(esp, id);
  956. + esp->es_client.ea_state = eapTlsRecv;
  957. + break;
  958. + }
  959. +
  960. + if(ets->alert_recv) {
  961. + eap_tls_sendack(esp, id);
  962. + esp->es_client.ea_state = eapTlsRecvFailure;
  963. + break;
  964. + }
  965. +
  966. + /* Check if TLS handshake is finished */
  967. + if(SSL_is_init_finished(ets->ssl)){
  968. +#ifdef MPPE
  969. + eaptls_gen_mppe_keys( ets, "client EAP encryption", 1 );
  970. +#endif
  971. + eaptls_free_session(ets);
  972. + eap_tls_sendack(esp, id);
  973. + esp->es_client.ea_state = eapTlsRecvSuccess;
  974. + break;
  975. + }
  976. +
  977. + eap_tls_response(esp,id);
  978. + esp->es_client.ea_state = (ets->frag ? eapTlsRecvAck :
  979. + eapTlsRecv);
  980. +
  981. + break;
  982. +
  983. + default:
  984. + eap_send_nak(esp, id, EAPT_TLS);
  985. + esp->es_client.ea_using_eaptls = 0;
  986. + break;
  987. + }
  988. +
  989. + break;
  990. +#endif /* USE_EAPTLS */
  991. +
  992. #ifdef USE_SRP
  993. case EAPT_SRP:
  994. if (len < 1) {
  995. @@ -1737,6 +2063,11 @@
  996. u_char dig[SHA_DIGESTSIZE];
  997. #endif /* USE_SRP */
  998. +#ifdef USE_EAPTLS
  999. + struct eaptls_session *ets;
  1000. + u_char flags;
  1001. +#endif /* USE_EAPTLS */
  1002. +
  1003. if (esp->es_server.ea_id != id) {
  1004. dbglog("EAP: discarding Response %d; expected ID %d", id,
  1005. esp->es_server.ea_id);
  1006. @@ -1776,6 +2107,60 @@
  1007. eap_figure_next_state(esp, 0);
  1008. break;
  1009. +#ifdef USE_EAPTLS
  1010. + case EAPT_TLS:
  1011. + switch(esp->es_server.ea_state) {
  1012. +
  1013. + case eapTlsRecv:
  1014. + ets = (struct eaptls_session *) esp->es_server.ea_session;
  1015. + eap_figure_next_state(esp,
  1016. + eaptls_receive(esp->es_server.ea_session, inp, len));
  1017. +
  1018. + if(ets->alert_recv) {
  1019. + eap_send_failure(esp);
  1020. + break;
  1021. + }
  1022. + break;
  1023. +
  1024. + case eapTlsRecvAck:
  1025. + if(len > 1) {
  1026. + dbglog("EAP-TLS ACK with extra data");
  1027. + }
  1028. + eap_figure_next_state(esp, 0);
  1029. + break;
  1030. +
  1031. + case eapTlsRecvClient:
  1032. + /* Receive authentication response from client */
  1033. +
  1034. + GETCHAR(flags, inp);
  1035. +
  1036. + if(len == 1 && !flags) { /* Ack = ok */
  1037. +#ifdef MPPE
  1038. + eaptls_gen_mppe_keys( esp->es_server.ea_session, "client EAP encryption", 0 );
  1039. +#endif
  1040. + eap_send_success(esp);
  1041. + }
  1042. + else { /* failure */
  1043. + eaptls_receive(esp->es_server.ea_session, inp, len);
  1044. + warn("Server authentication failed");
  1045. + eap_send_failure(esp);
  1046. + }
  1047. +
  1048. + eaptls_free_session(esp->es_server.ea_session);
  1049. +
  1050. + break;
  1051. +
  1052. + case eapTlsRecvAlertAck:
  1053. + eap_send_failure(esp);
  1054. + break;
  1055. +
  1056. + default:
  1057. + eap_figure_next_state(esp, 1);
  1058. + break;
  1059. + }
  1060. + break;
  1061. +#endif /* USE_EAPTLS */
  1062. +
  1063. case EAPT_NOTIFICATION:
  1064. dbglog("EAP unexpected Notification; response discarded");
  1065. break;
  1066. @@ -1807,6 +2192,13 @@
  1067. esp->es_server.ea_state = eapMD5Chall;
  1068. break;
  1069. +#ifdef USE_EAPTLS
  1070. + /* Send EAP-TLS start packet */
  1071. + case EAPT_TLS:
  1072. + esp->es_server.ea_state = eapTlsStart;
  1073. + break;
  1074. +#endif /* USE_EAPTLS */
  1075. +
  1076. default:
  1077. dbglog("EAP: peer requesting unknown Type %d", vallen);
  1078. switch (esp->es_server.ea_state) {
  1079. @@ -2018,13 +2410,27 @@
  1080. int id;
  1081. int len;
  1082. {
  1083. - if (esp->es_client.ea_state != eapOpen && !eap_client_active(esp)) {
  1084. + if (esp->es_client.ea_state != eapOpen && !eap_client_active(esp)
  1085. +#ifdef USE_EAPTLS
  1086. + && esp->es_client.ea_state != eapTlsRecvSuccess
  1087. +#endif /* USE_EAPTLS */
  1088. + ) {
  1089. dbglog("EAP unexpected success message in state %s (%d)",
  1090. eap_state_name(esp->es_client.ea_state),
  1091. esp->es_client.ea_state);
  1092. return;
  1093. }
  1094. +#ifdef USE_EAPTLS
  1095. + if(esp->es_client.ea_using_eaptls && esp->es_client.ea_state !=
  1096. + eapTlsRecvSuccess) {
  1097. + dbglog("EAP-TLS unexpected success message in state %s (%d)",
  1098. + eap_state_name(esp->es_client.ea_state),
  1099. + esp->es_client.ea_state);
  1100. + return;
  1101. + }
  1102. +#endif /* USE_EAPTLS */
  1103. +
  1104. if (esp->es_client.ea_timeout > 0) {
  1105. UNTIMEOUT(eap_client_timeout, (void *)esp);
  1106. }
  1107. @@ -2150,6 +2556,9 @@
  1108. int code, id, len, rtype, vallen;
  1109. u_char *pstart;
  1110. u_int32_t uval;
  1111. +#ifdef USE_EAPTLS
  1112. + u_char flags;
  1113. +#endif /* USE_EAPTLS */
  1114. if (inlen < EAP_HEADERLEN)
  1115. return (0);
  1116. @@ -2214,6 +2623,24 @@
  1117. }
  1118. break;
  1119. +#ifdef USE_EAPTLS
  1120. + case EAPT_TLS:
  1121. + if (len < 1)
  1122. + break;
  1123. + GETCHAR(flags, inp);
  1124. + len--;
  1125. +
  1126. + if(flags == 0 && len == 0){
  1127. + printer(arg, " Ack");
  1128. + break;
  1129. + }
  1130. +
  1131. + printer(arg, flags & EAP_TLS_FLAGS_LI ? " L":" -");
  1132. + printer(arg, flags & EAP_TLS_FLAGS_MF ? "M":"-");
  1133. + printer(arg, flags & EAP_TLS_FLAGS_START ? "S":"- ");
  1134. + break;
  1135. +#endif /* USE_EAPTLS */
  1136. +
  1137. case EAPT_SRP:
  1138. if (len < 3)
  1139. goto truncated;
  1140. @@ -2325,6 +2752,25 @@
  1141. }
  1142. break;
  1143. +#ifdef USE_EAPTLS
  1144. + case EAPT_TLS:
  1145. + if (len < 1)
  1146. + break;
  1147. + GETCHAR(flags, inp);
  1148. + len--;
  1149. +
  1150. + if(flags == 0 && len == 0){
  1151. + printer(arg, " Ack");
  1152. + break;
  1153. + }
  1154. +
  1155. + printer(arg, flags & EAP_TLS_FLAGS_LI ? " L":" -");
  1156. + printer(arg, flags & EAP_TLS_FLAGS_MF ? "M":"-");
  1157. + printer(arg, flags & EAP_TLS_FLAGS_START ? "S":"- ");
  1158. +
  1159. + break;
  1160. +#endif /* USE_EAPTLS */
  1161. +
  1162. case EAPT_NAK:
  1163. if (len <= 0) {
  1164. printer(arg, " <missing hint>");
  1165. @@ -2426,3 +2872,4 @@
  1166. return (inp - pstart);
  1167. }
  1168. +
  1169. --- ppp-2.4.6/pppd/eap.h
  1170. +++ ppp-2.4.6/pppd/eap.h
  1171. @@ -84,6 +84,16 @@
  1172. eapClosed, /* Authentication not in use */
  1173. eapListen, /* Client ready (and timer running) */
  1174. eapIdentify, /* EAP Identify sent */
  1175. + eapTlsStart, /* Send EAP-TLS start packet */
  1176. + eapTlsRecv, /* Receive EAP-TLS tls data */
  1177. + eapTlsSendAck, /* Send EAP-TLS ack */
  1178. + eapTlsSend, /* Send EAP-TLS tls data */
  1179. + eapTlsRecvAck, /* Receive EAP-TLS ack */
  1180. + eapTlsRecvClient, /* Receive EAP-TLS auth response from client*/
  1181. + eapTlsSendAlert, /* Send EAP-TLS tls alert (server)*/
  1182. + eapTlsRecvAlertAck, /* Receive EAP-TLS ack after sending alert */
  1183. + eapTlsRecvSuccess, /* Receive EAP success */
  1184. + eapTlsRecvFailure, /* Receive EAP failure */
  1185. eapSRP1, /* Sent EAP SRP-SHA1 Subtype 1 */
  1186. eapSRP2, /* Sent EAP SRP-SHA1 Subtype 2 */
  1187. eapSRP3, /* Sent EAP SRP-SHA1 Subtype 3 */
  1188. @@ -95,9 +105,18 @@
  1189. #define EAP_STATES \
  1190. "Initial", "Pending", "Closed", "Listen", "Identify", \
  1191. + "TlsStart", "TlsRecv", "TlsSendAck", "TlsSend", "TlsRecvAck", "TlsRecvClient",\
  1192. + "TlsSendAlert", "TlsRecvAlertAck" , "TlsRecvSuccess", "TlsRecvFailure", \
  1193. "SRP1", "SRP2", "SRP3", "MD5Chall", "Open", "SRP4", "BadAuth"
  1194. -#define eap_client_active(esp) ((esp)->es_client.ea_state == eapListen)
  1195. +#ifdef USE_EAPTLS
  1196. +#define eap_client_active(esp) ((esp)->es_client.ea_state != eapInitial ||\
  1197. + (esp)->es_client.ea_state != eapPending ||\
  1198. + (esp)->es_client.ea_state != eapClosed)
  1199. +#else
  1200. +#define eap_client_active(esp) ((esp)->es_client.ea_state == eapListen)
  1201. +#endif /* USE_EAPTLS */
  1202. +
  1203. #define eap_server_active(esp) \
  1204. ((esp)->es_server.ea_state >= eapIdentify && \
  1205. (esp)->es_server.ea_state <= eapMD5Chall)
  1206. @@ -112,11 +131,17 @@
  1207. u_short ea_namelen; /* Length of our name */
  1208. u_short ea_peerlen; /* Length of peer's name */
  1209. enum eap_state_code ea_state;
  1210. +#ifdef USE_EAPTLS
  1211. + enum eap_state_code ea_prev_state;
  1212. +#endif
  1213. u_char ea_id; /* Current id */
  1214. u_char ea_requests; /* Number of Requests sent/received */
  1215. u_char ea_responses; /* Number of Responses */
  1216. u_char ea_type; /* One of EAPT_* */
  1217. u_int32_t ea_keyflags; /* SRP shared key usage flags */
  1218. +#ifdef USE_EAPTLS
  1219. + bool ea_using_eaptls;
  1220. +#endif
  1221. };
  1222. /*
  1223. @@ -139,7 +164,12 @@
  1224. * Timeouts.
  1225. */
  1226. #define EAP_DEFTIMEOUT 3 /* Timeout (seconds) for rexmit */
  1227. +#ifdef USE_EAPTLS
  1228. +#define EAP_DEFTRANSMITS 30 /* max # times to transmit */
  1229. + /* certificates can be long ... */
  1230. +#else
  1231. #define EAP_DEFTRANSMITS 10 /* max # times to transmit */
  1232. +#endif /* USE_EAPTLS */
  1233. #define EAP_DEFREQTIME 20 /* Time to wait for peer request */
  1234. #define EAP_DEFALLOWREQ 20 /* max # times to accept requests */
  1235. --- ppp-2.4.6/pppd/eap-tls.c
  1236. +++ ppp-2.4.6/pppd/eap-tls.c
  1237. @@ -0,0 +1,1174 @@
  1238. +/*
  1239. + * eap-tls.c - EAP-TLS implementation for PPP
  1240. + *
  1241. + * Copyright (c) Beniamino Galvani 2005 All rights reserved.
  1242. + *
  1243. + * Redistribution and use in source and binary forms, with or without
  1244. + * modification, are permitted provided that the following conditions
  1245. + * are met:
  1246. + *
  1247. + * 1. Redistributions of source code must retain the above copyright
  1248. + * notice, this list of conditions and the following disclaimer.
  1249. + *
  1250. + * 2. Redistributions in binary form must reproduce the above copyright
  1251. + * notice, this list of conditions and the following disclaimer in
  1252. + * the documentation and/or other materials provided with the
  1253. + * distribution.
  1254. + *
  1255. + * 3. The name(s) of the authors of this software must not be used to
  1256. + * endorse or promote products derived from this software without
  1257. + * prior written permission.
  1258. + *
  1259. + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  1260. + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  1261. + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  1262. + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1263. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  1264. + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  1265. + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1266. + *
  1267. + */
  1268. +
  1269. +#include <string.h>
  1270. +#include <unistd.h>
  1271. +#include <sys/types.h>
  1272. +#include <sys/stat.h>
  1273. +#include <fcntl.h>
  1274. +
  1275. +#include <openssl/conf.h>
  1276. +#include <openssl/engine.h>
  1277. +#include <openssl/hmac.h>
  1278. +#include <openssl/err.h>
  1279. +#include <openssl/x509v3.h>
  1280. +
  1281. +#include "pppd.h"
  1282. +#include "eap.h"
  1283. +#include "eap-tls.h"
  1284. +#include "fsm.h"
  1285. +#include "lcp.h"
  1286. +#include "pathnames.h"
  1287. +
  1288. +/* The openssl configuration file and engines can be loaded only once */
  1289. +static CONF *ssl_config = NULL;
  1290. +static ENGINE *cert_engine = NULL;
  1291. +static ENGINE *pkey_engine = NULL;
  1292. +
  1293. +#ifdef MPPE
  1294. +
  1295. +/*
  1296. + * TLS PRF from RFC 2246
  1297. + */
  1298. +static void P_hash(const EVP_MD *evp_md,
  1299. + const unsigned char *secret, unsigned int secret_len,
  1300. + const unsigned char *seed, unsigned int seed_len,
  1301. + unsigned char *out, unsigned int out_len)
  1302. +{
  1303. + HMAC_CTX ctx_a, ctx_out;
  1304. + unsigned char a[HMAC_MAX_MD_CBLOCK];
  1305. + unsigned int size;
  1306. +
  1307. + HMAC_CTX_init(&ctx_a);
  1308. + HMAC_CTX_init(&ctx_out);
  1309. + HMAC_Init_ex(&ctx_a, secret, secret_len, evp_md, NULL);
  1310. + HMAC_Init_ex(&ctx_out, secret, secret_len, evp_md, NULL);
  1311. +
  1312. + size = HMAC_size(&ctx_out);
  1313. +
  1314. + /* Calculate A(1) */
  1315. + HMAC_Update(&ctx_a, seed, seed_len);
  1316. + HMAC_Final(&ctx_a, a, NULL);
  1317. +
  1318. + while (1) {
  1319. + /* Calculate next part of output */
  1320. + HMAC_Update(&ctx_out, a, size);
  1321. + HMAC_Update(&ctx_out, seed, seed_len);
  1322. +
  1323. + /* Check if last part */
  1324. + if (out_len < size) {
  1325. + HMAC_Final(&ctx_out, a, NULL);
  1326. + memcpy(out, a, out_len);
  1327. + break;
  1328. + }
  1329. +
  1330. + /* Place digest in output buffer */
  1331. + HMAC_Final(&ctx_out, out, NULL);
  1332. + HMAC_Init_ex(&ctx_out, NULL, 0, NULL, NULL);
  1333. + out += size;
  1334. + out_len -= size;
  1335. +
  1336. + /* Calculate next A(i) */
  1337. + HMAC_Init_ex(&ctx_a, NULL, 0, NULL, NULL);
  1338. + HMAC_Update(&ctx_a, a, size);
  1339. + HMAC_Final(&ctx_a, a, NULL);
  1340. + }
  1341. +
  1342. + HMAC_CTX_cleanup(&ctx_a);
  1343. + HMAC_CTX_cleanup(&ctx_out);
  1344. + memset(a, 0, sizeof(a));
  1345. +}
  1346. +
  1347. +static void PRF(const unsigned char *secret, unsigned int secret_len,
  1348. + const unsigned char *seed, unsigned int seed_len,
  1349. + unsigned char *out, unsigned char *buf, unsigned int out_len)
  1350. +{
  1351. + unsigned int i;
  1352. + unsigned int len = (secret_len + 1) / 2;
  1353. + const unsigned char *s1 = secret;
  1354. + const unsigned char *s2 = secret + (secret_len - len);
  1355. +
  1356. + P_hash(EVP_md5(), s1, len, seed, seed_len, out, out_len);
  1357. + P_hash(EVP_sha1(), s2, len, seed, seed_len, buf, out_len);
  1358. +
  1359. + for (i=0; i < out_len; i++) {
  1360. + out[i] ^= buf[i];
  1361. + }
  1362. +}
  1363. +
  1364. +#define EAPTLS_MPPE_KEY_LEN 32
  1365. +
  1366. +/*
  1367. + * Generate keys according to RFC 2716 and add to reply
  1368. + */
  1369. +void eaptls_gen_mppe_keys(struct eaptls_session *ets, const char *prf_label,
  1370. + int client)
  1371. +{
  1372. + unsigned char out[4*EAPTLS_MPPE_KEY_LEN], buf[4*EAPTLS_MPPE_KEY_LEN];
  1373. + unsigned char seed[64 + 2*SSL3_RANDOM_SIZE];
  1374. + unsigned char *p = seed;
  1375. + SSL *s = ets->ssl;
  1376. + size_t prf_size;
  1377. +
  1378. + prf_size = strlen(prf_label);
  1379. +
  1380. + memcpy(p, prf_label, prf_size);
  1381. + p += prf_size;
  1382. +
  1383. + memcpy(p, s->s3->client_random, SSL3_RANDOM_SIZE);
  1384. + p += SSL3_RANDOM_SIZE;
  1385. + prf_size += SSL3_RANDOM_SIZE;
  1386. +
  1387. + memcpy(p, s->s3->server_random, SSL3_RANDOM_SIZE);
  1388. + prf_size += SSL3_RANDOM_SIZE;
  1389. +
  1390. + PRF(s->session->master_key, s->session->master_key_length,
  1391. + seed, prf_size, out, buf, sizeof(out));
  1392. +
  1393. + /*
  1394. + * We now have the master send and receive keys.
  1395. + * From these, generate the session send and receive keys.
  1396. + * (see RFC3079 / draft-ietf-pppext-mppe-keys-03.txt for details)
  1397. + */
  1398. + if (client)
  1399. + {
  1400. + p = out;
  1401. + BCOPY( p, mppe_send_key, sizeof(mppe_send_key) );
  1402. + p += EAPTLS_MPPE_KEY_LEN;
  1403. + BCOPY( p, mppe_recv_key, sizeof(mppe_recv_key) );
  1404. + }
  1405. + else
  1406. + {
  1407. + p = out;
  1408. + BCOPY( p, mppe_recv_key, sizeof(mppe_recv_key) );
  1409. + p += EAPTLS_MPPE_KEY_LEN;
  1410. + BCOPY( p, mppe_send_key, sizeof(mppe_send_key) );
  1411. + }
  1412. +
  1413. + mppe_keys_set = 1;
  1414. +}
  1415. +
  1416. +#endif
  1417. +
  1418. +void log_ssl_errors( void )
  1419. +{
  1420. + unsigned long ssl_err = ERR_get_error();
  1421. +
  1422. + if (ssl_err != 0)
  1423. + dbglog("EAP-TLS SSL error stack:");
  1424. + while (ssl_err != 0) {
  1425. + dbglog( ERR_error_string( ssl_err, NULL ) );
  1426. + ssl_err = ERR_get_error();
  1427. + }
  1428. +}
  1429. +
  1430. +
  1431. +int password_callback (char *buf, int size, int rwflag, void *u)
  1432. +{
  1433. + if (buf)
  1434. + {
  1435. + strncpy (buf, passwd, size);
  1436. + return strlen (buf);
  1437. + }
  1438. + return 0;
  1439. +}
  1440. +
  1441. +
  1442. +CONF *eaptls_ssl_load_config( void )
  1443. +{
  1444. + CONF *config;
  1445. + int ret_code;
  1446. + long error_line = 33;
  1447. +
  1448. + config = NCONF_new( NULL );
  1449. + dbglog( "Loading OpenSSL config file" );
  1450. + ret_code = NCONF_load( config, _PATH_OPENSSLCONFFILE, &error_line );
  1451. + if (ret_code == 0)
  1452. + {
  1453. + warn( "EAP-TLS: Error in OpenSSL config file %s at line %d", _PATH_OPENSSLCONFFILE, error_line );
  1454. + NCONF_free( config );
  1455. + config = NULL;
  1456. + ERR_clear_error();
  1457. + }
  1458. +
  1459. + dbglog( "Loading OpenSSL built-ins" );
  1460. + ENGINE_load_builtin_engines();
  1461. + OPENSSL_load_builtin_modules();
  1462. +
  1463. + dbglog( "Loading OpenSSL configured modules" );
  1464. + if (CONF_modules_load( config, NULL, 0 ) <= 0 )
  1465. + {
  1466. + warn( "EAP-TLS: Error loading OpenSSL modules" );
  1467. + log_ssl_errors();
  1468. + config = NULL;
  1469. + }
  1470. +
  1471. + return config;
  1472. +}
  1473. +
  1474. +ENGINE *eaptls_ssl_load_engine( char *engine_name )
  1475. +{
  1476. + ENGINE *e = NULL;
  1477. +
  1478. + dbglog( "Enabling OpenSSL auto engines" );
  1479. + ENGINE_register_all_complete();
  1480. +
  1481. + dbglog( "Loading OpenSSL '%s' engine support", engine_name );
  1482. + e = ENGINE_by_id( engine_name );
  1483. + if (!e)
  1484. + {
  1485. + dbglog( "EAP-TLS: Cannot load '%s' engine support, trying 'dynamic'", engine_name );
  1486. + e = ENGINE_by_id( "dynamic" );
  1487. + if (e)
  1488. + {
  1489. + if (!ENGINE_ctrl_cmd_string(e, "SO_PATH", engine_name, 0)
  1490. + || !ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0))
  1491. + {
  1492. + warn( "EAP-TLS: Error loading dynamic engine '%s'", engine_name );
  1493. + log_ssl_errors();
  1494. + ENGINE_free(e);
  1495. + e = NULL;
  1496. + }
  1497. + }
  1498. + else
  1499. + {
  1500. + warn( "EAP-TLS: Cannot load dynamic engine support" );
  1501. + }
  1502. + }
  1503. +
  1504. + if (e)
  1505. + {
  1506. + dbglog( "Initialising engine" );
  1507. + if(!ENGINE_set_default(e, ENGINE_METHOD_ALL))
  1508. + {
  1509. + warn( "EAP-TLS: Cannot use that engine" );
  1510. + log_ssl_errors();
  1511. + ENGINE_free(e);
  1512. + e = NULL;
  1513. + }
  1514. + }
  1515. +
  1516. + return e;
  1517. +}
  1518. +
  1519. +/*
  1520. + * Initialize the SSL stacks and tests if certificates, key and crl
  1521. + * for client or server use can be loaded.
  1522. + */
  1523. +SSL_CTX *eaptls_init_ssl(int init_server, char *cacertfile,
  1524. + char *certfile, char *peer_certfile, char *privkeyfile)
  1525. +{
  1526. + char *cert_engine_name = NULL;
  1527. + char *cert_identifier = NULL;
  1528. + char *pkey_engine_name = NULL;
  1529. + char *pkey_identifier = NULL;
  1530. + SSL_CTX *ctx;
  1531. + X509_STORE *certstore;
  1532. + X509_LOOKUP *lookup;
  1533. + X509 *tmp;
  1534. +
  1535. + /*
  1536. + * Without these can't continue
  1537. + */
  1538. + if (!cacertfile[0])
  1539. + {
  1540. + error("EAP-TLS: CA certificate missing");
  1541. + return NULL;
  1542. + }
  1543. +
  1544. + if (!certfile[0])
  1545. + {
  1546. + error("EAP-TLS: User certificate missing");
  1547. + return NULL;
  1548. + }
  1549. +
  1550. + if (!privkeyfile[0])
  1551. + {
  1552. + error("EAP-TLS: User private key missing");
  1553. + return NULL;
  1554. + }
  1555. +
  1556. + SSL_library_init();
  1557. + SSL_load_error_strings();
  1558. +
  1559. + ctx = SSL_CTX_new(TLSv1_method());
  1560. +
  1561. + if (!ctx) {
  1562. + error("EAP-TLS: Cannot initialize SSL CTX context");
  1563. + goto fail;
  1564. + }
  1565. +
  1566. + /* if the certificate filename is of the form engine:id. e.g.
  1567. + pkcs11:12345
  1568. + then we try to load and use this engine.
  1569. + If the certificate filename starts with a / or . then we
  1570. + ALWAYS assume it is a file and not an engine/pkcs11 identifier
  1571. + */
  1572. + if ( index( certfile, '/' ) == NULL && index( certfile, '.') == NULL )
  1573. + {
  1574. + cert_identifier = index( certfile, ':' );
  1575. +
  1576. + if (cert_identifier)
  1577. + {
  1578. + cert_engine_name = certfile;
  1579. + *cert_identifier = '\0';
  1580. + cert_identifier++;
  1581. +
  1582. + dbglog( "Found certificate engine '%s'", cert_engine_name );
  1583. + dbglog( "Found certificate identifier '%s'", cert_identifier );
  1584. + }
  1585. + }
  1586. +
  1587. + /* if the privatekey filename is of the form engine:id. e.g.
  1588. + pkcs11:12345
  1589. + then we try to load and use this engine.
  1590. + If the privatekey filename starts with a / or . then we
  1591. + ALWAYS assume it is a file and not an engine/pkcs11 identifier
  1592. + */
  1593. + if ( index( privkeyfile, '/' ) == NULL && index( privkeyfile, '.') == NULL )
  1594. + {
  1595. + pkey_identifier = index( privkeyfile, ':' );
  1596. +
  1597. + if (pkey_identifier)
  1598. + {
  1599. + pkey_engine_name = privkeyfile;
  1600. + *pkey_identifier = '\0';
  1601. + pkey_identifier++;
  1602. +
  1603. + dbglog( "Found privatekey engine '%s'", pkey_engine_name );
  1604. + dbglog( "Found privatekey identifier '%s'", pkey_identifier );
  1605. + }
  1606. + }
  1607. +
  1608. + if (cert_identifier && pkey_identifier)
  1609. + {
  1610. + if (strlen( cert_identifier ) == 0)
  1611. + {
  1612. + if (strlen( pkey_identifier ) == 0)
  1613. + error( "EAP-TLS: both the certificate and privatekey identifiers are missing!" );
  1614. + else
  1615. + {
  1616. + dbglog( "Substituting privatekey identifier for certificate identifier" );
  1617. + cert_identifier = pkey_identifier;
  1618. + }
  1619. + }
  1620. + else
  1621. + {
  1622. + if (strlen( pkey_identifier ) == 0)
  1623. + {
  1624. + dbglog( "Substituting certificate identifier for privatekey identifier" );
  1625. + pkey_identifier = cert_identifier;
  1626. + }
  1627. + }
  1628. +
  1629. + }
  1630. +
  1631. + /* load the openssl config file only once */
  1632. + if (!ssl_config)
  1633. + {
  1634. + if (cert_engine_name || pkey_engine_name)
  1635. + ssl_config = eaptls_ssl_load_config();
  1636. +
  1637. + if (ssl_config && cert_engine_name)
  1638. + cert_engine = eaptls_ssl_load_engine( cert_engine_name );
  1639. +
  1640. + if (ssl_config && pkey_engine_name)
  1641. + {
  1642. + /* don't load the same engine twice */
  1643. + if ( strcmp( cert_engine_name, pkey_engine_name) == 0 )
  1644. + pkey_engine = cert_engine;
  1645. + else
  1646. + pkey_engine = eaptls_ssl_load_engine( pkey_engine_name );
  1647. + }
  1648. + }
  1649. +
  1650. + SSL_CTX_set_default_passwd_cb (ctx, password_callback);
  1651. +
  1652. + if (!SSL_CTX_load_verify_locations(ctx, cacertfile, NULL))
  1653. + {
  1654. + error("EAP-TLS: Cannot load or verify CA file %s", cacertfile);
  1655. + goto fail;
  1656. + }
  1657. +
  1658. + if (init_server)
  1659. + SSL_CTX_set_client_CA_list(ctx, SSL_load_client_CA_file(cacertfile));
  1660. +
  1661. + if (cert_engine)
  1662. + {
  1663. + struct
  1664. + {
  1665. + const char *s_slot_cert_id;
  1666. + X509 *cert;
  1667. + } cert_info;
  1668. +
  1669. + cert_info.s_slot_cert_id = cert_identifier;
  1670. + cert_info.cert = NULL;
  1671. +
  1672. + if (!ENGINE_ctrl_cmd( cert_engine, "LOAD_CERT_CTRL", 0, &cert_info, NULL, 0 ) )
  1673. + {
  1674. + error( "EAP-TLS: Error loading certificate with id '%s' from engine", cert_identifier );
  1675. + goto fail;
  1676. + }
  1677. +
  1678. + if (cert_info.cert)
  1679. + {
  1680. + dbglog( "Got the certificate, adding it to SSL context" );
  1681. + dbglog( "subject = %s", X509_NAME_oneline( X509_get_subject_name( cert_info.cert ), NULL, 0 ) );
  1682. + if (SSL_CTX_use_certificate(ctx, cert_info.cert) <= 0)
  1683. + {
  1684. + error("EAP-TLS: Cannot use PKCS11 certificate %s", cert_identifier);
  1685. + goto fail;
  1686. + }
  1687. + }
  1688. + else
  1689. + {
  1690. + warn("EAP-TLS: Cannot load PKCS11 key %s", cert_identifier);
  1691. + log_ssl_errors();
  1692. + }
  1693. + }
  1694. + else
  1695. + {
  1696. + if (!SSL_CTX_use_certificate_file(ctx, certfile, SSL_FILETYPE_PEM))
  1697. + {
  1698. + error( "EAP-TLS: Cannot use public certificate %s", certfile );
  1699. + goto fail;
  1700. + }
  1701. + }
  1702. +
  1703. + if (pkey_engine)
  1704. + {
  1705. + EVP_PKEY *pkey = NULL;
  1706. + PW_CB_DATA cb_data;
  1707. +
  1708. + cb_data.password = passwd;
  1709. + cb_data.prompt_info = pkey_identifier;
  1710. +
  1711. + dbglog( "Loading private key '%s' from engine", pkey_identifier );
  1712. + pkey = ENGINE_load_private_key(pkey_engine, pkey_identifier, NULL, &cb_data);
  1713. + if (pkey)
  1714. + {
  1715. + dbglog( "Got the private key, adding it to SSL context" );
  1716. + if (SSL_CTX_use_PrivateKey(ctx, pkey) <= 0)
  1717. + {
  1718. + error("EAP-TLS: Cannot use PKCS11 key %s", pkey_identifier);
  1719. + goto fail;
  1720. + }
  1721. + }
  1722. + else
  1723. + {
  1724. + warn("EAP-TLS: Cannot load PKCS11 key %s", pkey_identifier);
  1725. + log_ssl_errors();
  1726. + }
  1727. + }
  1728. + else
  1729. + {
  1730. + if (!SSL_CTX_use_PrivateKey_file(ctx, privkeyfile, SSL_FILETYPE_PEM))
  1731. + {
  1732. + error("EAP-TLS: Cannot use private key %s", privkeyfile);
  1733. + goto fail;
  1734. + }
  1735. + }
  1736. +
  1737. + if (SSL_CTX_check_private_key(ctx) != 1) {
  1738. + error("EAP-TLS: Private key %s fails security check", privkeyfile);
  1739. + goto fail;
  1740. + }
  1741. +
  1742. + SSL_CTX_set_options(ctx, SSL_OP_NO_SSLv2 | SSL_OP_NO_SSLv3);
  1743. + SSL_CTX_set_verify_depth(ctx, 5);
  1744. + SSL_CTX_set_verify(ctx,
  1745. + SSL_VERIFY_PEER |
  1746. + SSL_VERIFY_FAIL_IF_NO_PEER_CERT,
  1747. + &ssl_verify_callback);
  1748. +
  1749. + if (crl_dir) {
  1750. + if (!(certstore = SSL_CTX_get_cert_store(ctx))) {
  1751. + error("EAP-TLS: Failed to get certificate store");
  1752. + goto fail;
  1753. + }
  1754. +
  1755. + if (!(lookup =
  1756. + X509_STORE_add_lookup(certstore, X509_LOOKUP_hash_dir()))) {
  1757. + error("EAP-TLS: Store lookup for CRL failed");
  1758. +
  1759. + goto fail;
  1760. + }
  1761. +
  1762. + X509_LOOKUP_add_dir(lookup, crl_dir, X509_FILETYPE_PEM);
  1763. + X509_STORE_set_flags(certstore, X509_V_FLAG_CRL_CHECK);
  1764. + }
  1765. +
  1766. + /*
  1767. + * If a peer certificate file was specified, it must be valid, else fail
  1768. + */
  1769. + if (peer_certfile[0]) {
  1770. + if (!(tmp = get_X509_from_file(peer_certfile))) {
  1771. + error("EAP-TLS: Error loading client certificate from file %s",
  1772. + peer_certfile);
  1773. + goto fail;
  1774. + }
  1775. + X509_free(tmp);
  1776. + }
  1777. +
  1778. + return ctx;
  1779. +
  1780. +fail:
  1781. + log_ssl_errors();
  1782. + SSL_CTX_free(ctx);
  1783. + return NULL;
  1784. +}
  1785. +
  1786. +/*
  1787. + * Determine the maximum packet size by looking at the LCP handshake
  1788. + */
  1789. +
  1790. +int eaptls_get_mtu(int unit)
  1791. +{
  1792. + int mtu, mru;
  1793. +
  1794. + lcp_options *wo = &lcp_wantoptions[unit];
  1795. + lcp_options *go = &lcp_gotoptions[unit];
  1796. + lcp_options *ho = &lcp_hisoptions[unit];
  1797. + lcp_options *ao = &lcp_allowoptions[unit];
  1798. +
  1799. + mtu = ho->neg_mru? ho->mru: PPP_MRU;
  1800. + mru = go->neg_mru? MAX(wo->mru, go->mru): PPP_MRU;
  1801. + mtu = MIN(MIN(mtu, mru), ao->mru)- PPP_HDRLEN - 10;
  1802. +
  1803. + dbglog("MTU = %d", mtu);
  1804. + return mtu;
  1805. +}
  1806. +
  1807. +
  1808. +/*
  1809. + * Init the ssl handshake (server mode)
  1810. + */
  1811. +int eaptls_init_ssl_server(eap_state * esp)
  1812. +{
  1813. + struct eaptls_session *ets;
  1814. + char servcertfile[MAXWORDLEN];
  1815. + char clicertfile[MAXWORDLEN];
  1816. + char cacertfile[MAXWORDLEN];
  1817. + char pkfile[MAXWORDLEN];
  1818. + /*
  1819. + * Allocate new eaptls session
  1820. + */
  1821. + esp->es_server.ea_session = malloc(sizeof(struct eaptls_session));
  1822. + if (!esp->es_server.ea_session)
  1823. + fatal("Allocation error");
  1824. + ets = esp->es_server.ea_session;
  1825. +
  1826. + if (!esp->es_server.ea_peer) {
  1827. + error("EAP-TLS: Error: client name not set (BUG)");
  1828. + return 0;
  1829. + }
  1830. +
  1831. + strncpy(ets->peer, esp->es_server.ea_peer, MAXWORDLEN);
  1832. +
  1833. + dbglog( "getting eaptls secret" );
  1834. + if (!get_eaptls_secret(esp->es_unit, esp->es_server.ea_peer,
  1835. + esp->es_server.ea_name, clicertfile,
  1836. + servcertfile, cacertfile, pkfile, 1)) {
  1837. + error( "EAP-TLS: Cannot get secret/password for client \"%s\", server \"%s\"",
  1838. + esp->es_server.ea_peer, esp->es_server.ea_name );
  1839. + return 0;
  1840. + }
  1841. +
  1842. + ets->mtu = eaptls_get_mtu(esp->es_unit);
  1843. +
  1844. + ets->ctx = eaptls_init_ssl(1, cacertfile, servcertfile, clicertfile, pkfile);
  1845. + if (!ets->ctx)
  1846. + goto fail;
  1847. +
  1848. + if (!(ets->ssl = SSL_new(ets->ctx)))
  1849. + goto fail;
  1850. +
  1851. + /*
  1852. + * Set auto-retry to avoid timeouts on BIO_read
  1853. + */
  1854. + SSL_set_mode(ets->ssl, SSL_MODE_AUTO_RETRY);
  1855. +
  1856. + /*
  1857. + * Initialize the BIOs we use to read/write to ssl engine
  1858. + */
  1859. + ets->into_ssl = BIO_new(BIO_s_mem());
  1860. + ets->from_ssl = BIO_new(BIO_s_mem());
  1861. + SSL_set_bio(ets->ssl, ets->into_ssl, ets->from_ssl);
  1862. +
  1863. + SSL_set_msg_callback(ets->ssl, ssl_msg_callback);
  1864. + SSL_set_msg_callback_arg(ets->ssl, ets);
  1865. +
  1866. + /*
  1867. + * Attach the session struct to the connection, so we can later
  1868. + * retrieve it when doing certificate verification
  1869. + */
  1870. + SSL_set_ex_data(ets->ssl, 0, ets);
  1871. +
  1872. + SSL_set_accept_state(ets->ssl);
  1873. +
  1874. + ets->data = NULL;
  1875. + ets->datalen = 0;
  1876. + ets->alert_sent = 0;
  1877. + ets->alert_recv = 0;
  1878. +
  1879. + /*
  1880. + * If we specified the client certificate file, store it in ets->peercertfile,
  1881. + * so we can check it later in ssl_verify_callback()
  1882. + */
  1883. + if (clicertfile[0])
  1884. + strncpy(&ets->peercertfile[0], clicertfile, MAXWORDLEN);
  1885. + else
  1886. + ets->peercertfile[0] = 0;
  1887. +
  1888. + return 1;
  1889. +
  1890. +fail:
  1891. + SSL_CTX_free(ets->ctx);
  1892. + return 0;
  1893. +}
  1894. +
  1895. +/*
  1896. + * Init the ssl handshake (client mode)
  1897. + */
  1898. +int eaptls_init_ssl_client(eap_state * esp)
  1899. +{
  1900. + struct eaptls_session *ets;
  1901. + char servcertfile[MAXWORDLEN];
  1902. + char clicertfile[MAXWORDLEN];
  1903. + char cacertfile[MAXWORDLEN];
  1904. + char pkfile[MAXWORDLEN];
  1905. +
  1906. + /*
  1907. + * Allocate new eaptls session
  1908. + */
  1909. + esp->es_client.ea_session = malloc(sizeof(struct eaptls_session));
  1910. + if (!esp->es_client.ea_session)
  1911. + fatal("Allocation error");
  1912. + ets = esp->es_client.ea_session;
  1913. +
  1914. + /*
  1915. + * If available, copy server name in ets; it will be used in cert
  1916. + * verify
  1917. + */
  1918. + if (esp->es_client.ea_peer)
  1919. + strncpy(ets->peer, esp->es_client.ea_peer, MAXWORDLEN);
  1920. + else
  1921. + ets->peer[0] = 0;
  1922. +
  1923. + ets->mtu = eaptls_get_mtu(esp->es_unit);
  1924. +
  1925. + dbglog( "calling get_eaptls_secret" );
  1926. + if (!get_eaptls_secret(esp->es_unit, esp->es_client.ea_name,
  1927. + esp->es_client.ea_peer, clicertfile,
  1928. + servcertfile, cacertfile, pkfile, 0)) {
  1929. + error( "EAP-TLS: Cannot get secret/password for client \"%s\", server \"%s\"",
  1930. + esp->es_client.ea_name, esp->es_client.ea_peer );
  1931. + return 0;
  1932. + }
  1933. +
  1934. + dbglog( "calling eaptls_init_ssl" );
  1935. + ets->ctx = eaptls_init_ssl(0, cacertfile, clicertfile, servcertfile, pkfile);
  1936. + if (!ets->ctx)
  1937. + goto fail;
  1938. +
  1939. + ets->ssl = SSL_new(ets->ctx);
  1940. +
  1941. + if (!ets->ssl)
  1942. + goto fail;
  1943. +
  1944. + /*
  1945. + * Initialize the BIOs we use to read/write to ssl engine
  1946. + */
  1947. + dbglog( "Initializing SSL BIOs" );
  1948. + ets->into_ssl = BIO_new(BIO_s_mem());
  1949. + ets->from_ssl = BIO_new(BIO_s_mem());
  1950. + SSL_set_bio(ets->ssl, ets->into_ssl, ets->from_ssl);
  1951. +
  1952. + SSL_set_msg_callback(ets->ssl, ssl_msg_callback);
  1953. + SSL_set_msg_callback_arg(ets->ssl, ets);
  1954. +
  1955. + /*
  1956. + * Attach the session struct to the connection, so we can later
  1957. + * retrieve it when doing certificate verification
  1958. + */
  1959. + SSL_set_ex_data(ets->ssl, 0, ets);
  1960. +
  1961. + SSL_set_connect_state(ets->ssl);
  1962. +
  1963. + ets->data = NULL;
  1964. + ets->datalen = 0;
  1965. + ets->alert_sent = 0;
  1966. + ets->alert_recv = 0;
  1967. +
  1968. + /*
  1969. + * If we specified the server certificate file, store it in
  1970. + * ets->peercertfile, so we can check it later in
  1971. + * ssl_verify_callback()
  1972. + */
  1973. + if (servcertfile[0])
  1974. + strncpy(ets->peercertfile, servcertfile, MAXWORDLEN);
  1975. + else
  1976. + ets->peercertfile[0] = 0;
  1977. +
  1978. + return 1;
  1979. +
  1980. +fail:
  1981. + dbglog( "eaptls_init_ssl_client: fail" );
  1982. + SSL_CTX_free(ets->ctx);
  1983. + return 0;
  1984. +
  1985. +}
  1986. +
  1987. +void eaptls_free_session(struct eaptls_session *ets)
  1988. +{
  1989. + if (ets->ssl)
  1990. + SSL_free(ets->ssl);
  1991. +
  1992. + if (ets->ctx)
  1993. + SSL_CTX_free(ets->ctx);
  1994. +
  1995. + free(ets);
  1996. +}
  1997. +
  1998. +/*
  1999. + * Handle a received packet, reassembling fragmented messages and
  2000. + * passing them to the ssl engine
  2001. + */
  2002. +int eaptls_receive(struct eaptls_session *ets, u_char * inp, int len)
  2003. +{
  2004. + u_char flags;
  2005. + u_int tlslen;
  2006. + u_char dummy[65536];
  2007. +
  2008. + GETCHAR(flags, inp);
  2009. + len--;
  2010. +
  2011. + if (flags & EAP_TLS_FLAGS_LI && !ets->data) {
  2012. +
  2013. + /*
  2014. + * This is the first packet of a message
  2015. + */
  2016. +
  2017. + GETLONG(tlslen, inp);
  2018. + len -= 4;
  2019. +
  2020. + if (tlslen > EAP_TLS_MAX_LEN) {
  2021. + error("Error: tls message length > %d, truncated",
  2022. + EAP_TLS_MAX_LEN);
  2023. + tlslen = EAP_TLS_MAX_LEN;
  2024. + }
  2025. +
  2026. + /*
  2027. + * Allocate memory for the whole message
  2028. + */
  2029. + ets->data = malloc(tlslen);
  2030. + if (!ets->data)
  2031. + fatal("EAP TLS: allocation error\n");
  2032. +
  2033. + ets->datalen = 0;
  2034. + ets->tlslen = tlslen;
  2035. +
  2036. + }
  2037. + else if (flags & EAP_TLS_FLAGS_LI && ets->data) {
  2038. + /*
  2039. + * Non first with LI (strange...)
  2040. + */
  2041. +
  2042. + GETLONG(tlslen, inp);
  2043. + len -= 4;
  2044. +
  2045. + }
  2046. + else if (!ets->data) {
  2047. + /*
  2048. + * A non fragmented message without LI flag
  2049. + */
  2050. +
  2051. + ets->data = malloc(len);
  2052. + if (!ets->data)
  2053. + fatal("EAP TLS: allocation error\n");
  2054. +
  2055. + ets->datalen = 0;
  2056. + ets->tlslen = len;
  2057. + }
  2058. +
  2059. + if (flags & EAP_TLS_FLAGS_MF)
  2060. + ets->frag = 1;
  2061. + else
  2062. + ets->frag = 0;
  2063. +
  2064. + if (len + ets->datalen > ets->tlslen) {
  2065. + warn("EAP TLS: received data > TLS message length");
  2066. + return 1;
  2067. + }
  2068. +
  2069. + BCOPY(inp, ets->data + ets->datalen, len);
  2070. + ets->datalen += len;
  2071. +
  2072. + if (!ets->frag) {
  2073. +
  2074. + /*
  2075. + * If we have the whole message, pass it to ssl
  2076. + */
  2077. +
  2078. + if (ets->datalen != ets->tlslen) {
  2079. + warn("EAP TLS: received data != TLS message length");
  2080. + return 1;
  2081. + }
  2082. +
  2083. + if (BIO_write(ets->into_ssl, ets->data, ets->datalen) == -1)
  2084. + log_ssl_errors();
  2085. +
  2086. + SSL_read(ets->ssl, dummy, 65536);
  2087. +
  2088. + free(ets->data);
  2089. + ets->data = NULL;
  2090. + ets->datalen = 0;
  2091. + }
  2092. +
  2093. + return 0;
  2094. +}
  2095. +
  2096. +/*
  2097. + * Return an eap-tls packet in outp.
  2098. + * A TLS message read from the ssl engine is buffered in ets->data.
  2099. + * At each call we control if there is buffered data and send a
  2100. + * packet of mtu bytes.
  2101. + */
  2102. +int eaptls_send(struct eaptls_session *ets, u_char ** outp)
  2103. +{
  2104. + bool first = 0;
  2105. + int size;
  2106. + u_char fromtls[65536];
  2107. + int res;
  2108. + u_char *start;
  2109. +
  2110. + start = *outp;
  2111. +
  2112. + if (!ets->data) {
  2113. +
  2114. + if(!ets->alert_sent)
  2115. + SSL_read(ets->ssl, fromtls, 65536);
  2116. +
  2117. + /*
  2118. + * Read from ssl
  2119. + */
  2120. + if ((res = BIO_read(ets->from_ssl, fromtls, 65536)) == -1)
  2121. + fatal("No data from BIO_read");
  2122. +
  2123. + ets->datalen = res;
  2124. +
  2125. + ets->data = malloc(ets->datalen);
  2126. + BCOPY(fromtls, ets->data, ets->datalen);
  2127. +
  2128. + ets->offset = 0;
  2129. + first = 1;
  2130. +
  2131. + }
  2132. +
  2133. + size = ets->datalen - ets->offset;
  2134. +
  2135. + if (size > ets->mtu) {
  2136. + size = ets->mtu;
  2137. + ets->frag = 1;
  2138. + } else
  2139. + ets->frag = 0;
  2140. +
  2141. + PUTCHAR(EAPT_TLS, *outp);
  2142. +
  2143. + /*
  2144. + * Set right flags and length if necessary
  2145. + */
  2146. + if (ets->frag && first) {
  2147. + PUTCHAR(EAP_TLS_FLAGS_LI | EAP_TLS_FLAGS_MF, *outp);
  2148. + PUTLONG(ets->datalen, *outp);
  2149. + } else if (ets->frag) {
  2150. + PUTCHAR(EAP_TLS_FLAGS_MF, *outp);
  2151. + } else
  2152. + PUTCHAR(0, *outp);
  2153. +
  2154. + /*
  2155. + * Copy the data in outp
  2156. + */
  2157. + BCOPY(ets->data + ets->offset, *outp, size);
  2158. + INCPTR(size, *outp);
  2159. +
  2160. + /*
  2161. + * Copy the packet in retransmission buffer
  2162. + */
  2163. + BCOPY(start, &ets->rtx[0], *outp - start);
  2164. + ets->rtx_len = *outp - start;
  2165. +
  2166. + ets->offset += size;
  2167. +
  2168. + if (ets->offset >= ets->datalen) {
  2169. +
  2170. + /*
  2171. + * The whole message has been sent
  2172. + */
  2173. +
  2174. + free(ets->data);
  2175. + ets->data = NULL;
  2176. + ets->datalen = 0;
  2177. + ets->offset = 0;
  2178. + }
  2179. +
  2180. + return 0;
  2181. +}
  2182. +
  2183. +/*
  2184. + * Get the sent packet from the retransmission buffer
  2185. + */
  2186. +void eaptls_retransmit(struct eaptls_session *ets, u_char ** outp)
  2187. +{
  2188. + BCOPY(ets->rtx, *outp, ets->rtx_len);
  2189. + INCPTR(ets->rtx_len, *outp);
  2190. +}
  2191. +
  2192. +/*
  2193. + * Verify a certificate.
  2194. + * Most of the work (signatures and issuer attributes checking)
  2195. + * is done by ssl; we check the CN in the peer certificate
  2196. + * against the peer name.
  2197. + */
  2198. +int ssl_verify_callback(int preverify_ok, X509_STORE_CTX * ctx)
  2199. +{
  2200. + char subject[256];
  2201. + char cn_str[256];
  2202. + X509 *peer_cert;
  2203. + int err, depth;
  2204. + int ok = preverify_ok;
  2205. + SSL *ssl;
  2206. + struct eaptls_session *ets;
  2207. +
  2208. + peer_cert = X509_STORE_CTX_get_current_cert(ctx);
  2209. + err = X509_STORE_CTX_get_error(ctx);
  2210. + depth = X509_STORE_CTX_get_error_depth(ctx);
  2211. +
  2212. + dbglog("certificate verify depth: %d", depth);
  2213. +
  2214. + if (auth_required && !ok) {
  2215. + X509_NAME_oneline(X509_get_subject_name(peer_cert),
  2216. + subject, 256);
  2217. +
  2218. + X509_NAME_get_text_by_NID(X509_get_subject_name(peer_cert),
  2219. + NID_commonName, cn_str, 256);
  2220. +
  2221. + dbglog("Certificate verification error:\n depth: %d CN: %s"
  2222. + "\n err: %d (%s)\n", depth, cn_str, err,
  2223. + X509_verify_cert_error_string(err));
  2224. +
  2225. + return 0;
  2226. + }
  2227. +
  2228. + ssl = X509_STORE_CTX_get_ex_data(ctx,
  2229. + SSL_get_ex_data_X509_STORE_CTX_idx());
  2230. +
  2231. + ets = (struct eaptls_session *)SSL_get_ex_data(ssl, 0);
  2232. +
  2233. + if (ets == NULL) {
  2234. + error("Error: SSL_get_ex_data returned NULL");
  2235. + return 0;
  2236. + }
  2237. +
  2238. + log_ssl_errors();
  2239. +
  2240. + if (!depth) { /* This is the peer certificate */
  2241. +
  2242. + X509_NAME_oneline(X509_get_subject_name(peer_cert),
  2243. + subject, 256);
  2244. +
  2245. + X509_NAME_get_text_by_NID(X509_get_subject_name(peer_cert),
  2246. + NID_commonName, cn_str, 256);
  2247. +
  2248. + /*
  2249. + * If acting as client and the name of the server wasn't specified
  2250. + * explicitely, we can't verify the server authenticity
  2251. + */
  2252. + if (!ets->peer[0]) {
  2253. + warn("Peer name not specified: no check");
  2254. + return 1;
  2255. + }
  2256. +
  2257. + /*
  2258. + * Check the CN
  2259. + */
  2260. + if (strcmp(cn_str, ets->peer)) {
  2261. + error
  2262. + ("Certificate verification error: CN (%s) != peer_name (%s)",
  2263. + cn_str, ets->peer);
  2264. + return 0;
  2265. + }
  2266. +
  2267. + warn("Certificate CN: %s , peer name %s", cn_str, ets->peer);
  2268. +
  2269. + /*
  2270. + * If a peer certificate file was specified, here we check it
  2271. + */
  2272. + if (ets->peercertfile[0]) {
  2273. + if (ssl_cmp_certs(&ets->peercertfile[0], peer_cert)
  2274. + != 0) {
  2275. + error
  2276. + ("Peer certificate doesn't match stored certificate");
  2277. + return 0;
  2278. + }
  2279. + }
  2280. + }
  2281. +
  2282. + return 1;
  2283. +}
  2284. +
  2285. +/*
  2286. + * Compare a certificate with the one stored in a file
  2287. + */
  2288. +int ssl_cmp_certs(char *filename, X509 * a)
  2289. +{
  2290. + X509 *b;
  2291. + int ret;
  2292. +
  2293. + if (!(b = get_X509_from_file(filename)))
  2294. + return 1;
  2295. +
  2296. + ret = X509_cmp(a, b);
  2297. + X509_free(b);
  2298. +
  2299. + return ret;
  2300. +
  2301. +}
  2302. +
  2303. +X509 *get_X509_from_file(char *filename)
  2304. +{
  2305. + FILE *fp;
  2306. + X509 *ret;
  2307. +
  2308. + if (!(fp = fopen(filename, "r")))
  2309. + return NULL;
  2310. +
  2311. + ret = PEM_read_X509(fp, NULL, NULL, NULL);
  2312. +
  2313. + fclose(fp);
  2314. +
  2315. + return ret;
  2316. +}
  2317. +
  2318. +/*
  2319. + * Every sent & received message this callback function is invoked,
  2320. + * so we know when alert messages have arrived or are sent and
  2321. + * we can print debug information about TLS handshake.
  2322. + */
  2323. +void
  2324. +ssl_msg_callback(int write_p, int version, int content_type,
  2325. + const void *buf, size_t len, SSL * ssl, void *arg)
  2326. +{
  2327. + char string[256];
  2328. + struct eaptls_session *ets = (struct eaptls_session *)arg;
  2329. + unsigned char code;
  2330. +
  2331. + if(write_p)
  2332. + strcpy(string, " -> ");
  2333. + else
  2334. + strcpy(string, " <- ");
  2335. +
  2336. +
  2337. + switch(content_type) {
  2338. +
  2339. + case SSL3_RT_ALERT:
  2340. + strcat(string, "Alert: ");
  2341. + code = ((const unsigned char *)buf)[1];
  2342. +
  2343. + if (write_p) {
  2344. + ets->alert_sent = 1;
  2345. + ets->alert_sent_desc = code;
  2346. + } else {
  2347. + ets->alert_recv = 1;
  2348. + ets->alert_recv_desc = code;
  2349. + }
  2350. +
  2351. + strcat(string, SSL_alert_desc_string_long(code));
  2352. + break;
  2353. +
  2354. + case SSL3_RT_CHANGE_CIPHER_SPEC:
  2355. + strcat(string, "ChangeCipherSpec");
  2356. + break;
  2357. +
  2358. + case SSL3_RT_HANDSHAKE:
  2359. +
  2360. + strcat(string, "Handshake: ");
  2361. + code = ((const unsigned char *)buf)[0];
  2362. +
  2363. + switch(code) {
  2364. + case SSL3_MT_HELLO_REQUEST:
  2365. + strcat(string,"Hello Request");
  2366. + break;
  2367. + case SSL3_MT_CLIENT_HELLO:
  2368. + strcat(string,"Client Hello");
  2369. + break;
  2370. + case SSL3_MT_SERVER_HELLO:
  2371. + strcat(string,"Server Hello");
  2372. + break;
  2373. + case SSL3_MT_CERTIFICATE:
  2374. + strcat(string,"Certificate");
  2375. + break;
  2376. + case SSL3_MT_SERVER_KEY_EXCHANGE:
  2377. + strcat(string,"Server Key Exchange");
  2378. + break;
  2379. + case SSL3_MT_CERTIFICATE_REQUEST:
  2380. + strcat(string,"Certificate Request");
  2381. + break;
  2382. + case SSL3_MT_SERVER_DONE:
  2383. + strcat(string,"Server Hello Done");
  2384. + break;
  2385. + case SSL3_MT_CERTIFICATE_VERIFY:
  2386. + strcat(string,"Certificate Verify");
  2387. + break;
  2388. + case SSL3_MT_CLIENT_KEY_EXCHANGE:
  2389. + strcat(string,"Client Key Exchange");
  2390. + break;
  2391. + case SSL3_MT_FINISHED:
  2392. + strcat(string,"Finished");
  2393. + break;
  2394. +
  2395. + default:
  2396. + sprintf( string, "Handshake: Unknown SSL3 code received: %d", code );
  2397. + }
  2398. + break;
  2399. +
  2400. + default:
  2401. + sprintf( string, "SSL message contains unknown content type: %d", content_type );
  2402. +
  2403. + }
  2404. +
  2405. + /* Alert messages must always be displayed */
  2406. + if(content_type == SSL3_RT_ALERT)
  2407. + error("%s", string);
  2408. + else
  2409. + dbglog("%s", string);
  2410. +}
  2411. +
  2412. --- ppp-2.4.6/pppd/eap-tls.h
  2413. +++ ppp-2.4.6/pppd/eap-tls.h
  2414. @@ -0,0 +1,107 @@
  2415. +/*
  2416. + * eap-tls.h
  2417. + *
  2418. + * Copyright (c) Beniamino Galvani 2005 All rights reserved.
  2419. + *
  2420. + * Redistribution and use in source and binary forms, with or without
  2421. + * modification, are permitted provided that the following conditions
  2422. + * are met:
  2423. + *
  2424. + * 1. Redistributions of source code must retain the above copyright
  2425. + * notice, this list of conditions and the following disclaimer.
  2426. + *
  2427. + * 2. Redistributions in binary form must reproduce the above copyright
  2428. + * notice, this list of conditions and the following disclaimer in
  2429. + * the documentation and/or other materials provided with the
  2430. + * distribution.
  2431. + *
  2432. + * 3. The name(s) of the authors of this software must not be used to
  2433. + * endorse or promote products derived from this software without
  2434. + * prior written permission.
  2435. + *
  2436. + * THE AUTHORS OF THIS SOFTWARE DISCLAIM ALL WARRANTIES WITH REGARD TO
  2437. + * THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  2438. + * AND FITNESS, IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY
  2439. + * SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  2440. + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN
  2441. + * AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
  2442. + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  2443. + *
  2444. + */
  2445. +
  2446. +#ifndef __EAP_TLS_H__
  2447. +#define __EAP_TLS_H__
  2448. +
  2449. +#include "eap.h"
  2450. +
  2451. +#include <openssl/ssl.h>
  2452. +#include <openssl/bio.h>
  2453. +#include <openssl/md5.h>
  2454. +
  2455. +#define EAP_TLS_FLAGS_LI 128 /* length included flag */
  2456. +#define EAP_TLS_FLAGS_MF 64 /* more fragments flag */
  2457. +#define EAP_TLS_FLAGS_START 32 /* start flag */
  2458. +
  2459. +#define EAP_TLS_MAX_LEN 65536 /* max eap tls packet size */
  2460. +
  2461. +struct eaptls_session
  2462. +{
  2463. + u_char *data; /* buffered data */
  2464. + int datalen; /* buffered data len */
  2465. + int offset; /* from where to send */
  2466. + int tlslen; /* total length of tls data */
  2467. + bool frag; /* packet is fragmented */
  2468. + SSL_CTX *ctx;
  2469. + SSL *ssl; /* ssl connection */
  2470. + BIO *from_ssl;
  2471. + BIO *into_ssl;
  2472. + char peer[MAXWORDLEN]; /* peer name */
  2473. + char peercertfile[MAXWORDLEN];
  2474. + bool alert_sent;
  2475. + u_char alert_sent_desc;
  2476. + bool alert_recv;
  2477. + u_char alert_recv_desc;
  2478. + char rtx[65536]; /* retransmission buffer */
  2479. + int rtx_len;
  2480. + int mtu; /* unit mtu */
  2481. +};
  2482. +
  2483. +typedef struct pw_cb_data
  2484. +{
  2485. + const void *password;
  2486. + const char *prompt_info;
  2487. +} PW_CB_DATA;
  2488. +
  2489. +
  2490. +int ssl_verify_callback(int, X509_STORE_CTX *);
  2491. +void ssl_msg_callback(int write_p, int version, int ct, const void *buf,
  2492. + size_t len, SSL * ssl, void *arg);
  2493. +
  2494. +X509 *get_X509_from_file(char *filename);
  2495. +int ssl_cmp_certs(char *filename, X509 * a);
  2496. +
  2497. +SSL_CTX *eaptls_init_ssl(int init_server, char *cacertfile,
  2498. + char *certfile, char *peer_certfile, char *privkeyfile);
  2499. +int eaptls_init_ssl_server(eap_state * esp);
  2500. +int eaptls_init_ssl_client(eap_state * esp);
  2501. +void eaptls_free_session(struct eaptls_session *ets);
  2502. +
  2503. +int eaptls_receive(struct eaptls_session *ets, u_char * inp, int len);
  2504. +int eaptls_send(struct eaptls_session *ets, u_char ** outp);
  2505. +void eaptls_retransmit(struct eaptls_session *ets, u_char ** outp);
  2506. +
  2507. +int get_eaptls_secret(int unit, char *client, char *server,
  2508. + char *clicertfile, char *servcertfile, char *cacertfile,
  2509. + char *pkfile, int am_server);
  2510. +
  2511. +#ifdef MPPE
  2512. +#include "mppe.h" /* MPPE_MAX_KEY_LEN */
  2513. +extern u_char mppe_send_key[MPPE_MAX_KEY_LEN];
  2514. +extern u_char mppe_recv_key[MPPE_MAX_KEY_LEN];
  2515. +extern int mppe_keys_set;
  2516. +
  2517. +void eaptls_gen_mppe_keys(struct eaptls_session *ets, const char *prf_label, int client);
  2518. +
  2519. +#endif
  2520. +
  2521. +#endif
  2522. --- ppp-2.4.6/pppd/Makefile.linux
  2523. +++ ppp-2.4.6/pppd/Makefile.linux
  2524. @@ -76,6 +76,9 @@
  2525. # Use libutil
  2526. USE_LIBUTIL=y
  2527. +# Enable EAP-TLS authentication (requires libssl and libcrypto)
  2528. +USE_EAPTLS=y
  2529. +
  2530. MAXOCTETS=y
  2531. INCLUDE_DIRS= -I../include
  2532. @@ -115,6 +118,15 @@
  2533. PPPDOBJS += sha1.o
  2534. endif
  2535. +# EAP-TLS
  2536. +ifdef USE_EAPTLS
  2537. +CFLAGS += -DUSE_EAPTLS=1 -I/usr/kerberos/include
  2538. +LIBS += -lssl -lcrypto
  2539. +PPPDSRC += eap-tls.c
  2540. +HEADERS += eap-tls.h
  2541. +PPPDOBJS += eap-tls.o
  2542. +endif
  2543. +
  2544. ifdef HAS_SHADOW
  2545. CFLAGS += -DHAS_SHADOW
  2546. #LIBS += -lshadow $(LIBS)
  2547. --- ppp-2.4.6/pppd/md5.c
  2548. +++ ppp-2.4.6/pppd/md5.c
  2549. @@ -33,6 +33,8 @@
  2550. ***********************************************************************
  2551. */
  2552. +#ifndef USE_EAPTLS
  2553. +
  2554. #include <string.h>
  2555. #include "md5.h"
  2556. @@ -305,3 +307,5 @@
  2557. ** End of md5.c **
  2558. ******************************** (cut) ********************************
  2559. */
  2560. +#endif /* USE_EAPTLS */
  2561. +
  2562. --- ppp-2.4.6/pppd/md5.h
  2563. +++ ppp-2.4.6/pppd/md5.h
  2564. @@ -36,6 +36,7 @@
  2565. ** documentation and/or software. **
  2566. ***********************************************************************
  2567. */
  2568. +#ifndef USE_EAPTLS
  2569. #ifndef __MD5_INCLUDE__
  2570. @@ -63,3 +64,5 @@
  2571. #define __MD5_INCLUDE__
  2572. #endif /* __MD5_INCLUDE__ */
  2573. +
  2574. +#endif /* USE_EAPTLS */
  2575. --- ppp-2.4.6/pppd/options.c
  2576. +++ ppp-2.4.6/pppd/options.c
  2577. @@ -122,6 +122,11 @@
  2578. int child_wait = 5; /* # seconds to wait for children at exit */
  2579. struct userenv *userenv_list; /* user environment variables */
  2580. +#ifdef USE_EAPTLS
  2581. +bool only_update_crl_server = 0; /* update server crl and exit */
  2582. +bool only_update_crl_client = 0; /* update client crl and exit */
  2583. +#endif /* USE_EAPTLS */
  2584. +
  2585. #ifdef MAXOCTETS
  2586. unsigned int maxoctets = 0; /* default - no limit */
  2587. int maxoctets_dir = 0; /* default - sum of traffic */
  2588. @@ -338,6 +343,12 @@
  2589. { "mo-timeout", o_int, &maxoctets_timeout,
  2590. "Check for traffic limit every N seconds", OPT_PRIO | OPT_LLIMIT | 1 },
  2591. #endif
  2592. +#ifdef USE_EAPTLS
  2593. + { "only-update-crl-server", o_bool, &only_update_crl_server,
  2594. + "Update server CA CRLs and exit", 1 },
  2595. + { "only-update-crl-client", o_bool, &only_update_crl_client,
  2596. + "Update client CA CRLs and exit", 1 },
  2597. +#endif /* USE_EAPTLS */
  2598. { NULL }
  2599. };
  2600. --- ppp-2.4.6/pppd/pathnames.h
  2601. +++ ppp-2.4.6/pppd/pathnames.h
  2602. @@ -21,6 +21,13 @@
  2603. #define _PATH_UPAPFILE _ROOT_PATH "/etc/ppp/pap-secrets"
  2604. #define _PATH_CHAPFILE _ROOT_PATH "/etc/ppp/chap-secrets"
  2605. #define _PATH_SRPFILE _ROOT_PATH "/etc/ppp/srp-secrets"
  2606. +
  2607. +#ifdef USE_EAPTLS
  2608. +#define _PATH_EAPTLSCLIFILE _ROOT_PATH "/etc/ppp/eaptls-client"
  2609. +#define _PATH_EAPTLSSERVFILE _ROOT_PATH "/etc/ppp/eaptls-server"
  2610. +#define _PATH_OPENSSLCONFFILE _ROOT_PATH "/etc/ppp/openssl.cnf"
  2611. +#endif /* USE_EAPTLS */
  2612. +
  2613. #define _PATH_SYSOPTIONS _ROOT_PATH "/etc/ppp/options"
  2614. #define _PATH_IPUP _ROOT_PATH "/etc/ppp/ip-up"
  2615. #define _PATH_IPDOWN _ROOT_PATH "/etc/ppp/ip-down"
  2616. --- ppp-2.4.6/pppd/plugins/Makefile.linux
  2617. +++ ppp-2.4.6/pppd/plugins/Makefile.linux
  2618. @@ -4,6 +4,9 @@
  2619. LDFLAGS = -shared
  2620. INSTALL = install
  2621. +# EAP-TLS
  2622. +CFLAGS += -DUSE_EAPTLS=1
  2623. +
  2624. DESTDIR = $(INSTROOT)@DESTDIR@
  2625. BINDIR = $(DESTDIR)/sbin
  2626. MANDIR = $(DESTDIR)/share/man/man8
  2627. --- ppp-2.4.6/pppd/plugins/passprompt.c
  2628. +++ ppp-2.4.6/pppd/plugins/passprompt.c
  2629. @@ -107,4 +107,7 @@
  2630. {
  2631. add_options(options);
  2632. pap_passwd_hook = promptpass;
  2633. +#ifdef USE_EAPTLS
  2634. + eaptls_passwd_hook = promptpass;
  2635. +#endif
  2636. }
  2637. --- ppp-2.4.6/pppd/plugins/passwordfd.c
  2638. +++ ppp-2.4.6/pppd/plugins/passwordfd.c
  2639. @@ -79,4 +79,8 @@
  2640. chap_check_hook = pwfd_check;
  2641. chap_passwd_hook = pwfd_passwd;
  2642. +
  2643. +#ifdef USE_EAPTLS
  2644. + eaptls_passwd_hook = pwfd_passwd;
  2645. +#endif
  2646. }
  2647. --- ppp-2.4.6/pppd/pppd.h
  2648. +++ ppp-2.4.6/pppd/pppd.h
  2649. @@ -324,6 +324,10 @@
  2650. extern bool dryrun; /* check everything, print options, exit */
  2651. extern int child_wait; /* # seconds to wait for children at end */
  2652. +#ifdef USE_EAPTLS
  2653. +extern char *crl_dir;
  2654. +#endif /* USE_EAPTLS */
  2655. +
  2656. #ifdef MAXOCTETS
  2657. extern unsigned int maxoctets; /* Maximum octetes per session (in bytes) */
  2658. extern int maxoctets_dir; /* Direction :
  2659. @@ -738,6 +742,10 @@
  2660. extern int (*chap_passwd_hook) __P((char *user, char *passwd));
  2661. extern void (*multilink_join_hook) __P((void));
  2662. +#ifdef USE_EAPTLS
  2663. +extern int (*eaptls_passwd_hook) __P((char *user, char *passwd));
  2664. +#endif
  2665. +
  2666. /* Let a plugin snoop sent and received packets. Useful for L2TP */
  2667. extern void (*snoop_recv_hook) __P((unsigned char *p, int len));
  2668. extern void (*snoop_send_hook) __P((unsigned char *p, int len));
  2669. --- ppp-2.4.6/README.eap-tls
  2670. +++ ppp-2.4.6/README.eap-tls
  2671. @@ -0,0 +1,169 @@
  2672. +EAP-TLS authentication support for PPP
  2673. +======================================
  2674. +
  2675. +1. Intro
  2676. +
  2677. + The Extensible Authentication Protocol (EAP; RFC 3748) is a
  2678. + security protocol that can be used with PPP. It provides a means
  2679. + to plug in multiple optional authentication methods.
  2680. +
  2681. + Transport Level Security (TLS; RFC 2246) provides for mutual
  2682. + authentication, integrity-protected ciphersuite negotiation and
  2683. + key exchange between two endpoints. It also provides for optional
  2684. + MPPE encryption.
  2685. +
  2686. + EAP-TLS (RFC 2716) incapsulates the TLS messages in EAP packets,
  2687. + allowing TLS mutual authentication to be used as a generic EAP
  2688. + mechanism. It also provides optional encryption using the MPPE
  2689. + protocol.
  2690. +
  2691. + This patch provide EAP-TLS support to pppd.
  2692. + This authentication method can be used in both client or server
  2693. + mode.
  2694. +
  2695. +2. Building
  2696. +
  2697. + To build pppd with EAP-TLS support, OpenSSL (http://www.openssl.org)
  2698. + is required. Any version from 0.9.7 should work.
  2699. +
  2700. + Configure, compile, and install as usual.
  2701. +
  2702. +3. Configuration
  2703. +
  2704. + On the client side there are two ways to configure EAP-TLS:
  2705. +
  2706. + 1. supply the appropriate 'ca', 'cert' and 'key' command-line parameters
  2707. +
  2708. + 2. edit the /etc/ppp/eaptls-client file.
  2709. + Insert a line for each system with which you use EAP-TLS.
  2710. + The line is composed of this fields separated by tab:
  2711. +
  2712. + - Client name
  2713. + The name used by the client for authentication, can be *
  2714. + - Server name
  2715. + The name of the server, can be *
  2716. + - Client certificate file
  2717. + The file containing the certificate chain for the
  2718. + client in PEM format
  2719. + - Server certificate file
  2720. + If you want to specify the certificate that the
  2721. + server is allowed to use, put the certificate file name.
  2722. + Else put a dash '-'.
  2723. + - CA certificate file
  2724. + The file containing the trusted CA certificates in PEM
  2725. + format.
  2726. + - Client private key file
  2727. + The file containing the client private key in PEM format.
  2728. +
  2729. +
  2730. + On the server side edit the /etc/ppp/eaptls-server file.
  2731. + Insert a line for each system with which you use EAP-TLS.
  2732. + The line is composed of this fields separated by tab:
  2733. +
  2734. + - Client name
  2735. + The name used by the client for authentication, can be *
  2736. + - Server name
  2737. + The name of the server, can be *
  2738. + - Client certificate file
  2739. + If you want to specify the certificate that the
  2740. + client is allowed to use, put the certificate file name.
  2741. + Else put a dash '-'.
  2742. + - Server certificate file
  2743. + The file containing the certificate chain for the
  2744. + server in PEM format
  2745. + - CA certificate file
  2746. + The file containing the trusted CA certificates in PEM
  2747. + format.
  2748. + - Client private key file
  2749. + The file containing the server private key in PEM format.
  2750. + - addresses
  2751. + A list of IP addresses the client is allowed to use.
  2752. +
  2753. +
  2754. + OpenSSL engine support is included starting with v0.95 of this patch.
  2755. + Currently the only engine tested is the 'pkcs11' engine (hardware token
  2756. + support). To use the 'pksc11' engine:
  2757. + - Use a special private key fileiname in the /etc/ppp/eaptls-client file:
  2758. + <engine>:<identifier>
  2759. + e.g.
  2760. + pkcs11:123456
  2761. +
  2762. + - The certificate can also be loaded from the 'pkcs11' engine using
  2763. + a special client certificate filename in the /etc/ppp/eaptls-client file:
  2764. + <engine>:<identifier>
  2765. + e.g.
  2766. + pkcs11:123456
  2767. +
  2768. + - Create an /etc/ppp/openssl.cnf file to load the right OpenSSL engine prior
  2769. + to starting 'pppd'. A sample openssl.cnf file is
  2770. +
  2771. + openssl_conf = openssl_def
  2772. +
  2773. + [ openssl_def ]
  2774. + engines = engine_section
  2775. +
  2776. + [ engine_section ]
  2777. + pkcs11 = pkcs11_section
  2778. +
  2779. + [ pkcs11_section ]
  2780. + engine_id = pkcs11
  2781. + dynamic_path = /usr/lib64/openssl/engines/engine_pkcs11.so
  2782. + MODULE_PATH = /usr/lib64/libeTPkcs11.so
  2783. + init = 0
  2784. +
  2785. + - There are two ways to specify a password/PIN for the PKCS11 engine:
  2786. + - inside the openssl.cnf file using
  2787. + PIN = your-secret-pin
  2788. + Note The keyword 'PIN' is case sensitive!
  2789. + - Using the 'password' in the ppp options file.
  2790. + From v0.97 of the eap-tls patch the password can also be supplied
  2791. + using the appropriate 'eaptls_passwd_hook' (see plugins/passprompt.c
  2792. + for an example).
  2793. +
  2794. +
  2795. +4. Options
  2796. +
  2797. + These pppd options are available:
  2798. +
  2799. + ca <ca-file>
  2800. + Use the CA public certificate found in <ca-file> in PEM format
  2801. + cert <cert-file>
  2802. + Use the client public certificate found in <cert-file> in PEM format
  2803. + or in engine:engine_id format
  2804. + key <key-file>
  2805. + Use the client private key found in <key-file> in PEM format
  2806. + or in engine:engine_id format
  2807. + crl-dir <dir>
  2808. + Use CRL files from dir. It contains CRL files in PEM
  2809. + format and each file contains a CRL. The files are looked up
  2810. + by the issuer name hash value. Use the c_rehash utility
  2811. + to create necessary links.
  2812. + need-peer-eap
  2813. + If the peer doesn't ask us to authenticate or doesn't use eap
  2814. + to authenticate us, disconnect.
  2815. +
  2816. + Note:
  2817. + password-encrypted certificates can be used as of v0.94 of this
  2818. + patch. The password for the eap-tls.key file is specified using
  2819. + the regular
  2820. + password ....
  2821. + statement in the ppp options file, or by using the appropriate
  2822. + plugin which supplies a 'eaptls_passwd_hook' routine.
  2823. +
  2824. +5. Connecting
  2825. +
  2826. + If you're setting up a pppd server, edit the EAP-TLS configuration file
  2827. + as written above and then run pppd with the 'auth' option to authenticate
  2828. + the client. The EAP-TLS method will be used if the other eap methods can't
  2829. + be used (no secrets).
  2830. +
  2831. + If you're setting up a client, edit the configuration file and then run
  2832. + pppd with 'remotename' option to specify the server name. Add the
  2833. + 'need-peer-eap' option if you want to be sure the peer ask you to
  2834. + authenticate (and to use eap) and to disconnect if it doesn't.
  2835. +
  2836. +6. Notes
  2837. +
  2838. + This is experimental code.
  2839. + Send suggestions and comments to Jan Just Keijser <janjust@nikhef.nl>
  2840. +