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
b285bcd6
Commit
b285bcd6
authored
May 23, 2020
by
ginuerzh
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
support mutual TLS authentication
parent
60d7e011
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
18 additions
and
5 deletions
+18
-5
cmd/gost/cfg.go
cmd/gost/cfg.go
+12
-3
cmd/gost/main.go
cmd/gost/main.go
+1
-1
cmd/gost/route.go
cmd/gost/route.go
+5
-1
No files found.
cmd/gost/cfg.go
View file @
b285bcd6
...
...
@@ -44,8 +44,9 @@ var (
defaultKeyFile
=
"key.pem"
)
// Load the certificate from cert and key files, will use the default certificate if the provided info are invalid.
func
tlsConfig
(
certFile
,
keyFile
string
)
(
*
tls
.
Config
,
error
)
{
// Load the certificate from cert & key files and optional client CA file,
// will use the default certificate if the provided info are invalid.
func
tlsConfig
(
certFile
,
keyFile
,
caFile
string
)
(
*
tls
.
Config
,
error
)
{
if
certFile
==
""
||
keyFile
==
""
{
certFile
,
keyFile
=
defaultCertFile
,
defaultKeyFile
}
...
...
@@ -54,7 +55,15 @@ func tlsConfig(certFile, keyFile string) (*tls.Config, error) {
if
err
!=
nil
{
return
nil
,
err
}
return
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
cert
}},
nil
cfg
:=
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
cert
}}
if
pool
,
_
:=
loadCA
(
caFile
);
pool
!=
nil
{
cfg
.
ClientCAs
=
pool
cfg
.
ClientAuth
=
tls
.
RequireAndVerifyClientCert
}
return
cfg
,
nil
}
func
loadCA
(
caFile
string
)
(
cp
*
x509
.
CertPool
,
err
error
)
{
...
...
cmd/gost/main.go
View file @
b285bcd6
...
...
@@ -67,7 +67,7 @@ func main() {
}
// NOTE: as of 2.6, you can use custom cert/key files to initialize the default certificate.
tlsConfig
,
err
:=
tlsConfig
(
defaultCertFile
,
defaultKeyFile
)
tlsConfig
,
err
:=
tlsConfig
(
defaultCertFile
,
defaultKeyFile
,
""
)
if
err
!=
nil
{
// generate random self-signed certificate.
cert
,
err
:=
gost
.
GenCertificate
()
...
...
cmd/gost/route.go
View file @
b285bcd6
...
...
@@ -128,6 +128,10 @@ func parseChainNode(ns string) (nodes []gost.Node, err error) {
InsecureSkipVerify
:
!
node
.
GetBool
(
"secure"
),
RootCAs
:
rootCAs
,
}
if
cert
,
err
:=
tls
.
LoadX509KeyPair
(
node
.
Get
(
"cert"
),
node
.
Get
(
"key"
));
err
==
nil
{
tlsCfg
.
Certificates
=
[]
tls
.
Certificate
{
cert
}
}
wsOpts
:=
&
gost
.
WSOptions
{}
wsOpts
.
EnableCompression
=
node
.
GetBool
(
"compression"
)
wsOpts
.
ReadBufferSize
=
node
.
GetInt
(
"rbuf"
)
...
...
@@ -343,7 +347,7 @@ func (r *route) GenRouters() ([]router, error) {
}
}
certFile
,
keyFile
:=
node
.
Get
(
"cert"
),
node
.
Get
(
"key"
)
tlsCfg
,
err
:=
tlsConfig
(
certFile
,
keyFile
)
tlsCfg
,
err
:=
tlsConfig
(
certFile
,
keyFile
,
node
.
Get
(
"ca"
)
)
if
err
!=
nil
&&
certFile
!=
""
&&
keyFile
!=
""
{
return
nil
,
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