github.com/Psiphon-Labs/psiphon-tunnel-core@v2.0.28+incompatible/psiphon/server/net.go (about) 1 /* 2 * Copyright (c) 2016, Psiphon Inc. 3 * All rights reserved. 4 * 5 * This program is free software: you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License as published by 7 * the Free Software Foundation, either version 3 of the License, or 8 * (at your option) any later version. 9 * 10 * This program is distributed in the hope that it will be useful, 11 * but WITHOUT ANY WARRANTY; without even the implied warranty of 12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 * GNU General Public License for more details. 14 * 15 * You should have received a copy of the GNU General Public License 16 * along with this program. If not, see <http://www.gnu.org/licenses/>. 17 * 18 */ 19 20 // for HTTPSServer.ServeTLS: 21 /* 22 Copyright (c) 2012 The Go Authors. All rights reserved. 23 24 Redistribution and use in source and binary forms, with or without 25 modification, are permitted provided that the following conditions are 26 met: 27 28 * Redistributions of source code must retain the above copyright 29 notice, this list of conditions and the following disclaimer. 30 * Redistributions in binary form must reproduce the above 31 copyright notice, this list of conditions and the following disclaimer 32 in the documentation and/or other materials provided with the 33 distribution. 34 * Neither the name of Google Inc. nor the names of its 35 contributors may be used to endorse or promote products derived from 36 this software without specific prior written permission. 37 38 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 39 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 40 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 41 A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 42 OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 43 SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 44 LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 45 DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 46 THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 47 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 48 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 49 */ 50 51 package server 52 53 import ( 54 "net" 55 "net/http" 56 57 tris "github.com/Psiphon-Labs/tls-tris" 58 ) 59 60 // HTTPSServer is a wrapper around http.Server which adds the 61 // ServeTLS function. 62 type HTTPSServer struct { 63 *http.Server 64 } 65 66 // ServeTLS is similar to http.Serve, but uses TLS. 67 // 68 // The http package has both ListenAndServe and ListenAndServeTLS higher- 69 // level interfaces, but only Serve (not TLS) offers a lower-level interface that 70 // allows the caller to keep a refererence to the Listener, allowing for external 71 // shutdown. ListenAndServeTLS also requires the TLS cert and key to be in files 72 // and we avoid that here. 73 // 74 // Note that the http.Server.TLSConfig field is ignored and the tris.Config 75 // parameter is used intead. 76 func (server *HTTPSServer) ServeTLS(listener net.Listener, config *tris.Config) error { 77 tlsListener := tris.NewListener(listener, config) 78 return server.Serve(tlsListener) 79 }