remove old bootstrap code

pull/825/head
Rick V 5 years ago
parent 00d34709eb
commit 9232cef300
No known key found for this signature in database
GPG Key ID: C0EDC8723FDC3465

@ -1,4 +0,0 @@
*.o
mbedtls/
*.a
*.exe

@ -1,17 +0,0 @@
Copyright (c)2018-2019 Rick V. All rights reserved.
This software is provided 'as-is', without any express or implied
warranty. In no event will the authors be held liable for any damages
arising from the use of this software.
Permission is granted to anyone to use this software for any purpose,
including commercial applications, and to alter it and redistribute it
freely, subject to the following restrictions:
1. The origin of this software must not be misrepresented; you must not
claim that you wrote the original software. If you use this software
in a product, an acknowledgment in the product documentation would be
appreciated but is not required.
2. Altered source versions must be plainly marked as such, and must not be
misrepresented as being the original software.
3. This notice may not be removed or altered from any source distribution.

@ -1,76 +0,0 @@
# makefile for windows bootstrap
# requires mbedtls to be installed somewhere, for both native and windows targets
# requires wget to be installed for ca bundle download
# to build:
# $ [g]make prepare;[g]make lokinet-bootstrap
# set this beforehand if you use clang
CC ?= i686-w64-mingw32-gcc
NATIVE_CC ?= cc
# set these for the native system
INCLUDE ?=
LIBS ?=
# set these for 32-bit windows if cross-compiling
WINNT_INCLUDE ?=
WINNT_LIBS ?=
ifdef LTO
LTO_FLAG = -flto
LTO_LDFLAG = -flto -march=nocona -mfpmath=sse -Ofast
endif
ifndef DEBUG
CFLAGS = -Ofast -march=nocona -mfpmath=sse
LDFLAGS = -s
else
CFLAGS = -O0 -g3
endif
.PHONY: download prepare all default
# windows target only
.c.o:
$(CC) $(WINNT_INCLUDE) -Iinclude $(LTO_FLAG) $(CFLAGS) $< -c
zpipe: zpipe.c miniz.c
$(NATIVE_CC) $(INCLUDE) -Iinclude $(LIBS) $^ -s -static -o $@
base64enc: base64enc.c
$(NATIVE_CC) $(INCLUDE) -Iinclude $(LIBS) $^ -s -static -o $@ -lmbedx509 -lmbedtls -lmbedcrypto
download:
wget -O ./cacert.pem https://curl.haxx.se/ca/cacert.pem
# I *think* this only work with GNU sed...
prepare: zpipe base64enc download
./zpipe < cacert.pem > data.enc
./base64enc < data.enc > out.bin
sed -ie "s/.\{76\}/&\n/g" out.bin
sed -i 's/.*/\"&\"/g' out.bin
sed -i '61,2268d' bootstrap.c
echo ';' >> out.bin
sed -i '60r out.bin' bootstrap.c
prepare-testnet: zpipe base64enc download
./zpipe < cacert.pem > data.enc
./base64enc < data.enc > out.bin
sed -ie "s/.\{76\}/&\n/g" out.bin
sed -i 's/.*/\"&\"/g' out.bin
sed -i '58,2144d' testnet.c
echo ';' >> out.bin
sed -i '57r out.bin' testnet.c
lokinet-bootstrap: bootstrap.o miniz.o http.o header.o chunk.o
$(CC) $(WINNT_LIBS) $(LDFLAGS) -static $^ -o $@.exe $(LTO_LDFLAG) -lmbedx509 -lmbedtls -lmbedcrypto -lws2_32
clean:
-@rm lokinet*.exe
-@rm base64enc
-@rm zpipe
-@rm cacert.pem
-@rm data.enc
-@rm out.*
-@rm *.o

@ -1,35 +0,0 @@
# LokiNET bootstrap for Windows
This is a tiny executable that does the same thing as the `lokinet-bootstrap` shell script for Linux, specifically for the purpose of bypassing broken or outdated versions of Schannel that do not support current versions of TLS.
# Building
## requirements
- mbedtls 2.13.0 or later, for both host and windows
- wget for host (to download Netscape CA bundle from cURL website)
- Also included is a patch that can be applied to the mbedtls source to enable features like AES-NI in protected mode, plus some networking fixes for win32
native build:
$ export INCLUDE=/mingw32/include LIBS=/mingw32/lib # or a different path
$ export CC=cc # change these if you use clang
$ export NATIVE_CC=$CC
$ export WINNT_INCLUDE=$INCLUDE WINNT_LIBS=$LIBS
$ make prepare;make lokinet-bootstrap
cross-compile build (If you have *GNU* sed, you can also update the certificate trust store with `make prepare`):
$ export INCLUDE=/usr/local/include LIBS=/usr/local/lib # or a different path
$ export CC=i686-w64-mingw32-gcc # change these if you use clang, make sure these are in your system $PATH!
$ export NATIVE_CC=cc
$ export WINNT_INCLUDE=/path/to/win32/headers WINNT_LIBS=/path/to/win32/libs
$ make lokinet-bootstrap
# Usage
C:\>lokinet-bootstrap [uri] [local download path]
this is also included in the lokinet installer package.
-rick

@ -1,64 +0,0 @@
/*
* Copyright (c)2018-2019 Rick V. All rights reserved.
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
/* this is a tiny build-time utility that base64 encodes up to 512K
* of text/binary data from stdin. (On UNIX, we'd use GNU's [g]base64(1)
* to encode the stream. Can't guarantee that a windows user will have cygwin
* installed, so we bootstrap these at build-time instead.)
*
* here, it is used to encode the compressed zlib-stream of the
* Netscape root certificate trust store on behalf of the lokinet
* for NT bootstrap stubs.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "sysconf.h"
#ifdef HAVE_SETMODE
# define SET_BINARY_MODE(handle) setmode(handle, O_BINARY)
#else
# define SET_BINARY_MODE(handle) ((void)0)
#endif
#include <mbedtls/base64.h>
#include <mbedtls/error.h>
main(argc, argv)
char** argv;
{
int size,r, inl;
unsigned char in[524288];
unsigned char out[1048576];
unsigned char err[1024];
memset(&in, 0, 524288);
memset(&out, 0, 1048576);
SET_BINARY_MODE(0);
/* Read up to 512K of data from stdin */
inl = fread(in, 1, 524288, stdin);
r = mbedtls_base64_encode(out, 1048576, &size, in, inl);
if (r)
{
mbedtls_strerror(r, err, 1024);
printf("error: %s\n", err);
return r;
}
fprintf(stdout, "%s", out);
return 0;
}

File diff suppressed because it is too large Load Diff

@ -1,79 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
static const unsigned char http_chunk_state[] = {
/* * LF CR HEX */
0xC1, 0xC1, 0xC1, 1, /* s0: initial hex char */
0xC1, 0xC1, 2, 0x81, /* s1: additional hex chars, followed by CR */
0xC1, 0x83, 0xC1, 0xC1, /* s2: trailing LF */
0xC1, 0xC1, 4, 0xC1, /* s3: CR after chunk block */
0xC1, 0xC0, 0xC1, 0xC1, /* s4: LF after chunk block */
};
int http_parse_chunked(int* state, int *size, char ch)
{
int newstate, code = 0;
switch (ch) {
case '\n': code = 1; break;
case '\r': code = 2; break;
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
case '8': case '9': case 'a': case 'b':
case 'c': case 'd': case 'e': case 'f':
case 'A': case 'B': case 'C': case 'D':
case 'E': case 'F': code = 3; break;
}
newstate = http_chunk_state[*state * 4 + code];
*state = (newstate & 0xF);
switch (newstate) {
case 0xC0:
return *size != 0;
case 0xC1: /* error */
*size = -1;
return 0;
case 0x01: /* initial char */
*size = 0;
/* fallthrough */
case 0x81: /* size char */
if (ch >= 'a')
*size = *size * 16 + (ch - 'a' + 10);
else if (ch >= 'A')
*size = *size * 16 + (ch - 'A' + 10);
else
*size = *size * 16 + (ch - '0');
break;
case 0x83:
return *size == 0;
}
return 1;
}

@ -1,48 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HTTP_CHUNK_H
#define HTTP_CHUNK_H
#if defined(__cplusplus)
extern "C" {
#endif
/**
* Parses the size out of a chunk-encoded HTTP response. Returns non-zero if it
* needs more data. Retuns zero success or error. When error: size == -1 On
* success, size = size of following chunk data excluding trailing \r\n. User is
* expected to process or otherwise seek past chunk data up to the trailing
* \r\n. The state parameter is used for internal state and should be
* initialized to zero the first call.
*/
int http_parse_chunked(int* state, int *size, char ch);
#if defined(__cplusplus)
}
#endif
#endif

@ -1,19 +0,0 @@
/*
* Copyright (C) 2019 Rick V. All rights reserved.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* HTTP client for loki-msgr
*/

@ -1,72 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "header.h"
static unsigned char http_header_state[] = {
/* * \t \n \r ' ' , : PAD */
0x80, 1, 0xC1, 0xC1, 1, 0x80, 0x80, 0xC1, /* state 0: HTTP version */
0x81, 2, 0xC1, 0xC1, 2, 1, 1, 0xC1, /* state 1: Response code */
0x82, 0x82, 4, 3, 0x82, 0x82, 0x82, 0xC1, /* state 2: Response reason */
0xC1, 0xC1, 4, 0xC1, 0xC1, 0xC1, 0xC1, 0xC1, /* state 3: HTTP version newline */
0x84, 0xC1, 0xC0, 5, 0xC1, 0xC1, 6, 0xC1, /* state 4: Start of header field */
0xC1, 0xC1, 0xC0, 0xC1, 0xC1, 0xC1, 0xC1, 0xC1, /* state 5: Last CR before end of header */
0x87, 6, 0xC1, 0xC1, 6, 0x87, 0x87, 0xC1, /* state 6: leading whitespace before header value */
0x87, 0x87, 0xC4, 10, 0x87, 0x88, 0x87, 0xC1, /* state 7: header field value */
0x87, 0x88, 6, 9, 0x88, 0x88, 0x87, 0xC1, /* state 8: Split value field value */
0xC1, 0xC1, 6, 0xC1, 0xC1, 0xC1, 0xC1, 0xC1, /* state 9: CR after split value field */
0xC1, 0xC1, 0xC4, 0xC1, 0xC1, 0xC1, 0xC1, 0xC1, /* state 10:CR after header value */
};
int http_parse_header_char(int* state, char ch)
{
int newstate, code = 0;
switch (ch) {
case '\t': code = 1; break;
case '\n': code = 2; break;
case '\r': code = 3; break;
case ' ': code = 4; break;
case ',': code = 5; break;
case ':': code = 6; break;
}
newstate = http_header_state[*state * 8 + code];
*state = (newstate & 0xF);
switch (newstate) {
case 0xC0: return http_header_status_done;
case 0xC1: return http_header_status_done;
case 0xC4: return http_header_status_store_keyvalue;
case 0x80: return http_header_status_version_character;
case 0x81: return http_header_status_code_character;
case 0x82: return http_header_status_status_character;
case 0x84: return http_header_status_key_character;
case 0x87: return http_header_status_value_character;
case 0x88: return http_header_status_value_character;
}
return http_header_status_continue;
}

@ -1,61 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HTTP_HEADER_H
#define HTTP_HEADER_H
#if defined(__cplusplus)
extern "C" {
#endif
enum http_header_status
{
http_header_status_done,
http_header_status_continue,
http_header_status_version_character,
http_header_status_code_character,
http_header_status_status_character,
http_header_status_key_character,
http_header_status_value_character,
http_header_status_store_keyvalue
};
/**
* Parses a single character of an HTTP header stream. The state parameter is
* used as internal state and should be initialized to zero for the first call.
* Return value is a value from the http_header_status enuemeration specifying
* the semantics of the character. If an error is encountered,
* http_header_status_done will be returned with a non-zero state parameter. On
* success http_header_status_done is returned with the state parameter set to
* zero.
*/
int http_parse_header_char(int* state, char ch);
#if defined(__cplusplus)
}
#endif
#endif

@ -1,227 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#include "http.h"
#include <ctype.h>
#include <string.h>
#include "header.h"
#include "chunk.h"
static void append_body(struct http_roundtripper* rt, const char* data, int ndata)
{
rt->funcs.body(rt->opaque, data, ndata);
}
static void grow_scratch(struct http_roundtripper* rt, int size)
{
if (rt->nscratch >= size)
return;
if (size < 64)
size = 64;
int nsize = (rt->nscratch * 3) / 2;
if (nsize < size)
nsize = size;
rt->scratch = (char*)rt->funcs.realloc_scratch(rt->opaque, rt->scratch, nsize);
rt->nscratch = nsize;
}
static int min(int a, int b)
{
return a > b ? b : a;
}
enum http_roundtripper_state {
http_roundtripper_header,
http_roundtripper_chunk_header,
http_roundtripper_chunk_data,
http_roundtripper_raw_data,
http_roundtripper_unknown_data,
http_roundtripper_close,
http_roundtripper_error,
};
void http_init(struct http_roundtripper* rt, struct http_funcs funcs, void* opaque)
{
rt->funcs = funcs;
rt->scratch = 0;
rt->opaque = opaque;
rt->code = 0;
rt->parsestate = 0;
rt->contentlength = -1;
rt->state = http_roundtripper_header;
rt->nscratch = 0;
rt->nkey = 0;
rt->nvalue = 0;
rt->chunked = 0;
}
void http_free(struct http_roundtripper* rt)
{
if (rt->scratch) {
rt->funcs.realloc_scratch(rt->opaque, rt->scratch, 0);
rt->scratch = 0;
}
}
int http_data(struct http_roundtripper* rt, const char* data, int size, int* read)
{
const int initial_size = size;
while (size) {
switch (rt->state) {
case http_roundtripper_header:
switch (http_parse_header_char(&rt->parsestate, *data)) {
case http_header_status_done:
rt->funcs.code(rt->opaque, rt->code);
if (rt->parsestate != 0)
rt->state = http_roundtripper_error;
else if (rt->chunked) {
rt->contentlength = 0;
rt->state = http_roundtripper_chunk_header;
} else if (rt->contentlength == 0)
rt->state = http_roundtripper_close;
else if (rt->contentlength > 0)
rt->state = http_roundtripper_raw_data;
else if (rt->contentlength == -1)
rt->state = http_roundtripper_unknown_data;
else
rt->state = http_roundtripper_error;
break;
case http_header_status_code_character:
rt->code = rt->code * 10 + *data - '0';
break;
case http_header_status_key_character:
grow_scratch(rt, rt->nkey + 1);
rt->scratch[rt->nkey] = tolower(*data);
++rt->nkey;
break;
case http_header_status_value_character:
grow_scratch(rt, rt->nkey + rt->nvalue + 1);
rt->scratch[rt->nkey+rt->nvalue] = *data;
++rt->nvalue;
break;
case http_header_status_store_keyvalue:
if (rt->nkey == 17 && 0 == strncmp(rt->scratch, "transfer-encoding", rt->nkey))
rt->chunked = (rt->nvalue == 7 && 0 == strncmp(rt->scratch + rt->nkey, "chunked", rt->nvalue));
else if (rt->nkey == 14 && 0 == strncmp(rt->scratch, "content-length", rt->nkey)) {
int ii, end;
rt->contentlength = 0;
for (ii = rt->nkey, end = rt->nkey + rt->nvalue; ii != end; ++ii)
rt->contentlength = rt->contentlength * 10 + rt->scratch[ii] - '0';
}
rt->funcs.header(rt->opaque, rt->scratch, rt->nkey, rt->scratch + rt->nkey, rt->nvalue);
rt->nkey = 0;
rt->nvalue = 0;
break;
}
--size;
++data;
break;
case http_roundtripper_chunk_header:
if (!http_parse_chunked(&rt->parsestate, &rt->contentlength, *data)) {
if (rt->contentlength == -1)
rt->state = http_roundtripper_error;
else if (rt->contentlength == 0)
rt->state = http_roundtripper_close;
else
rt->state = http_roundtripper_chunk_data;
}
--size;
++data;
break;
case http_roundtripper_chunk_data: {
const int chunksize = min(size, rt->contentlength);
append_body(rt, data, chunksize);
rt->contentlength -= chunksize;
size -= chunksize;
data += chunksize;
if (rt->contentlength == 0) {
rt->contentlength = 1;
rt->state = http_roundtripper_chunk_header;
}
}
break;
case http_roundtripper_raw_data: {
const int chunksize = min(size, rt->contentlength);
append_body(rt, data, chunksize);
rt->contentlength -= chunksize;
size -= chunksize;
data += chunksize;
if (rt->contentlength == 0)
rt->state = http_roundtripper_close;
}
break;
case http_roundtripper_unknown_data: {
if (size == 0)
rt->state = http_roundtripper_close;
else {
append_body(rt, data, size);
size -= size;
data += size;
}
}
break;
case http_roundtripper_close:
case http_roundtripper_error:
break;
}
if (rt->state == http_roundtripper_error || rt->state == http_roundtripper_close) {
if (rt->scratch) {
rt->funcs.realloc_scratch(rt->opaque, rt->scratch, 0);
rt->scratch = 0;
}
*read = initial_size - size;
return 0;
}
}
*read = initial_size - size;
return 1;
}
int http_iserror(struct http_roundtripper* rt)
{
return rt->state == http_roundtripper_error;
}

@ -1,93 +0,0 @@
/*-
* Copyright 2012 Matthew Endsley
* All rights reserved
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted providing that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef HTTP_HTTP_H
#define HTTP_HTTP_H
#if defined(__cplusplus)
extern "C" {
#endif
/**
* Callbacks for handling response data.
* realloc_scratch - reallocate memory, cannot fail. There will only
* be one scratch buffer. Implemnentation may take
* advantage of this fact.
* body - handle HTTP response body data
* header - handle an HTTP header key/value pair
* code - handle the HTTP status code for the response
*/
struct http_funcs {
void* (*realloc_scratch)(void* opaque, void* ptr, int size);
void (*body)(void* opaque, const char* data, int size);
void (*header)(void* opaque, const char* key, int nkey, const char* value, int nvalue);
void (*code)(void* opqaue, int code);
};
struct http_roundtripper {
struct http_funcs funcs;
void *opaque;
char *scratch;
int code;
int parsestate;
int contentlength;
int state;
int nscratch;
int nkey;
int nvalue;
int chunked;
};
/**
* Initializes a rountripper with the specified response functions. This must
* be called before the rt object is used.
*/
void http_init(struct http_roundtripper* rt, struct http_funcs, void* opaque);
/**
* Frees any scratch memory allocated during parsing.
*/
void http_free(struct http_roundtripper* rt);
/**
* Parses a block of HTTP response data. Returns zero if the parser reached the
* end of the response, or an error was encountered. Use http_iserror to check
* for the presence of an error. Returns non-zero if more data is required for
* the response.
*/
int http_data(struct http_roundtripper* rt, const char* data, int size, int* read);
/**
* Returns non-zero if a completed parser encounted an error. If http_data did
* not return non-zero, the results of this function are undefined.
*/
int http_iserror(struct http_roundtripper* rt);
#if defined(__cplusplus)
}
#endif
#endif

File diff suppressed because it is too large Load Diff

@ -1,95 +0,0 @@
/**
* sysconf.h -- system-dependent macros and settings
*
* Copyright (C) 2002-2004 Cosmin Truta.
* Permission to use and distribute freely.
* No warranty.
**/
#ifndef SYSCONF_H
#define SYSCONF_H
/*****************************************************************************/
/* Platform identifiers */
/* Detect Unix. */
#if defined(unix) || defined(__linux__) || defined(BSD) || defined(__CYGWIN__)
/* Add more systems here. */
# ifndef UNIX
# define UNIX
# endif
#endif
/* Detect MS-DOS. */
#if defined(__MSDOS__)
# ifndef MSDOS
# define MSDOS
# endif
#endif
/* TO DO: Detect OS/2. */
/* Detect Windows. */
#if defined(_WIN32) || defined(__WIN32__)
# ifndef WIN32
# define WIN32
# endif
#endif
#if defined(_WIN64)
# ifndef WIN64
# define WIN64
# endif
#endif
#if defined(_WINDOWS) || defined(WIN32) || defined(WIN64)
# ifndef WINDOWS
# define WINDOWS
# endif
#endif
/* Enable POSIX-friendly symbols on Microsoft (Visual) C. */
#ifdef _MSC_VER
# define _POSIX_
#endif
/*****************************************************************************/
/* Library access */
#if defined(UNIX)
# include <unistd.h>
#endif
#if defined(_POSIX_VERSION)
# include <fcntl.h>
# ifndef HAVE_ISATTY
# define HAVE_ISATTY
# endif
#endif
#if defined(MSDOS) || defined(OS2) || defined(WINDOWS) || defined(__CYGWIN__)
/* Add more systems here, e.g. MacOS 9 and earlier. */
# include <fcntl.h>
# include <io.h>
# ifndef HAVE_ISATTY
# define HAVE_ISATTY
# endif
# ifndef HAVE_SETMODE
# define HAVE_SETMODE
# endif
#endif
/* Standard I/O handles. */
#define STDIN 0
#define STDOUT 1
#define STDERR 2
/* Provide a placeholder for O_BINARY, if it doesn't exist. */
#ifndef O_BINARY
# define O_BINARY 0
#endif
#endif /* SYSCONF_H */

@ -1,205 +0,0 @@
diff -ruN polarssl-master/include/mbedtls/aesni.h polarssl/include/mbedtls/aesni.h
--- polarssl-master/include/mbedtls/aesni.h 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/include/mbedtls/aesni.h 2018-04-17 15:47:59.320514100 -0500
@@ -26,17 +26,16 @@
#include "aes.h"
+/*
+ * despair: This code appears to be 32-bit clean. Remove the CPP macros
+ * that restrict usage to AMD64 and EM64T processors.
+ * Obviously, you still need to have this insn set available in order to
+ * use it in either of protected or long mode anyway.
+ */
+
#define MBEDTLS_AESNI_AES 0x02000000u
#define MBEDTLS_AESNI_CLMUL 0x00000002u
-#if defined(MBEDTLS_HAVE_ASM) && defined(__GNUC__) && \
- ( defined(__amd64__) || defined(__x86_64__) ) && \
- ! defined(MBEDTLS_HAVE_X86_64)
-#define MBEDTLS_HAVE_X86_64
-#endif
-
-#if defined(MBEDTLS_HAVE_X86_64)
-
#ifdef __cplusplus
extern "C" {
#endif
@@ -107,6 +106,4 @@
}
#endif
-#endif /* MBEDTLS_HAVE_X86_64 */
-
#endif /* MBEDTLS_AESNI_H */
diff -ruN polarssl-master/include/mbedtls/bn_mul.h polarssl/include/mbedtls/bn_mul.h
--- polarssl-master/include/mbedtls/bn_mul.h 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/include/mbedtls/bn_mul.h 2018-04-17 15:42:09.045117300 -0500
@@ -754,7 +754,9 @@
#if defined(MBEDTLS_HAVE_SSE2)
#define EMIT __asm _emit
-
+/* Because the Visual C++ inline assembler STILL does
+ not support MMX insns! reeeeee (old -GM flag no longer exists)
+ */
#define MULADDC_HUIT \
EMIT 0x0F EMIT 0x6E EMIT 0xC9 \
EMIT 0x0F EMIT 0x6E EMIT 0xC3 \
diff -ruN polarssl-master/include/mbedtls/config.h polarssl/include/mbedtls/config.h
--- polarssl-master/include/mbedtls/config.h 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/include/mbedtls/config.h 2018-04-17 17:27:18.350938700 -0500
@@ -91,7 +91,7 @@
*
* Uncomment if the CPU supports SSE2 (IA-32 specific).
*/
-//#define MBEDTLS_HAVE_SSE2
+#define MBEDTLS_HAVE_SSE2
/**
* \def MBEDTLS_HAVE_TIME
@@ -1571,7 +1571,7 @@
* Module: library/aesni.c
* Caller: library/aes.c
*
- * Requires: MBEDTLS_HAVE_ASM
+ * Requires: None. Enable only for i386 or AMD64 targets only! -despair
*
* This modules adds support for the AES-NI instructions on x86-64
*/
@@ -1850,7 +1850,7 @@
* Requires: MBEDTLS_AES_C or MBEDTLS_DES_C
*
*/
-//#define MBEDTLS_CMAC_C
+#define MBEDTLS_CMAC_C
/**
* \def MBEDTLS_CTR_DRBG_C
@@ -2055,7 +2055,7 @@
*
* Uncomment to enable the HAVEGE random generator.
*/
-//#define MBEDTLS_HAVEGE_C
+#define MBEDTLS_HAVEGE_C
/**
* \def MBEDTLS_HMAC_DRBG_C
diff -ruN polarssl-master/library/aes.c polarssl/library/aes.c
--- polarssl-master/library/aes.c 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/library/aes.c 2018-04-17 16:51:37.098413400 -0500
@@ -514,7 +514,7 @@
#endif
ctx->rk = RK = ctx->buf;
-#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+#if defined(MBEDTLS_AESNI_C)
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) )
return( mbedtls_aesni_setkey_enc( (unsigned char *) ctx->rk, key, keybits ) );
#endif
@@ -621,7 +621,7 @@
ctx->nr = cty.nr;
-#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+#if defined(MBEDTLS_AESNI_C)
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) )
{
mbedtls_aesni_inverse_key( (unsigned char *) ctx->rk,
@@ -850,7 +850,7 @@
const unsigned char input[16],
unsigned char output[16] )
{
-#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+#if defined(MBEDTLS_AESNI_C)
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_AES ) )
return( mbedtls_aesni_crypt_ecb( ctx, mode, input, output ) );
#endif
diff -ruN polarssl-master/library/aesni.c polarssl/library/aesni.c
--- polarssl-master/library/aesni.c 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/library/aesni.c 2018-04-17 16:09:26.050605000 -0500
@@ -30,7 +30,16 @@
#include MBEDTLS_CONFIG_FILE
#endif
-#if defined(MBEDTLS_AESNI_C)
+
+/*
+ * despair: This code appears to be 32-bit clean. Remove the CPP macros
+ * that restrict usage to AMD64 and EM64T processors.
+ * Obviously, you still need to have this insn set available in order to
+ * use it in either of protected or long mode anyway.
+ * GCC or Clang only, no MSVC here, sorry. (Must pass -march=core2 or later
+ * if your compiler's default is anything older or generic.)
+ */
+#if defined(MBEDTLS_AESNI_C) && !defined(_MSC_VER)
#include "mbedtls/aesni.h"
@@ -40,8 +49,6 @@
#define asm __asm
#endif
-#if defined(MBEDTLS_HAVE_X86_64)
-
/*
* AES-NI support detection routine
*/
@@ -459,6 +466,4 @@
return( 0 );
}
-#endif /* MBEDTLS_HAVE_X86_64 */
-
#endif /* MBEDTLS_AESNI_C */
diff -ruN polarssl-master/library/entropy_poll.c polarssl/library/entropy_poll.c
--- polarssl-master/library/entropy_poll.c 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/library/entropy_poll.c 2018-04-17 15:52:13.013004200 -0500
@@ -56,6 +56,12 @@
#include <windows.h>
#include <wincrypt.h>
+/*
+ * WARNING(despair): The next release of PolarSSL will remove the existing codepaths
+ * to enable Windows RT and UWP app support. This also breaks NT 5.x and early Longhorn.
+ *
+ * TODO(despair): create CPP macro to switch between old and new CAPI codepaths
+ */
int mbedtls_platform_entropy_poll( void *data, unsigned char *output, size_t len,
size_t *olen )
{
diff -ruN polarssl-master/library/gcm.c polarssl/library/gcm.c
--- polarssl-master/library/gcm.c 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/library/gcm.c 2018-04-17 16:53:18.630262400 -0500
@@ -126,7 +126,7 @@
ctx->HL[8] = vl;
ctx->HH[8] = vh;
-#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+#if defined(MBEDTLS_AESNI_C)
/* With CLMUL support, we need only h, not the rest of the table */
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) )
return( 0 );
@@ -217,7 +217,7 @@
unsigned char lo, hi, rem;
uint64_t zh, zl;
-#if defined(MBEDTLS_AESNI_C) && defined(MBEDTLS_HAVE_X86_64)
+#if defined(MBEDTLS_AESNI_C)
if( mbedtls_aesni_has_support( MBEDTLS_AESNI_CLMUL ) ) {
unsigned char h[16];
diff -ruN polarssl-master/library/net_sockets.c polarssl/library/net_sockets.c
--- polarssl-master/library/net_sockets.c 2018-03-16 11:25:12.000000000 -0500
+++ polarssl/library/net_sockets.c 2018-04-17 15:50:08.118440600 -0500
@@ -51,7 +51,8 @@
/* Enables getaddrinfo() & Co */
#define _WIN32_WINNT 0x0501
#include <ws2tcpip.h>
-
+/* despair: re-enable Windows 2000/XP */
+#include <wspiapi.h>
#include <winsock2.h>
#include <windows.h>

File diff suppressed because it is too large Load Diff

@ -1,209 +0,0 @@
/* zpipe.c: example of proper use of zlib's inflate() and deflate()
Not copyrighted -- provided to the public domain
Version 1.4 11 December 2005 Mark Adler */
/* Version history:
1.0 30 Oct 2004 First version
1.1 8 Nov 2004 Add void casting for unused return values
Use switch statement for inflate() return values
1.2 9 Nov 2004 Add assertions to document zlib guarantees
1.3 6 Apr 2005 Remove incorrect assertion in inf()
1.4 11 Dec 2005 Add hack to avoid MSDOS end-of-line conversions
Avoid some compiler warnings for input and output buffers
*/
#include <stdio.h>
#include <string.h>
#include <assert.h>
#include "miniz.h"
#if defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
# include <fcntl.h>
# include <io.h>
# define SET_BINARY_MODE(file) setmode(fileno(file), O_BINARY)
#else
# define SET_BINARY_MODE(file)
#endif
#define CHUNK 16384
/* Compress from file source to file dest until EOF on source.
def() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_STREAM_ERROR if an invalid compression
level is supplied, Z_VERSION_ERROR if the version of zlib.h and the
version of the library linked do not match, or Z_ERRNO if there is
an error reading or writing the files. */
int def(FILE *source, FILE *dest, int level)
{
int ret, flush;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];unsigned char out[CHUNK];
/* allocate deflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
ret = deflateInit(&strm, level);
if (ret != Z_OK)
return ret;
/* compress until end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
flush = feof(source) ? Z_FINISH : Z_NO_FLUSH;
strm.next_in = in;
/* run deflate() on input until output buffer not full, finish
compression if all of source has been read in */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = deflate(&strm, flush); /* no bad return value */
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)deflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
assert(strm.avail_in == 0); /* all input will be used */
/* done when last data in file processed */
} while (flush != Z_FINISH);
assert(ret == Z_STREAM_END); /* stream will be complete */
/* clean up and return */
(void)deflateEnd(&strm);
return Z_OK;
}
/* Decompress from file source to file dest until stream ends or EOF.
inf() returns Z_OK on success, Z_MEM_ERROR if memory could not be
allocated for processing, Z_DATA_ERROR if the deflate data is
invalid or incomplete, Z_VERSION_ERROR if the version of zlib.h and
the version of the library linked do not match, or Z_ERRNO if there
is an error reading or writing the files. */
int inf(FILE *source, FILE *dest)
{
int ret;
unsigned have;
z_stream strm;
unsigned char in[CHUNK];
unsigned char out[CHUNK];
/* allocate inflate state */
strm.zalloc = Z_NULL;
strm.zfree = Z_NULL;
strm.opaque = Z_NULL;
strm.avail_in = 0;
strm.next_in = Z_NULL;
ret = inflateInit(&strm);
if (ret != Z_OK)
return ret;
/* decompress until deflate stream ends or end of file */
do {
strm.avail_in = fread(in, 1, CHUNK, source);
if (ferror(source)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
if (strm.avail_in == 0)
break;
strm.next_in = in;
/* run inflate() on input until output buffer not full */
do {
strm.avail_out = CHUNK;
strm.next_out = out;
ret = inflate(&strm, Z_NO_FLUSH);
assert(ret != Z_STREAM_ERROR); /* state not clobbered */
switch (ret) {
case Z_NEED_DICT:
ret = Z_DATA_ERROR; /* and fall through */
case Z_DATA_ERROR:
case Z_MEM_ERROR:
(void)inflateEnd(&strm);
return ret;
}
have = CHUNK - strm.avail_out;
if (fwrite(out, 1, have, dest) != have || ferror(dest)) {
(void)inflateEnd(&strm);
return Z_ERRNO;
}
} while (strm.avail_out == 0);
/* done when inflate() says it's done */
} while (ret != Z_STREAM_END);
/* clean up and return */
(void)inflateEnd(&strm);
return ret == Z_STREAM_END ? Z_OK : Z_DATA_ERROR;
}
/* report a zlib or i/o error */
void zerr(int ret)
{
fputs("zpipe: ", stderr);
switch (ret) {
case Z_ERRNO:
if (ferror(stdin))
fputs("error reading stdin\n", stderr);
if (ferror(stdout))
fputs("error writing stdout\n", stderr);
break;
case Z_STREAM_ERROR:
fputs("invalid compression level\n", stderr);
break;
case Z_DATA_ERROR:
fputs("invalid or incomplete deflate data\n", stderr);
break;
case Z_MEM_ERROR:
fputs("out of memory\n", stderr);
break;
case Z_VERSION_ERROR:
fputs("zlib version mismatch!\n", stderr);
}
}
/* compress or decompress from stdin to stdout */
int main(int argc, char **argv)
{
int ret;
/* avoid end-of-line conversions */
SET_BINARY_MODE(stdin);
SET_BINARY_MODE(stdout);
/* do compression if no arguments */
/* Warning: Not compatible with plain libz, dial it back down to
* 9 if this is required, uber-level is 10
* since we have everything crammed in miniz, we don't depend on
* libz at all.
*/
if (argc == 1) {
ret = def(stdin, stdout, MZ_UBER_COMPRESSION);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* do decompression if -d specified */
else if (argc == 2 && strcmp(argv[1], "-d") == 0) {
ret = inf(stdin, stdout);
if (ret != Z_OK)
zerr(ret);
return ret;
}
/* otherwise, report usage */
else {
fputs("zpipe usage: zpipe [-d] < source > dest\n", stderr);
return 1;
}
}
Loading…
Cancel
Save