From: Ivo Timmermans Date: Thu, 30 Nov 2000 23:18:21 +0000 (+0000) Subject: New function read_rsa_public_key(); X-Git-Tag: release-1.0pre4~104 X-Git-Url: https://tinc-vpn.org/git/browse?p=tinc;a=commitdiff_plain;h=a0f7af3ed79c55d9680cbb0a569b3c8987581d43;ds=sidebyside New function read_rsa_public_key(); In net.c/setup_myself deleted old code to read the public key (which is now implicitly read in together with the private key). --- diff --git a/src/net.c b/src/net.c index 14a951ff..d89c7c6f 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.85 2000/11/30 22:48:48 zarq Exp $ + $Id: net.c,v 1.35.4.86 2000/11/30 23:18:19 zarq Exp $ */ #include "config.h" @@ -698,20 +698,40 @@ 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 key file `%s': %m"), + 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"), - cfg->data.ptr); + file); return -1; } @@ -771,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) { diff --git a/src/net.h b/src/net.h index 7c77fa29..2ed8a9ce 100644 --- a/src/net.h +++ b/src/net.h @@ -16,7 +16,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net.h,v 1.9.4.22 2000/11/20 19:12:13 guus Exp $ + $Id: net.h,v 1.9.4.23 2000/11/30 23:18:21 zarq Exp $ */ #ifndef __TINC_NET_H__ @@ -120,4 +120,14 @@ extern void terminate_connection(connection_t *); extern void flush_queues(connection_t *); extern void add_queue(packet_queue_t **, void *, size_t); + +#include +#ifdef HAVE_OPENSSL_RSA_H +# include +#else +# include +#endif + +extern int read_rsa_public_key(RSA **, const char *); + #endif /* __TINC_NET_H__ */ diff --git a/src/protocol.c b/src/protocol.c index 087589cd..a46894d0 100644 --- a/src/protocol.c +++ b/src/protocol.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: protocol.c,v 1.28.4.67 2000/11/25 13:33:33 guus Exp $ + $Id: protocol.c,v 1.28.4.68 2000/11/30 23:18:21 zarq Exp $ */ #include "config.h" @@ -255,8 +255,8 @@ cp if((cfg = get_config_val(cl->config, config_publickey))) { cl->rsa_key = RSA_new(); - BN_hex2bn(&cl->rsa_key->n, cfg->data.ptr); - BN_hex2bn(&cl->rsa_key->e, "FFFF"); + if(read_rsa_public_key(&(cl->rsa_key), cfg->data.ptr) < 0) + return -1; } else {