Mercurial > hg > quicktun-tcp
comparison include.h @ 0:17cb7cdbb8be draft default tip
Working prototype
author | Ivo Smits <Ivo@UCIS.nl> |
---|---|
date | Fri, 07 Feb 2014 23:28:39 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:17cb7cdbb8be |
---|---|
1 /* Copyright 2014 Ivo Smits <Ivo@UCIS.nl>. All rights reserved. | |
2 Redistribution and use in source and binary forms, with or without modification, are | |
3 permitted provided that the following conditions are met: | |
4 | |
5 1. Redistributions of source code must retain the above copyright notice, this list of | |
6 conditions and the following disclaimer. | |
7 | |
8 2. Redistributions in binary form must reproduce the above copyright notice, this list | |
9 of conditions and the following disclaimer in the documentation and/or other materials | |
10 provided with the distribution. | |
11 | |
12 THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED | |
13 WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND | |
14 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR | |
15 CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
16 CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | |
17 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON | |
18 ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING | |
19 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF | |
20 ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
21 | |
22 The views and conclusions contained in the software and documentation are those of the | |
23 authors and should not be interpreted as representing official policies, either expressed | |
24 or implied, of Ivo Smits.*/ | |
25 | |
26 #include <stdbool.h> | |
27 | |
28 typedef struct tunnel_context tunnel_context; | |
29 typedef struct connection_context connection_context; | |
30 | |
31 struct connection_context { | |
32 int recv_socket; | |
33 unsigned char recv_buffer[2000]; | |
34 int recv_offset; | |
35 bool recv_encrypted; | |
36 unsigned char recv_key[32]; | |
37 unsigned char recv_nonce[24]; | |
38 | |
39 int send_socket; | |
40 bool send_encrypted; | |
41 unsigned char send_key[32]; | |
42 unsigned char send_nonce[24]; | |
43 | |
44 unsigned char local_seckey_current[32]; | |
45 unsigned char local_seckey_next[32]; | |
46 unsigned char remote_pubkey[32]; | |
47 unsigned char nonce_next[24]; | |
48 | |
49 char* password; | |
50 | |
51 bool local_tunnelready; | |
52 bool remote_tunnelready; | |
53 bool key_updated; | |
54 | |
55 bool pong; | |
56 bool startcryptauthsent; | |
57 | |
58 unsigned char remote_pubkey_expect[32]; | |
59 bool require_key_authentication; | |
60 bool require_encryption; | |
61 bool require_password_authentication; | |
62 | |
63 tunnel_context* tunnel; | |
64 }; | |
65 | |
66 bool connection_init(connection_context* context); | |
67 bool connection_init_socket(connection_context* context, const int recvsocket, const int sendsocket); | |
68 bool connection_init_encryption(connection_context* context, const unsigned char* localseckey, const unsigned char* remotepubkey); | |
69 bool connection_init_passwordauth(connection_context* context, char* password); | |
70 bool connection_init_done(connection_context* context); | |
71 bool connection_update_key(connection_context* context); | |
72 bool connection_ping(connection_context* context); | |
73 bool connection_read(connection_context* context); | |
74 bool connection_write_data(connection_context* context, unsigned char* buffer, int len); | |
75 | |
76 struct tunnel_context { | |
77 int fd; | |
78 int fake_pi; | |
79 connection_context* connection; | |
80 }; | |
81 | |
82 bool tunnel_init(tunnel_context* context); | |
83 bool tunnel_read(tunnel_context* context); | |
84 bool tunnel_write_data(tunnel_context* tunnel, unsigned char* buffer, int len); | |
85 | |
86 extern char* (*getconf)(const char*); | |
87 int errorexit(const char* text); | |
88 int errorexitf(const char* text, const char* error); | |
89 bool errorexitp(const char* text); | |
90 |