|
1 | | -// This file was partly from https://github.com/elazarl/goproxy/blob/master/examples/goproxy-customca/cert.go |
| 1 | +// Copyright (C) 2020 CoolSpring8 |
2 | 2 |
|
3 | | -// Copyright (c) 2012 Elazar Leibovich. All rights reserved. |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU General Public License as published by |
| 5 | +// the Free Software Foundation, either version 3 of the License, or |
| 6 | +// (at your option) any later version. |
4 | 7 |
|
5 | | -// Redistribution and use in source and binary forms, with or without |
6 | | -// modification, are permitted provided that the following conditions are |
7 | | -// met: |
| 8 | +// This program is distributed in the hope that it will be useful, |
| 9 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | +// GNU General Public License for more details. |
8 | 12 |
|
9 | | -// * Redistributions of source code must retain the above copyright |
10 | | -// notice, this list of conditions and the following disclaimer. |
11 | | -// * Redistributions in binary form must reproduce the above |
12 | | -// copyright notice, this list of conditions and the following disclaimer |
13 | | -// in the documentation and/or other materials provided with the |
14 | | -// distribution. |
15 | | -// * Neither the name of Elazar Leibovich. nor the names of its |
16 | | -// contributors may be used to endorse or promote products derived from |
17 | | -// this software without specific prior written permission. |
18 | | - |
19 | | -// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
20 | | -// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
21 | | -// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
22 | | -// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
23 | | -// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
24 | | -// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
25 | | -// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
26 | | -// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
27 | | -// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
28 | | -// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
29 | | -// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 13 | +// You should have received a copy of the GNU General Public License |
| 14 | +// along with this program. If not, see <https://www.gnu.org/licenses/>. |
30 | 15 |
|
| 16 | +// Package cert provides operation functions on CA cert and key. |
31 | 17 | package cert |
32 | 18 |
|
33 | 19 | import ( |
34 | 20 | "crypto/rand" |
35 | 21 | "crypto/rsa" |
36 | | - "crypto/tls" |
37 | 22 | "crypto/x509" |
38 | 23 | "crypto/x509/pkix" |
39 | 24 | "encoding/pem" |
40 | 25 | "io/ioutil" |
41 | 26 | "math/big" |
42 | 27 | "os" |
43 | 28 | "time" |
44 | | - |
45 | | - "github.com/elazarl/goproxy" |
46 | 29 | ) |
47 | 30 |
|
48 | 31 | // GetCA returns a CA cert, a CA key or an error in file reading or writing process. |
@@ -114,24 +97,6 @@ func GetCA() ([]byte, []byte, error) { |
114 | 97 | return caCert, caKey, err |
115 | 98 | } |
116 | 99 |
|
117 | | -// SetCA takes CA cert and CA key, and sets up goproxy CA. |
118 | | -// Returns error in parsing and setting CA. |
119 | | -func SetCA(caCert, caKey []byte) error { |
120 | | - goproxyCa, err := tls.X509KeyPair(caCert, caKey) |
121 | | - if err != nil { |
122 | | - return err |
123 | | - } |
124 | | - if goproxyCa.Leaf, err = x509.ParseCertificate(goproxyCa.Certificate[0]); err != nil { |
125 | | - return err |
126 | | - } |
127 | | - goproxy.GoproxyCa = goproxyCa |
128 | | - goproxy.OkConnect = &goproxy.ConnectAction{Action: goproxy.ConnectAccept, TLSConfig: goproxy.TLSConfigFromCA(&goproxyCa)} |
129 | | - goproxy.MitmConnect = &goproxy.ConnectAction{Action: goproxy.ConnectMitm, TLSConfig: goproxy.TLSConfigFromCA(&goproxyCa)} |
130 | | - goproxy.HTTPMitmConnect = &goproxy.ConnectAction{Action: goproxy.ConnectHTTPMitm, TLSConfig: goproxy.TLSConfigFromCA(&goproxyCa)} |
131 | | - goproxy.RejectConnect = &goproxy.ConnectAction{Action: goproxy.ConnectReject, TLSConfig: goproxy.TLSConfigFromCA(&goproxyCa)} |
132 | | - return nil |
133 | | -} |
134 | | - |
135 | 100 | // fileExists checks if a file exists and is not a directory. |
136 | 101 | func fileExists(filename string) bool { |
137 | 102 | info, err := os.Stat(filename) |
|
0 commit comments