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