Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
G
gost
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nanahira
gost
Commits
fd079dd0
Commit
fd079dd0
authored
Sep 05, 2020
by
luyuhuang
Committed by
ginuerzh
Nov 18, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
certificate pinning for servers without domain
parent
f7995ab5
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
56 additions
and
26 deletions
+56
-26
cmd/gost/route.go
cmd/gost/route.go
+27
-0
tls.go
tls.go
+29
-26
No files found.
cmd/gost/route.go
View file @
fd079dd0
...
...
@@ -3,12 +3,14 @@ package main
import
(
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"encoding/base64"
"fmt"
"net"
"net/url"
"os"
"strings"
"time"
"github.com/ginuerzh/gost"
"github.com/go-log/log"
...
...
@@ -128,6 +130,31 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
InsecureSkipVerify
:
!
node
.
GetBool
(
"secure"
),
RootCAs
:
rootCAs
,
}
// If the argument `ca` is given, but not open `secure`, we verify the
// certificate manually.
if
rootCAs
!=
nil
&&
!
node
.
GetBool
(
"secure"
)
{
tlsCfg
.
VerifyConnection
=
func
(
state
tls
.
ConnectionState
)
error
{
opts
:=
x509
.
VerifyOptions
{
Roots
:
rootCAs
,
CurrentTime
:
time
.
Now
(),
DNSName
:
""
,
Intermediates
:
x509
.
NewCertPool
(),
}
certs
:=
state
.
PeerCertificates
for
i
,
cert
:=
range
certs
{
if
i
==
0
{
continue
}
opts
.
Intermediates
.
AddCert
(
cert
)
}
_
,
err
=
certs
[
0
]
.
Verify
(
opts
)
return
err
}
}
if
cert
,
err
:=
tls
.
LoadX509KeyPair
(
node
.
Get
(
"cert"
),
node
.
Get
(
"key"
));
err
==
nil
{
tlsCfg
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
}
...
...
tls.go
View file @
fd079dd0
...
...
@@ -2,7 +2,6 @@ package gost
import
(
"crypto/tls"
"crypto/x509"
"errors"
"net"
"sync"
...
...
@@ -290,6 +289,9 @@ func wrapTLSClient(conn net.Conn, tlsConfig *tls.Config, timeout time.Duration)
return
nil
,
err
}
// We can do this in `tls.Config.VerifyConnection`, which effective for
// other TLS protocols such as WebSocket. See `route.go:parseChainNode`
/*
// If crypto/tls is doing verification, there's no need to do our own.
if tlsConfig.InsecureSkipVerify == false {
return tlsConn, nil
...
...
@@ -320,6 +322,7 @@ func wrapTLSClient(conn net.Conn, tlsConfig *tls.Config, timeout time.Duration)
tlsConn.Close()
return nil, err
}
*/
return
tlsConn
,
err
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment