3 * Copyright © 2006 Daniele Lacamera
4 * Released under the terms of GNU GPL v.2
5 * http://www.gnu.org/copyleft/gpl.html
7 * This program is released under the GPL with the additional exemption that
8 * compiling, linking, and/or using OpenSSL is allowed.
15 #include <openssl/blowfish.h>
16 #include <openssl/evp.h>
18 #include <sys/types.h>
19 #include <sys/ioctl.h>
22 #include <sys/socket.h>
24 #include <netinet/in.h>
25 #include <arpa/inet.h>
33 #include <libvdeplug/libvdeplug.h>
38 #define FILENAMESIZE 16
43 #define XOR(a,b) a==b?0:1
45 #define before_time(a,b) a.tv_sec==b.tv_sec?a.tv_usec<b.tv_usec:a.tv_sec<b.tv_sec
50 #define MIN(a,b) a<b?a:b
59 #define CMD_LOGIN 0x41
60 #define CMD_CHALLENGE 0x42
61 #define CMD_RESPONSE 0x44
62 #define CMD_AUTH_OK 0x48
64 #define CMD_HANDOVER 0x4C
65 #define CMD_IDENTIFY 0x4E
69 #define ST_CHALLENGE 2
72 #define ST_WAIT_AUTH 5
75 #define SESSION_TIMEOUT 120
76 #define time_now(x) gettimeofday(x,NULL)
80 * This struct contains the other endpoint's informations.
84 struct peer
*next
; /* Next list element */
85 unsigned long long counter
; /* Progressive N number */
86 unsigned char key
[16]; /* Blowfish key */
87 unsigned char iv
[8]; /* Blowfish vector */
88 char id
[FILENAMESIZE
]; /* Filename for key on server */
89 char challenge
[128]; /* 128B Challenge for 4WHS */
90 struct sockaddr_in in_a
; /* Current transport address */
91 struct sockaddr_in handover_a
; /* Handover transport address */
92 struct timeval expire
; /* Expiration timer */
93 unsigned char state
; /* Connection state */
94 VDECONN
*plug
; /* Vde connection channel */
97 #define ip_address(X) X->in_a.sin_addr.s_addr
98 #define after(a,b) (a.tv_sec == b.tv_sec ) ? (a.tv_usec > b.tv_usec) : (a.tv_sec > b.tv_sec)
102 * Each datagram received from network or from vde_plug
103 * is arranged into a struct like this.
107 unsigned char data
[MAXPKT
];
116 *getpeer(struct sockaddr_in address
);
119 addpeer(struct peer
*np
);
122 removepeer(struct peer
*np
);
125 *generate_key (struct peer
*, char*);
131 *blowfish_select(int timeout
);
134 blowfish_login(struct peer
*p
);
137 send_udp(unsigned char *data
, size_t len
, struct peer
*p
, unsigned char flags
);
140 send_vde( const char *data
, size_t len
, struct peer
*p
);
143 autocleaner(int signo
);
146 deny_access(struct peer
*p
);
149 rcv_login(struct datagram
*pkt
, struct peer
*p
, char *);
152 *getpeerbynewaddr(struct sockaddr_in saddr
);
155 rcv_response(struct datagram
*pkt
, struct peer
*p
, void (*callback
)(struct peer
*));
158 rcv_challenge(struct datagram
*pkt
, struct peer
*p
);
161 *getpeerbyid(struct datagram
*pkt
);
164 vde_plug(struct peer
*);