Mercurial > hg > quicktun
annotate src/proto.nacltai.c @ 71:86b8afcf65c7 default tip master
Fixed order of tar arguments in build script
author | Ivo Smits <Ivo@UFO-Net.nl> |
---|---|
date | Mon, 22 Jul 2019 21:12:13 +0200 |
parents | 5b9e742bb704 |
children |
rev | line source |
---|---|
0 | 1 /* Copyright 2010 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 "common.c" | |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
27 #include "crypto_box_curve25519xsalsa20poly1305.h" |
19
3400045a57b8
Version 2.1.6, changed sourcecode archive generation, use NaCl version 20110221, do not duplicate NaCl sourcecode, support iproute2 for persistent tunnel creation on Debian, support running as root on Debian, removed autogenerated header files
Ivo Smits <Ivo@UCIS.nl>
parents:
11
diff
changeset
|
28 #include "crypto_scalarmult_curve25519.h" |
0 | 29 #include <sys/types.h> |
30 #include <sys/time.h> | |
31 | |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
32 struct packedtaia { |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
33 unsigned char buffer[16]; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
34 }; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
35 |
0 | 36 struct qt_proto_data_nacltai { |
62
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
37 unsigned char cenonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; |
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
38 unsigned char cdnonce[crypto_box_curve25519xsalsa20poly1305_NONCEBYTES]; |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
39 unsigned char cbefore[crypto_box_curve25519xsalsa20poly1305_BEFORENMBYTES]; |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
40 struct packedtaia cdtailog[5]; |
0 | 41 }; |
42 | |
6
cf9b44b46be5
Use stderr for output instead of stdout, added debugging code to nacltai
root <root@Really.UFO-Net.nl>
parents:
4
diff
changeset
|
43 #define noncelength 16 |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
44 #define nonceoffset (crypto_box_curve25519xsalsa20poly1305_NONCEBYTES - noncelength) |
62
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
45 static const int overhead = crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES + noncelength; |
0 | 46 |
44
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
47 static void taia_now_packed(unsigned char* b, int secoffset) { |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
48 struct timeval now; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
49 gettimeofday(&now, NULL); |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
50 u_int64_t sec = 4611686018427387914ULL + (u_int64_t)now.tv_sec + secoffset; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
51 b[0] = (sec >> 56) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
52 b[1] = (sec >> 48) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
53 b[2] = (sec >> 40) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
54 b[3] = (sec >> 32) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
55 b[4] = (sec >> 24) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
56 b[5] = (sec >> 16) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
57 b[6] = (sec >> 8) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
58 b[7] = (sec >> 0) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
59 u_int32_t nano = 1000 * now.tv_usec + 500; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
60 b[8] = (nano >> 24) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
61 b[9] = (nano >> 16) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
62 b[10] = (nano >> 8) & 0xff; |
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
63 b[11] = (nano >> 0) & 0xff; |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
64 if (++b[15] == 0 && ++b[14] == 0 && ++b[13] == 0) ++b[12]; |
0 | 65 } |
66 | |
44
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
67 //Packet format: <16 bytes taia packed timestamp><16 bytes checksum><n bytes encrypted data> |
0 | 68 |
69 static int encode(struct qtsession* sess, char* raw, char* enc, int len) { | |
30
6f0e6b7dc088
Fixed build script to support multiple abis on one machine, bugfix in code, minor improvements
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
70 if (debug) fprintf(stderr, "Encoding packet of %d bytes from %p to %p\n", len, raw, enc); |
0 | 71 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
72 memset(raw, 0, crypto_box_curve25519xsalsa20poly1305_ZEROBYTES); |
44
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
73 taia_now_packed(d->cenonce + nonceoffset, 0); |
62
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
74 if (crypto_box_curve25519xsalsa20poly1305_afternm((unsigned char*)enc, (unsigned char*)raw, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cenonce, d->cbefore)) |
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
75 return errorexit("Encryption failed"); |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
76 memcpy((void*)(enc + crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength), d->cenonce + nonceoffset, noncelength); |
0 | 77 len += overhead; |
30
6f0e6b7dc088
Fixed build script to support multiple abis on one machine, bugfix in code, minor improvements
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
78 if (debug) fprintf(stderr, "Encoded packet of %d bytes from %p to %p\n", len, raw, enc); |
0 | 79 return len; |
80 } | |
81 | |
82 static int decode(struct qtsession* sess, char* enc, char* raw, int len) { | |
30
6f0e6b7dc088
Fixed build script to support multiple abis on one machine, bugfix in code, minor improvements
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
83 if (debug) fprintf(stderr, "Decoding packet of %d bytes from %p to %p\n", len, enc, raw); |
0 | 84 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; |
85 int i; | |
86 if (len < overhead) { | |
87 fprintf(stderr, "Short packet received: %d\n", len); | |
41
54d28a81ca99
Small updates in preparation for stateful protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
38
diff
changeset
|
88 return -1; |
0 | 89 } |
90 len -= overhead; | |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
91 struct packedtaia* tailog = &d->cdtailog[0]; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
92 struct packedtaia* taiold = tailog; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
93 for (i = 0; i < 5; i++) { |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
94 if (memcmp(enc, tailog, 16) == 0) { |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
95 fprintf(stderr, "Duplicate timestamp received\n"); |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
96 return -1; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
97 } |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
98 if (memcmp(tailog, taiold, 16) < 0) taiold = tailog; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
99 tailog++; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
100 } |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
101 if (memcmp(enc, taiold, 16) <= 0) { |
0 | 102 fprintf(stderr, "Timestamp going back, ignoring packet\n"); |
41
54d28a81ca99
Small updates in preparation for stateful protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
38
diff
changeset
|
103 return -1; |
0 | 104 } |
44
55f379f0a650
Fixed/improved handling of timestamp in nonce in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
43
diff
changeset
|
105 memcpy(d->cdnonce + nonceoffset, enc, noncelength); |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
106 memset(enc, 0, crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES); |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
107 if (crypto_box_curve25519xsalsa20poly1305_open_afternm((unsigned char*)raw, (unsigned char*)enc, len + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, d->cdnonce, d->cbefore)) { |
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
108 fprintf(stderr, "Decryption failed len=%d\n", len); |
41
54d28a81ca99
Small updates in preparation for stateful protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
38
diff
changeset
|
109 return -1; |
0 | 110 } |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
111 memcpy(taiold, d->cdnonce + nonceoffset, 16); |
30
6f0e6b7dc088
Fixed build script to support multiple abis on one machine, bugfix in code, minor improvements
Ivo Smits <Ivo@UCIS.nl>
parents:
27
diff
changeset
|
112 if (debug) fprintf(stderr, "Decoded packet of %d bytes from %p to %p\n", len, enc, raw); |
0 | 113 return len; |
114 } | |
115 | |
116 static int init(struct qtsession* sess) { | |
117 struct qt_proto_data_nacltai* d = (struct qt_proto_data_nacltai*)sess->protocol_data; | |
118 char* envval; | |
119 printf("Initializing cryptography...\n"); | |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
120 unsigned char cownpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], cpublickey[crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES], csecretkey[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES]; |
0 | 121 if (!(envval = getconf("PUBLIC_KEY"))) return errorexit("Missing PUBLIC_KEY"); |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
122 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PUBLIC_KEY length"); |
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
123 hex2bin(cpublickey, envval, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
124 if ((envval = getconf("PRIVATE_KEY"))) { |
37
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
125 if (strlen(envval) != 2*crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES) return errorexit("PRIVATE_KEY length"); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
126 hex2bin(csecretkey, envval, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
127 } else if ((envval = getconf("PRIVATE_KEY_FILE"))) { |
37
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
128 FILE* pkfile = fopen(envval, "rb"); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
129 if (!pkfile) return errorexitp("Could not open PRIVATE_KEY_FILE"); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
130 char pktextbuf[crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES * 2]; |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
131 const size_t pktextsize = fread(pktextbuf, 1, sizeof(pktextbuf), pkfile); |
37
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
132 if (pktextsize == crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
133 memcpy(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
134 } else if (pktextsize == 2 * crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES) { |
37
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
135 hex2bin(csecretkey, pktextbuf, crypto_box_curve25519xsalsa20poly1305_SECRETKEYBYTES); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
136 } else { |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
137 return errorexit("PRIVATE_KEY length"); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
138 } |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
139 fclose(pkfile); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
140 } else { |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
141 return errorexit("Missing PRIVATE_KEY"); |
bb4bbf380938
Added option PRIVATE_KEY_FILE to read private key from file
Ivo Smits <Ivo@UCIS.nl>
parents:
32
diff
changeset
|
142 } |
62
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
143 if (crypto_box_curve25519xsalsa20poly1305_beforenm(d->cbefore, cpublickey, csecretkey)) |
5b9e742bb704
Fixed compiler warnings, removed redundant version dependencies in debian package
Ivo Smits <Ivo@UFO-Net.nl>
parents:
61
diff
changeset
|
144 return errorexit("Encryption key calculation failed"); |
0 | 145 |
24
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
146 memset(d->cenonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
dfac56805c77
Fixed support for shared NaCl library, explicitly refer to cryptographic primitives
Ivo Smits <Ivo@UCIS.nl>
parents:
22
diff
changeset
|
147 memset(d->cdnonce, 0, crypto_box_curve25519xsalsa20poly1305_NONCEBYTES); |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
148 memset(d->cdtailog, 0, 5 * 16); |
0 | 149 |
19
3400045a57b8
Version 2.1.6, changed sourcecode archive generation, use NaCl version 20110221, do not duplicate NaCl sourcecode, support iproute2 for persistent tunnel creation on Debian, support running as root on Debian, removed autogenerated header files
Ivo Smits <Ivo@UCIS.nl>
parents:
11
diff
changeset
|
150 crypto_scalarmult_curve25519_base(cownpublickey, csecretkey); |
0 | 151 |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
152 if ((envval = getconf("TIME_WINDOW"))) { |
52
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
153 struct packedtaia* tailog = d->cdtailog; |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
154 taia_now_packed((unsigned char*)&tailog[0], -atol(envval)); |
3115f8af98bb
Added support for libsodium, fixed bug in USE_PI compatibility mode, improved timestamp checking in nacltai protocol
Ivo Smits <Ivo@UCIS.nl>
parents:
44
diff
changeset
|
155 tailog[4] = tailog[3] = tailog[2] = tailog[1] = tailog[0]; |
0 | 156 } else { |
4 | 157 fprintf(stderr, "Warning: TIME_WINDOW not set, risking an initial replay attack\n"); |
0 | 158 } |
43
4adbd9b67fe2
Fix nonce calculation when both sides use the same key in nacltai and salty protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
41
diff
changeset
|
159 int role = memcmp(cownpublickey, cpublickey, crypto_box_curve25519xsalsa20poly1305_PUBLICKEYBYTES); |
55
5685fad38195
Fixed compiler warnings from clang (including small bug in private key loading)
Ivo Smits <Ivo@UCIS.nl>
parents:
52
diff
changeset
|
160 if ((envval = getconf("ROLE"))) role = atoi(envval) ? 1 : -1; |
43
4adbd9b67fe2
Fix nonce calculation when both sides use the same key in nacltai and salty protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
41
diff
changeset
|
161 role = (role == 0) ? 0 : ((role > 0) ? 1 : 2); |
4adbd9b67fe2
Fix nonce calculation when both sides use the same key in nacltai and salty protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
41
diff
changeset
|
162 d->cenonce[nonceoffset-1] = role & 1; |
4adbd9b67fe2
Fix nonce calculation when both sides use the same key in nacltai and salty protocols
Ivo Smits <Ivo@UCIS.nl>
parents:
41
diff
changeset
|
163 d->cdnonce[nonceoffset-1] = (role >> 1) & 1; |
6
cf9b44b46be5
Use stderr for output instead of stdout, added debugging code to nacltai
root <root@Really.UFO-Net.nl>
parents:
4
diff
changeset
|
164 return 0; |
0 | 165 } |
166 | |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
167 struct qtproto qtproto_nacltai = { |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
168 1, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
169 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
170 MAX_PACKET_LEN + crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
171 crypto_box_curve25519xsalsa20poly1305_ZEROBYTES, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
172 crypto_box_curve25519xsalsa20poly1305_BOXZEROBYTES - noncelength, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
173 encode, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
174 decode, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
175 init, |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
176 sizeof(struct qt_proto_data_nacltai), |
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
177 }; |
0 | 178 |
179 #ifndef COMBINED_BINARY | |
38
d9f5caa13898
Added support for NetBSD, added command line parsing to provide configuration options
Ivo Smits <Ivo@UCIS.nl>
parents:
37
diff
changeset
|
180 int main(int argc, char** argv) { |
0 | 181 print_header(); |
61
66d9d80215f0
Fixed -h and -v return status, fixed source file permissions (thanks github.com/rotty)
Ivo Smits <Ivo@UFO-Net.nl>
parents:
55
diff
changeset
|
182 int rc = qtprocessargs(argc, argv); |
66d9d80215f0
Fixed -h and -v return status, fixed source file permissions (thanks github.com/rotty)
Ivo Smits <Ivo@UFO-Net.nl>
parents:
55
diff
changeset
|
183 if (rc <= 0) return rc; |
27
5ba185ca7102
Fixed error checking during initialization, restructured code a bit to make it even simpler
Ivo Smits <Ivo@UCIS.nl>
parents:
26
diff
changeset
|
184 return qtrun(&qtproto_nacltai); |
0 | 185 } |
186 #endif |