Use the HAVE_OPENSSL_xxx_H defined from m4/openssl.m4 during
[tinc] / src / protocol.c
index aeeec1b..fbb0abf 100644 (file)
@@ -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.54 2000/11/03 22:35:11 zarq Exp $
+    $Id: protocol.c,v 1.28.4.60 2000/11/15 01:06:11 zarq Exp $
 */
 
 #include "config.h"
 
 #include <netinet/in.h>
 
-#include <openssl/sha.h>
-#include <openssl/rand.h>
-#include <openssl/evp.h>
+#ifdef HAVE_OPENSSL_SHA_H
+# include <openssl/sha.h>
+#else
+# include <sha.h>
+#endif
+
+#ifdef HAVE_OPENSSL_RAND_H
+# include <openssl/rand.h>
+#else
+# include <rand.h>
+#endif
+
+#ifdef HAVE_OPENSSL_EVP_H
+# include <openssl/evp.h>
+#else
+# include <evp.h>
+#endif
+
 
 #include "conf.h"
 #include "net.h"
@@ -225,7 +240,7 @@ cp
         }
     }
 cp    
-  if((cfg = get_config_val(cl->config, publickey)))
+  if((cfg = get_config_val(cl->config, config_publickey)))
     {
       cl->rsa_key = RSA_new();
       BN_hex2bn(&cl->rsa_key->n, cfg->data.ptr);
@@ -561,6 +576,8 @@ cp
   if(cl->status.outgoing)
     cl->allow_request = ACK;
 
+  setup_vpn_connection(cl);
+
   x = send_request(cl, "%d", ACK);
   cl->status.encryptout = 1;
 cp
@@ -872,7 +889,14 @@ cp
 
   new->nexthop = cl;
   new->status.active = 1;
+  new->cipher_pkttype = EVP_bf_cfb();
+  new->cipher_pktkeylength = cl->cipher_pkttype->key_len + cl->cipher_pkttype->iv_len;
 
+  /* Okay this is a bit ugly... it would be better to setup UDP sockets dynamically, or
+   * perhaps just one UDP socket... but then again, this has benefits too...
+   */
+   
+  setup_vpn_connection(new);
 cp
   return 0;
 }
@@ -1035,7 +1059,9 @@ cp
 
 int send_ping(conn_list_t *cl)
 {
+cp
   cl->status.pinged = 1;
+  cl->last_ping_time = time(NULL);
 cp
   return send_request(cl, "%d", PING);
 }
@@ -1055,7 +1081,7 @@ cp
 int pong_h(conn_list_t *cl)
 {
 cp
-  cl->status.got_pong = 1;
+  cl->status.pinged = 0;
 cp
   return 0;
 }
@@ -1195,7 +1221,7 @@ cp
       return -1;
     }
 
-  /* Update origin's packet key */
+  /* Check correctness of packet key */
 
   keylength = strlen(pktkey);
 
@@ -1207,17 +1233,8 @@ cp
       return -1;
     }
 
-  if(from->cipher_pktkey)
-    free(from->cipher_pktkey);
-
-  keylength /= 2;
-  hex2bin(pktkey, pktkey, keylength);
-  pktkey[keylength] = '\0';
-  from->cipher_pktkey = pktkey;
+  /* Forward it if necessary */
 
-  from->status.validkey = 1;
-  from->status.waitingforkey = 0;
-    
   if(strcmp(to_id, myself->name))
     {
       if(!(to = lookup_id(to_id)))
@@ -1230,6 +1247,19 @@ cp
       send_ans_key(from, to, pktkey);
     }
 
+  /* Update our copy of the origin's packet key */
+
+  if(from->cipher_pktkey)
+    free(from->cipher_pktkey);
+
+  keylength /= 2;
+  hex2bin(pktkey, pktkey, keylength);
+  pktkey[keylength] = '\0';
+  from->cipher_pktkey = pktkey;
+
+  from->status.validkey = 1;
+  from->status.waitingforkey = 0;
+    
   free(from_id); free(to_id);
 cp
   return 0;