X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet.c;h=ed00610d04d0a3b5eb6e9bdde5e755e172224f78;hp=893892c033bedbb453453829ddd384a853ac45ed;hb=6327f32f43dc9109fad9952fd50a23876d0acaf0;hpb=1eedf54681d4556c6874f7baee8e810cab867756 diff --git a/src/net.c b/src/net.c index 893892c0..ed00610d 100644 --- a/src/net.c +++ b/src/net.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.c,v 1.35.4.82 2000/11/25 13:33:30 guus Exp $ + $Id: net.c,v 1.35.4.87 2000/12/05 08:59:29 zarq Exp $ */ #include "config.h" @@ -59,6 +59,12 @@ # include #endif +#ifdef HAVE_OPENSSL_PEM_H +# include +#else +# include +#endif + #ifdef HAVE_TUNTAP #include LINUX_IF_TUN_H #endif @@ -380,9 +386,9 @@ int setup_tap_fd(void) const char *tapfname; config_t const *cfg; #ifdef HAVE_LINUX - #ifdef HAVE_TUNTAP +# ifdef HAVE_TUNTAP struct ifreq ifr; - #endif +# endif #endif cp @@ -391,11 +397,11 @@ cp else { #ifdef HAVE_LINUX - #ifdef HAVE_TUNTAP +# ifdef HAVE_TUNTAP tapfname = "/dev/misc/net/tun"; - #else +# else tapfname = "/dev/tap0"; - #endif +# endif #endif #ifdef HAVE_FREEBSD tapfname = "/dev/tap0"; @@ -692,6 +698,61 @@ cp return 0; } +int read_rsa_public_key(RSA **key, const char *file) +{ + FILE *fp; + + if((fp = fopen(file, "r")) == NULL) + { + syslog(LOG_ERR, _("Error reading RSA public key file `%s': %m"), + file); + return -1; + } + if(PEM_read_RSAPublicKey(fp, key, NULL, NULL) == NULL) + { + syslog(LOG_ERR, _("Reading RSA private key file `%s' failed: %m"), + file); + return -1; + } + + return 0; +} + +int read_rsa_private_key(RSA **key, const char *file) +{ + FILE *fp; + + if((fp = fopen(file, "r")) == NULL) + { + syslog(LOG_ERR, _("Error reading RSA private key file `%s': %m"), + file); + return -1; + } + if(PEM_read_RSAPrivateKey(fp, key, NULL, NULL) == NULL) + { + syslog(LOG_ERR, _("Reading RSA private key file `%s' failed: %m"), + file); + return -1; + } + + return 0; +} + +int read_rsa_keys(void) +{ + config_t const *cfg; + + if(!(cfg = get_config_val(config, config_privatekey))) + { + syslog(LOG_ERR, _("Private key for tinc daemon required!")); + return -1; + } + + myself->rsa_key = RSA_new(); + + return read_rsa_private_key(&(myself->rsa_key), cfg->data.ptr); +} + /* Configure connection_t myself and set up the local sockets (listen only) */ @@ -721,17 +782,8 @@ cp return -1; } cp - if(!(cfg = get_config_val(config, config_privatekey))) - { - syslog(LOG_ERR, _("Private key for tinc daemon required!")); - return -1; - } - else - { - myself->rsa_key = RSA_new(); - BN_hex2bn(&myself->rsa_key->d, cfg->data.ptr); - BN_hex2bn(&myself->rsa_key->e, "FFFF"); - } + if(read_rsa_keys()) + return -1; if(read_host_config(myself)) { @@ -739,15 +791,7 @@ cp return -1; } cp - if(!(cfg = get_config_val(myself->config, config_publickey))) - { - syslog(LOG_ERR, _("Public key for tinc daemon required!")); - return -1; - } - else - { - BN_hex2bn(&myself->rsa_key->n, cfg->data.ptr); - } + /* if(RSA_check_key(myself->rsa_key) != 1) {