├── .dockerignore ├── .gitignore ├── .gitmodules ├── AUTHORS ├── Dockerfile ├── LICENSE ├── Makefile ├── README.md ├── alarm.go ├── boringssl └── openssl │ ├── aead.h │ ├── aes.h │ ├── arm_arch.h │ ├── asn1.h │ ├── asn1_mac.h │ ├── asn1t.h │ ├── base.h │ ├── base64.h │ ├── bio.h │ ├── blowfish.h │ ├── bn.h │ ├── buf.h │ ├── buffer.h │ ├── bytestring.h │ ├── cast.h │ ├── chacha.h │ ├── cipher.h │ ├── cmac.h │ ├── conf.h │ ├── cpu.h │ ├── crypto.h │ ├── curve25519.h │ ├── des.h │ ├── dh.h │ ├── digest.h │ ├── dsa.h │ ├── dtls1.h │ ├── ec.h │ ├── ec_key.h │ ├── ecdh.h │ ├── ecdsa.h │ ├── engine.h │ ├── err.h │ ├── evp.h │ ├── ex_data.h │ ├── hkdf.h │ ├── hmac.h │ ├── lhash.h │ ├── lhash_macros.h │ ├── md4.h │ ├── md5.h │ ├── mem.h │ ├── newhope.h │ ├── nid.h │ ├── obj.h │ ├── obj_mac.h │ ├── objects.h │ ├── openssl │ ├── aead.h │ ├── aes.h │ ├── arm_arch.h │ ├── asn1.h │ ├── asn1_mac.h │ ├── asn1t.h │ ├── base.h │ ├── base64.h │ ├── bio.h │ ├── blowfish.h │ ├── bn.h │ ├── buf.h │ ├── buffer.h │ ├── bytestring.h │ ├── cast.h │ ├── chacha.h │ ├── cipher.h │ ├── cmac.h │ ├── conf.h │ ├── cpu.h │ ├── crypto.h │ ├── curve25519.h │ ├── des.h │ ├── dh.h │ ├── digest.h │ ├── dsa.h │ ├── dtls1.h │ ├── ec.h │ ├── ec_key.h │ ├── ecdh.h │ ├── ecdsa.h │ ├── engine.h │ ├── err.h │ ├── evp.h │ ├── ex_data.h │ ├── hkdf.h │ ├── hmac.h │ ├── lhash.h │ ├── lhash_macros.h │ ├── md4.h │ ├── md5.h │ ├── mem.h │ ├── newhope.h │ ├── nid.h │ ├── obj.h │ ├── obj_mac.h │ ├── objects.h │ ├── opensslconf.h │ ├── opensslv.h │ ├── ossl_typ.h │ ├── pem.h │ ├── pkcs12.h │ ├── pkcs7.h │ ├── pkcs8.h │ ├── poly1305.h │ ├── pqueue.h │ ├── rand.h │ ├── rc4.h │ ├── ripemd.h │ ├── rsa.h │ ├── safestack.h │ ├── sha.h │ ├── srtp.h │ ├── ssl.h │ ├── ssl3.h │ ├── stack.h │ ├── stack_macros.h │ ├── thread.h │ ├── time_support.h │ ├── tls1.h │ ├── type_check.h │ ├── x509.h │ ├── x509_vfy.h │ └── x509v3.h │ ├── opensslconf.h │ ├── opensslfeatures.h │ ├── opensslv.h │ ├── ossl_typ.h │ ├── pem.h │ ├── pkcs12.h │ ├── pkcs7.h │ ├── pkcs8.h │ ├── poly1305.h │ ├── pqueue.h │ ├── rand.h │ ├── rc4.h │ ├── ripemd.h │ ├── rsa.h │ ├── safestack.h │ ├── sha.h │ ├── srtp.h │ ├── ssl.h │ ├── ssl3.h │ ├── stack.h │ ├── stack_macros.h │ ├── thread.h │ ├── time_support.h │ ├── tls1.h │ ├── type_check.h │ ├── x509.h │ ├── x509_vfy.h │ └── x509v3.h ├── bufferpool.go ├── build_libs.sh ├── client.go ├── client_conn.go ├── client_wrapper.go ├── datastream_client.go ├── datastream_server.go ├── dispatcher.go ├── example ├── README.md ├── client.go ├── config_generator.go ├── reverse_proxy.go └── server.go ├── go_functions.c ├── go_functions.h ├── go_structs.h ├── goquic.go ├── init.go ├── init_posix.go ├── ip.go ├── proof_source.go ├── proof_verifier.go ├── ptr.go ├── ptr_gen.py ├── quicstream_client.go ├── quicstream_server.go ├── server.go ├── server_config.go ├── src ├── adaptor.cc ├── adaptor.h ├── adaptor_client.cc ├── adaptor_client.h ├── chlo_extractor.cc ├── chlo_extractor.h ├── go_ephemeral_key_source.cc ├── go_ephemeral_key_source.h ├── go_functions.h ├── go_proof_verifier.cc ├── go_proof_verifier.h ├── go_quic_alarm_factory.cc ├── go_quic_alarm_factory.h ├── go_quic_alarm_go_wrapper.h ├── go_quic_client_packet_writer.cc ├── go_quic_client_packet_writer.h ├── go_quic_client_session.cc ├── go_quic_client_session.h ├── go_quic_connection_helper.cc ├── go_quic_connection_helper.h ├── go_quic_dispatcher.cc ├── go_quic_dispatcher.h ├── go_quic_per_connection_packet_writer.cc ├── go_quic_per_connection_packet_writer.h ├── go_quic_process_packet_interface.h ├── go_quic_server_packet_writer.cc ├── go_quic_server_packet_writer.h ├── go_quic_simple_crypto_server_stream_helper.cc ├── go_quic_simple_crypto_server_stream_helper.h ├── go_quic_simple_dispatcher.cc ├── go_quic_simple_dispatcher.h ├── go_quic_simple_server_session.cc ├── go_quic_simple_server_session.h ├── go_quic_simple_server_session_helper.cc ├── go_quic_simple_server_session_helper.h ├── go_quic_simple_server_stream.cc ├── go_quic_simple_server_stream.h ├── go_quic_spdy_client_stream.cc ├── go_quic_spdy_client_stream.h ├── go_quic_time_wait_list_manager.cc ├── go_quic_time_wait_list_manager.h ├── go_structs.h ├── go_utils.cc ├── go_utils.h ├── proof_source_goquic.cc ├── proof_source_goquic.h ├── stateless_rejector.cc └── stateless_rejector.h ├── statistics.go ├── stream.go ├── task_runner.go ├── vendor ├── github.com │ ├── gorilla │ │ └── handlers │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── canonical.go │ │ │ ├── compress.go │ │ │ ├── cors.go │ │ │ ├── doc.go │ │ │ ├── handlers.go │ │ │ ├── proxy_headers.go │ │ │ └── recovery.go │ ├── oleiade │ │ └── lane │ │ │ ├── LICENSE │ │ │ ├── README.md │ │ │ ├── deque.go │ │ │ ├── doc.go │ │ │ ├── pqueue.go │ │ │ ├── queue.go │ │ │ └── stack.go │ └── vanillahsu │ │ └── go_reuseport │ │ ├── LICENSE │ │ ├── README.md │ │ ├── reuseport.go │ │ ├── reuseport_bsd.go │ │ └── reuseport_linux.go ├── golang.org │ └── x │ │ └── net │ │ ├── LICENSE │ │ ├── PATENTS │ │ ├── http2 │ │ ├── Dockerfile │ │ ├── Makefile │ │ ├── README │ │ ├── client_conn_pool.go │ │ ├── configure_transport.go │ │ ├── errors.go │ │ ├── fixed_buffer.go │ │ ├── flow.go │ │ ├── frame.go │ │ ├── go16.go │ │ ├── go17.go │ │ ├── gotrack.go │ │ ├── headermap.go │ │ ├── hpack │ │ │ ├── encode.go │ │ │ ├── hpack.go │ │ │ ├── huffman.go │ │ │ └── tables.go │ │ ├── http2.go │ │ ├── not_go16.go │ │ ├── not_go17.go │ │ ├── pipe.go │ │ ├── server.go │ │ ├── transport.go │ │ ├── write.go │ │ └── writesched.go │ │ └── lex │ │ └── httplex │ │ └── httplex.go └── vendor.json └── writer.go /.dockerignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | .DS_Store 4 | 5 | lib 6 | build 7 | 8 | libquic/build 9 | 10 | *.pem 11 | *.key 12 | *.csr 13 | *.crt 14 | *.srl 15 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *.swo 3 | tags 4 | build/ 5 | libgoquic.a 6 | nbproject/ 7 | lib/ 8 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "libquic"] 2 | path = libquic 3 | url = https://github.com/devsisters/libquic 4 | -------------------------------------------------------------------------------- /AUTHORS: -------------------------------------------------------------------------------- 1 | # Names should be added to this file with this pattern: 2 | # 3 | # For individuals: 4 | # Name 5 | # 6 | # For organizations: 7 | # Organization 8 | # 9 | # See python fnmatch module documentation for more information. 10 | 11 | Brian Sung-jin Hong 12 | Joonsung Lee 13 | Jaeman An 14 | 15 | Devsisters Corp. <*@devsisters.com> 16 | 17 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.7 2 | MAINTAINER Server Team "se@devsisters.com" 3 | 4 | RUN apt-get -qq update && apt-get install -y build-essential cmake ninja-build 5 | ADD . /go/src/github.com/devsisters/goquic 6 | 7 | WORKDIR /go/src/github.com/devsisters/goquic 8 | RUN ./build_libs.sh -a -r 9 | RUN go build $GOPATH/src/github.com/devsisters/goquic/example/reverse_proxy.go 10 | 11 | EXPOSE 8080 12 | EXPOSE 8080/udp 13 | 14 | ENTRYPOINT ["/go/src/github.com/devsisters/goquic/reverse_proxy"] 15 | CMD ["--help"] 16 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The libquic Authors. All rights reserved. 2 | // 3 | // Redistribution and use in source and binary forms, with or without 4 | // modification, are permitted provided that the following conditions are 5 | // met: 6 | // 7 | // * Redistributions of source code must retain the above copyright 8 | // notice, this list of conditions and the following disclaimer. 9 | // * Redistributions in binary form must reproduce the above 10 | // copyright notice, this list of conditions and the following disclaimer 11 | // in the documentation and/or other materials provided with the 12 | // distribution. 13 | // * Neither the name of Devsisters Corp. nor the names of its 14 | // contributors may be used to endorse or promote products derived from 15 | // this software without specific prior written permission. 16 | // 17 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | #CXX=g++-4.8 2 | #AR=ar 3 | #CC=gcc-4.8 4 | CFLAGS=-Wall -Ilibquic/src -Ilibquic/src/third_party/protobuf/src -DUSE_OPENSSL=1 -Iboringssl/include -g 5 | CPPFLAGS=--std=gnu++11 6 | CPP_FILES:=$(wildcard src/*.cc) 7 | CPP_BASE_FILES:=$(CPP_FILES:src/%=%) 8 | #C_FILES:=$(wildcard src/*.c) 9 | #C_BASE_FILES:=$(C_FILES:src/%=%) 10 | OBJ_FILES:=$(addprefix build/,$(CPP_BASE_FILES:.cc=.o)) 11 | #OBJ_FILES:=$(addprefix build/,$(CPP_BASE_FILES:.cc=.o)) $(addprefix build/,$(C_BASE_FILES:.c=.o)) 12 | LIB_FILE=libgoquic.a 13 | 14 | ifeq ($(GOQUIC_BUILD),Release) 15 | OPTFLAGS=-O3 -DNDEBUG 16 | else 17 | OPTFLAGS= 18 | endif 19 | 20 | 21 | all: $(OBJ_FILES) $(LIB_FILE) 22 | 23 | $(LIB_FILE): $(OBJ_FILES) 24 | $(AR) rvs $@ $(OBJ_FILES) 25 | 26 | #build/%.o: src/%.c 27 | # mkdir -p $(dir $@) 28 | # $(C) $(CFLAGS) -c -o $@ $< 29 | 30 | build/%.o: src/%.cc 31 | mkdir -p $(dir $@) 32 | $(CXX) $(CFLAGS) $(OPTFLAGS) $(CPPFLAGS) -c -o $@ $< 33 | 34 | clean: 35 | rm -f build/* 36 | rm -f libgoquic.a 37 | -------------------------------------------------------------------------------- /alarm.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include 4 | // #include "src/adaptor.h" 5 | import "C" 6 | import ( 7 | "fmt" 8 | "time" 9 | "unsafe" 10 | ) 11 | 12 | type GoQuicAlarm struct { 13 | deadline int64 14 | isDestroyed bool 15 | isCanceled bool 16 | invalidateCh chan bool 17 | wrapper unsafe.Pointer 18 | clock unsafe.Pointer 19 | taskRunner *TaskRunner 20 | } 21 | 22 | func (alarm *GoQuicAlarm) SetImpl() { 23 | if alarm.isDestroyed { 24 | return 25 | } 26 | alarm.isCanceled = false 27 | alarm.taskRunner.RunAlarm(alarm) 28 | } 29 | 30 | // Called by C++ side when the C++ wrapper object is destoryed 31 | func (alarm *GoQuicAlarm) Destroy() { 32 | alarm.isDestroyed = true 33 | alarm.CancelImpl() 34 | alarm.taskRunner.UnregisterAlarm(alarm) 35 | } 36 | 37 | func (alarm *GoQuicAlarm) CancelImpl() { 38 | alarm.isCanceled = true 39 | alarm.taskRunner.CancelAlarm(alarm) 40 | } 41 | 42 | func (alarm *GoQuicAlarm) OnAlarm() { 43 | if now := int64(C.clock_now(alarm.clock)); now < alarm.deadline { 44 | // This should be very rarely occrued. Otherwise this could be performance bottleneck. 45 | fmt.Println(now, time.Now().UnixNano()/1000000, alarm.wrapper, alarm.deadline, "Warning: Timer not adjustted") 46 | alarm.SetImpl() 47 | return 48 | } 49 | 50 | // There can be race condition between QuicAlarm destruction and OnAlarm callback. So this check is needed 51 | if alarm.isCanceled { 52 | return 53 | } 54 | 55 | C.go_quic_alarm_fire(alarm.wrapper) 56 | } 57 | 58 | func (alarm *GoQuicAlarm) Now() int64 { 59 | return int64(C.clock_now(alarm.clock)) 60 | } 61 | 62 | //export CreateGoQuicAlarm 63 | func CreateGoQuicAlarm(go_quic_alarm_go_wrapper_c unsafe.Pointer, clock_c unsafe.Pointer, go_task_runner_key int64) int64 { 64 | alarm := &GoQuicAlarm{ 65 | wrapper: go_quic_alarm_go_wrapper_c, 66 | taskRunner: taskRunnerPtr.Get(go_task_runner_key), 67 | clock: clock_c, 68 | isCanceled: false, 69 | } 70 | alarm.taskRunner.RegisterAlarm(alarm) 71 | 72 | return goQuicAlarmPtr.Set(alarm) 73 | } 74 | 75 | //export GoQuicAlarmSetImpl 76 | func GoQuicAlarmSetImpl(go_quic_alarm_key int64, deadline int64) { 77 | alarm := goQuicAlarmPtr.Get(go_quic_alarm_key) 78 | alarm.deadline = deadline 79 | alarm.SetImpl() 80 | } 81 | 82 | //export GoQuicAlarmCancelImpl 83 | func GoQuicAlarmCancelImpl(go_quic_alarm_key int64) { 84 | alarm := goQuicAlarmPtr.Get(go_quic_alarm_key) 85 | alarm.CancelImpl() 86 | } 87 | 88 | //export GoQuicAlarmDestroy 89 | func GoQuicAlarmDestroy(go_quic_alarm_key int64) { 90 | alarm := goQuicAlarmPtr.Get(go_quic_alarm_key) 91 | alarm.Destroy() 92 | goQuicAlarmPtr.Del(go_quic_alarm_key) 93 | } 94 | -------------------------------------------------------------------------------- /boringssl/openssl/asn1_mac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 | * All rights reserved. 3 | * 4 | * This package is an SSL implementation written 5 | * by Eric Young (eay@cryptsoft.com). 6 | * The implementation was written so as to conform with Netscapes SSL. 7 | * 8 | * This library is free for commercial and non-commercial use as long as 9 | * the following conditions are aheared to. The following conditions 10 | * apply to all code found in this distribution, be it the RC4, RSA, 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 | * included with this distribution is covered by the same copyright terms 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 | * 15 | * Copyright remains Eric Young's, and as such any Copyright notices in 16 | * the code are not to be removed. 17 | * If this package is used in a product, Eric Young should be given attribution 18 | * as the author of the parts of the library used. 19 | * This can be in the form of a textual message at program startup or 20 | * in documentation (online or textual) provided with the package. 21 | * 22 | * Redistribution and use in source and binary forms, with or without 23 | * modification, are permitted provided that the following conditions 24 | * are met: 25 | * 1. Redistributions of source code must retain the copyright 26 | * notice, this list of conditions and the following disclaimer. 27 | * 2. Redistributions in binary form must reproduce the above copyright 28 | * notice, this list of conditions and the following disclaimer in the 29 | * documentation and/or other materials provided with the distribution. 30 | * 3. All advertising materials mentioning features or use of this software 31 | * must display the following acknowledgement: 32 | * "This product includes cryptographic software written by 33 | * Eric Young (eay@cryptsoft.com)" 34 | * The word 'cryptographic' can be left out if the rouines from the library 35 | * being used are not cryptographic related :-). 36 | * 4. If you include any Windows specific code (or a derivative thereof) from 37 | * the apps directory (application code) you must include an acknowledgement: 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 | * SUCH DAMAGE. 51 | * 52 | * The licence and distribution terms for any publically available version or 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be 54 | * copied and put under another distribution licence 55 | * [including the GNU Public Licence.] 56 | */ 57 | 58 | #ifndef HEADER_ASN1_MAC_H 59 | #define HEADER_ASN1_MAC_H 60 | 61 | #include 62 | 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | 68 | OPENSSL_EXPORT int asn1_GetSequence(ASN1_const_CTX *c, long *length); 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /boringssl/openssl/buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "buf.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/chacha.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CHACHA_H 16 | #define OPENSSL_HEADER_CHACHA_H 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* CRYPTO_chacha_20 encrypts |in_len| bytes from |in| with the given key and 26 | * nonce and writes the result to |out|, which may be equal to |in|. The 27 | * initial block counter is specified by |counter|. */ 28 | OPENSSL_EXPORT void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, 29 | size_t in_len, const uint8_t key[32], 30 | const uint8_t nonce[12], uint32_t counter); 31 | 32 | 33 | #if defined(__cplusplus) 34 | } /* extern C */ 35 | #endif 36 | 37 | #endif /* OPENSSL_HEADER_CHACHA_H */ 38 | -------------------------------------------------------------------------------- /boringssl/openssl/cmac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CMAC_H 16 | #define OPENSSL_HEADER_CMAC_H 17 | 18 | #include 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* CMAC. 26 | * 27 | * CMAC is a MAC based on AES-CBC and defined in 28 | * https://tools.ietf.org/html/rfc4493#section-2.3. */ 29 | 30 | 31 | /* One-shot functions. */ 32 | 33 | /* AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of 34 | * |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select 35 | * between AES-128 and AES-256. It returns one on success or zero on error. */ 36 | OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len, 37 | const uint8_t *in, size_t in_len); 38 | 39 | 40 | /* Incremental interface. */ 41 | 42 | /* CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on 43 | * error. */ 44 | OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void); 45 | 46 | /* CMAC_CTX_free frees a |CMAC_CTX|. */ 47 | OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx); 48 | 49 | /* CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC 50 | * only specifies the use of AES-128 thus |key_len| should be 16 and |cipher| 51 | * should be |EVP_aes_128_cbc()|. However, this implementation also supports 52 | * AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The 53 | * |engine| argument is ignored. 54 | * 55 | * It returns one on success or zero on error. */ 56 | OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len, 57 | const EVP_CIPHER *cipher, ENGINE *engine); 58 | 59 | 60 | /* CMAC_Reset resets |ctx| so that a fresh message can be authenticated. */ 61 | OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx); 62 | 63 | /* CMAC_Update processes |in_len| bytes of message from |in|. It returns one on 64 | * success or zero on error. */ 65 | OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len); 66 | 67 | /* CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes 68 | * of authenticator to it. It returns one on success or zero on error. */ 69 | OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len); 70 | 71 | 72 | #if defined(__cplusplus) 73 | } /* extern C */ 74 | #endif 75 | 76 | #endif /* OPENSSL_HEADER_CMAC_H */ 77 | -------------------------------------------------------------------------------- /boringssl/openssl/crypto.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CRYPTO_H 16 | #define OPENSSL_HEADER_CRYPTO_H 17 | 18 | #include 19 | 20 | /* Upstream OpenSSL defines |OPENSSL_malloc|, etc., in crypto.h rather than 21 | * mem.h. */ 22 | #include 23 | 24 | /* Upstream OpenSSL defines |CRYPTO_LOCK|, etc., in crypto.h rather than 25 | * thread.h. */ 26 | #include 27 | 28 | 29 | #if defined(__cplusplus) 30 | extern "C" { 31 | #endif 32 | 33 | 34 | /* crypto.h contains functions for initializing the crypto library. */ 35 | 36 | 37 | /* CRYPTO_library_init initializes the crypto library. It must be called if the 38 | * library is built with BORINGSSL_NO_STATIC_INITIALIZER. Otherwise, it does 39 | * nothing and a static initializer is used instead. It is safe to call this 40 | * function multiple times and concurrently from multiple threads. 41 | * 42 | * On some ARM configurations, this function may require filesystem access and 43 | * should be called before entering a sandbox. */ 44 | OPENSSL_EXPORT void CRYPTO_library_init(void); 45 | 46 | 47 | /* Deprecated functions. */ 48 | 49 | /* OPENSSL_VERSION_TEXT contains a string the identifies the version of 50 | * “OpenSSL”. node.js requires a version number in this text. */ 51 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2 (compatible; BoringSSL)" 52 | 53 | #define SSLEAY_VERSION 0 54 | 55 | /* SSLeay_version is a compatibility function that returns the string 56 | * "BoringSSL". */ 57 | OPENSSL_EXPORT const char *SSLeay_version(int unused); 58 | 59 | /* SSLeay is a compatibility function that returns OPENSSL_VERSION_NUMBER from 60 | * base.h. */ 61 | OPENSSL_EXPORT unsigned long SSLeay(void); 62 | 63 | /* CRYPTO_malloc_init returns one. */ 64 | OPENSSL_EXPORT int CRYPTO_malloc_init(void); 65 | 66 | /* ENGINE_load_builtin_engines does nothing. */ 67 | OPENSSL_EXPORT void ENGINE_load_builtin_engines(void); 68 | 69 | /* OPENSSL_load_builtin_modules does nothing. */ 70 | OPENSSL_EXPORT void OPENSSL_load_builtin_modules(void); 71 | 72 | /* FIPS_mode returns zero. */ 73 | OPENSSL_EXPORT int FIPS_mode(void); 74 | 75 | 76 | #if defined(__cplusplus) 77 | } /* extern C */ 78 | #endif 79 | 80 | #endif /* OPENSSL_HEADER_CRYPTO_H */ 81 | -------------------------------------------------------------------------------- /boringssl/openssl/dtls1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/engine.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_ENGINE_H 16 | #define OPENSSL_HEADER_ENGINE_H 17 | 18 | #include 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* Engines are collections of methods. Methods are tables of function pointers, 26 | * defined for certain algorithms, that allow operations on those algorithms to 27 | * be overridden via a callback. This can be used, for example, to implement an 28 | * RSA* that forwards operations to a hardware module. 29 | * 30 | * Methods are reference counted but |ENGINE|s are not. When creating a method, 31 | * you should zero the whole structure and fill in the function pointers that 32 | * you wish before setting it on an |ENGINE|. Any functions pointers that 33 | * are NULL indicate that the default behaviour should be used. */ 34 | 35 | 36 | /* Allocation and destruction. */ 37 | 38 | /* ENGINE_new returns an empty ENGINE that uses the default method for all 39 | * algorithms. */ 40 | OPENSSL_EXPORT ENGINE *ENGINE_new(void); 41 | 42 | /* ENGINE_free decrements the reference counts for all methods linked from 43 | * |engine| and frees |engine| itself. */ 44 | OPENSSL_EXPORT void ENGINE_free(ENGINE *engine); 45 | 46 | 47 | /* Method accessors. 48 | * 49 | * Method accessors take a method pointer and the size of the structure. The 50 | * size allows for ABI compatibility in the case that the method structure is 51 | * extended with extra elements at the end. Methods are always copied by the 52 | * set functions. 53 | * 54 | * Set functions return one on success and zero on allocation failure. */ 55 | 56 | OPENSSL_EXPORT int ENGINE_set_RSA_method(ENGINE *engine, 57 | const RSA_METHOD *method, 58 | size_t method_size); 59 | OPENSSL_EXPORT RSA_METHOD *ENGINE_get_RSA_method(const ENGINE *engine); 60 | 61 | OPENSSL_EXPORT int ENGINE_set_ECDSA_method(ENGINE *engine, 62 | const ECDSA_METHOD *method, 63 | size_t method_size); 64 | OPENSSL_EXPORT ECDSA_METHOD *ENGINE_get_ECDSA_method(const ENGINE *engine); 65 | 66 | 67 | /* Generic method functions. 68 | * 69 | * These functions take a void* type but actually operate on all method 70 | * structures. */ 71 | 72 | /* METHOD_ref increments the reference count of |method|. This is a no-op for 73 | * now because all methods are currently static. */ 74 | void METHOD_ref(void *method); 75 | 76 | /* METHOD_unref decrements the reference count of |method| and frees it if the 77 | * reference count drops to zero. This is a no-op for now because all methods 78 | * are currently static. */ 79 | void METHOD_unref(void *method); 80 | 81 | 82 | /* Private functions. */ 83 | 84 | /* openssl_method_common_st contains the common part of all method structures. 85 | * This must be the first member of all method structures. */ 86 | struct openssl_method_common_st { 87 | int references; /* dummy – not used. */ 88 | char is_static; 89 | }; 90 | 91 | 92 | #if defined(__cplusplus) 93 | } /* extern C */ 94 | #endif 95 | 96 | #define ENGINE_R_OPERATION_NOT_SUPPORTED 100 97 | 98 | #endif /* OPENSSL_HEADER_ENGINE_H */ 99 | -------------------------------------------------------------------------------- /boringssl/openssl/hkdf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_HKDF_H 16 | #define OPENSSL_HEADER_HKDF_H 17 | 18 | #include 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* HKDF. */ 26 | 27 | 28 | /* HKDF computes HKDF (as specified by RFC 5869) of initial keying material 29 | * |secret| with |salt| and |info| using |digest|, and outputs |out_len| bytes 30 | * to |out_key|. It returns one on success and zero on error. 31 | * 32 | * HKDF is an Extract-and-Expand algorithm. It does not do any key stretching, 33 | * and as such, is not suited to be used alone to generate a key from a 34 | * password. */ 35 | OPENSSL_EXPORT int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest, 36 | const uint8_t *secret, size_t secret_len, 37 | const uint8_t *salt, size_t salt_len, 38 | const uint8_t *info, size_t info_len); 39 | 40 | 41 | #if defined(__cplusplus) 42 | } /* extern C */ 43 | #endif 44 | 45 | #define HKDF_R_OUTPUT_TOO_LARGE 100 46 | 47 | #endif /* OPENSSL_HEADER_HKDF_H */ 48 | -------------------------------------------------------------------------------- /boringssl/openssl/newhope.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_NEWHOPE_H 16 | #define OPENSSL_HEADER_NEWHOPE_H 17 | 18 | #include 19 | #include 20 | 21 | #if defined(__cplusplus) 22 | extern "C" { 23 | #endif 24 | 25 | 26 | /* Post-quantum key agreement, based upon the reference 27 | * implementation. Note: this implementation does not interoperate 28 | * with the reference implementation! 29 | * 30 | * Source: https://github.com/tpoeppelmann/newhope 31 | * 32 | * The authors' permission to use their code is gratefully acknowledged. */ 33 | 34 | 35 | /* NEWHOPE_POLY_new returns a new |NEWHOPE_POLY| object, or NULL on error. */ 36 | OPENSSL_EXPORT NEWHOPE_POLY *NEWHOPE_POLY_new(void); 37 | 38 | /* NEWHOPE_POLY_free frees |p|. */ 39 | OPENSSL_EXPORT void NEWHOPE_POLY_free(NEWHOPE_POLY *p); 40 | 41 | /* NEWHOPE_SERVERMSG_LENGTH is the length of the server's message to the 42 | * client. */ 43 | #define NEWHOPE_SERVERMSG_LENGTH (((1024 * 14) / 8) + 32) 44 | 45 | /* NEWHOPE_CLIENTMSG_LENGTH is the length of the client's message to the 46 | * server. */ 47 | #define NEWHOPE_CLIENTMSG_LENGTH (((1024 * 14) / 8) + 1024 / 4) 48 | 49 | /* NEWHOPE_keygen initializes |out_msg| and |out_sk| for a new key 50 | * exchange. |msg| must have room for |NEWHOPE_SERVERMSG_LENGTH| bytes. Neither 51 | * output may be cached. */ 52 | OPENSSL_EXPORT void NEWHOPE_keygen(uint8_t out_msg[NEWHOPE_SERVERMSG_LENGTH], 53 | NEWHOPE_POLY *out_sk); 54 | 55 | /* NEWHOPE_server_compute_key completes a key exchange given a client message 56 | * |msg| and the previously generated server secret |sk|. The result of the 57 | * key exchange is written to |out_key|, which must have space for 58 | * |SHA256_DIGEST_LENGTH| bytes. Returns 1 on success and 0 on error. */ 59 | OPENSSL_EXPORT int NEWHOPE_server_compute_key( 60 | uint8_t out_key[SHA256_DIGEST_LENGTH], const NEWHOPE_POLY *sk, 61 | const uint8_t msg[NEWHOPE_CLIENTMSG_LENGTH], size_t msg_len); 62 | 63 | /* NEWHOPE_client_compute_key completes a key exchange given a server message 64 | * |msg|. The result of the key exchange is written to |out_key|, which must 65 | * have space for |SHA256_DIGEST_LENGTH| bytes. The message to be send to the 66 | * client is written to |out_msg|, which must have room for 67 | * |NEWHOPE_CLIENTMSG_LENGTH| bytes. Returns 1 on success and 0 on error. */ 68 | OPENSSL_EXPORT int NEWHOPE_client_compute_key( 69 | uint8_t out_key[SHA256_DIGEST_LENGTH], 70 | uint8_t out_msg[NEWHOPE_CLIENTMSG_LENGTH], 71 | const uint8_t msg[NEWHOPE_SERVERMSG_LENGTH], size_t msg_len); 72 | 73 | 74 | #if defined(__cplusplus) 75 | } /* extern "C" */ 76 | #endif 77 | 78 | #endif /* OPENSSL_HEADER_NEWHOPE_H */ 79 | -------------------------------------------------------------------------------- /boringssl/openssl/obj_mac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "nid.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/objects.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "obj.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/asn1_mac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (C) 1995-1998 Eric Young (eay@cryptsoft.com) 2 | * All rights reserved. 3 | * 4 | * This package is an SSL implementation written 5 | * by Eric Young (eay@cryptsoft.com). 6 | * The implementation was written so as to conform with Netscapes SSL. 7 | * 8 | * This library is free for commercial and non-commercial use as long as 9 | * the following conditions are aheared to. The following conditions 10 | * apply to all code found in this distribution, be it the RC4, RSA, 11 | * lhash, DES, etc., code; not just the SSL code. The SSL documentation 12 | * included with this distribution is covered by the same copyright terms 13 | * except that the holder is Tim Hudson (tjh@cryptsoft.com). 14 | * 15 | * Copyright remains Eric Young's, and as such any Copyright notices in 16 | * the code are not to be removed. 17 | * If this package is used in a product, Eric Young should be given attribution 18 | * as the author of the parts of the library used. 19 | * This can be in the form of a textual message at program startup or 20 | * in documentation (online or textual) provided with the package. 21 | * 22 | * Redistribution and use in source and binary forms, with or without 23 | * modification, are permitted provided that the following conditions 24 | * are met: 25 | * 1. Redistributions of source code must retain the copyright 26 | * notice, this list of conditions and the following disclaimer. 27 | * 2. Redistributions in binary form must reproduce the above copyright 28 | * notice, this list of conditions and the following disclaimer in the 29 | * documentation and/or other materials provided with the distribution. 30 | * 3. All advertising materials mentioning features or use of this software 31 | * must display the following acknowledgement: 32 | * "This product includes cryptographic software written by 33 | * Eric Young (eay@cryptsoft.com)" 34 | * The word 'cryptographic' can be left out if the rouines from the library 35 | * being used are not cryptographic related :-). 36 | * 4. If you include any Windows specific code (or a derivative thereof) from 37 | * the apps directory (application code) you must include an acknowledgement: 38 | * "This product includes software written by Tim Hudson (tjh@cryptsoft.com)" 39 | * 40 | * THIS SOFTWARE IS PROVIDED BY ERIC YOUNG ``AS IS'' AND 41 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 | * SUCH DAMAGE. 51 | * 52 | * The licence and distribution terms for any publically available version or 53 | * derivative of this code cannot be changed. i.e. this code cannot simply be 54 | * copied and put under another distribution licence 55 | * [including the GNU Public Licence.] 56 | */ 57 | 58 | #ifndef HEADER_ASN1_MAC_H 59 | #define HEADER_ASN1_MAC_H 60 | 61 | #include 62 | 63 | #ifdef __cplusplus 64 | extern "C" { 65 | #endif 66 | 67 | 68 | OPENSSL_EXPORT int asn1_GetSequence(ASN1_const_CTX *c, long *length); 69 | 70 | 71 | #ifdef __cplusplus 72 | } 73 | #endif 74 | 75 | #endif 76 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/buffer.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "buf.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/chacha.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CHACHA_H 16 | #define OPENSSL_HEADER_CHACHA_H 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* CRYPTO_chacha_20 encrypts |in_len| bytes from |in| with the given key and 26 | * nonce and writes the result to |out|, which may be equal to |in|. The 27 | * initial block counter is specified by |counter|. */ 28 | OPENSSL_EXPORT void CRYPTO_chacha_20(uint8_t *out, const uint8_t *in, 29 | size_t in_len, const uint8_t key[32], 30 | const uint8_t nonce[12], uint32_t counter); 31 | 32 | 33 | #if defined(__cplusplus) 34 | } /* extern C */ 35 | #endif 36 | 37 | #endif /* OPENSSL_HEADER_CHACHA_H */ 38 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/cmac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CMAC_H 16 | #define OPENSSL_HEADER_CMAC_H 17 | 18 | #include 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* CMAC. 26 | * 27 | * CMAC is a MAC based on AES-CBC and defined in 28 | * https://tools.ietf.org/html/rfc4493#section-2.3. */ 29 | 30 | 31 | /* One-shot functions. */ 32 | 33 | /* AES_CMAC calculates the 16-byte, CMAC authenticator of |in_len| bytes of 34 | * |in| and writes it to |out|. The |key_len| may be 16 or 32 bytes to select 35 | * between AES-128 and AES-256. It returns one on success or zero on error. */ 36 | OPENSSL_EXPORT int AES_CMAC(uint8_t out[16], const uint8_t *key, size_t key_len, 37 | const uint8_t *in, size_t in_len); 38 | 39 | 40 | /* Incremental interface. */ 41 | 42 | /* CMAC_CTX_new allocates a fresh |CMAC_CTX| and returns it, or NULL on 43 | * error. */ 44 | OPENSSL_EXPORT CMAC_CTX *CMAC_CTX_new(void); 45 | 46 | /* CMAC_CTX_free frees a |CMAC_CTX|. */ 47 | OPENSSL_EXPORT void CMAC_CTX_free(CMAC_CTX *ctx); 48 | 49 | /* CMAC_Init configures |ctx| to use the given |key| and |cipher|. The CMAC RFC 50 | * only specifies the use of AES-128 thus |key_len| should be 16 and |cipher| 51 | * should be |EVP_aes_128_cbc()|. However, this implementation also supports 52 | * AES-256 by setting |key_len| to 32 and |cipher| to |EVP_aes_256_cbc()|. The 53 | * |engine| argument is ignored. 54 | * 55 | * It returns one on success or zero on error. */ 56 | OPENSSL_EXPORT int CMAC_Init(CMAC_CTX *ctx, const void *key, size_t key_len, 57 | const EVP_CIPHER *cipher, ENGINE *engine); 58 | 59 | 60 | /* CMAC_Reset resets |ctx| so that a fresh message can be authenticated. */ 61 | OPENSSL_EXPORT int CMAC_Reset(CMAC_CTX *ctx); 62 | 63 | /* CMAC_Update processes |in_len| bytes of message from |in|. It returns one on 64 | * success or zero on error. */ 65 | OPENSSL_EXPORT int CMAC_Update(CMAC_CTX *ctx, const uint8_t *in, size_t in_len); 66 | 67 | /* CMAC_Final sets |*out_len| to 16 and, if |out| is not NULL, writes 16 bytes 68 | * of authenticator to it. It returns one on success or zero on error. */ 69 | OPENSSL_EXPORT int CMAC_Final(CMAC_CTX *ctx, uint8_t *out, size_t *out_len); 70 | 71 | 72 | #if defined(__cplusplus) 73 | } /* extern C */ 74 | #endif 75 | 76 | #endif /* OPENSSL_HEADER_CMAC_H */ 77 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/crypto.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_CRYPTO_H 16 | #define OPENSSL_HEADER_CRYPTO_H 17 | 18 | #include 19 | 20 | /* Upstream OpenSSL defines |OPENSSL_malloc|, etc., in crypto.h rather than 21 | * mem.h. */ 22 | #include 23 | 24 | /* Upstream OpenSSL defines |CRYPTO_LOCK|, etc., in crypto.h rather than 25 | * thread.h. */ 26 | #include 27 | 28 | 29 | #if defined(__cplusplus) 30 | extern "C" { 31 | #endif 32 | 33 | 34 | /* crypto.h contains functions for initializing the crypto library. */ 35 | 36 | 37 | /* CRYPTO_library_init initializes the crypto library. It must be called if the 38 | * library is built with BORINGSSL_NO_STATIC_INITIALIZER. Otherwise, it does 39 | * nothing and a static initializer is used instead. It is safe to call this 40 | * function multiple times and concurrently from multiple threads. 41 | * 42 | * On some ARM configurations, this function may require filesystem access and 43 | * should be called before entering a sandbox. */ 44 | OPENSSL_EXPORT void CRYPTO_library_init(void); 45 | 46 | 47 | /* Deprecated functions. */ 48 | 49 | /* OPENSSL_VERSION_TEXT contains a string the identifies the version of 50 | * “OpenSSL”. node.js requires a version number in this text. */ 51 | #define OPENSSL_VERSION_TEXT "OpenSSL 1.0.2 (compatible; BoringSSL)" 52 | 53 | #define SSLEAY_VERSION 0 54 | 55 | /* SSLeay_version is a compatibility function that returns the string 56 | * "BoringSSL". */ 57 | OPENSSL_EXPORT const char *SSLeay_version(int unused); 58 | 59 | /* SSLeay is a compatibility function that returns OPENSSL_VERSION_NUMBER from 60 | * base.h. */ 61 | OPENSSL_EXPORT unsigned long SSLeay(void); 62 | 63 | /* CRYPTO_malloc_init returns one. */ 64 | OPENSSL_EXPORT int CRYPTO_malloc_init(void); 65 | 66 | /* ENGINE_load_builtin_engines does nothing. */ 67 | OPENSSL_EXPORT void ENGINE_load_builtin_engines(void); 68 | 69 | /* OPENSSL_load_builtin_modules does nothing. */ 70 | OPENSSL_EXPORT void OPENSSL_load_builtin_modules(void); 71 | 72 | /* FIPS_mode returns zero. */ 73 | OPENSSL_EXPORT int FIPS_mode(void); 74 | 75 | 76 | #if defined(__cplusplus) 77 | } /* extern C */ 78 | #endif 79 | 80 | #endif /* OPENSSL_HEADER_CRYPTO_H */ 81 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/dtls1.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/hkdf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_HKDF_H 16 | #define OPENSSL_HEADER_HKDF_H 17 | 18 | #include 19 | 20 | #if defined(__cplusplus) 21 | extern "C" { 22 | #endif 23 | 24 | 25 | /* HKDF. */ 26 | 27 | 28 | /* HKDF computes HKDF (as specified by RFC 5869) of initial keying material 29 | * |secret| with |salt| and |info| using |digest|, and outputs |out_len| bytes 30 | * to |out_key|. It returns one on success and zero on error. 31 | * 32 | * HKDF is an Extract-and-Expand algorithm. It does not do any key stretching, 33 | * and as such, is not suited to be used alone to generate a key from a 34 | * password. */ 35 | OPENSSL_EXPORT int HKDF(uint8_t *out_key, size_t out_len, const EVP_MD *digest, 36 | const uint8_t *secret, size_t secret_len, 37 | const uint8_t *salt, size_t salt_len, 38 | const uint8_t *info, size_t info_len); 39 | 40 | 41 | #if defined(__cplusplus) 42 | } /* extern C */ 43 | #endif 44 | 45 | #define HKDF_R_OUTPUT_TOO_LARGE 100 46 | 47 | #endif /* OPENSSL_HEADER_HKDF_H */ 48 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/newhope.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_NEWHOPE_H 16 | #define OPENSSL_HEADER_NEWHOPE_H 17 | 18 | #include 19 | #include 20 | 21 | #if defined(__cplusplus) 22 | extern "C" { 23 | #endif 24 | 25 | 26 | /* Post-quantum key agreement, based upon the reference 27 | * implementation. Note: this implementation does not interoperate 28 | * with the reference implementation! 29 | * 30 | * Source: https://github.com/tpoeppelmann/newhope 31 | * 32 | * The authors' permission to use their code is gratefully acknowledged. */ 33 | 34 | 35 | /* NEWHOPE_POLY_new returns a new |NEWHOPE_POLY| object, or NULL on error. */ 36 | OPENSSL_EXPORT NEWHOPE_POLY *NEWHOPE_POLY_new(void); 37 | 38 | /* NEWHOPE_POLY_free frees |p|. */ 39 | OPENSSL_EXPORT void NEWHOPE_POLY_free(NEWHOPE_POLY *p); 40 | 41 | /* NEWHOPE_SERVERMSG_LENGTH is the length of the server's message to the 42 | * client. */ 43 | #define NEWHOPE_SERVERMSG_LENGTH (((1024 * 14) / 8) + 32) 44 | 45 | /* NEWHOPE_CLIENTMSG_LENGTH is the length of the client's message to the 46 | * server. */ 47 | #define NEWHOPE_CLIENTMSG_LENGTH (((1024 * 14) / 8) + 1024 / 4) 48 | 49 | /* NEWHOPE_keygen initializes |out_msg| and |out_sk| for a new key 50 | * exchange. |msg| must have room for |NEWHOPE_SERVERMSG_LENGTH| bytes. Neither 51 | * output may be cached. */ 52 | OPENSSL_EXPORT void NEWHOPE_keygen(uint8_t out_msg[NEWHOPE_SERVERMSG_LENGTH], 53 | NEWHOPE_POLY *out_sk); 54 | 55 | /* NEWHOPE_server_compute_key completes a key exchange given a client message 56 | * |msg| and the previously generated server secret |sk|. The result of the 57 | * key exchange is written to |out_key|, which must have space for 58 | * |SHA256_DIGEST_LENGTH| bytes. Returns 1 on success and 0 on error. */ 59 | OPENSSL_EXPORT int NEWHOPE_server_compute_key( 60 | uint8_t out_key[SHA256_DIGEST_LENGTH], const NEWHOPE_POLY *sk, 61 | const uint8_t msg[NEWHOPE_CLIENTMSG_LENGTH], size_t msg_len); 62 | 63 | /* NEWHOPE_client_compute_key completes a key exchange given a server message 64 | * |msg|. The result of the key exchange is written to |out_key|, which must 65 | * have space for |SHA256_DIGEST_LENGTH| bytes. The message to be send to the 66 | * client is written to |out_msg|, which must have room for 67 | * |NEWHOPE_CLIENTMSG_LENGTH| bytes. Returns 1 on success and 0 on error. */ 68 | OPENSSL_EXPORT int NEWHOPE_client_compute_key( 69 | uint8_t out_key[SHA256_DIGEST_LENGTH], 70 | uint8_t out_msg[NEWHOPE_CLIENTMSG_LENGTH], 71 | const uint8_t msg[NEWHOPE_SERVERMSG_LENGTH], size_t msg_len); 72 | 73 | 74 | #if defined(__cplusplus) 75 | } /* extern "C" */ 76 | #endif 77 | 78 | #endif /* OPENSSL_HEADER_NEWHOPE_H */ 79 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/obj_mac.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2016, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "nid.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/objects.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "obj.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #ifndef OPENSSL_HEADER_OPENSSLCONF_H 19 | #define OPENSSL_HEADER_OPENSSLCONF_H 20 | 21 | 22 | #define OPENSSL_NO_BF 23 | #define OPENSSL_NO_BUF_FREELISTS 24 | #define OPENSSL_NO_CAMELLIA 25 | #define OPENSSL_NO_CAPIENG 26 | #define OPENSSL_NO_CAST 27 | #define OPENSSL_NO_CMS 28 | #define OPENSSL_NO_COMP 29 | #define OPENSSL_NO_DANE 30 | #define OPENSSL_NO_DEPRECATED 31 | #define OPENSSL_NO_DYNAMIC_ENGINE 32 | #define OPENSSL_NO_EC_NISTP_64_GCC_128 33 | #define OPENSSL_NO_EC2M 34 | #define OPENSSL_NO_ENGINE 35 | #define OPENSSL_NO_GMP 36 | #define OPENSSL_NO_GOST 37 | #define OPENSSL_NO_HEARTBEATS 38 | #define OPENSSL_NO_HW 39 | #define OPENSSL_NO_IDEA 40 | #define OPENSSL_NO_JPAKE 41 | #define OPENSSL_NO_KRB5 42 | #define OPENSSL_NO_MD2 43 | #define OPENSSL_NO_MDC2 44 | #define OPENSSL_NO_OCB 45 | #define OPENSSL_NO_OCSP 46 | #define OPENSSL_NO_RC2 47 | #define OPENSSL_NO_RC5 48 | #define OPENSSL_NO_RFC3779 49 | #define OPENSSL_NO_RIPEMD 50 | #define OPENSSL_NO_RMD160 51 | #define OPENSSL_NO_SCTP 52 | #define OPENSSL_NO_SEED 53 | #define OPENSSL_NO_SRP 54 | #define OPENSSL_NO_SSL2 55 | #define OPENSSL_NO_STATIC_ENGINE 56 | #define OPENSSL_NO_STORE 57 | #define OPENSSL_NO_WHIRLPOOL 58 | 59 | 60 | #endif /* OPENSSL_HEADER_OPENSSLCONF_H */ 61 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/opensslv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "crypto.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/ossl_typ.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "base.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/pkcs12.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "pkcs8.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/pkcs7.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/poly1305.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_POLY1305_H 16 | #define OPENSSL_HEADER_POLY1305_H 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | typedef uint8_t poly1305_state[512]; 26 | 27 | /* CRYPTO_poly1305_init sets up |state| so that it can be used to calculate an 28 | * authentication tag with the one-time key |key|. Note that |key| is a 29 | * one-time key and therefore there is no `reset' method because that would 30 | * enable several messages to be authenticated with the same key. */ 31 | OPENSSL_EXPORT void CRYPTO_poly1305_init(poly1305_state* state, 32 | const uint8_t key[32]); 33 | 34 | /* CRYPTO_poly1305_update processes |in_len| bytes from |in|. It can be called 35 | * zero or more times after poly1305_init. */ 36 | OPENSSL_EXPORT void CRYPTO_poly1305_update(poly1305_state* state, 37 | const uint8_t* in, 38 | size_t in_len); 39 | 40 | /* CRYPTO_poly1305_finish completes the poly1305 calculation and writes a 16 41 | * byte authentication tag to |mac|. The |mac| address must be 16-byte 42 | * aligned. */ 43 | OPENSSL_EXPORT void CRYPTO_poly1305_finish(poly1305_state* state, 44 | uint8_t mac[16]); 45 | 46 | 47 | #if defined(__cplusplus) 48 | } /* extern C */ 49 | #endif 50 | 51 | #endif /* OPENSSL_HEADER_POLY1305_H */ 52 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/safestack.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/openssl/srtp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "ssl.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/opensslconf.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #ifndef OPENSSL_HEADER_OPENSSLCONF_H 19 | #define OPENSSL_HEADER_OPENSSLCONF_H 20 | 21 | 22 | #define OPENSSL_NO_BF 23 | #define OPENSSL_NO_BUF_FREELISTS 24 | #define OPENSSL_NO_CAMELLIA 25 | #define OPENSSL_NO_CAPIENG 26 | #define OPENSSL_NO_CAST 27 | #define OPENSSL_NO_CMS 28 | #define OPENSSL_NO_COMP 29 | #define OPENSSL_NO_DANE 30 | #define OPENSSL_NO_DEPRECATED 31 | #define OPENSSL_NO_DYNAMIC_ENGINE 32 | #define OPENSSL_NO_EC_NISTP_64_GCC_128 33 | #define OPENSSL_NO_EC2M 34 | #define OPENSSL_NO_ENGINE 35 | #define OPENSSL_NO_GMP 36 | #define OPENSSL_NO_GOST 37 | #define OPENSSL_NO_HEARTBEATS 38 | #define OPENSSL_NO_HW 39 | #define OPENSSL_NO_IDEA 40 | #define OPENSSL_NO_JPAKE 41 | #define OPENSSL_NO_KRB5 42 | #define OPENSSL_NO_MD2 43 | #define OPENSSL_NO_MDC2 44 | #define OPENSSL_NO_OCB 45 | #define OPENSSL_NO_OCSP 46 | #define OPENSSL_NO_RC2 47 | #define OPENSSL_NO_RC5 48 | #define OPENSSL_NO_RFC3779 49 | #define OPENSSL_NO_RIPEMD 50 | #define OPENSSL_NO_RMD160 51 | #define OPENSSL_NO_SCTP 52 | #define OPENSSL_NO_SEED 53 | #define OPENSSL_NO_SRP 54 | #define OPENSSL_NO_SSL2 55 | #define OPENSSL_NO_STATIC_ENGINE 56 | #define OPENSSL_NO_STORE 57 | #define OPENSSL_NO_WHIRLPOOL 58 | 59 | 60 | #endif /* OPENSSL_HEADER_OPENSSLCONF_H */ 61 | -------------------------------------------------------------------------------- /boringssl/openssl/opensslfeatures.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #ifndef OPENSSL_HEADER_OPENSSLFEATURES_H 19 | #define OPENSSL_HEADER_OPENSSLFEATURES_H 20 | 21 | 22 | #define OPENSSL_NO_BF 23 | #define OPENSSL_NO_BUF_FREELISTS 24 | #define OPENSSL_NO_CAMELLIA 25 | #define OPENSSL_NO_CAPIENG 26 | #define OPENSSL_NO_CAST 27 | #define OPENSSL_NO_CMS 28 | #define OPENSSL_NO_COMP 29 | #define OPENSSL_NO_DANE 30 | #define OPENSSL_NO_DEPRECATED 31 | #define OPENSSL_NO_DYNAMIC_ENGINE 32 | #define OPENSSL_NO_EC_NISTP_64_GCC_128 33 | #define OPENSSL_NO_EC2M 34 | #define OPENSSL_NO_ENGINE 35 | #define OPENSSL_NO_GMP 36 | #define OPENSSL_NO_GOST 37 | #define OPENSSL_NO_HEARTBEATS 38 | #define OPENSSL_NO_HW 39 | #define OPENSSL_NO_IDEA 40 | #define OPENSSL_NO_JPAKE 41 | #define OPENSSL_NO_KRB5 42 | #define OPENSSL_NO_MD2 43 | #define OPENSSL_NO_MDC2 44 | #define OPENSSL_NO_OCB 45 | #define OPENSSL_NO_OCSP 46 | #define OPENSSL_NO_RC2 47 | #define OPENSSL_NO_RC5 48 | #define OPENSSL_NO_RFC3779 49 | #define OPENSSL_NO_RIPEMD 50 | #define OPENSSL_NO_RMD160 51 | #define OPENSSL_NO_SCTP 52 | #define OPENSSL_NO_SEED 53 | #define OPENSSL_NO_SRP 54 | #define OPENSSL_NO_SSL2 55 | #define OPENSSL_NO_STATIC_ENGINE 56 | #define OPENSSL_NO_STORE 57 | #define OPENSSL_NO_WHIRLPOOL 58 | 59 | 60 | #endif /* OPENSSL_HEADER_OPENSSLFEATURES_H */ 61 | -------------------------------------------------------------------------------- /boringssl/openssl/opensslv.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "crypto.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/ossl_typ.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "base.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/pkcs12.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "pkcs8.h" 19 | -------------------------------------------------------------------------------- /boringssl/openssl/pkcs7.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/poly1305.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | #ifndef OPENSSL_HEADER_POLY1305_H 16 | #define OPENSSL_HEADER_POLY1305_H 17 | 18 | #include 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | 25 | typedef uint8_t poly1305_state[512]; 26 | 27 | /* CRYPTO_poly1305_init sets up |state| so that it can be used to calculate an 28 | * authentication tag with the one-time key |key|. Note that |key| is a 29 | * one-time key and therefore there is no `reset' method because that would 30 | * enable several messages to be authenticated with the same key. */ 31 | OPENSSL_EXPORT void CRYPTO_poly1305_init(poly1305_state* state, 32 | const uint8_t key[32]); 33 | 34 | /* CRYPTO_poly1305_update processes |in_len| bytes from |in|. It can be called 35 | * zero or more times after poly1305_init. */ 36 | OPENSSL_EXPORT void CRYPTO_poly1305_update(poly1305_state* state, 37 | const uint8_t* in, 38 | size_t in_len); 39 | 40 | /* CRYPTO_poly1305_finish completes the poly1305 calculation and writes a 16 41 | * byte authentication tag to |mac|. The |mac| address must be 16-byte 42 | * aligned. */ 43 | OPENSSL_EXPORT void CRYPTO_poly1305_finish(poly1305_state* state, 44 | uint8_t mac[16]); 45 | 46 | 47 | #if defined(__cplusplus) 48 | } /* extern C */ 49 | #endif 50 | 51 | #endif /* OPENSSL_HEADER_POLY1305_H */ 52 | -------------------------------------------------------------------------------- /boringssl/openssl/safestack.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2014, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | -------------------------------------------------------------------------------- /boringssl/openssl/srtp.h: -------------------------------------------------------------------------------- 1 | /* Copyright (c) 2015, Google Inc. 2 | * 3 | * Permission to use, copy, modify, and/or distribute this software for any 4 | * purpose with or without fee is hereby granted, provided that the above 5 | * copyright notice and this permission notice appear in all copies. 6 | * 7 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 8 | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 9 | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY 10 | * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 11 | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION 12 | * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN 13 | * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ 14 | 15 | /* This header is provided in order to make compiling against code that expects 16 | OpenSSL easier. */ 17 | 18 | #include "ssl.h" 19 | -------------------------------------------------------------------------------- /bufferpool.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | type BytesBufferPool struct { 4 | c chan []byte 5 | poolsize int 6 | bufsize int 7 | } 8 | 9 | func NewBytesBufferPool(poolsize int, bufsize int) (bp *BytesBufferPool) { 10 | return &BytesBufferPool{ 11 | c: make(chan []byte, poolsize), 12 | poolsize: poolsize, 13 | bufsize: bufsize, 14 | } 15 | } 16 | 17 | func (bp *BytesBufferPool) Get() (b []byte) { 18 | select { 19 | case b = <-bp.c: 20 | // reuse existing buffer 21 | default: 22 | // create new buffer 23 | b = make([]byte, bp.bufsize) 24 | } 25 | return 26 | } 27 | 28 | func (bp *BytesBufferPool) Put(b []byte) { 29 | select { 30 | case bp.c <- b: 31 | default: // Discard the buffer if the pool is full. 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /build_libs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh -e 2 | 3 | while getopts "arh" opt; do 4 | case $opt in 5 | a) 6 | BUILD_CLEAN=1 7 | ;; 8 | r) 9 | if [ -z $GOQUIC_BUILD ]; then 10 | GOQUIC_BUILD="Release" 11 | else 12 | echo "Both GOQUIC_BUILD and -r provided. Please provide only either one." 13 | exit 1; 14 | fi 15 | ;; 16 | h) 17 | echo "Usage: ./build_libs.sh [-a] [-r] [-h]" 18 | echo " -a: Force rebuild all" 19 | echo " -r: Release build" 20 | echo " -h: Help" 21 | exit 1; 22 | ;; 23 | esac 24 | done 25 | 26 | ARCH_TYPE=$(uname -m) 27 | OS_TYPE=$(uname -s) 28 | 29 | if [ $ARCH_TYPE = "x86_64" ]; then 30 | GOARCH="amd64" 31 | elif [ $ARCH_TYPE = "x86" ]; then 32 | GOARCH="386" 33 | elif [ $ARCH_TYPE = "amd64" ]; then # freeBSD? 34 | GOARCH="amd64" 35 | else 36 | echo "Unknown architecture" 37 | exit 1 38 | fi 39 | 40 | if [ $OS_TYPE = "Linux" ]; then 41 | GOOS="linux" 42 | elif [ $OS_TYPE = "Darwin" ]; then 43 | GOOS="darwin" 44 | elif [ $OS_TYPE = "FreeBSD" ]; then 45 | GOOS="freebsd" 46 | else 47 | echo "Unknown OS" 48 | exit 1 49 | fi 50 | 51 | if [ "$GOQUIC_BUILD" = "Release" ]; then 52 | OPT="-DCMAKE_BUILD_TYPE=Release" 53 | BUILD_DIR="build/release" 54 | else 55 | OPT="" 56 | BUILD_DIR="build/debug" 57 | fi 58 | 59 | echo "GOARCH: $GOARCH" 60 | echo "GOOS: $GOOS" 61 | echo "OPTION: $OPT" 62 | 63 | if [ ! -d libquic ]; then 64 | echo "try git submodule init && git submodule update first" 65 | exit 1 66 | fi 67 | 68 | if [ ! -z $BUILD_CLEAN ]; then 69 | rm -fr libquic/$BUILD_DIR 70 | fi 71 | mkdir -p libquic/$BUILD_DIR 72 | 73 | cd libquic/$BUILD_DIR 74 | cmake -GNinja $OPT ../.. 75 | cd - 76 | 77 | ninja -Clibquic/$BUILD_DIR 78 | 79 | TARGET_DIR=lib/${GOOS}_${GOARCH}/ 80 | mkdir -p $TARGET_DIR 81 | cp libquic/$BUILD_DIR/boringssl/crypto/libcrypto.a libquic/$BUILD_DIR/boringssl/ssl/libssl.a libquic/$BUILD_DIR/libquic.a libquic/$BUILD_DIR/protobuf/libprotobuf.a $TARGET_DIR 82 | 83 | rm -fr build libgoquic.a 84 | 85 | if [ $GOOS = "freebsd" ]; then 86 | GOQUIC_BUILD=$GOQUIC_BUILD gmake -j 87 | else 88 | GOQUIC_BUILD=$GOQUIC_BUILD make -j 89 | fi 90 | mv libgoquic.a $TARGET_DIR 91 | 92 | echo $TARGET_DIR updated 93 | -------------------------------------------------------------------------------- /dispatcher.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include 4 | // #include "src/adaptor.h" 5 | import "C" 6 | import ( 7 | "net" 8 | "unsafe" 9 | ) 10 | 11 | type QuicDispatcher struct { 12 | quicDispatcher unsafe.Pointer 13 | quicServerSessions map[*QuicServerSession]bool 14 | TaskRunner *TaskRunner 15 | createQuicServerSession func() IncomingDataStreamCreator 16 | } 17 | 18 | type QuicServerSession struct { 19 | quicServerSession unsafe.Pointer 20 | quicServerStreams map[*QuicServerStream]bool 21 | streamCreator IncomingDataStreamCreator // == session 22 | } 23 | 24 | type QuicEncryptedPacket struct { 25 | encryptedPacket unsafe.Pointer 26 | } 27 | 28 | func CreateQuicDispatcher(writer *ServerWriter, createQuicServerSession func() IncomingDataStreamCreator, taskRunner *TaskRunner, cryptoConfig *QuicCryptoServerConfig) *QuicDispatcher { 29 | dispatcher := &QuicDispatcher{ 30 | quicServerSessions: make(map[*QuicServerSession]bool), 31 | TaskRunner: taskRunner, 32 | createQuicServerSession: createQuicServerSession, 33 | } 34 | 35 | dispatcher.quicDispatcher = C.create_quic_dispatcher( 36 | C.GoPtr(serverWriterPtr.Set(writer)), C.GoPtr(quicDispatcherPtr.Set(dispatcher)), C.GoPtr(taskRunnerPtr.Set(taskRunner)), cryptoConfig.cryptoServerConfig) 37 | return dispatcher 38 | } 39 | 40 | func (d *QuicDispatcher) ProcessPacket(self_address *net.UDPAddr, peer_address *net.UDPAddr, buffer []byte) { 41 | self_address_p := CreateIPEndPoint(self_address) 42 | peer_address_p := CreateIPEndPoint(peer_address) 43 | C.quic_dispatcher_process_packet( 44 | d.quicDispatcher, 45 | (*C.uint8_t)(unsafe.Pointer(&self_address_p.packed[0])), 46 | C.size_t(len(self_address_p.packed)), 47 | C.uint16_t(self_address_p.port), 48 | (*C.uint8_t)(unsafe.Pointer(&peer_address_p.packed[0])), 49 | C.size_t(len(peer_address_p.packed)), 50 | C.uint16_t(peer_address_p.port), 51 | (*C.char)(unsafe.Pointer(&buffer[0])), C.size_t(len(buffer)), 52 | ) 53 | } 54 | 55 | func (d *QuicDispatcher) Statistics() DispatcherStatistics { 56 | stat := DispatcherStatistics{make([]SessionStatistics, 0)} 57 | for session, _ := range d.quicServerSessions { 58 | stat.SessionStatistics = append(stat.SessionStatistics, SessionStatistics{C.quic_server_session_connection_stat(session.quicServerSession)}) 59 | } 60 | return stat 61 | } 62 | 63 | //export CreateGoSession 64 | func CreateGoSession(dispatcher_key int64, session_c unsafe.Pointer) int64 { 65 | dispatcher := quicDispatcherPtr.Get(dispatcher_key) 66 | userSession := dispatcher.createQuicServerSession() 67 | session := &QuicServerSession{ 68 | quicServerSession: session_c, 69 | quicServerStreams: make(map[*QuicServerStream]bool), 70 | streamCreator: userSession, 71 | } 72 | 73 | // This is to prevent garbage collection. This is cleaned up on DeleteGoSession() 74 | dispatcher.quicServerSessions[session] = true 75 | 76 | return quicServerSessionPtr.Set(session) 77 | } 78 | 79 | //export DeleteGoSession 80 | func DeleteGoSession(dispatcher_key int64, go_session_key int64) { 81 | dispatcher := quicDispatcherPtr.Get(dispatcher_key) 82 | go_session := quicServerSessionPtr.Get(go_session_key) 83 | delete(dispatcher.quicServerSessions, go_session) 84 | quicServerSessionPtr.Del(go_session_key) 85 | } 86 | 87 | //export ReleaseQuicDispatcher 88 | func ReleaseQuicDispatcher(task_runner_key int64) { 89 | quicDispatcherPtr.Del(task_runner_key) 90 | } 91 | 92 | //export ReleaseTaskRunner 93 | func ReleaseTaskRunner(task_runner_key int64) { 94 | taskRunnerPtr.Del(task_runner_key) 95 | } 96 | -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | SPDY/QUIC enabled server/client written in Go 2 | ============================================= 3 | 4 | We currently have [server](server.go), [client](client.go), 5 | and [reverse proxy](reverse_proxy.go) implementation. 6 | 7 | 8 | ## How to build 9 | 10 | Due to Go 1.4's cgo restrictions, use an environment variable like below to 11 | build your projects. This restriction will be removed from Go 1.5. 12 | 13 | ```bash 14 | CGO_CFLAGS="-I$GOPATH/src/github.com/devsisters/goquic/libquic/boringssl/include" 15 | CGO_LDFLAGS="-L$GOPATH/src/github.com/devsisters/goquic/lib/$GOOS_$GOARCH" 16 | 17 | go build $GOPATH/src/github.com/devsisters/goquic/example/server.go 18 | go build $GOPATH/src/github.com/devsisters/goquic/example/client.go 19 | go build $GOPATH/src/github.com/devsisters/goquic/example/reverse_proxy.go 20 | ``` 21 | 22 | For example, building goquic example server in Mac: 23 | 24 | ```bash 25 | CGO_CFLAGS="-I$GOPATH/src/github.com/devsisters/goquic/libquic/boringssl/include" \ 26 | CGO_LDFLAGS="-L$GOPATH/src/github.com/devsisters/goquic/lib/darwin_amd64" \ 27 | go build $GOPATH/src/github.com/devsisters/goquic/example/server.go 28 | ``` 29 | 30 | In Linux: 31 | 32 | ```bash 33 | CGO_CFLAGS="-I$GOPATH/src/github.com/devsisters/goquic/libquic/boringssl/include" \ 34 | CGO_LDFLAGS="-L$GOPATH/src/github.com/devsisters/goquic/lib/linux_amd64" \ 35 | go build $GOPATH/src/github.com/devsisters/goquic/example/server.go 36 | ``` 37 | -------------------------------------------------------------------------------- /example/client.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "flag" 5 | "fmt" 6 | "io/ioutil" 7 | "net/http" 8 | 9 | "github.com/devsisters/goquic" 10 | ) 11 | 12 | var url string 13 | var logLevel int 14 | 15 | func init() { 16 | flag.StringVar(&url, "url", "http://127.0.0.1:8080/", "host to connect") 17 | flag.IntVar(&logLevel, "loglevel", -1, "Log level") 18 | } 19 | 20 | func main() { 21 | flag.Parse() 22 | goquic.SetLogLevel(logLevel) 23 | 24 | client := &http.Client{ 25 | Transport: goquic.NewRoundTripper(false), 26 | } 27 | 28 | resp, err := client.Get(url) 29 | if err != nil { 30 | panic(err) 31 | } 32 | 33 | b, err := ioutil.ReadAll(resp.Body) 34 | if err != nil { 35 | panic(err) 36 | } 37 | 38 | fmt.Println("Header:", resp.Header) 39 | fmt.Println("Body:", string(b)) 40 | fmt.Println("Trailer:", resp.Trailer) 41 | } 42 | -------------------------------------------------------------------------------- /example/config_generator.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "encoding/json" 5 | "fmt" 6 | "log" 7 | 8 | "github.com/devsisters/goquic" 9 | ) 10 | 11 | func main() { 12 | cfg := goquic.GenerateSerializedServerConfig() 13 | 14 | b, err := json.Marshal(cfg) 15 | if err != nil { 16 | log.Fatal(err) 17 | } 18 | fmt.Println(string(b)) 19 | } 20 | -------------------------------------------------------------------------------- /example/reverse_proxy.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "crypto/tls" 5 | "encoding/json" 6 | "flag" 7 | "fmt" 8 | "io" 9 | "io/ioutil" 10 | "log" 11 | "net/http" 12 | "net/http/httputil" 13 | _ "net/http/pprof" 14 | "net/url" 15 | "os" 16 | 17 | "github.com/devsisters/goquic" 18 | "github.com/gorilla/handlers" 19 | ) 20 | 21 | var numOfServers int 22 | var port int 23 | var addr string 24 | var logLevel int 25 | var cert string 26 | var key string 27 | var quicOnly bool 28 | var usesslv3 bool 29 | var serverConfig string 30 | 31 | func init() { 32 | flag.IntVar(&numOfServers, "n", 1, "Number of concurrent quic dispatchers") 33 | flag.IntVar(&port, "port", 8080, "TCP/UDP port number to listen") 34 | flag.StringVar(&addr, "addr", "0.0.0.0", "TCP/UDP listen address") 35 | flag.IntVar(&logLevel, "loglevel", -1, "Log level") 36 | flag.StringVar(&cert, "cert", "", "Certificate file (PEM), will use encrypted QUIC and TLS when provided") 37 | flag.StringVar(&key, "key", "", "Private key file (PEM), will use encrypted QUIC and TLS when provided") 38 | flag.BoolVar(&quicOnly, "quic_only", false, "Use QUIC Only") 39 | flag.BoolVar(&usesslv3, "use_sslv3", false, "Use SSLv3 on HTTP 1.1. HTTP2 and QUIC are not affected.") 40 | flag.StringVar(&serverConfig, "scfg", "", "Server config JSON file. If not provided, new one will be generated") 41 | 42 | flag.Usage = func() { 43 | fmt.Fprintf(os.Stderr, "Usage: %s backend_url\n", os.Args[0]) 44 | fmt.Fprintf(os.Stderr, "Options:\n") 45 | flag.PrintDefaults() 46 | } 47 | } 48 | 49 | type PrefixedLogWriter struct { 50 | prefix []byte 51 | writer io.Writer 52 | } 53 | 54 | func (w PrefixedLogWriter) Write(p []byte) (int, error) { 55 | if _, err := w.writer.Write(w.prefix); err != nil { 56 | return 0, err 57 | } 58 | 59 | return w.writer.Write(p) 60 | } 61 | 62 | func main() { 63 | flag.Parse() 64 | goquic.SetLogLevel(logLevel) 65 | 66 | if flag.NArg() != 1 { 67 | flag.Usage() 68 | return 69 | } 70 | 71 | proxyUrl := flag.Arg(0) 72 | 73 | log.Printf("About to listen on %s. Go to https://%s:%d/", addr, addr, port) 74 | addrStr := fmt.Sprintf("%s:%d", addr, port) 75 | 76 | parsedUrl, err := url.Parse(proxyUrl) 77 | if err != nil { 78 | log.Fatal(err) 79 | } 80 | 81 | log.Printf("Starting reverse proxy for backend URL: %v", parsedUrl) 82 | 83 | var quicHdr, nonQuicHdr http.Handler 84 | 85 | if !quicOnly { 86 | nonQuicHdr = handlers.CombinedLoggingHandler(PrefixedLogWriter{[]byte("H2 | "), os.Stdout}, httputil.NewSingleHostReverseProxy(parsedUrl)) 87 | } 88 | 89 | quicHdr = handlers.CombinedLoggingHandler(PrefixedLogWriter{[]byte("Q | "), os.Stdout}, httputil.NewSingleHostReverseProxy(parsedUrl)) 90 | 91 | var tlsConfig *tls.Config 92 | if usesslv3 { 93 | tlsConfig = &tls.Config{MinVersion: tls.VersionSSL30} 94 | } 95 | 96 | server, err := goquic.NewServer(addrStr, cert, key, numOfServers, quicHdr, nonQuicHdr, tlsConfig) 97 | if err != nil { 98 | log.Fatal(err) 99 | } 100 | 101 | if len(serverConfig) != 0 { 102 | if b, err := ioutil.ReadFile(serverConfig); err == nil { 103 | var cfg *goquic.SerializedServerConfig 104 | if err := json.Unmarshal(b, &cfg); err != nil { 105 | log.Printf("Cannot parse %s, new serverConfig will be generated", serverConfig) 106 | } else { 107 | server.ServerConfig = cfg 108 | log.Printf("Successfully parsed %s", serverConfig) 109 | } 110 | } else { 111 | log.Printf("Cannot open %s, new serverConfig will be generated", serverConfig) 112 | } 113 | } 114 | 115 | go func() { 116 | log.Println(http.ListenAndServe("0.0.0.0:6060", nil)) 117 | }() 118 | 119 | if err := server.ListenAndServe(); err != nil { 120 | log.Fatal(err) 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /go_functions.h: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include "go_structs.h" 5 | 6 | #ifdef __cplusplus 7 | extern "C" { 8 | #endif 9 | void WriteToUDP_C(int64_t go_writer, void* peer_ip, size_t peer_ip_sz, uint16_t peer_port, void* buffer, size_t buf_len); 10 | void WriteToUDPClient_C(int64_t go_writer, void* peer_ip, size_t peer_ip_sz, uint16_t peer_port, void* buffer, size_t buf_len); 11 | int64_t CreateGoSession_C(int64_t go_quic_dispatcher, void* quic_server_session); 12 | void DeleteGoSession_C(int64_t go_quic_dispatcher, int64_t go_quic_server_session); 13 | int GetProof_C(int64_t go_proof_source, char* server_ip, size_t server_ip_sz, char* hostname, size_t hostname_sz, char* server_config, size_t server_config_sz, int quic_version, char* chlo_hash, size_t chlo_hash_len, char **out_signature, size_t *out_signature_sz); 14 | int64_t CreateIncomingDynamicStream_C(int64_t go_quic_server_session, uint32_t id, void* go_quic_simple_server_stream_go_wrapper); 15 | void UnregisterQuicServerStreamFromSession_C(int64_t go_stream); 16 | void UnregisterQuicClientStreamFromSession_C(int64_t go_stream); 17 | 18 | int64_t CreateGoQuicAlarm_C(void* go_quic_alarm_go_wrapper, void* clock, int64_t go_task_runner); 19 | void GoQuicAlarmSetImpl_C(int64_t go_quic_alarm, int64_t deadline); 20 | void GoQuicAlarmCancelImpl_C(int64_t go_quic_alarm); 21 | void GoQuicAlarmDestroy_C(int64_t go_quic_alarm); 22 | 23 | void GoQuicSpdyClientStreamOnInitialHeadersComplete_C(int64_t go_quic_spdy_client_stream, struct GoSpdyHeader* headers); 24 | void GoQuicSpdyClientStreamOnTrailingHeadersComplete_C(int64_t go_quic_spdy_client_stream, struct GoSpdyHeader* headers); 25 | void GoQuicSpdyClientStreamOnDataAvailable_C(int64_t go_quic_spdy_client_stream, const char *data, uint32_t data_len, int is_closed); 26 | void GoQuicSpdyClientStreamOnClose_C(int64_t go_quic_spdy_client_stream); 27 | void GoQuicSimpleServerStreamOnInitialHeadersComplete_C(int64_t go_quic_spdy_client_stream, struct GoSpdyHeader* headers, const char *peer_address, uint32_t peer_address_len); 28 | void GoQuicSimpleServerStreamOnDataAvailable_C(int64_t go_quic_simple_server_stream, const char *data, uint32_t data_len, int is_closed); 29 | void GoQuicSimpleServerStreamOnClose_C(int64_t go_quic_simple_server_stream); 30 | 31 | int64_t NewProofVerifyJob_C(int64_t go_proof_verifier, int quic_version, const char* hostname, size_t hostname_len, const char* server_config, size_t server_config_len, const char* chlo_hash, size_t chlo_hash_len, const char* cert_sct, size_t cert_sct_len, const char* signature, size_t signature_len); 32 | void ProofVerifyJobAddCert_C(int64_t job, const char* cert, size_t cert_len); 33 | int ProofVerifyJobVerifyProof_C(int64_t job); 34 | 35 | void ReleaseClientWriter_C(int64_t go_client_writer); 36 | void ReleaseServerWriter_C(int64_t go_server_writer); 37 | void ReleaseQuicDispatcher_C(int64_t go_quic_dispatcher); 38 | void ReleaseTaskRunner_C(int64_t go_task_runner); 39 | void ReleaseProofSource_C(int64_t go_proof_source); 40 | void ReleaseProofVerifier_C(int64_t go_proof_verifier); 41 | 42 | #ifdef __cplusplus 43 | } 44 | #endif 45 | -------------------------------------------------------------------------------- /go_structs.h: -------------------------------------------------------------------------------- 1 | #ifndef __GO_STRUCTS_H__ 2 | #define __GO_STRUCTS_H__ 3 | 4 | #include 5 | #include 6 | 7 | struct ConnStat { 8 | uint64_t Conn_id; 9 | 10 | uint64_t Bytes_sent; // Includes retransmissions, fec. 11 | uint64_t Packets_sent; 12 | // Non-retransmitted bytes sent in a stream frame. 13 | uint64_t Stream_bytes_sent; 14 | // Packets serialized and discarded before sending. 15 | uint64_t Packets_discarded; 16 | 17 | // These include version negotiation and public reset packets, which do not 18 | // have packet numbers or frame data. 19 | uint64_t Bytes_received; // Includes duplicate data for a stream, fec. 20 | // Includes packets which were not processable. 21 | uint64_t Packets_received; 22 | // Excludes packets which were not processable. 23 | uint64_t Packets_processed; 24 | uint64_t Stream_bytes_received; // Bytes received in a stream frame. 25 | 26 | uint64_t Bytes_retransmitted; 27 | uint64_t Packets_retransmitted; 28 | 29 | uint64_t Bytes_spuriously_retransmitted; 30 | uint64_t Packets_spuriously_retransmitted; 31 | // Number of packets abandoned as lost by the loss detection algorithm. 32 | uint64_t Packets_lost; 33 | 34 | // Number of packets sent in slow start. 35 | uint64_t Slowstart_packets_sent; 36 | // Number of packets lost exiting slow start. 37 | uint64_t Slowstart_packets_lost; 38 | 39 | uint64_t Packets_dropped; // Duplicate or less than least unacked. 40 | size_t Crypto_retransmit_count; 41 | // Count of times the loss detection alarm fired. At least one packet should 42 | // be lost when the alarm fires. 43 | size_t Loss_timeout_count; 44 | size_t Tlp_count; 45 | size_t Rto_count; // Count of times the rto timer fired. 46 | 47 | int64_t Min_rtt_us; // Minimum RTT in microseconds. 48 | int64_t Srtt_us; // Smoothed RTT in microseconds. 49 | uint64_t Max_packet_size; 50 | uint64_t Max_received_packet_size; 51 | 52 | int64_t Estimated_bandwidth_bits_per_sec; 53 | 54 | // Reordering stats for received packets. 55 | // Number of packets received out of packet number order. 56 | uint64_t Packets_reordered; 57 | // Maximum reordering observed in packet number space. 58 | uint64_t Max_sequence_reordering; 59 | // Maximum reordering observed in microseconds 60 | int64_t Max_time_reordering_us; 61 | 62 | // The following stats are used only in TcpCubicSender. 63 | // The number of loss events from TCP's perspective. Each loss event includes 64 | // one or more lost packets. 65 | uint32_t Tcp_loss_events; 66 | }; 67 | 68 | struct GoQuicServerConfig { 69 | char* Server_config; 70 | int Server_config_len; 71 | 72 | char** Private_keys; 73 | int* Private_keys_len; 74 | uint32_t* Private_keys_tag; // QuicTag == uint32_t 75 | int Num_of_keys; 76 | }; 77 | 78 | struct GoSpdyHeader { 79 | int N; // Size of header 80 | int* Keys_len; // Length of each keys in header 81 | int* Values_len; // Length of each values in header 82 | 83 | // Used on C side to pass headers to Go. 84 | const char** Keys; 85 | const char** Values; 86 | }; 87 | 88 | typedef int64_t GoPtr; 89 | 90 | #endif // __GO_STRUCTS_H__ 91 | -------------------------------------------------------------------------------- /goquic.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #cgo CFLAGS: -Iboringssl/ 4 | // #cgo CXXFLAGS: -DUSE_OPENSSL=1 -std=gnu++11 5 | // #cgo LDFLAGS: -pthread -lgoquic -lquic -lssl -lcrypto -lstdc++ -lm -lprotobuf 6 | // #cgo darwin LDFLAGS: -framework CoreFoundation -framework Cocoa -framework Security 7 | // #cgo darwin,amd64 LDFLAGS: -L${SRCDIR}/lib/darwin_amd64 8 | // #cgo darwin,386 LDFLAGS: -L${SRCDIR}/lib/darwin_386 9 | // #cgo freebsd,amd64 LDFLAGS: -L${SRCDIR}/lib/freebsd_amd64 10 | // #cgo freebsd,386 LDFLAGS: -L${SRCDIR}/lib/freebsd_386 11 | // #cgo linux,amd64 LDFLAGS: -L${SRCDIR}/lib/linux_amd64 12 | // #cgo linux,386 LDFLAGS: -L${SRCDIR}/lib/linux_386 13 | // #include 14 | // #include "src/adaptor.h" 15 | import "C" 16 | 17 | //go:generate python ptr_gen.py ProofSource ProofVerifier ProofVerifyJob TaskRunner ServerWriter ClientWriter QuicDispatcher QuicServerSession GoQuicAlarm QuicServerStream QuicClientStream 18 | 19 | func SetLogLevel(level int) { 20 | C.set_log_level(C.int(level)) 21 | } 22 | -------------------------------------------------------------------------------- /init.go: -------------------------------------------------------------------------------- 1 | // +build cgo 2 | 3 | package goquic 4 | 5 | /* 6 | #include 7 | #include 8 | #include 9 | #include "src/adaptor.h" 10 | 11 | extern int goquic_init_locks(); 12 | extern void goquic_thread_locking_callback(int, int, const char*, int); 13 | extern void goquic_thread_id(CRYPTO_THREADID *id); 14 | 15 | static int goquic_init_thread_callbacks() { 16 | // Source code referenced from: http://curl.haxx.se/libcurl/c/threaded-ssl.html 17 | int ret = goquic_init_locks(); 18 | if (ret != 0) { 19 | return ret; 20 | } 21 | CRYPTO_set_locking_callback(goquic_thread_locking_callback); 22 | CRYPTO_THREADID_set_callback(goquic_thread_id); 23 | return 0; 24 | } 25 | 26 | */ 27 | import "C" 28 | 29 | import "fmt" 30 | 31 | func init() { 32 | ret := C.goquic_init_thread_callbacks() 33 | if ret != 0 { 34 | panic(fmt.Errorf("goquic_init_thread_callbacks failed with error node %d", ret)) 35 | } 36 | 37 | // This initializes Chromium's base library codes 38 | C.initialize() 39 | } 40 | -------------------------------------------------------------------------------- /init_posix.go: -------------------------------------------------------------------------------- 1 | // +build linux darwin cgo 2 | // +build !windows 3 | 4 | package goquic 5 | 6 | /* 7 | #include 8 | #include 9 | #include 10 | #include 11 | 12 | pthread_mutex_t* goopenssl_locks; 13 | 14 | int goquic_init_locks() { 15 | int rc = 0; 16 | int nlock; 17 | int i; 18 | int locks_needed = CRYPTO_num_locks(); 19 | 20 | goopenssl_locks = (pthread_mutex_t*)malloc( 21 | sizeof(pthread_mutex_t) * locks_needed); 22 | if (!goopenssl_locks) { 23 | return ENOMEM; 24 | } 25 | for (nlock = 0; nlock < locks_needed; ++nlock) { 26 | rc = pthread_mutex_init(&goopenssl_locks[nlock], NULL); 27 | if (rc != 0) { 28 | break; 29 | } 30 | } 31 | 32 | if (rc != 0) { 33 | for (i = nlock - 1; i >= 0; --i) { 34 | pthread_mutex_destroy(&goopenssl_locks[i]); 35 | } 36 | free(goopenssl_locks); 37 | goopenssl_locks = NULL; 38 | } 39 | return rc; 40 | } 41 | 42 | void goquic_thread_locking_callback(int mode, int n, const char *file, int line) { 43 | if (mode & CRYPTO_LOCK) { 44 | pthread_mutex_lock(&goopenssl_locks[n]); 45 | } else { 46 | pthread_mutex_unlock(&goopenssl_locks[n]); 47 | } 48 | } 49 | 50 | void goquic_thread_id(CRYPTO_THREADID *id) 51 | { 52 | unsigned long ret; 53 | 54 | ret = (unsigned long)pthread_self(); 55 | CRYPTO_THREADID_set_numeric(id, ret); 56 | } 57 | */ 58 | import "C" 59 | -------------------------------------------------------------------------------- /ip.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include 4 | // #include "src/adaptor.h" 5 | import "C" 6 | import "net" 7 | 8 | type GoIPEndPoint struct { 9 | packed []byte 10 | port int 11 | } 12 | 13 | func CreateIPEndPoint(udpAddr *net.UDPAddr) *GoIPEndPoint { 14 | // Note: string(ip) != ip.String() 15 | // 4 byte vs human-readable repr 16 | 17 | ip := udpAddr.IP.To4() 18 | if ip == nil { 19 | ip = udpAddr.IP 20 | } 21 | 22 | return &GoIPEndPoint{packed: []byte(ip), port: udpAddr.Port} 23 | } 24 | -------------------------------------------------------------------------------- /ptr_gen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | 3 | from string import Template 4 | import sys 5 | 6 | 7 | HEADER = Template('''\ 8 | package goquic 9 | 10 | import ( 11 | "sync" 12 | "math" 13 | ) 14 | 15 | // Generated by `ptr_gen.py ${args}` 16 | // Do not edit manually! 17 | 18 | 19 | ''') 20 | 21 | TMPL = Template('''\ 22 | var ${inst}Ptr = &${cls}Ptr{pool: make(map[int64]*${cls})} 23 | 24 | type ${cls}Ptr struct { 25 | sync.RWMutex 26 | pool map[int64]*${cls} 27 | index int64 28 | } 29 | 30 | func (p *${cls}Ptr) Get(key int64) *${cls} { 31 | p.RLock() 32 | defer p.RUnlock() 33 | return p.pool[key] 34 | } 35 | 36 | func (p *${cls}Ptr) Set(pt *${cls}) int64 { 37 | p.Lock() 38 | defer p.Unlock() 39 | for { 40 | if _, ok := p.pool[p.index]; !ok { 41 | break 42 | } 43 | p.index += 1 44 | if p.index == math.MaxInt64 { 45 | p.index = 0 46 | } 47 | } 48 | p.pool[p.index] = pt 49 | p.index += 1 50 | return p.index - 1 51 | } 52 | 53 | func (p *${cls}Ptr) Del(key int64) { 54 | p.Lock() 55 | defer p.Unlock() 56 | delete(p.pool, key) 57 | } 58 | 59 | ''') 60 | 61 | if __name__ == "__main__": 62 | with open("ptr.go", "w") as f: 63 | f.write(HEADER.substitute(args=" ".join(sys.argv[1:]))) 64 | 65 | for t in sys.argv[1:]: 66 | f.write(TMPL.substitute(cls=t, inst=t[0].lower()+t[1:])) 67 | -------------------------------------------------------------------------------- /quicstream_client.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include "src/adaptor.h" 4 | // #include "src/adaptor_client.h" 5 | import "C" 6 | import ( 7 | "net/http" 8 | "unsafe" 9 | ) 10 | 11 | // implement QuicStream 12 | type QuicClientStream struct { 13 | userStream DataStreamProcessor 14 | wrapper unsafe.Pointer 15 | session *QuicClientSession 16 | } 17 | 18 | func (stream *QuicClientStream) UserStream() DataStreamProcessor { 19 | return stream.userStream 20 | } 21 | 22 | func (stream *QuicClientStream) WriteHeader(header http.Header, is_body_empty bool) { 23 | keys, keylen, values, valuelen := digSpdyHeader(header) 24 | 25 | if is_body_empty { 26 | C.quic_spdy_client_stream_write_headers(stream.wrapper, C.int(len(keylen)), 27 | (*C.char)(unsafe.Pointer(&keys[0])), (*C.int)(unsafe.Pointer(&keylen[0])), 28 | (*C.char)(unsafe.Pointer(&values[0])), (*C.int)(unsafe.Pointer(&valuelen[0])), 1) 29 | } else { 30 | C.quic_spdy_client_stream_write_headers(stream.wrapper, C.int(len(keylen)), 31 | (*C.char)(unsafe.Pointer(&keys[0])), (*C.int)(unsafe.Pointer(&keylen[0])), 32 | (*C.char)(unsafe.Pointer(&values[0])), (*C.int)(unsafe.Pointer(&valuelen[0])), 0) 33 | } 34 | } 35 | 36 | func (stream *QuicClientStream) WriteOrBufferData(body []byte, fin bool) { 37 | fin_int := C.int(0) 38 | if fin { 39 | fin_int = C.int(1) 40 | } 41 | 42 | if len(body) == 0 { 43 | C.quic_spdy_client_stream_write_or_buffer_data(stream.wrapper, (*C.char)(unsafe.Pointer(nil)), C.size_t(0), fin_int) 44 | } else { 45 | C.quic_spdy_client_stream_write_or_buffer_data(stream.wrapper, (*C.char)(unsafe.Pointer(&body[0])), C.size_t(len(body)), fin_int) 46 | } 47 | } 48 | 49 | func (stream *QuicClientStream) WriteTrailers(header http.Header) { 50 | // Client does not support trailer send 51 | } 52 | -------------------------------------------------------------------------------- /quicstream_server.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include "src/adaptor.h" 4 | import "C" 5 | import ( 6 | "net/http" 7 | "unsafe" 8 | ) 9 | 10 | // implement QuicStream 11 | type QuicServerStream struct { 12 | userStream DataStreamProcessor 13 | wrapper unsafe.Pointer 14 | session *QuicServerSession 15 | } 16 | 17 | func (stream *QuicServerStream) UserStream() DataStreamProcessor { 18 | return stream.userStream 19 | } 20 | 21 | func (stream *QuicServerStream) WriteHeader(header http.Header, is_body_empty bool) { 22 | keys, keylen, values, valuelen := digSpdyHeader(header) 23 | 24 | if is_body_empty { 25 | C.quic_simple_server_stream_write_headers(stream.wrapper, C.int(len(keylen)), 26 | (*C.char)(unsafe.Pointer(&keys[0])), (*C.int)(unsafe.Pointer(&keylen[0])), 27 | (*C.char)(unsafe.Pointer(&values[0])), (*C.int)(unsafe.Pointer(&valuelen[0])), 1) 28 | } else { 29 | C.quic_simple_server_stream_write_headers(stream.wrapper, C.int(len(keylen)), 30 | (*C.char)(unsafe.Pointer(&keys[0])), (*C.int)(unsafe.Pointer(&keylen[0])), 31 | (*C.char)(unsafe.Pointer(&values[0])), (*C.int)(unsafe.Pointer(&valuelen[0])), 0) 32 | } 33 | } 34 | 35 | func (stream *QuicServerStream) WriteOrBufferData(body []byte, fin bool) { 36 | fin_int := C.int(0) 37 | if fin { 38 | fin_int = C.int(1) 39 | } 40 | 41 | if len(body) == 0 { 42 | C.quic_simple_server_stream_write_or_buffer_data(stream.wrapper, (*C.char)(unsafe.Pointer(nil)), C.size_t(0), fin_int) 43 | } else { 44 | C.quic_simple_server_stream_write_or_buffer_data(stream.wrapper, (*C.char)(unsafe.Pointer(&body[0])), C.size_t(len(body)), fin_int) 45 | } 46 | } 47 | 48 | func (stream *QuicServerStream) WriteTrailers(header http.Header) { 49 | keys, keylen, values, valuelen := digSpdyHeader(header) 50 | 51 | C.quic_simple_server_stream_write_trailers(stream.wrapper, C.int(len(keylen)), 52 | (*C.char)(unsafe.Pointer(&keys[0])), (*C.int)(unsafe.Pointer(&keylen[0])), 53 | (*C.char)(unsafe.Pointer(&values[0])), (*C.int)(unsafe.Pointer(&valuelen[0]))) 54 | } 55 | 56 | // TODO(hodduc): delete(stream.session.quicServerStreams, stream) 57 | -------------------------------------------------------------------------------- /server_config.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include "src/adaptor.h" 4 | // #include "src/go_structs.h" 5 | import "C" 6 | import "unsafe" 7 | 8 | // Serialized server config 9 | type SerializedServerConfig struct { 10 | ServerConfig []byte 11 | Keys []*ServerConfigPrivateKey 12 | } 13 | 14 | type ServerConfigPrivateKey struct { 15 | Key []byte 16 | Tag uint32 17 | } 18 | 19 | // Wrapper for QuicCryptoServerConfig C++ object 20 | type QuicCryptoServerConfig struct { 21 | cryptoServerConfig unsafe.Pointer 22 | } 23 | 24 | func NewCryptoServerConfig(proofSource *ProofSource, stkSecret string, cfg *SerializedServerConfig) *QuicCryptoServerConfig { 25 | serverCfg_c := C.create_goquic_crypto_config((*C.char)(unsafe.Pointer(&cfg.ServerConfig[0])), C.size_t(len(cfg.ServerConfig)), C.int(len(cfg.Keys))) 26 | defer C.delete_goquic_crypto_config(serverCfg_c) 27 | 28 | for idx, key := range cfg.Keys { 29 | C.goquic_crypto_config_set_key(serverCfg_c, C.int(idx), C.uint32_t(key.Tag), (*C.char)(unsafe.Pointer(&key.Key[0])), C.size_t(len(key.Key))) 30 | } 31 | cryptoConfig_c := C.init_crypto_config(serverCfg_c, proofSource.proofSource_c, (*C.char)(unsafe.Pointer(&[]byte(stkSecret)[0])), C.size_t(len(stkSecret))) 32 | 33 | return &QuicCryptoServerConfig{cryptoConfig_c} 34 | } 35 | 36 | func DeleteCryptoServerConfig(config *QuicCryptoServerConfig) { 37 | C.delete_crypto_config(config.cryptoServerConfig) 38 | } 39 | 40 | func GenerateSerializedServerConfig() *SerializedServerConfig { 41 | serverCfg_c := C.generate_goquic_crypto_config() 42 | defer C.delete_goquic_crypto_config(serverCfg_c) 43 | 44 | r := &SerializedServerConfig{} 45 | N := int(serverCfg_c.Num_of_keys) 46 | 47 | r.ServerConfig = C.GoBytes(unsafe.Pointer((*C.char)(serverCfg_c.Server_config)), serverCfg_c.Server_config_len) 48 | r.Keys = make([]*ServerConfigPrivateKey, N) 49 | 50 | tagsArray := (*[1 << 30]C.uint32_t)(unsafe.Pointer(serverCfg_c.Private_keys_tag))[:N:N] 51 | lenArray := (*[1 << 30]C.int)(unsafe.Pointer(serverCfg_c.Private_keys_len))[:N:N] 52 | keysArray := (*[1 << 30](*C.char))(unsafe.Pointer(serverCfg_c.Private_keys))[:N:N] 53 | 54 | for i := 0; i < N; i++ { 55 | r.Keys[i] = &ServerConfigPrivateKey{ 56 | Key: C.GoBytes(unsafe.Pointer((*C.char)(keysArray[i])), lenArray[i]), 57 | Tag: uint32(tagsArray[i]), 58 | } 59 | } 60 | 61 | return r 62 | } 63 | -------------------------------------------------------------------------------- /src/adaptor_client.h: -------------------------------------------------------------------------------- 1 | #ifndef __ADAPTOR_CLIENT_H__ 2 | #define __ADAPTOR_CLIENT_H__ 3 | #include 4 | #include 5 | 6 | #include "go_structs.h" 7 | 8 | #ifdef __cplusplus 9 | #include "go_quic_client_session.h" 10 | #include "go_quic_spdy_client_stream.h" 11 | #include "net/base/ip_endpoint.h" 12 | #include "net/quic/core/quic_protocol.h" 13 | using namespace net; 14 | 15 | extern "C" { 16 | #else 17 | typedef void IPEndPoint; 18 | typedef void GoQuicClientSession; 19 | typedef void GoQuicSpdyClientStream; 20 | #endif 21 | 22 | GoQuicClientSession* create_go_quic_client_session_and_initialize( 23 | GoPtr go_writer, 24 | GoPtr task_runner, 25 | GoPtr go_proof_verifier, 26 | uint8_t* server_address_ip, 27 | size_t server_address_len, 28 | uint16_t server_address_port); 29 | void delete_go_quic_client_session(GoQuicClientSession* go_quic_client_session); 30 | int go_quic_client_encryption_being_established(GoQuicClientSession* session); 31 | int go_quic_client_session_is_connected(GoQuicClientSession* session); 32 | GoQuicSpdyClientStream* quic_client_session_create_reliable_quic_stream( 33 | GoQuicClientSession* session, 34 | GoPtr go_quic_client_stream); 35 | int quic_client_session_num_active_requests(GoQuicClientSession* session); 36 | void quic_spdy_client_stream_write_headers(GoQuicSpdyClientStream* stream, 37 | int header_size, 38 | char* header_keys, 39 | int* header_key_len, 40 | char* header_values, 41 | int* header_value_len, 42 | int is_empty_body); 43 | void quic_spdy_client_stream_write_or_buffer_data( 44 | GoQuicSpdyClientStream* stream, 45 | char* buf, 46 | size_t bufsize, 47 | int fin); 48 | void go_quic_client_session_process_packet(GoQuicClientSession* session, 49 | uint8_t* self_address_ip, 50 | size_t self_address_len, 51 | uint16_t self_address_port, 52 | uint8_t* peer_address_ip, 53 | size_t peer_address_len, 54 | uint16_t peer_address_port, 55 | char* buffer, 56 | size_t length); 57 | void go_quic_client_session_connection_send_connection_close_packet( 58 | GoQuicClientSession* session); 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | #endif // __ADAPTOR_CLIENT_H__ 63 | -------------------------------------------------------------------------------- /src/chlo_extractor.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2016 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef NET_TOOLS_QUIC_CHLO_EXTRACTOR_H_ 6 | #define NET_TOOLS_QUIC_CHLO_EXTRACTOR_H_ 7 | 8 | #include "net/quic/core/crypto/crypto_handshake_message.h" 9 | #include "net/quic/core/quic_protocol.h" 10 | 11 | namespace net { 12 | 13 | // A utility for extracting QUIC Client Hello messages from packets, 14 | // without needs to spin up a full QuicSession. 15 | class ChloExtractor { 16 | public: 17 | class Delegate { 18 | public: 19 | virtual ~Delegate() {} 20 | 21 | // Called when a CHLO message is found in the packets. 22 | virtual void OnChlo(QuicVersion version, 23 | QuicConnectionId connection_id, 24 | const CryptoHandshakeMessage& chlo) = 0; 25 | }; 26 | 27 | // Extracts a CHLO message from |packet| and invokes the OnChlo method 28 | // of |delegate|. Return true if a CHLO message was found, and false 29 | // otherwise. 30 | static bool Extract(const QuicEncryptedPacket& packet, 31 | const QuicVersionVector& versions, 32 | Delegate* delegate); 33 | 34 | ChloExtractor(const ChloExtractor&) = delete; 35 | ChloExtractor operator=(const ChloExtractor&) = delete; 36 | }; 37 | 38 | } // namespace net 39 | 40 | #endif // NET_TOOLS_QUIC_CHLO_EXTRACTOR_H_ 41 | -------------------------------------------------------------------------------- /src/go_ephemeral_key_source.cc: -------------------------------------------------------------------------------- 1 | #include "go_ephemeral_key_source.h" 2 | 3 | namespace net { 4 | 5 | GoEphemeralKeySource::GoEphemeralKeySource() 6 | : forward_secure_key_exchange_(nullptr), 7 | key_created_time_(net::QuicTime::Zero()) {} 8 | 9 | std::string GoEphemeralKeySource::CalculateForwardSecureKey( 10 | const net::KeyExchange* key_exchange, 11 | net::QuicRandom* rand, 12 | net::QuicTime now, 13 | base::StringPiece peer_public_value, 14 | std::string* public_value) { 15 | // Cache forward_secure_key_exchange for 10 seconds 16 | if (forward_secure_key_exchange_.get() == nullptr || 17 | (now - key_created_time_).ToSeconds() > 10) { 18 | forward_secure_key_exchange_.reset(key_exchange->NewKeyPair(rand)); 19 | key_created_time_ = now; 20 | } 21 | 22 | *public_value = forward_secure_key_exchange_->public_value().as_string(); 23 | std::string forward_secure_premaster_secret; 24 | forward_secure_key_exchange_->CalculateSharedKey( 25 | peer_public_value, &forward_secure_premaster_secret); 26 | return forward_secure_premaster_secret; 27 | } 28 | 29 | } // namespace net 30 | -------------------------------------------------------------------------------- /src/go_ephemeral_key_source.h: -------------------------------------------------------------------------------- 1 | #ifndef __GO_EPHEMERAL_KEY_SOURCE__H__ 2 | #define __GO_EPHEMERAL_KEY_SOURCE__H__ 3 | 4 | #include "net/quic/core/crypto/key_exchange.h" 5 | #include "net/quic/core/crypto/ephemeral_key_source.h" 6 | #include "net/quic/core/quic_time.h" 7 | 8 | namespace net { 9 | 10 | class GoEphemeralKeySource : public EphemeralKeySource { 11 | public: 12 | GoEphemeralKeySource(); 13 | 14 | virtual std::string CalculateForwardSecureKey( 15 | const KeyExchange* key_exchange, 16 | QuicRandom* rand, 17 | QuicTime now, 18 | base::StringPiece peer_public_value, 19 | std::string* public_value) override; 20 | 21 | private: 22 | std::unique_ptr forward_secure_key_exchange_; 23 | QuicTime key_created_time_; 24 | }; 25 | 26 | } // namespace net 27 | 28 | #endif // __GO_EPHEMERAL_KEY_SOURCE__H__ 29 | -------------------------------------------------------------------------------- /src/go_functions.h: -------------------------------------------------------------------------------- 1 | ../go_functions.h -------------------------------------------------------------------------------- /src/go_proof_verifier.cc: -------------------------------------------------------------------------------- 1 | #include "go_proof_verifier.h" 2 | #include "go_functions.h" 3 | 4 | #include "base/logging.h" 5 | 6 | namespace net { 7 | 8 | GoProofVerifier::GoProofVerifier(GoPtr go_proof_verifier) 9 | : go_proof_verifier_(go_proof_verifier) {} 10 | 11 | GoProofVerifier::~GoProofVerifier() { 12 | ReleaseProofVerifier_C(go_proof_verifier_); 13 | } 14 | 15 | QuicAsyncStatus GoProofVerifier::VerifyProof( 16 | const std::string& hostname, 17 | const uint16_t port, 18 | const std::string& server_config, 19 | QuicVersion quic_version, 20 | base::StringPiece chlo_hash, 21 | const std::vector& certs, 22 | const std::string& cert_sct, 23 | const std::string& signature, 24 | const ProofVerifyContext* context, 25 | std::string* error_details, 26 | std::unique_ptr* details, 27 | std::unique_ptr callback) { 28 | // XXX(hodduc): Should we implement verifying on go-side asynchronously? 29 | // XXX(hodduc): QUIC_VERSION_31 support 30 | 31 | std::unique_ptr verify_details_; 32 | verify_details_.reset(new GoProofVerifyDetails); 33 | 34 | if (certs.empty()) { 35 | *error_details = "Failed to create certificate chain. Certs are empty."; 36 | DLOG(WARNING) << *error_details; 37 | // verify_details_->cert_verify_result.cert_status = CERT_STATUS_INVALID; 38 | *details = std::move(verify_details_); 39 | return QUIC_FAILURE; 40 | } 41 | 42 | auto chlo_hash_str = chlo_hash.as_string(); 43 | 44 | // Convery certs to X509Certificate. 45 | GoPtr job = NewProofVerifyJob_C( 46 | go_proof_verifier_, (int)(quic_version), 47 | (char*)(hostname.c_str()), (size_t)(hostname.length()), 48 | (char*)(server_config.c_str()), (size_t)(server_config.length()), 49 | (char*)(chlo_hash_str.c_str()), (size_t)(chlo_hash_str.length()), 50 | (char*)(cert_sct.c_str()), (size_t)(cert_sct.length()), 51 | (char*)(signature.c_str()), (size_t)(signature.length())); 52 | 53 | for (auto it = certs.begin(); it != certs.end(); it++) { 54 | ProofVerifyJobAddCert_C(job, (char*)it->c_str(), (size_t)it->length()); 55 | } 56 | 57 | // TODO(hodduc) detailed error msg 58 | int ret = ProofVerifyJobVerifyProof_C(job); 59 | 60 | if (ret == 1) { 61 | *details = std::move(verify_details_); 62 | return QUIC_SUCCESS; 63 | } else { 64 | *error_details = "Failed to verify proof"; 65 | DLOG(WARNING) << *error_details; 66 | *details = std::move(verify_details_); 67 | return QUIC_FAILURE; 68 | } 69 | } 70 | 71 | QuicAsyncStatus GoProofVerifier::VerifyCertChain( 72 | const std::string& hostname, 73 | const std::vector& certs, 74 | const ProofVerifyContext* context, 75 | std::string* error_details, 76 | std::unique_ptr* details, 77 | std::unique_ptr callback) { 78 | // TODO(hodduc) 79 | } 80 | 81 | } // namespace net 82 | -------------------------------------------------------------------------------- /src/go_proof_verifier.h: -------------------------------------------------------------------------------- 1 | #ifndef __GO_PROOF_VERIFIER__H__ 2 | #define __GO_PROOF_VERIFIER__H__ 3 | 4 | #include 5 | 6 | #include "net/quic/core/crypto/proof_verifier.h" 7 | #include "go_structs.h" 8 | 9 | namespace net { 10 | 11 | class NET_EXPORT_PRIVATE GoProofVerifyDetails : public ProofVerifyDetails { 12 | public: 13 | ProofVerifyDetails* Clone() const override { 14 | // TODO 15 | return nullptr; 16 | } 17 | 18 | // CertVerifyResult cert_verify_result; 19 | }; 20 | 21 | class NET_EXPORT_PRIVATE GoProofVerifier : public ProofVerifier { 22 | public: 23 | GoProofVerifier(GoPtr go_proof_verifier); 24 | ~GoProofVerifier() override; 25 | 26 | // ProofVerifier interface 27 | QuicAsyncStatus VerifyProof(const std::string& hostname, 28 | const uint16_t port, 29 | const std::string& server_config, 30 | QuicVersion quic_version, 31 | base::StringPiece chlo_hash, 32 | const std::vector& certs, 33 | const std::string& cert_sct, 34 | const std::string& signature, 35 | const ProofVerifyContext* context, 36 | std::string* error_details, 37 | std::unique_ptr* details, 38 | std::unique_ptr callback) override; 39 | 40 | QuicAsyncStatus VerifyCertChain( 41 | const std::string& hostname, 42 | const std::vector& certs, 43 | const ProofVerifyContext* context, 44 | std::string* error_details, 45 | std::unique_ptr* details, 46 | std::unique_ptr callback) override; 47 | private: 48 | GoPtr go_proof_verifier_; 49 | 50 | DISALLOW_COPY_AND_ASSIGN(GoProofVerifier); 51 | }; 52 | 53 | } // namespace net 54 | 55 | #endif // __GO_PROOF_VERIFIER__H__ 56 | -------------------------------------------------------------------------------- /src/go_quic_alarm_factory.cc: -------------------------------------------------------------------------------- 1 | #include "go_quic_alarm_factory.h" 2 | #include "go_quic_alarm_go_wrapper.h" 3 | 4 | namespace net { 5 | 6 | GoQuicAlarmFactory::GoQuicAlarmFactory(QuicClock* clock, GoPtr task_runner) 7 | : clock_(clock), 8 | task_runner_(task_runner) {} 9 | GoQuicAlarmFactory::~GoQuicAlarmFactory() { 10 | ReleaseTaskRunner_C(task_runner_); 11 | } 12 | 13 | QuicAlarm* GoQuicAlarmFactory::CreateAlarm( 14 | QuicAlarm::Delegate* delegate) { 15 | return new GoQuicAlarmGoWrapper(clock_, task_runner_, 16 | QuicArenaScopedPtr(delegate)); // Should be deleted by caller 17 | } 18 | 19 | QuicArenaScopedPtr GoQuicAlarmFactory::CreateAlarm( 20 | QuicArenaScopedPtr delegate, 21 | QuicConnectionArena* arena) { 22 | if (arena != nullptr) { 23 | return arena->New(clock_, task_runner_, std::move(delegate)); 24 | } else { 25 | return QuicArenaScopedPtr( 26 | new GoQuicAlarmGoWrapper(clock_, task_runner_, std::move(delegate))); 27 | } 28 | } 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/go_quic_alarm_factory.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_ALARM_FACTORY_H_ 2 | #define GO_QUIC_ALARM_FACTORY_H_ 3 | 4 | #include "go_structs.h" 5 | #include "net/quic/core/quic_alarm.h" 6 | #include "net/quic/core/quic_alarm_factory.h" 7 | #include "net/quic/core/quic_clock.h" 8 | 9 | namespace net { 10 | 11 | class GoQuicAlarmFactory : public QuicAlarmFactory { 12 | public: 13 | explicit GoQuicAlarmFactory(QuicClock* clock, GoPtr task_runner); 14 | ~GoQuicAlarmFactory() override; 15 | 16 | // QuicAlarmFactory interface. 17 | QuicAlarm* CreateAlarm(QuicAlarm::Delegate* delegate) override; 18 | QuicArenaScopedPtr CreateAlarm( 19 | QuicArenaScopedPtr delegate, 20 | QuicConnectionArena* arena) override; 21 | 22 | private: 23 | QuicClock* clock_; // Not owned ( may be owned by connection helper ) TODO(hodduc): should ref-counted? 24 | GoPtr task_runner_; 25 | 26 | DISALLOW_COPY_AND_ASSIGN(GoQuicAlarmFactory); 27 | }; 28 | 29 | } // namespace net 30 | 31 | #endif // GO_QUIC_ALARM_FACTORY_H_ 32 | -------------------------------------------------------------------------------- /src/go_quic_alarm_go_wrapper.h: -------------------------------------------------------------------------------- 1 | #ifndef __GO_QUIC_ALARM_GO_WRAPPER_H__ 2 | #define __GO_QUIC_ALARM_GO_WRAPPER_H__ 3 | #include "go_functions.h" 4 | #include "net/quic/core/quic_clock.h" 5 | #include "net/quic/core/quic_alarm.h" 6 | #include "base/logging.h" 7 | #include 8 | 9 | namespace net { 10 | 11 | class GoQuicAlarmGoWrapper : public QuicAlarm { 12 | public: 13 | GoQuicAlarmGoWrapper(QuicClock* clock, 14 | GoPtr task_runner, 15 | QuicArenaScopedPtr delegate) 16 | : QuicAlarm(std::move(delegate)), 17 | go_quic_alarm_(CreateGoQuicAlarm_C(this, clock, task_runner)) {} 18 | 19 | virtual ~GoQuicAlarmGoWrapper() { 20 | // Notify go object that we are destroyed 21 | GoQuicAlarmDestroy_C(go_quic_alarm_); 22 | } 23 | 24 | // Should be called by gowrapper only 25 | void Fire_() { Fire(); } 26 | 27 | void SetGoQuicAlarm(GoPtr go_quic_alarm) { go_quic_alarm_ = go_quic_alarm; } 28 | 29 | protected: 30 | void SetImpl() override { 31 | GoQuicAlarmSetImpl_C(go_quic_alarm_, quic_clock_to_int64(deadline())); 32 | } 33 | void CancelImpl() override { GoQuicAlarmCancelImpl_C(go_quic_alarm_); } 34 | 35 | private: 36 | GoPtr go_quic_alarm_; 37 | 38 | int64_t quic_clock_to_int64(QuicTime time) { 39 | return (time - QuicTime::Zero()).ToMicroseconds(); 40 | } 41 | }; 42 | } 43 | #endif 44 | -------------------------------------------------------------------------------- /src/go_quic_client_packet_writer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include 6 | 7 | #include "go_quic_client_packet_writer.h" 8 | 9 | #include "net/base/net_errors.h" 10 | #include "go_functions.h" 11 | 12 | namespace net { 13 | 14 | GoQuicClientPacketWriter::GoQuicClientPacketWriter(GoPtr go_writer) 15 | : go_writer_(go_writer), write_blocked_(false) {} 16 | 17 | GoQuicClientPacketWriter::~GoQuicClientPacketWriter() { 18 | ReleaseClientWriter_C(go_writer_); 19 | } 20 | 21 | WriteResult GoQuicClientPacketWriter::WritePacket( 22 | const char* buffer, 23 | size_t buf_len, 24 | const IPAddress& self_address, 25 | const IPEndPoint& peer_address, 26 | PerPacketOptions* /*options*/) { 27 | DCHECK(!IsWriteBlocked()); 28 | int rv; 29 | if (buf_len <= static_cast(std::numeric_limits::max())) { 30 | auto peer_ip = peer_address.address().bytes(); 31 | WriteToUDPClient_C(go_writer_, reinterpret_cast(peer_ip.data()), peer_ip.size(), 32 | peer_address.port(), (void*)buffer, buf_len); 33 | 34 | rv = buf_len; 35 | } else { 36 | rv = ERR_MSG_TOO_BIG; 37 | } 38 | WriteStatus status = WRITE_STATUS_OK; 39 | if (rv < 0) { 40 | if (rv != ERR_IO_PENDING) { 41 | status = WRITE_STATUS_ERROR; 42 | } else { 43 | status = WRITE_STATUS_BLOCKED; 44 | write_blocked_ = true; 45 | } 46 | } 47 | return WriteResult(status, rv); 48 | } 49 | 50 | bool GoQuicClientPacketWriter::IsWriteBlockedDataBuffered() const { 51 | return false; 52 | } 53 | 54 | bool GoQuicClientPacketWriter::IsWriteBlocked() const { 55 | return write_blocked_; 56 | } 57 | 58 | void GoQuicClientPacketWriter::SetWritable() { 59 | write_blocked_ = false; 60 | } 61 | 62 | QuicByteCount GoQuicClientPacketWriter::GetMaxPacketSize( 63 | const IPEndPoint& peer_address) const { 64 | return kMaxPacketSize; 65 | } 66 | 67 | } // namespace net 68 | -------------------------------------------------------------------------------- /src/go_quic_client_packet_writer.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_CLIENT_PACKET_WRITER_H_ 2 | #define GO_QUIC_CLIENT_PACKET_WRITER_H_ 3 | 4 | #include "net/base/ip_address.h" 5 | #include "net/base/ip_endpoint.h" 6 | #include "net/quic/core/quic_packet_writer.h" 7 | #include "go_structs.h" 8 | 9 | namespace net { 10 | 11 | struct WriteResult; 12 | 13 | class GoQuicClientPacketWriter : public QuicPacketWriter { 14 | public: 15 | GoQuicClientPacketWriter(GoPtr go_writer); 16 | ~GoQuicClientPacketWriter() override; 17 | 18 | // QuicPacketWriter implementation: 19 | WriteResult WritePacket(const char* buffer, 20 | size_t buf_len, 21 | const IPAddress& self_address, 22 | const IPEndPoint& peer_address, 23 | PerPacketOptions* options) override; 24 | bool IsWriteBlockedDataBuffered() const override; 25 | bool IsWriteBlocked() const override; 26 | void SetWritable() override; 27 | QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; 28 | 29 | protected: 30 | void set_write_blocked(bool is_blocked) { write_blocked_ = is_blocked; } 31 | 32 | private: 33 | GoPtr go_writer_; 34 | 35 | // Whether a write is currently in flight. 36 | bool write_blocked_; 37 | 38 | DISALLOW_COPY_AND_ASSIGN(GoQuicClientPacketWriter); 39 | }; 40 | 41 | } // namespace net 42 | 43 | #endif // GO_QUIC_CLIENT_PACKET_WRITER_H_ 44 | -------------------------------------------------------------------------------- /src/go_quic_client_session.cc: -------------------------------------------------------------------------------- 1 | #include "go_quic_client_session.h" 2 | 3 | #include "net/quic/core/crypto/crypto_protocol.h" 4 | #include "net/quic/core/quic_server_id.h" 5 | #include "go_quic_spdy_client_stream.h" 6 | 7 | using std::string; 8 | 9 | namespace net { 10 | 11 | GoQuicClientSession::GoQuicClientSession( 12 | const QuicConfig& config, 13 | QuicConnection* connection, 14 | const QuicServerId& server_id, 15 | QuicCryptoClientConfig* crypto_config, 16 | QuicClientPushPromiseIndex* push_promise_index) 17 | : QuicClientSessionBase(connection, push_promise_index, config), 18 | server_id_(server_id), 19 | crypto_config_(crypto_config), 20 | respect_goaway_(true) {} 21 | 22 | GoQuicClientSession::~GoQuicClientSession() {} 23 | 24 | void GoQuicClientSession::Initialize() { 25 | crypto_stream_.reset(CreateQuicCryptoStream()); 26 | QuicClientSessionBase::Initialize(); 27 | } 28 | 29 | void GoQuicClientSession::OnProofValid( 30 | const QuicCryptoClientConfig::CachedState& /*cached*/) {} 31 | 32 | void GoQuicClientSession::OnProofVerifyDetailsAvailable( 33 | const ProofVerifyDetails& /*verify_details*/) {} 34 | 35 | bool GoQuicClientSession::ShouldCreateOutgoingDynamicStream() { 36 | if (!crypto_stream_->encryption_established()) { 37 | DVLOG(1) << "Encryption not active so no outgoing stream created."; 38 | return false; 39 | } 40 | if (GetNumOpenOutgoingStreams() >=max_open_outgoing_streams()) { 41 | DVLOG(1) << "Failed to create a new outgoing stream. " 42 | << "Already " << GetNumOpenOutgoingStreams() << " open."; 43 | return false; 44 | } 45 | if (goaway_received() && respect_goaway_) { 46 | DVLOG(1) << "Failed to create a new outgoing stream. " 47 | << "Already received goaway."; 48 | return false; 49 | } 50 | return true; 51 | } 52 | 53 | GoQuicSpdyClientStream* GoQuicClientSession::CreateOutgoingDynamicStream( 54 | SpdyPriority priority) { 55 | if (!ShouldCreateOutgoingDynamicStream()) { 56 | return nullptr; 57 | } 58 | GoQuicSpdyClientStream* stream = CreateClientStream(); 59 | stream->SetPriority(priority); 60 | ActivateStream(stream); 61 | return stream; 62 | } 63 | 64 | GoQuicSpdyClientStream* GoQuicClientSession::CreateClientStream() { 65 | return new GoQuicSpdyClientStream(GetNextOutgoingStreamId(), this); 66 | } 67 | 68 | QuicCryptoClientStreamBase* GoQuicClientSession::GetCryptoStream() { 69 | return crypto_stream_.get(); 70 | } 71 | 72 | void GoQuicClientSession::CryptoConnect() { 73 | DCHECK(flow_controller()); 74 | crypto_stream_->CryptoConnect(); 75 | } 76 | 77 | int GoQuicClientSession::GetNumSentClientHellos() const { 78 | return crypto_stream_->num_sent_client_hellos(); 79 | } 80 | 81 | int GoQuicClientSession::GetNumReceivedServerConfigUpdates() const { 82 | return crypto_stream_->num_scup_messages_received(); 83 | } 84 | 85 | QuicSpdyStream* GoQuicClientSession::CreateIncomingDynamicStream( 86 | QuicStreamId id) { 87 | // TODO(hodduc) Support server push 88 | DLOG(ERROR) << "Server push not supported"; 89 | return nullptr; 90 | } 91 | 92 | QuicCryptoClientStreamBase* GoQuicClientSession::CreateQuicCryptoStream() { 93 | return new QuicCryptoClientStream( 94 | server_id_, this, nullptr, 95 | crypto_config_, this); 96 | // XXX(hodduc) third parameter is for implementation-specific context, which 97 | // is nullable. 98 | } 99 | 100 | bool GoQuicClientSession::IsAuthorized(const string& authority) { 101 | return true; 102 | } 103 | 104 | } // namespace net 105 | -------------------------------------------------------------------------------- /src/go_quic_client_session.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_CLIENT_SESSION_H_ 2 | #define GO_QUIC_CLIENT_SESSION_H_ 3 | 4 | #include 5 | 6 | #include "net/quic/core/quic_client_session_base.h" 7 | #include "net/quic/core/quic_crypto_client_stream.h" 8 | #include "net/quic/core/quic_protocol.h" 9 | #include "go_quic_spdy_client_stream.h" 10 | 11 | namespace net { 12 | 13 | class GoQuicClientSession : public QuicClientSessionBase { 14 | public: 15 | GoQuicClientSession(const QuicConfig& config, 16 | QuicConnection* connection, 17 | const QuicServerId& server_id, 18 | QuicCryptoClientConfig* crypto_config, 19 | QuicClientPushPromiseIndex* push_promise_index); 20 | ~GoQuicClientSession() override; 21 | // Set up the QuicClientSession. Must be called prior to use. 22 | void Initialize() override; 23 | 24 | // QuicSession methods: 25 | GoQuicSpdyClientStream* CreateOutgoingDynamicStream( 26 | SpdyPriority priority) override; 27 | QuicCryptoClientStreamBase* GetCryptoStream() override; 28 | 29 | bool IsAuthorized(const std::string& authority) override; 30 | 31 | // QuicClientSessionBase methods: 32 | void OnProofValid(const QuicCryptoClientConfig::CachedState& cached) override; 33 | void OnProofVerifyDetailsAvailable( 34 | const ProofVerifyDetails& verify_details) override; 35 | 36 | // Performs a crypto handshake with the server 37 | void CryptoConnect(); 38 | 39 | // Returns the number of client hello messages that have been sent on the 40 | // crypto stream. If the handshake has completed then this is one greater 41 | // than the number of round-trips needed for the handshake. 42 | int GetNumSentClientHellos() const; 43 | 44 | int GetNumReceivedServerConfigUpdates() const; 45 | 46 | void set_respect_goaway(bool respect_goaway) { 47 | respect_goaway_ = respect_goaway; 48 | } 49 | 50 | protected: 51 | // QuicSession methods: 52 | QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override; 53 | // If an outgoing stream can be created, return true. 54 | bool ShouldCreateOutgoingDynamicStream() override; 55 | 56 | // If an incoming stream can be created, return true. 57 | bool ShouldCreateIncomingDynamicStream(QuicStreamId id) override {} // TODO(hodduc) 58 | 59 | // Create the crypto stream. Called by Initialize() 60 | virtual QuicCryptoClientStreamBase* CreateQuicCryptoStream(); 61 | 62 | // Unlike CreateOutgoingDynamicStream, which applies a bunch of sanity checks, 63 | // this simply returns a new QuicSpdyClientStream. This may be used by 64 | // subclasses which want to use a subclass of QuicSpdyClientStream for streams 65 | // but wish to use the sanity checks in CreateOutgoingDynamicStream. 66 | virtual GoQuicSpdyClientStream* CreateClientStream(); 67 | 68 | const QuicServerId& server_id() { return server_id_; } 69 | QuicCryptoClientConfig* crypto_config() { return crypto_config_; } 70 | 71 | private: 72 | std::unique_ptr crypto_stream_; 73 | QuicServerId server_id_; 74 | QuicCryptoClientConfig* crypto_config_; 75 | 76 | // If this is set to false, the client will ignore server GOAWAYs and allow 77 | // the creation of streams regardless of the high chance they will fail. 78 | bool respect_goaway_; 79 | 80 | DISALLOW_COPY_AND_ASSIGN(GoQuicClientSession); 81 | }; 82 | 83 | } // namespace net 84 | 85 | #endif // GO_QUIC_CLIENT_SESSION_H_ 86 | -------------------------------------------------------------------------------- /src/go_quic_connection_helper.cc: -------------------------------------------------------------------------------- 1 | #include "go_quic_connection_helper.h" 2 | 3 | #include "net/quic/core/quic_connection.h" 4 | #include "net/quic/core/quic_clock.h" 5 | #include "net/quic/core/crypto/quic_random.h" 6 | 7 | namespace net { 8 | 9 | GoQuicConnectionHelper::GoQuicConnectionHelper(QuicClock* clock, 10 | QuicRandom* random_generator) 11 | : random_generator_(random_generator) { 12 | clock_.reset(clock); 13 | } 14 | 15 | GoQuicConnectionHelper::~GoQuicConnectionHelper() {} 16 | 17 | const QuicClock* GoQuicConnectionHelper::GetClock() const { 18 | return clock_.get(); 19 | } 20 | 21 | QuicRandom* GoQuicConnectionHelper::GetRandomGenerator() { 22 | return random_generator_; 23 | } 24 | 25 | QuicBufferAllocator* GoQuicConnectionHelper::GetBufferAllocator() { 26 | return &buffer_allocator_; 27 | } 28 | 29 | } // namespace net 30 | -------------------------------------------------------------------------------- /src/go_quic_connection_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_CONNECTION_HELPER_H_ 2 | #define GO_QUIC_CONNECTION_HELPER_H_ 3 | #include "net/quic/core/quic_connection.h" 4 | #include "net/quic/core/quic_clock.h" 5 | #include "net/quic/core/quic_simple_buffer_allocator.h" 6 | #include "go_structs.h" 7 | 8 | namespace net { 9 | 10 | class QuicRandom; 11 | 12 | using QuicStreamBufferAllocator = SimpleBufferAllocator; 13 | 14 | class GoQuicConnectionHelper : public QuicConnectionHelperInterface { 15 | public: 16 | GoQuicConnectionHelper(QuicClock* clock, 17 | QuicRandom* random_generator); 18 | ~GoQuicConnectionHelper() override; 19 | 20 | // QuicConnectionHelperInterface 21 | const QuicClock* GetClock() const override; 22 | QuicRandom* GetRandomGenerator() override; 23 | 24 | QuicBufferAllocator* GetBufferAllocator() override; 25 | 26 | private: 27 | 28 | std::unique_ptr clock_; 29 | QuicRandom* random_generator_; 30 | QuicStreamBufferAllocator buffer_allocator_; 31 | 32 | DISALLOW_COPY_AND_ASSIGN(GoQuicConnectionHelper); 33 | }; 34 | 35 | } // namespace net 36 | 37 | #endif // GO_QUIC_CONNECTION_HELPER_H_ 38 | -------------------------------------------------------------------------------- /src/go_quic_per_connection_packet_writer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_per_connection_packet_writer.h" 6 | 7 | #include "base/bind.h" 8 | #include "go_quic_server_packet_writer.h" 9 | 10 | namespace net { 11 | 12 | GoQuicPerConnectionPacketWriter::GoQuicPerConnectionPacketWriter( 13 | GoQuicServerPacketWriter* shared_writer) 14 | : shared_writer_(shared_writer), 15 | connection_(nullptr), 16 | weak_factory_(this) {} 17 | 18 | GoQuicPerConnectionPacketWriter::~GoQuicPerConnectionPacketWriter() {} 19 | 20 | QuicPacketWriter* GoQuicPerConnectionPacketWriter::shared_writer() const { 21 | return shared_writer_; 22 | } 23 | 24 | WriteResult GoQuicPerConnectionPacketWriter::WritePacket( 25 | const char* buffer, 26 | size_t buf_len, 27 | const IPAddress& self_address, 28 | const IPEndPoint& peer_address, 29 | PerPacketOptions* options) { 30 | return shared_writer_->WritePacketWithCallback( 31 | buffer, buf_len, self_address, peer_address, options, 32 | base::Bind(&GoQuicPerConnectionPacketWriter::OnWriteComplete, 33 | weak_factory_.GetWeakPtr())); 34 | } 35 | 36 | bool GoQuicPerConnectionPacketWriter::IsWriteBlockedDataBuffered() const { 37 | return shared_writer_->IsWriteBlockedDataBuffered(); 38 | } 39 | 40 | bool GoQuicPerConnectionPacketWriter::IsWriteBlocked() const { 41 | return shared_writer_->IsWriteBlocked(); 42 | } 43 | 44 | void GoQuicPerConnectionPacketWriter::SetWritable() { 45 | shared_writer_->SetWritable(); 46 | } 47 | 48 | void GoQuicPerConnectionPacketWriter::OnWriteComplete(WriteResult result) { 49 | if (connection_ && result.status == WRITE_STATUS_ERROR) { 50 | connection_->OnWriteError(result.error_code); 51 | } 52 | } 53 | 54 | QuicByteCount GoQuicPerConnectionPacketWriter::GetMaxPacketSize( 55 | const IPEndPoint& peer_address) const { 56 | return shared_writer_->GetMaxPacketSize(peer_address); 57 | } 58 | 59 | } // namespace net 60 | -------------------------------------------------------------------------------- /src/go_quic_per_connection_packet_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef GO_QUIC_PER_CONNECTION_PACKET_WRITER_H_ 6 | #define GO_QUIC_PER_CONNECTION_PACKET_WRITER_H_ 7 | 8 | #include "base/memory/weak_ptr.h" 9 | #include "net/base/ip_address.h" 10 | #include "net/quic/core/quic_connection.h" 11 | #include "net/quic/core/quic_packet_writer.h" 12 | 13 | namespace net { 14 | 15 | class GoQuicServerPacketWriter; 16 | 17 | // A connection-specific packet writer that notifies its connection when its 18 | // writes to the shared GoQuicServerPacketWriter complete. 19 | // This class is necessary because multiple connections can share the same 20 | // GoQuicServerPacketWriter, so it has no way to know which connection to 21 | // notify. 22 | class GoQuicPerConnectionPacketWriter : public QuicPacketWriter { 23 | public: 24 | // Does not take ownership of |shared_writer| or |connection|. 25 | GoQuicPerConnectionPacketWriter(GoQuicServerPacketWriter* shared_writer); 26 | ~GoQuicPerConnectionPacketWriter() override; 27 | 28 | QuicPacketWriter* shared_writer() const; 29 | void set_connection(QuicConnection* connection) { connection_ = connection; } 30 | QuicConnection* connection() const { return connection_; } 31 | 32 | // Default implementation of the QuicPacketWriter interface: Passes everything 33 | // to |shared_writer_|. 34 | WriteResult WritePacket(const char* buffer, 35 | size_t buf_len, 36 | const IPAddress& self_address, 37 | const IPEndPoint& peer_address, 38 | PerPacketOptions* options) override; 39 | bool IsWriteBlockedDataBuffered() const override; 40 | bool IsWriteBlocked() const override; 41 | void SetWritable() override; 42 | QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; 43 | 44 | private: 45 | void OnWriteComplete(WriteResult result); 46 | 47 | GoQuicServerPacketWriter* shared_writer_; // Not owned. 48 | QuicConnection* connection_; // Not owned. 49 | 50 | base::WeakPtrFactory weak_factory_; 51 | 52 | DISALLOW_COPY_AND_ASSIGN(GoQuicPerConnectionPacketWriter); 53 | }; 54 | 55 | } // namespace net 56 | 57 | #endif // GO_QUIC_PER_CONNECTION_PACKET_WRITER_H_ 58 | -------------------------------------------------------------------------------- /src/go_quic_process_packet_interface.h: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef GO_QUIC_PROCESS_PACKET_INTERFACE_H_ 6 | #define GO_QUIC_PROCESS_PACKET_INTERFACE_H_ 7 | 8 | #include "base/macros.h" 9 | #include "net/base/ip_endpoint.h" 10 | #include "net/quic/core/quic_protocol.h" 11 | 12 | namespace net { 13 | 14 | // A class to process each incoming packet. 15 | class ProcessPacketInterface { 16 | public: 17 | virtual ~ProcessPacketInterface() {} 18 | virtual void ProcessPacket(const IPEndPoint& server_address, 19 | const IPEndPoint& client_address, 20 | const QuicReceivedPacket& packet) = 0; 21 | }; 22 | 23 | } // namespace net 24 | 25 | #endif // GO_QUIC_PROCESS_PACKET_INTERFACE_H_ 26 | -------------------------------------------------------------------------------- /src/go_quic_server_packet_writer.cc: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_server_packet_writer.h" 6 | 7 | #include "base/callback_helpers.h" 8 | #include "base/location.h" 9 | #include "base/logging.h" 10 | #include "base/metrics/sparse_histogram.h" 11 | #include "net/base/io_buffer.h" 12 | #include "net/base/net_errors.h" 13 | 14 | #include "go_functions.h" 15 | 16 | namespace net { 17 | 18 | GoQuicServerPacketWriter::GoQuicServerPacketWriter( 19 | GoPtr go_writer, 20 | QuicBlockedWriterInterface* blocked_writer) 21 | : go_writer_(go_writer), 22 | blocked_writer_(blocked_writer), 23 | write_blocked_(false), 24 | weak_factory_(this) {} 25 | 26 | GoQuicServerPacketWriter::~GoQuicServerPacketWriter() { 27 | ReleaseServerWriter_C(go_writer_); 28 | // TODO(hodduc): release go_writer 29 | } 30 | 31 | WriteResult GoQuicServerPacketWriter::WritePacketWithCallback( 32 | const char* buffer, 33 | size_t buf_len, 34 | const IPAddress& self_address, 35 | const IPEndPoint& peer_address, 36 | PerPacketOptions* options, 37 | WriteCallback callback) { 38 | DCHECK(callback_.is_null()); 39 | callback_ = callback; 40 | WriteResult result = 41 | WritePacket(buffer, buf_len, self_address, peer_address, options); 42 | if (result.status != WRITE_STATUS_BLOCKED) { 43 | callback_.Reset(); 44 | } 45 | return result; 46 | } 47 | 48 | void GoQuicServerPacketWriter::OnWriteComplete(int rv) { 49 | DCHECK_NE(rv, ERR_IO_PENDING); 50 | write_blocked_ = false; 51 | WriteResult result(rv < 0 ? WRITE_STATUS_ERROR : WRITE_STATUS_OK, rv); 52 | if (!callback_.is_null()) { 53 | base::ResetAndReturn(&callback_).Run(result); 54 | } 55 | blocked_writer_->OnCanWrite(); 56 | } 57 | 58 | bool GoQuicServerPacketWriter::IsWriteBlockedDataBuffered() const { 59 | // UDPServerSocket::SendTo buffers the data until the Write is permitted. 60 | return true; 61 | } 62 | 63 | bool GoQuicServerPacketWriter::IsWriteBlocked() const { 64 | return write_blocked_; 65 | } 66 | 67 | void GoQuicServerPacketWriter::SetWritable() { 68 | write_blocked_ = false; 69 | } 70 | 71 | WriteResult GoQuicServerPacketWriter::WritePacket( 72 | const char* buffer, 73 | size_t buf_len, 74 | const IPAddress& self_address, 75 | const IPEndPoint& peer_address, 76 | PerPacketOptions* options) { 77 | // scoped_refptr buf( 78 | // new StringIOBuffer(std::string(buffer, buf_len))); 79 | DCHECK(!IsWriteBlocked()); 80 | int rv; 81 | if (buf_len <= static_cast(std::numeric_limits::max())) { 82 | auto peer_ip = peer_address.address().bytes(); 83 | 84 | WriteToUDP_C(go_writer_, reinterpret_cast(peer_ip.data()), peer_ip.size(), 85 | peer_address.port(), (void*)buffer, buf_len); 86 | rv = buf_len; 87 | } else { 88 | rv = ERR_MSG_TOO_BIG; 89 | } 90 | WriteStatus status = WRITE_STATUS_OK; 91 | if (rv < 0) { 92 | if (rv != ERR_IO_PENDING) { 93 | UMA_HISTOGRAM_SPARSE_SLOWLY("Net.QuicSession.WriteError", -rv); 94 | status = WRITE_STATUS_ERROR; 95 | } else { 96 | status = WRITE_STATUS_BLOCKED; 97 | write_blocked_ = true; 98 | } 99 | } 100 | return WriteResult(status, rv); 101 | } 102 | 103 | QuicByteCount GoQuicServerPacketWriter::GetMaxPacketSize( 104 | const IPEndPoint& peer_address) const { 105 | return kMaxPacketSize; 106 | } 107 | 108 | } // namespace net 109 | -------------------------------------------------------------------------------- /src/go_quic_server_packet_writer.h: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef GO_QUIC_SERVER_PACKET_WRITER_H_ 6 | #define GO_QUIC_SERVER_PACKET_WRITER_H_ 7 | 8 | #include "base/memory/weak_ptr.h" 9 | #include "base/callback.h" 10 | #include "net/base/ip_address.h" 11 | #include "net/base/ip_endpoint.h" 12 | #include "net/quic/core/quic_connection.h" 13 | #include "net/quic/core/quic_packet_writer.h" 14 | #include "net/quic/core/quic_protocol.h" 15 | #include "go_structs.h" 16 | 17 | namespace net { 18 | 19 | class QuicBlockedWriterInterface; 20 | struct WriteResult; 21 | 22 | class GoQuicServerPacketWriter : public QuicPacketWriter { 23 | public: 24 | typedef base::Callback WriteCallback; 25 | 26 | GoQuicServerPacketWriter(GoPtr go_writer, 27 | QuicBlockedWriterInterface* blocked_writer); 28 | ~GoQuicServerPacketWriter() override; 29 | 30 | // Wraps WritePacket, and ensures that |callback| is run on successful write. 31 | WriteResult WritePacketWithCallback(const char* buffer, 32 | size_t buf_len, 33 | const IPAddress& self_address, 34 | const IPEndPoint& peer_address, 35 | PerPacketOptions* options, 36 | WriteCallback callback); 37 | 38 | WriteResult WritePacket(const char* buffer, 39 | size_t buf_len, 40 | const IPAddress& self_address, 41 | const IPEndPoint& peer_address, 42 | PerPacketOptions* options) override; 43 | 44 | void OnWriteComplete(int rv); 45 | 46 | // QuicPacketWriter implementation: 47 | bool IsWriteBlockedDataBuffered() const override; 48 | bool IsWriteBlocked() const override; 49 | void SetWritable() override; 50 | QuicByteCount GetMaxPacketSize(const IPEndPoint& peer_address) const override; 51 | 52 | private: 53 | GoPtr go_writer_; 54 | 55 | // To be notified after every successful asynchronous write. 56 | QuicBlockedWriterInterface* blocked_writer_; 57 | 58 | // To call once the write completes. 59 | WriteCallback callback_; 60 | 61 | // Whether a write is currently in flight. 62 | bool write_blocked_; 63 | 64 | base::WeakPtrFactory weak_factory_; 65 | 66 | DISALLOW_COPY_AND_ASSIGN(GoQuicServerPacketWriter); 67 | }; 68 | 69 | } // namespace net 70 | 71 | #endif // GO_QUIC_SERVER_PACKET_WRITER_H_ 72 | -------------------------------------------------------------------------------- /src/go_quic_simple_crypto_server_stream_helper.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_simple_crypto_server_stream_helper.h" 6 | 7 | namespace net { 8 | 9 | GoQuicSimpleCryptoServerStreamHelper::GoQuicSimpleCryptoServerStreamHelper( 10 | QuicRandom* random) 11 | : random_(random) {} 12 | 13 | GoQuicSimpleCryptoServerStreamHelper::~GoQuicSimpleCryptoServerStreamHelper() {} 14 | 15 | QuicConnectionId 16 | GoQuicSimpleCryptoServerStreamHelper::GenerateConnectionIdForReject( 17 | QuicConnectionId /*connection_id*/) const { 18 | return random_->RandUint64(); 19 | } 20 | 21 | bool GoQuicSimpleCryptoServerStreamHelper::CanAcceptClientHello( 22 | const CryptoHandshakeMessage& message, 23 | const IPEndPoint& self_address, 24 | std::string* error_details) const { 25 | return true; 26 | } 27 | 28 | } // namespace net 29 | -------------------------------------------------------------------------------- /src/go_quic_simple_crypto_server_stream_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_SIMPLE_CRYPTO_SERVER_STREAM_HELPER_H_ 2 | #define GO_QUIC_SIMPLE_CRYPTO_SERVER_STREAM_HELPER_H_ 3 | 4 | #include "net/quic/core/crypto/quic_random.h" 5 | #include "net/quic/core/quic_crypto_server_stream.h" 6 | 7 | namespace net { 8 | 9 | // Simple helper for server sessions which generates a new random 10 | // connection ID for stateless rejects. 11 | class GoQuicSimpleCryptoServerStreamHelper 12 | : public QuicCryptoServerStream::Helper { 13 | public: 14 | explicit GoQuicSimpleCryptoServerStreamHelper(QuicRandom* random); 15 | 16 | ~GoQuicSimpleCryptoServerStreamHelper() override; 17 | 18 | QuicConnectionId GenerateConnectionIdForReject( 19 | QuicConnectionId /*connection_id*/) const override; 20 | 21 | bool CanAcceptClientHello(const CryptoHandshakeMessage& message, 22 | const IPEndPoint& self_address, 23 | std::string* error_details) const override; 24 | 25 | private: 26 | QuicRandom* random_; // Unowned. 27 | }; 28 | 29 | } // namespace net 30 | 31 | #endif // GO_QUIC_SIMPLE_CRYPTO_SERVER_STREAM_HELPER_H_ 32 | -------------------------------------------------------------------------------- /src/go_quic_simple_dispatcher.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_simple_dispatcher.h" 6 | #include "go_quic_simple_server_session.h" 7 | #include "go_functions.h" 8 | 9 | namespace net { 10 | 11 | GoQuicSimpleDispatcher::GoQuicSimpleDispatcher( 12 | const QuicConfig& config, 13 | const QuicCryptoServerConfig* crypto_config, 14 | QuicVersionManager* version_manager, 15 | std::unique_ptr helper, 16 | std::unique_ptr session_helper, 17 | std::unique_ptr alarm_factory, 18 | GoPtr go_quic_dispatcher) 19 | : GoQuicDispatcher(config, 20 | crypto_config, 21 | version_manager, 22 | std::move(helper), 23 | std::move(session_helper), 24 | std::move(alarm_factory), 25 | go_quic_dispatcher) {} 26 | 27 | GoQuicSimpleDispatcher::~GoQuicSimpleDispatcher() {} 28 | 29 | QuicServerSessionBase* GoQuicSimpleDispatcher::CreateQuicSession( 30 | QuicConnectionId connection_id, 31 | const IPEndPoint& client_address) { 32 | // The QuicServerSessionBase takes ownership of |connection| below. 33 | QuicConnection* connection = new QuicConnection( 34 | connection_id, client_address, helper(), alarm_factory(), 35 | CreatePerConnectionWriter(), 36 | /* owns_writer= */ true, Perspective::IS_SERVER, GetSupportedVersions()); 37 | 38 | GoQuicSimpleServerSession* session = 39 | new GoQuicSimpleServerSession(config(), connection, this, session_helper(), 40 | crypto_config(), compressed_certs_cache()); 41 | 42 | GoPtr dispatcher = go_quic_dispatcher(); 43 | session->SetGoSession(dispatcher, GoPtr(CreateGoSession_C(dispatcher, session))); 44 | session->Initialize(); 45 | return session; 46 | } 47 | 48 | } // namespace net 49 | -------------------------------------------------------------------------------- /src/go_quic_simple_dispatcher.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #ifndef GO_QUIC_SIMPLE_DISPATCHER_H_ 6 | #define GO_QUIC_SIMPLE_DISPATCHER_H_ 7 | 8 | #include "go_quic_dispatcher.h" 9 | #include "go_structs.h" 10 | 11 | namespace net { 12 | 13 | class GoQuicSimpleDispatcher : public GoQuicDispatcher { 14 | public: 15 | GoQuicSimpleDispatcher( 16 | const QuicConfig& config, 17 | const QuicCryptoServerConfig* crypto_config, 18 | QuicVersionManager* version_manager, 19 | std::unique_ptr helper, 20 | std::unique_ptr session_helper, 21 | std::unique_ptr alarm_factory, 22 | GoPtr go_quic_dispatcher); 23 | 24 | ~GoQuicSimpleDispatcher() override; 25 | 26 | protected: 27 | QuicServerSessionBase* CreateQuicSession( 28 | QuicConnectionId connection_id, 29 | const IPEndPoint& client_address) override; 30 | }; 31 | 32 | } // namespace net 33 | 34 | #endif // GO_QUIC_SIMPLE_DISPATCHER_H_ 35 | -------------------------------------------------------------------------------- /src/go_quic_simple_server_session.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_simple_server_session.h" 6 | #include "go_quic_simple_server_stream.h" 7 | #include "go_functions.h" 8 | 9 | #include "base/logging.h" 10 | #include "net/quic/core/proto/cached_network_parameters.pb.h" 11 | #include "net/quic/core/quic_connection.h" 12 | #include "net/quic/core/quic_flags.h" 13 | #include "net/quic/core/quic_spdy_session.h" 14 | #include "net/quic/core/reliable_quic_stream.h" 15 | 16 | using std::string; 17 | 18 | namespace net { 19 | 20 | GoQuicSimpleServerSession::GoQuicSimpleServerSession( 21 | const QuicConfig& config, 22 | QuicConnection* connection, 23 | QuicServerSessionBase::Visitor* visitor, 24 | QuicCryptoServerStream::Helper* helper, 25 | const QuicCryptoServerConfig* crypto_config, 26 | QuicCompressedCertsCache* compressed_certs_cache) 27 | : QuicServerSessionBase(config, 28 | connection, 29 | visitor, 30 | helper, 31 | crypto_config, 32 | compressed_certs_cache) {} 33 | 34 | GoQuicSimpleServerSession::~GoQuicSimpleServerSession() { 35 | delete connection(); 36 | DeleteGoSession_C(go_quic_dispatcher_, go_session_); 37 | } 38 | 39 | QuicCryptoServerStreamBase* 40 | GoQuicSimpleServerSession::CreateQuicCryptoServerStream( 41 | const QuicCryptoServerConfig* crypto_config, 42 | QuicCompressedCertsCache* compressed_certs_cache) { 43 | return new QuicCryptoServerStream(crypto_config, compressed_certs_cache, 44 | FLAGS_enable_quic_stateless_reject_support, 45 | this, stream_helper()); 46 | } 47 | 48 | QuicSpdyStream* GoQuicSimpleServerSession::CreateIncomingDynamicStream( 49 | QuicStreamId id) { 50 | if (!ShouldCreateIncomingDynamicStream(id)) { 51 | return nullptr; 52 | } 53 | 54 | GoQuicSimpleServerStream* stream = new GoQuicSimpleServerStream( 55 | id, this); // Managed by stream_map_ of QuicSession. Deleted by 56 | // STLDeleteElements function call in QuicSession 57 | stream->SetGoQuicSimpleServerStream( 58 | CreateIncomingDynamicStream_C(go_session_, id, stream)); 59 | ActivateStream(stream); 60 | 61 | return stream; 62 | } 63 | 64 | GoQuicSimpleServerStream* GoQuicSimpleServerSession::CreateOutgoingDynamicStream( 65 | SpdyPriority priority) { 66 | if (!ShouldCreateOutgoingDynamicStream()) { 67 | return nullptr; 68 | } 69 | 70 | // Should not be called! 71 | 72 | GoQuicSimpleServerStream* stream = 73 | new GoQuicSimpleServerStream(GetNextOutgoingStreamId(), this); 74 | stream->SetPriority(priority); 75 | ActivateStream(stream); 76 | return stream; 77 | } 78 | 79 | } // namespace net 80 | -------------------------------------------------------------------------------- /src/go_quic_simple_server_session.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | // 5 | // A toy server specific QuicSession subclass. 6 | 7 | #ifndef GO_QUIC_SIMPLE_SERVER_SESSION_H_ 8 | #define GO_QUIC_SIMPLE_SERVER_SESSION_H_ 9 | 10 | #include 11 | 12 | #include 13 | #include 14 | #include 15 | 16 | #include "base/macros.h" 17 | #include "net/quic/core/quic_crypto_server_stream.h" 18 | #include "net/quic/core/quic_protocol.h" 19 | #include "net/quic/core/quic_server_session_base.h" 20 | #include "net/quic/core/quic_spdy_session.h" 21 | 22 | #include "go_quic_simple_server_stream.h" 23 | 24 | namespace net { 25 | 26 | class QuicBlockedWriterInterface; 27 | class QuicConfig; 28 | class QuicConnection; 29 | class QuicCryptoServerConfig; 30 | class ReliableQuicStream; 31 | 32 | class GoQuicSimpleServerSession : public QuicServerSessionBase { 33 | public: 34 | // Takes ownership of |connection|. 35 | GoQuicSimpleServerSession(const QuicConfig& config, 36 | QuicConnection* connection, 37 | QuicServerSessionBase::Visitor* visitor, 38 | QuicCryptoServerStream::Helper* helper, 39 | const QuicCryptoServerConfig* crypto_config, 40 | QuicCompressedCertsCache* compressed_certs_cache); 41 | 42 | ~GoQuicSimpleServerSession() override; 43 | 44 | void SetGoSession(GoPtr go_quic_dispatcher, GoPtr go_session) { 45 | go_quic_dispatcher_ = go_quic_dispatcher; 46 | go_session_ = go_session; 47 | } 48 | 49 | protected: 50 | // QuicSession methods: 51 | QuicSpdyStream* CreateIncomingDynamicStream(QuicStreamId id) override; 52 | GoQuicSimpleServerStream* CreateOutgoingDynamicStream( 53 | SpdyPriority priority) override; 54 | 55 | QuicCryptoServerStreamBase* CreateQuicCryptoServerStream( 56 | const QuicCryptoServerConfig* crypto_config, 57 | QuicCompressedCertsCache* compressed_certs_cache) override; 58 | 59 | private: 60 | 61 | GoPtr go_session_; 62 | GoPtr go_quic_dispatcher_; 63 | 64 | DISALLOW_COPY_AND_ASSIGN(GoQuicSimpleServerSession); 65 | }; 66 | 67 | } // namespace net 68 | 69 | #endif // GO_QUIC_SIMPLE_SERVER_SESSION_H_ 70 | -------------------------------------------------------------------------------- /src/go_quic_simple_server_session_helper.cc: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | 5 | #include "go_quic_simple_server_session_helper.h" 6 | 7 | namespace net { 8 | 9 | GoQuicSimpleServerSessionHelper::GoQuicSimpleServerSessionHelper(QuicRandom* random) 10 | : random_(random) {} 11 | 12 | GoQuicSimpleServerSessionHelper::~GoQuicSimpleServerSessionHelper() {} 13 | 14 | QuicConnectionId GoQuicSimpleServerSessionHelper::GenerateConnectionIdForReject( 15 | QuicConnectionId /*connection_id*/) const { 16 | return random_->RandUint64(); 17 | } 18 | 19 | bool GoQuicSimpleServerSessionHelper::CanAcceptClientHello( 20 | const CryptoHandshakeMessage& message, 21 | const IPEndPoint& self_address, 22 | std::string* error_details) const { 23 | return true; 24 | } 25 | 26 | } // namespace net 27 | -------------------------------------------------------------------------------- /src/go_quic_simple_server_session_helper.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_SIMPLE_SERVER_SESSION_HELPER_H_ 2 | #define GO_QUIC_SIMPLE_SERVER_SESSION_HELPER_H_ 3 | 4 | #include "net/quic/core/crypto/quic_random.h" 5 | #include "net/quic/core/quic_server_session_base.h" 6 | 7 | namespace net { 8 | 9 | // Simple helper for server sessions which generates a new random 10 | // connection ID for stateless rejects. 11 | class GoQuicSimpleServerSessionHelper : public QuicCryptoServerStream::Helper { 12 | public: 13 | explicit GoQuicSimpleServerSessionHelper(QuicRandom* random); 14 | 15 | ~GoQuicSimpleServerSessionHelper() override; 16 | 17 | QuicConnectionId GenerateConnectionIdForReject( 18 | QuicConnectionId /*connection_id*/) const override; 19 | 20 | bool CanAcceptClientHello(const CryptoHandshakeMessage& message, 21 | const IPEndPoint& self_address, 22 | std::string* error_details) const override; 23 | 24 | private: 25 | QuicRandom* random_; // Unowned. 26 | }; 27 | 28 | } // namespace net 29 | 30 | #endif // GO_QUIC_SIMPLE_SERVER_SESSION_HELPER_H_ 31 | -------------------------------------------------------------------------------- /src/go_quic_simple_server_stream.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_QUIC_SIMPLE_SERVER_STREAM_H__ 2 | #define GO_QUIC_SIMPLE_SERVER_STREAM_H__ 3 | 4 | #include 5 | 6 | #include "net/quic/core/quic_spdy_stream.h" 7 | #include "go_structs.h" 8 | 9 | namespace net { 10 | 11 | class QuicSpdySession; 12 | 13 | class GoQuicSimpleServerStream : public QuicSpdyStream { 14 | public: 15 | GoQuicSimpleServerStream(QuicStreamId id, QuicSpdySession* session); 16 | ~GoQuicSimpleServerStream() override; 17 | 18 | void SetGoQuicSimpleServerStream(GoPtr go_quic_simple_server_stream); 19 | 20 | // QuicSpdyStream 21 | void OnInitialHeadersComplete(bool fin, size_t frame_len) override; 22 | void OnTrailingHeadersComplete(bool fin, size_t frame_len) override; 23 | void OnInitialHeadersComplete(bool fin, 24 | size_t frame_len, 25 | const QuicHeaderList& header_list) override; 26 | void OnTrailingHeadersComplete(bool fin, 27 | size_t frame_len, 28 | const QuicHeaderList& header_list) override; 29 | 30 | // ReliableQuicStream implementation called by the sequencer when there is 31 | // data (or a FIN) to be read. 32 | void OnDataAvailable() override; 33 | 34 | void OnClose() override; 35 | 36 | // The response body of error responses. 37 | static const char* const kErrorResponseBody; 38 | static const char* const kNotFoundResponseBody; 39 | 40 | size_t WriteHeaders(SpdyHeaderBlock header_block, 41 | bool fin, 42 | QuicAckListenerInterface* ack_notifier_delegate) override; 43 | 44 | protected: 45 | // Sends a basic 500 response using SendHeaders for the headers and WriteData 46 | // for the body. 47 | virtual void SendErrorResponse(); 48 | 49 | private: 50 | GoPtr go_quic_simple_server_stream_; 51 | 52 | SpdyHeaderBlock request_headers_; 53 | int64_t content_length_; 54 | std::string body_; 55 | 56 | DISALLOW_COPY_AND_ASSIGN(GoQuicSimpleServerStream); 57 | }; 58 | 59 | } // namespace net 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/go_quic_spdy_client_stream.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style license that can be 3 | // found in the LICENSE file. 4 | // 5 | // NOTE: This code is not shared between Google and Chrome. 6 | 7 | #ifndef GO_QUIC_SPDY_CLIENT_STREAM_H_ 8 | #define GO_QUIC_SPDY_CLIENT_STREAM_H_ 9 | 10 | #include 11 | 12 | #include "net/quic/core/quic_spdy_stream.h" 13 | #include "go_structs.h" 14 | 15 | namespace net { 16 | 17 | class GoQuicClientSession; 18 | 19 | // All this does right now is send an SPDY request, and aggregate the 20 | // SPDY response. 21 | class GoQuicSpdyClientStream : public QuicSpdyStream { 22 | public: 23 | GoQuicSpdyClientStream(QuicStreamId id, GoQuicClientSession* session); 24 | ~GoQuicSpdyClientStream() override; 25 | 26 | void SetGoQuicClientStream(GoPtr go_quic_client_stream); 27 | 28 | // Override the base class to close the write side as soon as we get a 29 | // response. 30 | // SPDY/HTTP does not support bidirectional streaming. 31 | void OnStreamFrame(const QuicStreamFrame& frame) override; 32 | 33 | // Override the base class to parse and store headers. 34 | void OnInitialHeadersComplete(bool fin, size_t frame_len) override; 35 | 36 | // Override the base class to parse and store headers. 37 | void OnInitialHeadersComplete(bool fin, 38 | size_t frame_len, 39 | const QuicHeaderList& header_list) override; 40 | 41 | // Override the base class to parse and store trailers. 42 | void OnTrailingHeadersComplete(bool fin, 43 | size_t frame_len, 44 | const QuicHeaderList& header_list) override; 45 | 46 | // ReliableQuicStream implementation called by the session when there's 47 | // data for us. 48 | void OnDataAvailable() override; 49 | 50 | void OnClose() override; 51 | 52 | // While the server's SetPriority shouldn't be called externally, the creator 53 | // of client-side streams should be able to set the priority. 54 | using QuicSpdyStream::SetPriority; 55 | 56 | void set_allow_bidirectional_data(bool value) { 57 | allow_bidirectional_data_ = value; 58 | } 59 | 60 | bool allow_bidirectional_data() const { return allow_bidirectional_data_; } 61 | 62 | private: 63 | // The parsed headers received from the server. 64 | SpdyHeaderBlock response_headers_; 65 | 66 | // The parsed content-length, or -1 if none is specified. 67 | int64_t content_length_; 68 | int response_code_; 69 | size_t header_bytes_read_; 70 | GoPtr go_quic_client_stream_; 71 | // When true allows the sending of a request to continue while the response is 72 | // arriving. 73 | // XXX: Currently not supported in goquic 74 | bool allow_bidirectional_data_; 75 | 76 | GoQuicClientSession* session_; 77 | 78 | DISALLOW_COPY_AND_ASSIGN(GoQuicSpdyClientStream); 79 | }; 80 | 81 | } // namespace net 82 | 83 | #endif // GO_QUIC_SPDY_CLIENT_STREAM_H_ 84 | -------------------------------------------------------------------------------- /src/go_structs.h: -------------------------------------------------------------------------------- 1 | ../go_structs.h -------------------------------------------------------------------------------- /src/go_utils.cc: -------------------------------------------------------------------------------- 1 | #include "go_utils.h" 2 | #include "net/spdy/spdy_header_block.h" 3 | 4 | namespace net { 5 | 6 | GoSpdyHeader* CreateGoSpdyHeader(const SpdyHeaderBlock& header_block) { 7 | size_t N = header_block.size(); 8 | GoSpdyHeader* hdr = new GoSpdyHeader; 9 | 10 | hdr->N = N; 11 | hdr->Keys = new const char*[N]; 12 | hdr->Values = new const char*[N]; 13 | hdr->Keys_len = new int[N]; 14 | hdr->Values_len = new int[N]; 15 | 16 | int idx = 0; 17 | for(auto it = header_block.begin(); it != header_block.end(); it++, idx++) { 18 | auto p = *it; 19 | hdr->Keys[idx] = p.first.data(); 20 | hdr->Keys_len[idx] = p.first.length(); 21 | hdr->Values[idx] = p.second.data(); 22 | hdr->Values_len[idx] = p.second.length(); 23 | } 24 | 25 | return hdr; 26 | } 27 | 28 | void DeleteGoSpdyHeader(GoSpdyHeader* go_header) { 29 | delete(go_header->Keys); 30 | delete(go_header->Keys_len); 31 | delete(go_header->Values); 32 | delete(go_header->Values_len); 33 | delete(go_header); 34 | } 35 | 36 | void CreateSpdyHeaderBlock(SpdyHeaderBlock& block, int N, char* key_ptr, int* key_len, char* value_ptr, int* value_len) { 37 | for (int i = 0; i < N; i++) { 38 | block[base::StringPiece(key_ptr, key_len[i])] = base::StringPiece(value_ptr, value_len[i]); 39 | key_ptr += key_len[i]; 40 | value_ptr += value_len[i]; 41 | } 42 | } 43 | 44 | } 45 | 46 | -------------------------------------------------------------------------------- /src/go_utils.h: -------------------------------------------------------------------------------- 1 | #ifndef GO_UTILS_H_ 2 | #define GO_UTILS_H_ 3 | 4 | #include "go_structs.h" 5 | 6 | namespace net { 7 | 8 | class SpdyHeaderBlock; 9 | 10 | GoSpdyHeader* CreateGoSpdyHeader(const SpdyHeaderBlock& header_block); 11 | void DeleteGoSpdyHeader(GoSpdyHeader* go_header); 12 | void CreateSpdyHeaderBlock(SpdyHeaderBlock& block, int N, char* key_ptr, int* key_len, char* value_ptr, int* value_len); 13 | 14 | } 15 | 16 | #endif // GO_UTILS_H_ 17 | -------------------------------------------------------------------------------- /src/proof_source_goquic.cc: -------------------------------------------------------------------------------- 1 | #include "proof_source_goquic.h" 2 | 3 | #include "base/logging.h" 4 | 5 | #include "go_functions.h" 6 | #include "net/base/ip_address.h" 7 | 8 | namespace net { 9 | 10 | ProofSourceGoquic::ProofSourceGoquic(GoPtr go_proof_source) 11 | : go_proof_source_(go_proof_source) {} 12 | 13 | ProofSourceGoquic::~ProofSourceGoquic() { 14 | ReleaseProofSource_C(go_proof_source_); 15 | } 16 | 17 | void ProofSourceGoquic::AddCert(char* cert_c, size_t cert_sz) { 18 | certs_.push_back(std::string(cert_c, cert_sz)); 19 | } 20 | 21 | void ProofSourceGoquic::BuildCertChain() { 22 | chain_ = new ProofSource::Chain(certs_); 23 | } 24 | 25 | // ProofSource interface 26 | bool ProofSourceGoquic::GetProof(const net::IPAddress& server_ip, 27 | const std::string& hostname, 28 | const std::string& server_config, 29 | QuicVersion quic_version, 30 | base::StringPiece chlo_hash, 31 | scoped_refptr* out_chain, 32 | std::string* out_signature, 33 | std::string* out_leaf_cert_sct) { 34 | char* c_out_signature; 35 | size_t c_out_signature_sz; 36 | 37 | auto server_ip_bytes = server_ip.bytes(); 38 | auto chlo_hash_str = chlo_hash.as_string(); 39 | 40 | int ret = GetProof_C(go_proof_source_, 41 | reinterpret_cast(server_ip_bytes.data()), server_ip_bytes.size(), 42 | (char*)hostname.c_str(), (size_t)hostname.length(), 43 | (char*)server_config.c_str(), (size_t)server_config.length(), 44 | (int)quic_version, 45 | (char*)chlo_hash_str.c_str(), (size_t)chlo_hash_str.length(), 46 | &c_out_signature, &c_out_signature_sz); 47 | 48 | if (!ret) { 49 | return false; 50 | } 51 | 52 | std::string signature(c_out_signature, c_out_signature_sz); 53 | free(c_out_signature); // Created from go side 54 | 55 | *out_chain = chain_; 56 | *out_signature = signature; 57 | 58 | return true; 59 | 60 | //TODO(hodduc): cache? 61 | } 62 | 63 | void ProofSourceGoquic::GetProof(const IPAddress& server_ip, 64 | const std::string& hostname, 65 | const std::string& server_config, 66 | QuicVersion quic_version, 67 | base::StringPiece chlo_hash, 68 | std::unique_ptr callback) { 69 | // As a transitional implementation, just call the synchronous version of 70 | // GetProof, then invoke the callback with the results and destroy it. 71 | scoped_refptr chain; 72 | std::string signature; 73 | std::string leaf_cert_sct; 74 | const bool ok = GetProof(server_ip, hostname, server_config, quic_version, 75 | chlo_hash, &chain, &signature, &leaf_cert_sct); 76 | callback->Run(ok, chain, signature, leaf_cert_sct, nullptr /* details */); 77 | } 78 | 79 | } // namespace net 80 | -------------------------------------------------------------------------------- /src/proof_source_goquic.h: -------------------------------------------------------------------------------- 1 | #ifndef __PROOF_SOURCE_GOQUIC__H__ 2 | #define __PROOF_SOURCE_GOQUIC__H__ 3 | 4 | #include 5 | 6 | #include "net/quic/core/crypto/proof_source.h" 7 | #include "net/base/host_port_pair.h" 8 | #include "go_structs.h" 9 | 10 | namespace net { 11 | 12 | class IPAddress; 13 | 14 | // This should be thread-safe, because multiple dispatcher may concurrently call 15 | // GetProof() 16 | class ProofSourceGoquic : public ProofSource { 17 | public: 18 | ProofSourceGoquic(GoPtr go_proof_source); 19 | ~ProofSourceGoquic() override; 20 | 21 | // Initialize functions. 22 | // BuildCertChain should be called after all certs be added. 23 | void AddCert(char* cert_c, size_t cert_sz); 24 | void BuildCertChain(); 25 | 26 | // ProofSource interface 27 | bool GetProof(const IPAddress& server_ip, 28 | const std::string& hostname, 29 | const std::string& server_config, 30 | QuicVersion quic_version, 31 | base::StringPiece chlo_hash, 32 | scoped_refptr* out_chain, 33 | std::string* out_signature, 34 | std::string* out_leaf_cert_sct) override; 35 | 36 | void GetProof(const IPAddress& server_ip, 37 | const std::string& hostname, 38 | const std::string& server_config, 39 | QuicVersion quic_version, 40 | base::StringPiece chlo_hash, 41 | std::unique_ptr callback) override; 42 | 43 | private: 44 | GoPtr go_proof_source_; 45 | //std::map*> certs_cache_; 46 | std::vector certs_; 47 | scoped_refptr chain_; 48 | DISALLOW_COPY_AND_ASSIGN(ProofSourceGoquic); 49 | }; 50 | 51 | } // namespace net 52 | 53 | #endif // __PROOF_SOURCE_GOQUIC__H__ 54 | -------------------------------------------------------------------------------- /statistics.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include 4 | // #include "src/go_structs.h" 5 | import "C" 6 | 7 | type ServerStatistics struct { 8 | SessionStatistics []SessionStatistics 9 | } 10 | 11 | type DispatcherStatistics struct { 12 | SessionStatistics []SessionStatistics 13 | } 14 | 15 | type SessionStatistics struct { 16 | Cstat C.struct_ConnStat 17 | } 18 | 19 | type statCallback chan DispatcherStatistics 20 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/handlers/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 The Gorilla Handlers Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are met: 5 | 6 | Redistributions of source code must retain the above copyright notice, this 7 | list of conditions and the following disclaimer. 8 | 9 | Redistributions in binary form must reproduce the above copyright notice, 10 | this list of conditions and the following disclaimer in the documentation 11 | and/or other materials provided with the distribution. 12 | 13 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 14 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 15 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 16 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 17 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 18 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 19 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 20 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 21 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 22 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 23 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/handlers/README.md: -------------------------------------------------------------------------------- 1 | gorilla/handlers 2 | ================ 3 | [![GoDoc](https://godoc.org/github.com/gorilla/handlers?status.svg)](https://godoc.org/github.com/gorilla/handlers) [![Build Status](https://travis-ci.org/gorilla/handlers.svg?branch=master)](https://travis-ci.org/gorilla/handlers) 4 | 5 | Package handlers is a collection of handlers (aka "HTTP middleware") for use 6 | with Go's `net/http` package (or any framework supporting `http.Handler`), including: 7 | 8 | * [**LoggingHandler**](https://godoc.org/github.com/gorilla/handlers#LoggingHandler) for logging HTTP requests in the Apache [Common Log 9 | Format](http://httpd.apache.org/docs/2.2/logs.html#common). 10 | * [**CombinedLoggingHandler**](https://godoc.org/github.com/gorilla/handlers#CombinedLoggingHandler) for logging HTTP requests in the Apache [Combined Log 11 | Format](http://httpd.apache.org/docs/2.2/logs.html#combined) commonly used by 12 | both Apache and nginx. 13 | * [**CompressHandler**](https://godoc.org/github.com/gorilla/handlers#CompressHandler) for gzipping responses. 14 | * [**ContentTypeHandler**](https://godoc.org/github.com/gorilla/handlers#ContentTypeHandler) for validating requests against a list of accepted 15 | content types. 16 | * [**MethodHandler**](https://godoc.org/github.com/gorilla/handlers#MethodHandler) for matching HTTP methods against handlers in a 17 | `map[string]http.Handler` 18 | * [**ProxyHeaders**](https://godoc.org/github.com/gorilla/handlers#ProxyHeaders) for populating `r.RemoteAddr` and `r.URL.Scheme` based on the 19 | `X-Forwarded-For`, `X-Real-IP`, `X-Forwarded-Proto` and RFC7239 `Forwarded` 20 | headers when running a Go server behind a HTTP reverse proxy. 21 | * [**CanonicalHost**](https://godoc.org/github.com/gorilla/handlers#CanonicalHost) for re-directing to the preferred host when handling multiple 22 | domains (i.e. multiple CNAME aliases). 23 | * [**RecoveryHandler**](https://godoc.org/github.com/gorilla/handlers#RecoveryHandler) for recovering from unexpected panics. 24 | 25 | Other handlers are documented [on the Gorilla 26 | website](http://www.gorillatoolkit.org/pkg/handlers). 27 | 28 | ## Example 29 | 30 | A simple example using `handlers.LoggingHandler` and `handlers.CompressHandler`: 31 | 32 | ```go 33 | import ( 34 | "net/http" 35 | "github.com/gorilla/handlers" 36 | ) 37 | 38 | func main() { 39 | r := http.NewServeMux() 40 | 41 | // Only log requests to our admin dashboard to stdout 42 | r.Handle("/admin", handlers.LoggingHandler(os.Stdout, http.HandlerFunc(ShowAdminDashboard))) 43 | r.HandleFunc("/", ShowIndex) 44 | 45 | // Wrap our server with our gzip handler to gzip compress all responses. 46 | http.ListenAndServe(":8000", handlers.CompressHandler(r)) 47 | } 48 | ``` 49 | 50 | ## License 51 | 52 | BSD licensed. See the included LICENSE file for details. 53 | 54 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/handlers/canonical.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "net/http" 5 | "net/url" 6 | "strings" 7 | ) 8 | 9 | type canonical struct { 10 | h http.Handler 11 | domain string 12 | code int 13 | } 14 | 15 | // CanonicalHost is HTTP middleware that re-directs requests to the canonical 16 | // domain. It accepts a domain and a status code (e.g. 301 or 302) and 17 | // re-directs clients to this domain. The existing request path is maintained. 18 | // 19 | // Note: If the provided domain is considered invalid by url.Parse or otherwise 20 | // returns an empty scheme or host, clients are not re-directed. 21 | // 22 | // Example: 23 | // 24 | // r := mux.NewRouter() 25 | // canonical := handlers.CanonicalHost("http://www.gorillatoolkit.org", 302) 26 | // r.HandleFunc("/route", YourHandler) 27 | // 28 | // log.Fatal(http.ListenAndServe(":7000", canonical(r))) 29 | // 30 | func CanonicalHost(domain string, code int) func(h http.Handler) http.Handler { 31 | fn := func(h http.Handler) http.Handler { 32 | return canonical{h, domain, code} 33 | } 34 | 35 | return fn 36 | } 37 | 38 | func (c canonical) ServeHTTP(w http.ResponseWriter, r *http.Request) { 39 | dest, err := url.Parse(c.domain) 40 | if err != nil { 41 | // Call the next handler if the provided domain fails to parse. 42 | c.h.ServeHTTP(w, r) 43 | return 44 | } 45 | 46 | if dest.Scheme == "" || dest.Host == "" { 47 | // Call the next handler if the scheme or host are empty. 48 | // Note that url.Parse won't fail on in this case. 49 | c.h.ServeHTTP(w, r) 50 | return 51 | } 52 | 53 | if !strings.EqualFold(cleanHost(r.Host), dest.Host) { 54 | // Re-build the destination URL 55 | dest := dest.Scheme + "://" + dest.Host + r.URL.Path 56 | if r.URL.RawQuery != "" { 57 | dest += "?" + r.URL.RawQuery 58 | } 59 | http.Redirect(w, r, dest, c.code) 60 | return 61 | } 62 | 63 | c.h.ServeHTTP(w, r) 64 | } 65 | 66 | // cleanHost cleans invalid Host headers by stripping anything after '/' or ' '. 67 | // This is backported from Go 1.5 (in response to issue #11206) and attempts to 68 | // mitigate malformed Host headers that do not match the format in RFC7230. 69 | func cleanHost(in string) string { 70 | if i := strings.IndexAny(in, " /"); i != -1 { 71 | return in[:i] 72 | } 73 | return in 74 | } 75 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/handlers/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Package handlers is a collection of handlers (aka "HTTP middleware") for use 3 | with Go's net/http package (or any framework supporting http.Handler). 4 | 5 | The package includes handlers for logging in standardised formats, compressing 6 | HTTP responses, validating content types and other useful tools for manipulating 7 | requests and responses. 8 | */ 9 | package handlers 10 | -------------------------------------------------------------------------------- /vendor/github.com/gorilla/handlers/recovery.go: -------------------------------------------------------------------------------- 1 | package handlers 2 | 3 | import ( 4 | "log" 5 | "net/http" 6 | "runtime/debug" 7 | ) 8 | 9 | type recoveryHandler struct { 10 | handler http.Handler 11 | logger *log.Logger 12 | printStack bool 13 | } 14 | 15 | // RecoveryOption provides a functional approach to define 16 | // configuration for a handler; such as setting the logging 17 | // whether or not to print strack traces on panic. 18 | type RecoveryOption func(http.Handler) 19 | 20 | func parseRecoveryOptions(h http.Handler, opts ...RecoveryOption) http.Handler { 21 | for _, option := range opts { 22 | option(h) 23 | } 24 | 25 | return h 26 | } 27 | 28 | // RecoveryHandler is HTTP middleware that recovers from a panic, 29 | // logs the panic, writes http.StatusInternalServerError, and 30 | // continues to the next handler. 31 | // 32 | // Example: 33 | // 34 | // r := mux.NewRouter() 35 | // r.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 36 | // panic("Unexpected error!") 37 | // }) 38 | // 39 | // http.ListenAndServe(":1123", handlers.RecoveryHandler()(r)) 40 | func RecoveryHandler(opts ...RecoveryOption) func(h http.Handler) http.Handler { 41 | return func(h http.Handler) http.Handler { 42 | r := &recoveryHandler{handler: h} 43 | return parseRecoveryOptions(r, opts...) 44 | } 45 | } 46 | 47 | // RecoveryLogger is a functional option to override 48 | // the default logger 49 | func RecoveryLogger(logger *log.Logger) RecoveryOption { 50 | return func(h http.Handler) { 51 | r := h.(*recoveryHandler) 52 | r.logger = logger 53 | } 54 | } 55 | 56 | // PrintRecoveryStack is a functional option to enable 57 | // or disable printing stack traces on panic. 58 | func PrintRecoveryStack(print bool) RecoveryOption { 59 | return func(h http.Handler) { 60 | r := h.(*recoveryHandler) 61 | r.printStack = print 62 | } 63 | } 64 | 65 | func (h recoveryHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { 66 | defer func() { 67 | if err := recover(); err != nil { 68 | w.WriteHeader(http.StatusInternalServerError) 69 | h.log(err) 70 | } 71 | }() 72 | 73 | h.handler.ServeHTTP(w, req) 74 | } 75 | 76 | func (h recoveryHandler) log(message interface{}) { 77 | if h.logger != nil { 78 | h.logger.Println(message) 79 | } else { 80 | log.Println(message) 81 | } 82 | 83 | if h.printStack { 84 | debug.PrintStack() 85 | } 86 | } 87 | -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013 Theo crevon 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in 11 | all copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 19 | THE SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/deque.go: -------------------------------------------------------------------------------- 1 | package lane 2 | 3 | import ( 4 | "container/list" 5 | "sync" 6 | ) 7 | 8 | // Deque is a head-tail linked list data structure implementation. 9 | // It is based on a doubly linked list container, so that every 10 | // operations time complexity is O(1). 11 | // 12 | // every operations over an instiated Deque are synchronized and 13 | // safe for concurrent usage. 14 | type Deque struct { 15 | sync.RWMutex 16 | container *list.List 17 | capacity int 18 | } 19 | 20 | // NewDeque creates a Deque. 21 | func NewDeque() *Deque { 22 | return NewCappedDeque(-1) 23 | } 24 | 25 | // NewCappedDeque creates a Deque with the specified capacity limit. 26 | func NewCappedDeque(capacity int) *Deque { 27 | return &Deque{ 28 | container: list.New(), 29 | capacity: capacity, 30 | } 31 | } 32 | 33 | // Append inserts element at the back of the Deque in a O(1) time complexity, 34 | // returning true if successful or false if the deque is at capacity. 35 | func (s *Deque) Append(item interface{}) bool { 36 | s.Lock() 37 | defer s.Unlock() 38 | 39 | if s.capacity < 0 || s.container.Len() < s.capacity { 40 | s.container.PushBack(item) 41 | return true 42 | } 43 | 44 | return false 45 | } 46 | 47 | // Prepend inserts element at the Deques front in a O(1) time complexity, 48 | // returning true if successful or false if the deque is at capacity. 49 | func (s *Deque) Prepend(item interface{}) bool { 50 | s.Lock() 51 | defer s.Unlock() 52 | 53 | if s.capacity < 0 || s.container.Len() < s.capacity { 54 | s.container.PushFront(item) 55 | return true 56 | } 57 | 58 | return false 59 | } 60 | 61 | // Pop removes the last element of the deque in a O(1) time complexity 62 | func (s *Deque) Pop() interface{} { 63 | s.Lock() 64 | defer s.Unlock() 65 | 66 | var item interface{} = nil 67 | var lastContainerItem *list.Element = nil 68 | 69 | lastContainerItem = s.container.Back() 70 | if lastContainerItem != nil { 71 | item = s.container.Remove(lastContainerItem) 72 | } 73 | 74 | return item 75 | } 76 | 77 | // Shift removes the first element of the deque in a O(1) time complexity 78 | func (s *Deque) Shift() interface{} { 79 | s.Lock() 80 | defer s.Unlock() 81 | 82 | var item interface{} = nil 83 | var firstContainerItem *list.Element = nil 84 | 85 | firstContainerItem = s.container.Front() 86 | if firstContainerItem != nil { 87 | item = s.container.Remove(firstContainerItem) 88 | } 89 | 90 | return item 91 | } 92 | 93 | // First returns the first value stored in the deque in a O(1) time complexity 94 | func (s *Deque) First() interface{} { 95 | s.RLock() 96 | defer s.RUnlock() 97 | 98 | item := s.container.Front() 99 | if item != nil { 100 | return item.Value 101 | } else { 102 | return nil 103 | } 104 | } 105 | 106 | // Last returns the last value stored in the deque in a O(1) time complexity 107 | func (s *Deque) Last() interface{} { 108 | s.RLock() 109 | defer s.RUnlock() 110 | 111 | item := s.container.Back() 112 | if item != nil { 113 | return item.Value 114 | } else { 115 | return nil 116 | } 117 | } 118 | 119 | // Size returns the actual deque size 120 | func (s *Deque) Size() int { 121 | s.RLock() 122 | defer s.RUnlock() 123 | 124 | return s.container.Len() 125 | } 126 | 127 | // Capacity returns the capacity of the deque, or -1 if unlimited 128 | func (s *Deque) Capacity() int { 129 | s.RLock() 130 | defer s.RUnlock() 131 | return s.capacity 132 | } 133 | 134 | // Empty checks if the deque is empty 135 | func (s *Deque) Empty() bool { 136 | s.RLock() 137 | defer s.RUnlock() 138 | 139 | return s.container.Len() == 0 140 | } 141 | 142 | // Full checks if the deque is full 143 | func (s *Deque) Full() bool { 144 | s.RLock() 145 | defer s.RUnlock() 146 | 147 | return s.capacity >= 0 && s.container.Len() >= s.capacity 148 | } 149 | -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/doc.go: -------------------------------------------------------------------------------- 1 | /* 2 | Lane package provides queue, priority queue, stack and deque data structures 3 | implementations. Its was designed with simplicity, performance, and concurrent 4 | usage in mind. 5 | */ 6 | package lane 7 | -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/pqueue.go: -------------------------------------------------------------------------------- 1 | package lane 2 | 3 | import ( 4 | "fmt" 5 | "sync" 6 | ) 7 | 8 | // PQType represents a priority queue ordering kind (see MAXPQ and MINPQ) 9 | type PQType int 10 | 11 | const ( 12 | MAXPQ PQType = iota 13 | MINPQ 14 | ) 15 | 16 | type item struct { 17 | value interface{} 18 | priority int 19 | } 20 | 21 | // PQueue is a heap priority queue data structure implementation. 22 | // It can be whether max or min ordered and it is synchronized 23 | // and is safe for concurrent operations. 24 | type PQueue struct { 25 | sync.RWMutex 26 | items []*item 27 | elemsCount int 28 | comparator func(int, int) bool 29 | } 30 | 31 | func newItem(value interface{}, priority int) *item { 32 | return &item{ 33 | value: value, 34 | priority: priority, 35 | } 36 | } 37 | 38 | func (i *item) String() string { 39 | return fmt.Sprintf("", i.value, i.priority) 40 | } 41 | 42 | // NewPQueue creates a new priority queue with the provided pqtype 43 | // ordering type 44 | func NewPQueue(pqType PQType) *PQueue { 45 | var cmp func(int, int) bool 46 | 47 | if pqType == MAXPQ { 48 | cmp = max 49 | } else { 50 | cmp = min 51 | } 52 | 53 | items := make([]*item, 1) 54 | items[0] = nil // Heap queue first element should always be nil 55 | 56 | return &PQueue{ 57 | items: items, 58 | elemsCount: 0, 59 | comparator: cmp, 60 | } 61 | } 62 | 63 | // Push the value item into the priority queue with provided priority. 64 | func (pq *PQueue) Push(value interface{}, priority int) { 65 | item := newItem(value, priority) 66 | 67 | pq.Lock() 68 | pq.items = append(pq.items, item) 69 | pq.elemsCount += 1 70 | pq.swim(pq.size()) 71 | pq.Unlock() 72 | } 73 | 74 | // Pop and returns the highest/lowest priority item (depending on whether 75 | // you're using a MINPQ or MAXPQ) from the priority queue 76 | func (pq *PQueue) Pop() (interface{}, int) { 77 | pq.Lock() 78 | defer pq.Unlock() 79 | 80 | if pq.size() < 1 { 81 | return nil, 0 82 | } 83 | 84 | var max *item = pq.items[1] 85 | 86 | pq.exch(1, pq.size()) 87 | pq.items = pq.items[0:pq.size()] 88 | pq.elemsCount -= 1 89 | pq.sink(1) 90 | 91 | return max.value, max.priority 92 | } 93 | 94 | // Head returns the highest/lowest priority item (depending on whether 95 | // you're using a MINPQ or MAXPQ) from the priority queue 96 | func (pq *PQueue) Head() (interface{}, int) { 97 | pq.RLock() 98 | defer pq.RUnlock() 99 | 100 | if pq.size() < 1 { 101 | return nil, 0 102 | } 103 | 104 | headValue := pq.items[1].value 105 | headPriority := pq.items[1].priority 106 | 107 | return headValue, headPriority 108 | } 109 | 110 | // Size returns the elements present in the priority queue count 111 | func (pq *PQueue) Size() int { 112 | pq.RLock() 113 | defer pq.RUnlock() 114 | return pq.size() 115 | } 116 | 117 | // Check queue is empty 118 | func (pq *PQueue) Empty() bool { 119 | pq.RLock() 120 | defer pq.RUnlock() 121 | return pq.size() == 0 122 | } 123 | 124 | func (pq *PQueue) size() int { 125 | return pq.elemsCount 126 | } 127 | 128 | func max(i, j int) bool { 129 | return i < j 130 | } 131 | 132 | func min(i, j int) bool { 133 | return i > j 134 | } 135 | 136 | func (pq *PQueue) less(i, j int) bool { 137 | return pq.comparator(pq.items[i].priority, pq.items[j].priority) 138 | } 139 | 140 | func (pq *PQueue) exch(i, j int) { 141 | var tmpItem *item = pq.items[i] 142 | 143 | pq.items[i] = pq.items[j] 144 | pq.items[j] = tmpItem 145 | } 146 | 147 | func (pq *PQueue) swim(k int) { 148 | for k > 1 && pq.less(k/2, k) { 149 | pq.exch(k/2, k) 150 | k = k / 2 151 | } 152 | 153 | } 154 | 155 | func (pq *PQueue) sink(k int) { 156 | for 2*k <= pq.size() { 157 | var j int = 2 * k 158 | 159 | if j < pq.size() && pq.less(j, j+1) { 160 | j++ 161 | } 162 | 163 | if !pq.less(k, j) { 164 | break 165 | } 166 | 167 | pq.exch(k, j) 168 | k = j 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/queue.go: -------------------------------------------------------------------------------- 1 | package lane 2 | 3 | // Queue is a FIFO (First in first out) data structure implementation. 4 | // It is based on a deque container and focuses its API on core 5 | // functionalities: Enqueue, Dequeue, Head, Size, Empty. Every operations time complexity 6 | // is O(1). 7 | // 8 | // As it is implemented using a Deque container, every operations 9 | // over an instiated Queue are synchronized and safe for concurrent 10 | // usage. 11 | type Queue struct { 12 | *Deque 13 | } 14 | 15 | func NewQueue() *Queue { 16 | return &Queue{ 17 | Deque: NewDeque(), 18 | } 19 | } 20 | 21 | // Enqueue adds an item at the back of the queue 22 | func (q *Queue) Enqueue(item interface{}) { 23 | q.Prepend(item) 24 | } 25 | 26 | // Dequeue removes and returns the front queue item 27 | func (q *Queue) Dequeue() interface{} { 28 | return q.Pop() 29 | } 30 | 31 | // Head returns the front queue item 32 | func (q *Queue) Head() interface{} { 33 | return q.Last() 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/oleiade/lane/stack.go: -------------------------------------------------------------------------------- 1 | package lane 2 | 3 | // Stack is a LIFO (Last in first out) data structure implementation. 4 | // It is based on a deque container and focuses its API on core 5 | // functionalities: Push, Pop, Head, Size, Empty. Every operations time complexity 6 | // is O(1). 7 | // 8 | // As it is implemented using a Deque container, every operations 9 | // over an instiated Stack are synchronized and safe for concurrent 10 | // usage. 11 | type Stack struct { 12 | *Deque 13 | } 14 | 15 | func NewStack() *Stack { 16 | return &Stack{ 17 | Deque: NewDeque(), 18 | } 19 | } 20 | 21 | // Push adds on an item on the top of the Stack 22 | func (s *Stack) Push(item interface{}) { 23 | s.Prepend(item) 24 | } 25 | 26 | // Pop removes and returns the item on the top of the Stack 27 | func (s *Stack) Pop() interface{} { 28 | return s.Shift() 29 | } 30 | 31 | // Head returns the item on the top of the stack 32 | func (s *Stack) Head() interface{} { 33 | return s.First() 34 | } 35 | -------------------------------------------------------------------------------- /vendor/github.com/vanillahsu/go_reuseport/LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Max Riveiro 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /vendor/github.com/vanillahsu/go_reuseport/README.md: -------------------------------------------------------------------------------- 1 | # GO_REUSEPORT 2 | 3 | [![Build Status](https://travis-ci.org/kavu/go_reuseport.png?branch=master)](https://travis-ci.org/kavu/go_reuseport) 4 | [![GoDoc](https://godoc.org/github.com/kavu/go_reuseport?status.png)](https://godoc.org/github.com/kavu/go_reuseport) 5 | 6 | **GO_REUSEPORT** is a little expirement to create a `net.Listener` that supports [SO_REUSEPORT](http://lwn.net/Articles/542629/) socket option. 7 | 8 | For now, Darwin and Linux (from 3.9) systems are supported. I'll be pleased if you'll test other systems and tell me the results. 9 | documentation on [godoc.org](http://godoc.org/github.com/kavu/go_reuseport "go_reuseport documentation"). 10 | 11 | ## Example ## 12 | 13 | ```go 14 | package main 15 | 16 | import ( 17 | "fmt" 18 | "html" 19 | "net/http" 20 | "os" 21 | "runtime" 22 | "github.com/kavu/go_reuseport" 23 | ) 24 | 25 | func main() { 26 | runtime.GOMAXPROCS(runtime.NumCPU()) 27 | 28 | listener, err := reuseport.NewReusablePortListener("tcp4", "localhost:8881") 29 | if err != nil { 30 | panic(err) 31 | } 32 | defer listener.Close() 33 | 34 | server := &http.Server{} 35 | http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { 36 | fmt.Println(os.Getgid()) 37 | fmt.Fprintf(w, "Hello, %q\n", html.EscapeString(r.URL.Path)) 38 | }) 39 | 40 | panic(server.Serve(listener)) 41 | } 42 | ``` 43 | 44 | Now you can run several instances of this tint server without `Address already in use` errors. 45 | 46 | ## Thanks 47 | 48 | Inspired by [Artur Siekielski](https://github.com/aartur) [post](http://freeprogrammersblog.vhex.net/post/linux-39-introdued-new-way-of-writing-socket-servers/2) about `SO_REUSEPORT`. 49 | 50 | -------------------------------------------------------------------------------- /vendor/github.com/vanillahsu/go_reuseport/reuseport_bsd.go: -------------------------------------------------------------------------------- 1 | // +build darwin dragonfly freebsd netbsd openbsd 2 | 3 | package reuseport 4 | 5 | import "syscall" 6 | 7 | var reusePort = syscall.SO_REUSEPORT 8 | -------------------------------------------------------------------------------- /vendor/github.com/vanillahsu/go_reuseport/reuseport_linux.go: -------------------------------------------------------------------------------- 1 | package reuseport 2 | 3 | var reusePort = 0x0F 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2009 The Go Authors. All rights reserved. 2 | 3 | Redistribution and use in source and binary forms, with or without 4 | modification, are permitted provided that the following conditions are 5 | met: 6 | 7 | * Redistributions of source code must retain the above copyright 8 | notice, this list of conditions and the following disclaimer. 9 | * Redistributions in binary form must reproduce the above 10 | copyright notice, this list of conditions and the following disclaimer 11 | in the documentation and/or other materials provided with the 12 | distribution. 13 | * Neither the name of Google Inc. nor the names of its 14 | contributors may be used to endorse or promote products derived from 15 | this software without specific prior written permission. 16 | 17 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/PATENTS: -------------------------------------------------------------------------------- 1 | Additional IP Rights Grant (Patents) 2 | 3 | "This implementation" means the copyrightable works distributed by 4 | Google as part of the Go project. 5 | 6 | Google hereby grants to You a perpetual, worldwide, non-exclusive, 7 | no-charge, royalty-free, irrevocable (except as stated in this section) 8 | patent license to make, have made, use, offer to sell, sell, import, 9 | transfer and otherwise run, modify and propagate the contents of this 10 | implementation of Go, where such license applies only to those patent 11 | claims, both currently owned or controlled by Google and acquired in 12 | the future, licensable by Google that are necessarily infringed by this 13 | implementation of Go. This grant does not include claims that would be 14 | infringed only as a consequence of further modification of this 15 | implementation. If you or your agent or exclusive licensee institute or 16 | order or agree to the institution of patent litigation against any 17 | entity (including a cross-claim or counterclaim in a lawsuit) alleging 18 | that this implementation of Go or any code incorporated within this 19 | implementation of Go constitutes direct or contributory patent 20 | infringement, or inducement of patent infringement, then any patent 21 | rights granted to you under this License for this implementation of Go 22 | shall terminate as of the date such litigation is filed. 23 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Dockerfile: -------------------------------------------------------------------------------- 1 | # 2 | # This Dockerfile builds a recent curl with HTTP/2 client support, using 3 | # a recent nghttp2 build. 4 | # 5 | # See the Makefile for how to tag it. If Docker and that image is found, the 6 | # Go tests use this curl binary for integration tests. 7 | # 8 | 9 | FROM ubuntu:trusty 10 | 11 | RUN apt-get update && \ 12 | apt-get upgrade -y && \ 13 | apt-get install -y git-core build-essential wget 14 | 15 | RUN apt-get install -y --no-install-recommends \ 16 | autotools-dev libtool pkg-config zlib1g-dev \ 17 | libcunit1-dev libssl-dev libxml2-dev libevent-dev \ 18 | automake autoconf 19 | 20 | # The list of packages nghttp2 recommends for h2load: 21 | RUN apt-get install -y --no-install-recommends make binutils \ 22 | autoconf automake autotools-dev \ 23 | libtool pkg-config zlib1g-dev libcunit1-dev libssl-dev libxml2-dev \ 24 | libev-dev libevent-dev libjansson-dev libjemalloc-dev \ 25 | cython python3.4-dev python-setuptools 26 | 27 | # Note: setting NGHTTP2_VER before the git clone, so an old git clone isn't cached: 28 | ENV NGHTTP2_VER 895da9a 29 | RUN cd /root && git clone https://github.com/tatsuhiro-t/nghttp2.git 30 | 31 | WORKDIR /root/nghttp2 32 | RUN git reset --hard $NGHTTP2_VER 33 | RUN autoreconf -i 34 | RUN automake 35 | RUN autoconf 36 | RUN ./configure 37 | RUN make 38 | RUN make install 39 | 40 | WORKDIR /root 41 | RUN wget http://curl.haxx.se/download/curl-7.45.0.tar.gz 42 | RUN tar -zxvf curl-7.45.0.tar.gz 43 | WORKDIR /root/curl-7.45.0 44 | RUN ./configure --with-ssl --with-nghttp2=/usr/local 45 | RUN make 46 | RUN make install 47 | RUN ldconfig 48 | 49 | CMD ["-h"] 50 | ENTRYPOINT ["/usr/local/bin/curl"] 51 | 52 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/Makefile: -------------------------------------------------------------------------------- 1 | curlimage: 2 | docker build -t gohttp2/curl . 3 | 4 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/README: -------------------------------------------------------------------------------- 1 | This is a work-in-progress HTTP/2 implementation for Go. 2 | 3 | It will eventually live in the Go standard library and won't require 4 | any changes to your code to use. It will just be automatic. 5 | 6 | Status: 7 | 8 | * The server support is pretty good. A few things are missing 9 | but are being worked on. 10 | * The client work has just started but shares a lot of code 11 | is coming along much quicker. 12 | 13 | Docs are at https://godoc.org/golang.org/x/net/http2 14 | 15 | Demo test server at https://http2.golang.org/ 16 | 17 | Help & bug reports welcome! 18 | 19 | Contributing: https://golang.org/doc/contribute.html 20 | Bugs: https://golang.org/issue/new?title=x/net/http2:+ 21 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/configure_transport.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "fmt" 12 | "net/http" 13 | ) 14 | 15 | func configureTransport(t1 *http.Transport) (*Transport, error) { 16 | connPool := new(clientConnPool) 17 | t2 := &Transport{ 18 | ConnPool: noDialClientConnPool{connPool}, 19 | t1: t1, 20 | } 21 | connPool.t = t2 22 | if err := registerHTTPSProtocol(t1, noDialH2RoundTripper{t2}); err != nil { 23 | return nil, err 24 | } 25 | if t1.TLSClientConfig == nil { 26 | t1.TLSClientConfig = new(tls.Config) 27 | } 28 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "h2") { 29 | t1.TLSClientConfig.NextProtos = append([]string{"h2"}, t1.TLSClientConfig.NextProtos...) 30 | } 31 | if !strSliceContains(t1.TLSClientConfig.NextProtos, "http/1.1") { 32 | t1.TLSClientConfig.NextProtos = append(t1.TLSClientConfig.NextProtos, "http/1.1") 33 | } 34 | upgradeFn := func(authority string, c *tls.Conn) http.RoundTripper { 35 | addr := authorityAddr("https", authority) 36 | if used, err := connPool.addConnIfNeeded(addr, t2, c); err != nil { 37 | go c.Close() 38 | return erringRoundTripper{err} 39 | } else if !used { 40 | // Turns out we don't need this c. 41 | // For example, two goroutines made requests to the same host 42 | // at the same time, both kicking off TCP dials. (since protocol 43 | // was unknown) 44 | go c.Close() 45 | } 46 | return t2 47 | } 48 | if m := t1.TLSNextProto; len(m) == 0 { 49 | t1.TLSNextProto = map[string]func(string, *tls.Conn) http.RoundTripper{ 50 | "h2": upgradeFn, 51 | } 52 | } else { 53 | m["h2"] = upgradeFn 54 | } 55 | return t2, nil 56 | } 57 | 58 | // registerHTTPSProtocol calls Transport.RegisterProtocol but 59 | // convering panics into errors. 60 | func registerHTTPSProtocol(t *http.Transport, rt http.RoundTripper) (err error) { 61 | defer func() { 62 | if e := recover(); e != nil { 63 | err = fmt.Errorf("%v", e) 64 | } 65 | }() 66 | t.RegisterProtocol("https", rt) 67 | return nil 68 | } 69 | 70 | // noDialH2RoundTripper is a RoundTripper which only tries to complete the request 71 | // if there's already has a cached connection to the host. 72 | type noDialH2RoundTripper struct{ t *Transport } 73 | 74 | func (rt noDialH2RoundTripper) RoundTrip(req *http.Request) (*http.Response, error) { 75 | res, err := rt.t.RoundTrip(req) 76 | if err == ErrNoCachedConn { 77 | return nil, http.ErrSkipAltProtocol 78 | } 79 | return res, err 80 | } 81 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/fixed_buffer.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "errors" 9 | ) 10 | 11 | // fixedBuffer is an io.ReadWriter backed by a fixed size buffer. 12 | // It never allocates, but moves old data as new data is written. 13 | type fixedBuffer struct { 14 | buf []byte 15 | r, w int 16 | } 17 | 18 | var ( 19 | errReadEmpty = errors.New("read from empty fixedBuffer") 20 | errWriteFull = errors.New("write on full fixedBuffer") 21 | ) 22 | 23 | // Read copies bytes from the buffer into p. 24 | // It is an error to read when no data is available. 25 | func (b *fixedBuffer) Read(p []byte) (n int, err error) { 26 | if b.r == b.w { 27 | return 0, errReadEmpty 28 | } 29 | n = copy(p, b.buf[b.r:b.w]) 30 | b.r += n 31 | if b.r == b.w { 32 | b.r = 0 33 | b.w = 0 34 | } 35 | return n, nil 36 | } 37 | 38 | // Len returns the number of bytes of the unread portion of the buffer. 39 | func (b *fixedBuffer) Len() int { 40 | return b.w - b.r 41 | } 42 | 43 | // Write copies bytes from p into the buffer. 44 | // It is an error to write more data than the buffer can hold. 45 | func (b *fixedBuffer) Write(p []byte) (n int, err error) { 46 | // Slide existing data to beginning. 47 | if b.r > 0 && len(p) > len(b.buf)-b.w { 48 | copy(b.buf, b.buf[b.r:b.w]) 49 | b.w -= b.r 50 | b.r = 0 51 | } 52 | 53 | // Write new data. 54 | n = copy(b.buf[b.w:], p) 55 | b.w += n 56 | if n < len(p) { 57 | err = errWriteFull 58 | } 59 | return n, err 60 | } 61 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/flow.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // Flow control 6 | 7 | package http2 8 | 9 | // flow is the flow control window's size. 10 | type flow struct { 11 | // n is the number of DATA bytes we're allowed to send. 12 | // A flow is kept both on a conn and a per-stream. 13 | n int32 14 | 15 | // conn points to the shared connection-level flow that is 16 | // shared by all streams on that conn. It is nil for the flow 17 | // that's on the conn directly. 18 | conn *flow 19 | } 20 | 21 | func (f *flow) setConnFlow(cf *flow) { f.conn = cf } 22 | 23 | func (f *flow) available() int32 { 24 | n := f.n 25 | if f.conn != nil && f.conn.n < n { 26 | n = f.conn.n 27 | } 28 | return n 29 | } 30 | 31 | func (f *flow) take(n int32) { 32 | if n > f.available() { 33 | panic("internal error: took too much") 34 | } 35 | f.n -= n 36 | if f.conn != nil { 37 | f.conn.n -= n 38 | } 39 | } 40 | 41 | // add adds n bytes (positive or negative) to the flow control window. 42 | // It returns false if the sum would exceed 2^31-1. 43 | func (f *flow) add(n int32) bool { 44 | remain := (1<<31 - 1) - f.n 45 | if n > remain { 46 | return false 47 | } 48 | f.n += n 49 | return true 50 | } 51 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "net/http" 12 | "time" 13 | ) 14 | 15 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 16 | return t1.ExpectContinueTimeout 17 | } 18 | 19 | // isBadCipher reports whether the cipher is blacklisted by the HTTP/2 spec. 20 | func isBadCipher(cipher uint16) bool { 21 | switch cipher { 22 | case tls.TLS_RSA_WITH_RC4_128_SHA, 23 | tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, 24 | tls.TLS_RSA_WITH_AES_128_CBC_SHA, 25 | tls.TLS_RSA_WITH_AES_256_CBC_SHA, 26 | tls.TLS_RSA_WITH_AES_128_GCM_SHA256, 27 | tls.TLS_RSA_WITH_AES_256_GCM_SHA384, 28 | tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 29 | tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 30 | tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 31 | tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, 32 | tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 33 | tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 34 | tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: 35 | // Reject cipher suites from Appendix A. 36 | // "This list includes those cipher suites that do not 37 | // offer an ephemeral key exchange and those that are 38 | // based on the TLS null, stream or block cipher type" 39 | return true 40 | default: 41 | return false 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "context" 11 | "net" 12 | "net/http" 13 | "net/http/httptrace" 14 | "time" 15 | ) 16 | 17 | type contextContext interface { 18 | context.Context 19 | } 20 | 21 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 22 | ctx, cancel = context.WithCancel(context.Background()) 23 | ctx = context.WithValue(ctx, http.LocalAddrContextKey, c.LocalAddr()) 24 | if hs := opts.baseConfig(); hs != nil { 25 | ctx = context.WithValue(ctx, http.ServerContextKey, hs) 26 | } 27 | return 28 | } 29 | 30 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 31 | return context.WithCancel(ctx) 32 | } 33 | 34 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 35 | return req.WithContext(ctx) 36 | } 37 | 38 | type clientTrace httptrace.ClientTrace 39 | 40 | func reqContext(r *http.Request) context.Context { return r.Context() } 41 | 42 | func setResponseUncompressed(res *http.Response) { res.Uncompressed = true } 43 | 44 | func traceGotConn(req *http.Request, cc *ClientConn) { 45 | trace := httptrace.ContextClientTrace(req.Context()) 46 | if trace == nil || trace.GotConn == nil { 47 | return 48 | } 49 | ci := httptrace.GotConnInfo{Conn: cc.tconn} 50 | cc.mu.Lock() 51 | ci.Reused = cc.nextStreamID > 1 52 | ci.WasIdle = len(cc.streams) == 0 && ci.Reused 53 | if ci.WasIdle && !cc.lastActive.IsZero() { 54 | ci.IdleTime = time.Now().Sub(cc.lastActive) 55 | } 56 | cc.mu.Unlock() 57 | 58 | trace.GotConn(ci) 59 | } 60 | 61 | func traceWroteHeaders(trace *clientTrace) { 62 | if trace != nil && trace.WroteHeaders != nil { 63 | trace.WroteHeaders() 64 | } 65 | } 66 | 67 | func traceGot100Continue(trace *clientTrace) { 68 | if trace != nil && trace.Got100Continue != nil { 69 | trace.Got100Continue() 70 | } 71 | } 72 | 73 | func traceWait100Continue(trace *clientTrace) { 74 | if trace != nil && trace.Wait100Continue != nil { 75 | trace.Wait100Continue() 76 | } 77 | } 78 | 79 | func traceWroteRequest(trace *clientTrace, err error) { 80 | if trace != nil && trace.WroteRequest != nil { 81 | trace.WroteRequest(httptrace.WroteRequestInfo{Err: err}) 82 | } 83 | } 84 | 85 | func traceFirstResponseByte(trace *clientTrace) { 86 | if trace != nil && trace.GotFirstResponseByte != nil { 87 | trace.GotFirstResponseByte() 88 | } 89 | } 90 | 91 | func requestTrace(req *http.Request) *clientTrace { 92 | trace := httptrace.ContextClientTrace(req.Context()) 93 | return (*clientTrace)(trace) 94 | } 95 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/headermap.go: -------------------------------------------------------------------------------- 1 | // Copyright 2014 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | package http2 6 | 7 | import ( 8 | "net/http" 9 | "strings" 10 | ) 11 | 12 | var ( 13 | commonLowerHeader = map[string]string{} // Go-Canonical-Case -> lower-case 14 | commonCanonHeader = map[string]string{} // lower-case -> Go-Canonical-Case 15 | ) 16 | 17 | func init() { 18 | for _, v := range []string{ 19 | "accept", 20 | "accept-charset", 21 | "accept-encoding", 22 | "accept-language", 23 | "accept-ranges", 24 | "age", 25 | "access-control-allow-origin", 26 | "allow", 27 | "authorization", 28 | "cache-control", 29 | "content-disposition", 30 | "content-encoding", 31 | "content-language", 32 | "content-length", 33 | "content-location", 34 | "content-range", 35 | "content-type", 36 | "cookie", 37 | "date", 38 | "etag", 39 | "expect", 40 | "expires", 41 | "from", 42 | "host", 43 | "if-match", 44 | "if-modified-since", 45 | "if-none-match", 46 | "if-unmodified-since", 47 | "last-modified", 48 | "link", 49 | "location", 50 | "max-forwards", 51 | "proxy-authenticate", 52 | "proxy-authorization", 53 | "range", 54 | "referer", 55 | "refresh", 56 | "retry-after", 57 | "server", 58 | "set-cookie", 59 | "strict-transport-security", 60 | "trailer", 61 | "transfer-encoding", 62 | "user-agent", 63 | "vary", 64 | "via", 65 | "www-authenticate", 66 | } { 67 | chk := http.CanonicalHeaderKey(v) 68 | commonLowerHeader[chk] = v 69 | commonCanonHeader[v] = chk 70 | } 71 | } 72 | 73 | func lowerHeader(v string) string { 74 | if s, ok := commonLowerHeader[v]; ok { 75 | return s 76 | } 77 | return strings.ToLower(v) 78 | } 79 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go16.go: -------------------------------------------------------------------------------- 1 | // Copyright 2015 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.6 6 | 7 | package http2 8 | 9 | import ( 10 | "crypto/tls" 11 | "net/http" 12 | "time" 13 | ) 14 | 15 | func configureTransport(t1 *http.Transport) (*Transport, error) { 16 | return nil, errTransportVersion 17 | } 18 | 19 | func transportExpectContinueTimeout(t1 *http.Transport) time.Duration { 20 | return 0 21 | 22 | } 23 | 24 | // isBadCipher reports whether the cipher is blacklisted by the HTTP/2 spec. 25 | func isBadCipher(cipher uint16) bool { 26 | switch cipher { 27 | case tls.TLS_RSA_WITH_RC4_128_SHA, 28 | tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, 29 | tls.TLS_RSA_WITH_AES_128_CBC_SHA, 30 | tls.TLS_RSA_WITH_AES_256_CBC_SHA, 31 | tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, 32 | tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, 33 | tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, 34 | tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, 35 | tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, 36 | tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, 37 | tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA: 38 | // Reject cipher suites from Appendix A. 39 | // "This list includes those cipher suites that do not 40 | // offer an ephemeral key exchange and those that are 41 | // based on the TLS null, stream or block cipher type" 42 | return true 43 | default: 44 | return false 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /vendor/golang.org/x/net/http2/not_go17.go: -------------------------------------------------------------------------------- 1 | // Copyright 2016 The Go Authors. All rights reserved. 2 | // Use of this source code is governed by a BSD-style 3 | // license that can be found in the LICENSE file. 4 | 5 | // +build !go1.7 6 | 7 | package http2 8 | 9 | import ( 10 | "net" 11 | "net/http" 12 | ) 13 | 14 | type contextContext interface{} 15 | 16 | type fakeContext struct{} 17 | 18 | func (fakeContext) Done() <-chan struct{} { return nil } 19 | func (fakeContext) Err() error { panic("should not be called") } 20 | 21 | func reqContext(r *http.Request) fakeContext { 22 | return fakeContext{} 23 | } 24 | 25 | func setResponseUncompressed(res *http.Response) { 26 | // Nothing. 27 | } 28 | 29 | type clientTrace struct{} 30 | 31 | func requestTrace(*http.Request) *clientTrace { return nil } 32 | func traceGotConn(*http.Request, *ClientConn) {} 33 | func traceFirstResponseByte(*clientTrace) {} 34 | func traceWroteHeaders(*clientTrace) {} 35 | func traceWroteRequest(*clientTrace, error) {} 36 | func traceGot100Continue(trace *clientTrace) {} 37 | func traceWait100Continue(trace *clientTrace) {} 38 | 39 | func nop() {} 40 | 41 | func serverConnBaseContext(c net.Conn, opts *ServeConnOpts) (ctx contextContext, cancel func()) { 42 | return nil, nop 43 | } 44 | 45 | func contextWithCancel(ctx contextContext) (_ contextContext, cancel func()) { 46 | return ctx, nop 47 | } 48 | 49 | func requestWithContext(req *http.Request, ctx contextContext) *http.Request { 50 | return req 51 | } 52 | -------------------------------------------------------------------------------- /vendor/vendor.json: -------------------------------------------------------------------------------- 1 | { 2 | "comment": "", 3 | "ignore": "test", 4 | "package": [ 5 | { 6 | "checksumSHA1": "6/9VW/AyJyjRXLu+nbhqGYvOO2k=", 7 | "path": "github.com/gorilla/handlers", 8 | "revision": "a5775781a543af3c6b9f5baf10995e4d14168950", 9 | "revisionTime": "2016-08-16T18:47:29Z" 10 | }, 11 | { 12 | "checksumSHA1": "GNxRPEHfnfvmhuLZM5KDOTvlLAc=", 13 | "path": "github.com/oleiade/lane", 14 | "revision": "3053869314bb02cb983dc2205da8ea2abe46fa96", 15 | "revisionTime": "2016-08-17T06:58:15Z" 16 | }, 17 | { 18 | "checksumSHA1": "00kIGjHPVVmXIsu5JxHaNdZtGGg=", 19 | "path": "github.com/vanillahsu/go_reuseport", 20 | "revision": "087e013b0a0c193ca9b1bb21f453b74aa9b31138", 21 | "revisionTime": "2014-06-03T07:39:48Z" 22 | }, 23 | { 24 | "checksumSHA1": "3YDeFG6PJWWoPAucRUfFuDVPVfs=", 25 | "path": "golang.org/x/net/http2", 26 | "revision": "7394c112eae4dba7e96bfcfe738e6373d61772b4", 27 | "revisionTime": "2016-08-19T20:57:39Z" 28 | }, 29 | { 30 | "checksumSHA1": "EYNaHp7XdLWRydUCE0amEkKAtgk=", 31 | "path": "golang.org/x/net/http2/hpack", 32 | "revision": "7394c112eae4dba7e96bfcfe738e6373d61772b4", 33 | "revisionTime": "2016-08-19T20:57:39Z" 34 | }, 35 | { 36 | "checksumSHA1": "yhndhWXMs/VSEDLks4dNyFMQStA=", 37 | "path": "golang.org/x/net/lex/httplex", 38 | "revision": "7394c112eae4dba7e96bfcfe738e6373d61772b4", 39 | "revisionTime": "2016-08-19T20:57:39Z" 40 | } 41 | ], 42 | "rootPath": "github.com/devsisters/goquic" 43 | } 44 | -------------------------------------------------------------------------------- /writer.go: -------------------------------------------------------------------------------- 1 | package goquic 2 | 3 | // #include 4 | // #include "src/adaptor.h" 5 | import "C" 6 | import ( 7 | "net" 8 | "unsafe" 9 | ) 10 | 11 | type UdpData struct { 12 | Addr *net.UDPAddr 13 | Buf []byte 14 | N int 15 | } 16 | 17 | type ServerWriter struct { 18 | Ch chan UdpData 19 | } 20 | 21 | type ClientWriter struct { 22 | Ch chan UdpData 23 | } 24 | 25 | func NewServerWriter(ch chan UdpData) *ServerWriter { 26 | return &ServerWriter{ch} 27 | } 28 | 29 | func NewClientWriter(ch chan UdpData) *ClientWriter { 30 | return &ClientWriter{ch} 31 | } 32 | 33 | func writeToUDP(go_writer_key int64, peer_ip unsafe.Pointer, peer_ip_sz C.size_t, peer_port uint16, buffer_c unsafe.Pointer, length_c C.size_t, isServer bool) { 34 | buf := C.GoBytes(buffer_c, C.int(length_c)) 35 | 36 | if isServer { 37 | peer_addr := &net.UDPAddr{ 38 | IP: net.IP(C.GoBytes(peer_ip, C.int(peer_ip_sz))), 39 | Port: int(peer_port), 40 | } 41 | 42 | serverWriterPtr.Get(go_writer_key).Ch <- UdpData{Buf: buf, Addr: peer_addr, N: int(length_c)} 43 | } else { 44 | clientWriterPtr.Get(go_writer_key).Ch <- UdpData{Buf: buf, N: int(length_c)} 45 | } 46 | } 47 | 48 | //export WriteToUDP 49 | func WriteToUDP(go_writer_key int64, peer_ip unsafe.Pointer, peer_ip_sz C.size_t, peer_port uint16, buffer_c unsafe.Pointer, length_c C.size_t) { 50 | writeToUDP(go_writer_key, peer_ip, peer_ip_sz, peer_port, buffer_c, length_c, true) 51 | } 52 | 53 | //export WriteToUDPClient 54 | func WriteToUDPClient(go_writer_key int64, peer_ip unsafe.Pointer, peer_ip_sz C.size_t, peer_port uint16, buffer_c unsafe.Pointer, length_c C.size_t) { 55 | writeToUDP(go_writer_key, peer_ip, peer_ip_sz, peer_port, buffer_c, length_c, false) 56 | } 57 | 58 | //export ReleaseClientWriter 59 | func ReleaseClientWriter(go_client_writer_key int64) { 60 | clientWriterPtr.Del(go_client_writer_key) 61 | } 62 | 63 | //export ReleaseServerWriter 64 | func ReleaseServerWriter(go_server_writer_key int64) { 65 | serverWriterPtr.Del(go_server_writer_key) 66 | } 67 | --------------------------------------------------------------------------------