-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(ca): repair to Mozilla CA (#147)
Co-authored-by: dyhkwong <50692134+dyhkwong@users.noreply.github.com> (cherry picked from commit efd0d03) Signed-off-by: HystericalDragon <HystericalDragons@proton.me>
- Loading branch information
1 parent
eae969f
commit f5f9bd4
Showing
7 changed files
with
165 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
-----BEGIN PRIVATE KEY----- | ||
MIIEvAIBADANBgkqhkiG9w0BAQEFAASCBKYwggSiAgEAAoIBAQDAEL1EAvGu/IAg | ||
gR1cIZ6QVOpgALx1nUd3ReBdFqyB984NuhZBLBM5uR9Yf2L77ktXfxR+rHLMF4Fy | ||
n5J8YCRRwGyZ6gEekIure1rRCff3hf0RFYolgllDFuQwMnav9B1PfrTo6NK4eK6R | ||
VW9UaHnCvF6nx5ITyjGiOtpVeyfKdXdrtBiCuW1LgYq1EAzsYD0FKSq+68WotPWM | ||
eUOkvzbAH4+g8jWGMql6CJo4KHCNdJb3Sh8Rpc9osbj8dqLIctZHWtORLgc9TF4m | ||
loZrOUQGC+/ILSgaKuW3lrRfA5wbHbtjEQ8EhLQ5hiUM0XGs0j5tJ5lcgle0WKaa | ||
EyyA0JJhAgMBAAECggEABUxw7D9oi3tLzZnCRZhn13OAQ8XBbT05i4DR/79wYuWD | ||
Ob24f3PH0//XbYmWIX0hdvh6iEQZpqe/WnosgGHmnprAZD6g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Nyr3470kKNNzn/h5ojFaEScE | ||
lAVuGaApa25cWq3Fogb4I/rexV7TGKKI8FPjZlKjLe9ea1crdetQtL0mOnQR9jIQ | ||
YXNK6VotYlcuNt85m8vV+A== | ||
-----END PRIVATE KEY----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
-----BEGIN CERTIFICATE----- | ||
MIIC+TCCAeGgAwIBAgIQC8avJKUFemltDXLL6qouGjANBgkqhkiG9w0BAQsFADAS | ||
MRAwDgYDVQQDEwdodXNpLmZyMCAXDTI0MDcyNzIyMTk0OVoYDzI4NTcxMDI3MjMx | ||
OTQ4WjASMRAwDgYDVQQDEwdodXNpLmZyMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8A | ||
MIIBCgKCAQEAwBC9RALxrvyAIIEdXCGekFTqYAC8dZ1Hd0XgXRasgffODboWQSwT | ||
ObkfWH9i++5LV38UfqxyzBeBcp+SfGAkUcBsmeoBHpCLq3ta0Qn394X9ERWKJYJZ | ||
QxbkMDJ2r/QdT3606OjSuHiukVVvVGh5wrxep8eSE8oxojraVXsnynV3a7QYgrlt | ||
S4GKtRAM7GA9BSkqvuvFqLT1jHlDpL82wB+PoPI1hjKpegiaOChwjXSW90ofEaXP | ||
aLG4/HaiyHLWR1rTkS4HPUxeJpaGazlEBgvvyC0oGirlt5a0XwOcGx27YxEPBIS0 | ||
OYYlDNFxrNI+bSeZXIJXtFimmhMsgNCSYQIDAQABo0kwRzAOBgNVHQ8BAf8EBAMC | ||
BaAwEwYDVR0lBAwwCgYIKwYBBQUHAwEwDAYDVR0TAQH/BAIwADASBgNVHREECzAJ | ||
ggdodXNpLmZyMA0GCSqGSIb3DQEBCwUAA4IBAQCwhr2Du+qNSdFVblBpbnxhFEWf | ||
ozrR/YJrcek9sQsPwg6tVd8C5a8sttjNV620U7ql7q4Rj5fSkayIH8rPTK6Met+l | ||
+xsbQqn/PihRFuKjdmK3rb1zuM6rmRliViCi/aj4MYPX5L+CKEO1wv3/YMv241ps | ||
Dpu++/NQj3DPvktpWAMkuYwGQgWBw+hGHa4XKLv1EJv4oNd9mSskhR71KoQFxsoL | ||
5qrP9lKcLQj3rQ527FvfdS5JYFQGHwIu+IwGw4QeXLqHjPVmf40TyrE8ITmTvvSt | ||
U6ltmvaq8C2ROxTohQPjohI7ktqPImAwIhhfzWfedleEVBtX7t98aal2YFEn | ||
-----END CERTIFICATE----- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
package libcore | ||
|
||
import ( | ||
"crypto/tls" | ||
"net" | ||
"testing" | ||
|
||
"github.com/sagernet/sing/common" | ||
N "github.com/sagernet/sing/common/network" | ||
) | ||
|
||
func TestUpdateRootCACerts(t *testing.T) { | ||
const ( | ||
chinaRailway = "www.12306.cn" // Use CA from China | ||
trustAsiaAddress = chinaRailway + ":443" | ||
|
||
husi = "husi.fr" | ||
) | ||
listener := common.Must1(net.Listen(N.NetworkTCP, "127.0.0.1:0")) | ||
defer listener.Close() | ||
listen := listener.Addr().String() | ||
|
||
done := make(chan struct{}) | ||
go func(listener net.Listener, done chan struct{}) { | ||
cert := common.Must1(tls.LoadX509KeyPair("ca.pem", "ca.key")) | ||
config := &tls.Config{ | ||
Certificates: []tls.Certificate{cert}, | ||
ServerName: husi, | ||
} | ||
done <- struct{}{} | ||
go func(listener net.Listener, done chan struct{}) { | ||
<-done | ||
_ = listener.Close() | ||
}(listener, done) | ||
for { | ||
select { | ||
case <-done: | ||
return | ||
default: | ||
} | ||
conn, err := listener.Accept() | ||
if err != nil { | ||
return | ||
} | ||
go func(config *tls.Config, conn net.Conn) { | ||
defer conn.Close() | ||
tlsConn := tls.Server(conn, config) | ||
err := tlsConn.Handshake() | ||
if err != nil { | ||
return | ||
} | ||
defer tlsConn.Close() | ||
// Write something to prevent client EOF | ||
_, _ = tlsConn.Write([]byte("hello")) | ||
}(config, conn) | ||
} | ||
}(listener, done) | ||
<-done | ||
defer close(done) | ||
|
||
testConnect := func(serverName, address string, wantErr bool, testName string) { | ||
config := &tls.Config{ | ||
ServerName: serverName, | ||
} | ||
conn, err := tls.Dial(N.NetworkTCP, address, config) | ||
if err == nil { | ||
_ = conn.Close() | ||
if wantErr { | ||
t.Errorf("[%s] wants error but not", testName) | ||
} | ||
} else { | ||
if !wantErr { | ||
t.Errorf("[%s] got unexpected error: %v", testName, err) | ||
} | ||
} | ||
} | ||
|
||
// normal | ||
testConnect(chinaRailway, trustAsiaAddress, false, "normal 12306") | ||
testConnect(husi, listen, true, "normal local") | ||
|
||
// Load local cert and Mozilla CA | ||
UpdateRootCACerts(true) | ||
testConnect(chinaRailway, trustAsiaAddress, true, "mozilla 12306") | ||
testConnect(husi, listen, false, "loaded custom") | ||
|
||
// Set back but load local | ||
UpdateRootCACerts(false) | ||
testConnect(chinaRailway, trustAsiaAddress, false, "normal 12306 2") | ||
testConnect(husi, listen, false, "loaded custom 2") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters