X-Git-Url: https://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fauth.c;h=1e9cba09825555ad6146c984ebd1e739cad97796;hp=ffa0e14afb097e775e18cc0257f0e56d7256d9a9;hb=509f04959ad891d7f981f035ed461d51bd1f74b0;hpb=61821b9b6106a1e834ce14783a0b03b8c5301328 diff --git a/pppd/auth.c b/pppd/auth.c index ffa0e14..1e9cba0 100644 --- a/pppd/auth.c +++ b/pppd/auth.c @@ -70,6 +70,10 @@ #define RCSID "$Id: auth.c,v 1.117 2008/07/01 12:27:56 paulus Exp $" +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include #include #include @@ -93,7 +97,7 @@ #include -#ifdef HAS_SHADOW +#ifdef HAVE_SHADOW_H #include #ifndef PW_PPP #define PW_PPP PW_LOGIN @@ -101,6 +105,10 @@ #endif #include +#ifdef HAVE_CRYPT_H +#include +#endif + #ifdef SYSTEMD #include #endif @@ -114,10 +122,10 @@ #include "upap.h" #include "chap-new.h" #include "eap.h" -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS #include "eap-tls.h" #endif -#ifdef CBCP_SUPPORT +#ifdef PPP_WITH_CBCP #include "cbcp.h" #endif #include "pathnames.h" @@ -190,7 +198,7 @@ int (*chap_check_hook)(void) = NULL; /* Hook for a plugin to get the CHAP password for authenticating us */ int (*chap_passwd_hook)(char *user, char *passwd) = NULL; -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS /* Hook for a plugin to get the EAP-TLS password for authenticating us */ int (*eaptls_passwd_hook)(char *user, char *passwd) = NULL; #endif @@ -202,7 +210,7 @@ int (*null_auth_hook)(struct wordlist **paddrs, int (*allowed_address_hook)(u_int32_t addr) = NULL; -#ifdef HAVE_MULTILINK +#ifdef PPP_WITH_MULTILINK /* Hook for plugin to hear when an interface joins a multilink bundle */ void (*multilink_join_hook)(void) = NULL; #endif @@ -236,7 +244,7 @@ bool cryptpap = 0; /* Passwords in pap-secrets are encrypted */ bool refuse_pap = 0; /* Don't wanna auth. ourselves with PAP */ bool refuse_chap = 0; /* Don't wanna auth. ourselves with CHAP */ bool refuse_eap = 0; /* Don't wanna auth. ourselves with EAP */ -#ifdef CHAPMS +#ifdef PPP_WITH_CHAPMS bool refuse_mschap = 0; /* Don't wanna auth. ourselves with MS-CHAP */ bool refuse_mschap_v2 = 0; /* Don't wanna auth. ourselves with MS-CHAPv2 */ #else @@ -250,20 +258,25 @@ bool explicit_remote = 0; /* User specified explicit remote name */ bool explicit_user = 0; /* Set if "user" option supplied */ bool explicit_passwd = 0; /* Set if "password" option supplied */ char remote_name[MAXNAMELEN]; /* Peer's name for authentication */ -#ifdef USE_EAPTLS -char *cacert_file = NULL; /* CA certificate file (pem format) */ -char *ca_path = NULL; /* directory with CA certificates */ -char *cert_file = NULL; /* client certificate file (pem format) */ -char *privkey_file = NULL; /* client private key file (pem format) */ -char *crl_dir = NULL; /* directory containing CRL files */ -char *crl_file = NULL; /* Certificate Revocation List (CRL) file (pem format) */ -char *max_tls_version = NULL; /* Maximum TLS protocol version (default=1.2) */ -bool need_peer_eap = 0; /* Require peer to authenticate us */ + +#if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP) +char *cacert_file = NULL; /* CA certificate file (pem format) */ +char *ca_path = NULL; /* Directory with CA certificates */ +char *crl_dir = NULL; /* Directory containing CRL files */ +char *crl_file = NULL; /* Certificate Revocation List (CRL) file (pem format) */ +char *max_tls_version = NULL; /* Maximum TLS protocol version (default=1.2) */ +char *tls_verify_method = NULL; /* Verify certificate method */ +bool tls_verify_key_usage = 0; /* Verify peer certificate key usage */ #endif -static char *uafname; /* name of most recent +ua file */ +#if defined(PPP_WITH_EAPTLS) +char *cert_file = NULL; /* Client certificate file (pem format) */ +char *privkey_file = NULL; /* Client private key file (pem format) */ +char *pkcs12_file = NULL; /* Client private key envelope file (pkcs12 format) */ +bool need_peer_eap = 0; /* Require peer to authenticate us */ +#endif -extern char *crypt (const char *, const char *); +static char *uafname; /* name of most recent +ua file */ /* Prototypes for procedures local to this file. */ @@ -277,7 +290,7 @@ static int have_chap_secret (char *, char *, int, int *); static int have_srp_secret(char *client, char *server, int need_ip, int *lacks_ipp); -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS static int have_eaptls_secret_server (char *client, char *server, int need_ip, int *lacks_ipp); static int have_eaptls_secret_client (char *client, char *server); @@ -305,7 +318,7 @@ static int set_permitted_number (char **); static void check_access (FILE *, char *); static int wordlist_count (struct wordlist *); -#ifdef MAXOCTETS +#ifdef PPP_WITH_MAXOCTETS static void check_maxoctets (void *); #endif @@ -332,7 +345,7 @@ option_t auth_options[] = { "Require CHAP authentication from peer", OPT_ALIAS | OPT_PRIOSUB | OPT_A2OR | MDTYPE_MD5, &lcp_wantoptions[0].chap_mdtype }, -#ifdef CHAPMS +#ifdef PPP_WITH_CHAPMS { "require-mschap", o_bool, &auth_required, "Require MS-CHAP authentication from peer", OPT_PRIOSUB | OPT_A2OR | MDTYPE_MICROSOFT, @@ -363,7 +376,7 @@ option_t auth_options[] = { "Don't allow CHAP authentication with peer", OPT_ALIAS | OPT_A2CLRB | MDTYPE_MD5, &lcp_allowoptions[0].chap_mdtype }, -#ifdef CHAPMS +#ifdef PPP_WITH_CHAPMS { "refuse-mschap", o_bool, &refuse_mschap, "Don't agree to auth to peer with MS-CHAP", OPT_A2CLRB | MDTYPE_MICROSOFT, @@ -436,18 +449,26 @@ option_t auth_options[] = { "Set telephone number(s) which are allowed to connect", OPT_PRIV | OPT_A2LIST }, -#ifdef USE_EAPTLS - { "ca", o_string, &cacert_file, "EAP-TLS CA certificate in PEM format" }, - { "capath", o_string, &ca_path, "EAP-TLS CA certificate directory" }, - { "cert", o_string, &cert_file, "EAP-TLS client certificate in PEM format" }, - { "key", o_string, &privkey_file, "EAP-TLS client private key in PEM format" }, - { "crl-dir", o_string, &crl_dir, "Use CRLs in directory" }, - { "crl", o_string, &crl_file, "Use specific CRL file" }, +#if defined(PPP_WITH_EAPTLS) || defined(PPP_WITH_PEAP) + { "ca", o_string, &cacert_file, "CA certificate in PEM format" }, + { "capath", o_string, &ca_path, "TLS CA certificate directory" }, + { "crl-dir", o_string, &crl_dir, "Use CRLs in directory" }, + { "crl", o_string, &crl_file, "Use specific CRL file" }, { "max-tls-version", o_string, &max_tls_version, "Maximum TLS version (1.0/1.1/1.2 (default)/1.3)" }, + { "tls-verify-key-usage", o_bool, &tls_verify_key_usage, + "Verify certificate type and extended key usage" }, + { "tls-verify-method", o_string, &tls_verify_method, + "Verify peer by method (none|subject|name|suffix)" }, +#endif + +#if defined(PPP_WITH_EAPTLS) + { "cert", o_string, &cert_file, "client certificate in PEM format" }, + { "key", o_string, &privkey_file, "client private key in PEM format" }, + { "pkcs12", o_string, &pkcs12_file, "EAP-TLS client credentials in PKCS12 format" }, { "need-peer-eap", o_bool, &need_peer_eap, "Require the peer to authenticate us", 1 }, -#endif /* USE_EAPTLS */ +#endif /* PPP_WITH_EAPTLS */ { NULL } }; @@ -772,7 +793,7 @@ link_established(int unit) lcp_options *wo = &lcp_wantoptions[unit]; lcp_options *go = &lcp_gotoptions[unit]; lcp_options *ho = &lcp_hisoptions[unit]; -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS lcp_options *ao = &lcp_allowoptions[unit]; #endif int i; @@ -809,7 +830,7 @@ link_established(int unit) } } -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS if (need_peer_eap && !ao->neg_eap) { warn("eap required to authenticate us but no suitable secrets"); lcp_close(unit, "couldn't negotiate eap"); @@ -876,8 +897,8 @@ network_phase(int unit) /* * If the peer had to authenticate, run the auth-up script now. */ + notify(auth_up_notifier, 0); if (go->neg_chap || go->neg_upap || go->neg_eap) { - notify(auth_up_notifier, 0); auth_state = s_up; if (auth_script_state == s_down && auth_script_pid == 0) { auth_script_state = s_up; @@ -885,7 +906,7 @@ network_phase(int unit) } } -#ifdef CBCP_SUPPORT +#ifdef PPP_WITH_CBCP /* * If we negotiated callback, do it now. */ @@ -916,7 +937,7 @@ start_networks(int unit) new_phase(PHASE_NETWORK); -#ifdef HAVE_MULTILINK +#ifdef PPP_WITH_MULTILINK if (multilink) { if (mp_join_bundle()) { if (multilink_join_hook) @@ -926,9 +947,9 @@ start_networks(int unit) return; } } -#endif /* HAVE_MULTILINK */ +#endif /* PPP_WITH_MULTILINK */ -#ifdef PPP_FILTER +#ifdef PPP_WITH_FILTER if (!demand) set_filters(&pass_filter, &active_filter); #endif @@ -998,7 +1019,7 @@ auth_peer_success(int unit, int protocol, int prot_flavor, case CHAP_MD5: bit |= CHAP_MD5_PEER; break; -#ifdef CHAPMS +#ifdef PPP_WITH_CHAPMS case CHAP_MICROSOFT: bit |= CHAP_MS_PEER; break; @@ -1074,7 +1095,7 @@ auth_withpeer_success(int unit, int protocol, int prot_flavor) case CHAP_MD5: bit |= CHAP_MD5_WITHPEER; break; -#ifdef CHAPMS +#ifdef PPP_WITH_CHAPMS case CHAP_MICROSOFT: bit |= CHAP_MS_WITHPEER; break; @@ -1143,7 +1164,7 @@ np_up(int unit, int proto) if (maxconnect > 0) TIMEOUT(connect_time_expired, 0, maxconnect); -#ifdef MAXOCTETS +#ifdef PPP_WITH_MAXOCTETS if (maxoctets > 0) TIMEOUT(check_maxoctets, NULL, maxoctets_timeout); #endif @@ -1173,7 +1194,7 @@ np_down(int unit, int proto) if (--num_np_up == 0) { UNTIMEOUT(check_idle, NULL); UNTIMEOUT(connect_time_expired, NULL); -#ifdef MAXOCTETS +#ifdef PPP_WITH_MAXOCTETS UNTIMEOUT(check_maxoctets, NULL); #endif new_phase(PHASE_NETWORK); @@ -1192,7 +1213,7 @@ np_finished(int unit, int proto) } } -#ifdef MAXOCTETS +#ifdef PPP_WITH_MAXOCTETS static void check_maxoctets(void *arg) { @@ -1331,7 +1352,7 @@ auth_check_options(void) our_name, 1, &lacks_ip); } -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS if (!can_auth && wo->neg_eap) { can_auth = have_eaptls_secret_server((explicit_remote ? remote_name : @@ -1394,7 +1415,7 @@ auth_reset(int unit) (hadchap == 1 || (hadchap == -1 && have_chap_secret(user, (explicit_remote? remote_name: NULL), 0, NULL))) || have_srp_secret(user, (explicit_remote? remote_name: NULL), 0, NULL) -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS || have_eaptls_secret_client(user, (explicit_remote? remote_name: NULL)) #endif ); @@ -1413,7 +1434,7 @@ auth_reset(int unit) 1, NULL))) && !have_srp_secret((explicit_remote? remote_name: NULL), our_name, 1, NULL) -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS && !have_eaptls_secret_server((explicit_remote? remote_name: NULL), our_name, 1, NULL) #endif @@ -1509,8 +1530,10 @@ check_passwd(int unit, if (secret[0] != 0 && !login_secret) { /* password given in pap-secrets - must match */ if (cryptpap || strcmp(passwd, secret) != 0) { +#ifdef HAVE_CRYPT_H char *cbuf = crypt(passwd, secret); if (!cbuf || strcmp(cbuf, secret) != 0) +#endif ret = UPAP_AUTHNAK; } } @@ -2384,13 +2407,14 @@ auth_script(char *script) argv[3] = user_name; argv[4] = devnam; argv[5] = strspeed; - argv[6] = NULL; + argv[6] = ipparam; + argv[7] = NULL; auth_script_pid = run_program(script, argv, 0, auth_script_done, NULL, 0); } -#ifdef USE_EAPTLS +#ifdef PPP_WITH_EAPTLS static int have_eaptls_secret_server(char *client, char *server, int need_ip, int *lacks_ipp) @@ -2458,6 +2482,8 @@ have_eaptls_secret_client(char *client, char *server) if ((cacert_file || ca_path) && cert_file && privkey_file) return 1; + if (pkcs12_file) + return 1; filename = _PATH_EAPTLSCLIFILE; f = fopen(filename, "r"); @@ -2641,7 +2667,7 @@ scan_authfile_eaptls(FILE *f, char *client, char *server, int get_eaptls_secret(int unit, char *client, char *server, char *clicertfile, char *servcertfile, char *cacertfile, - char *capath, char *pkfile, int am_server) + char *capath, char *pkfile, char *pkcs12, int am_server) { FILE *fp; int ret; @@ -2655,6 +2681,7 @@ get_eaptls_secret(int unit, char *client, char *server, bzero(cacertfile, MAXWORDLEN); bzero(capath, MAXWORDLEN); bzero(pkfile, MAXWORDLEN); + bzero(pkcs12, MAXWORDLEN); /* the ca+cert+privkey can also be specified as options */ if (!am_server && (cacert_file || ca_path) && cert_file && privkey_file ) @@ -2666,6 +2693,14 @@ get_eaptls_secret(int unit, char *client, char *server, strlcpy( capath, ca_path, MAXWORDLEN ); strlcpy( pkfile, privkey_file, MAXWORDLEN ); } + else if (!am_server && pkcs12_file) + { + strlcpy( pkcs12, pkcs12_file, MAXWORDLEN ); + if (cacert_file) + strlcpy( cacertfile, cacert_file, MAXWORDLEN ); + if (ca_path) + strlcpy( capath, ca_path, MAXWORDLEN ); + } else { filename = (am_server ? _PATH_EAPTLSSERVFILE : _PATH_EAPTLSCLIFILE);