Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
comms
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package registry
Container registry
Model registry
Operate
Terraform modules
Analyze
Contributor analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
xx network
comms
Commits
c1d9fafd
Commit
c1d9fafd
authored
Nov 22, 2022
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Swap to using GetCertificate in tlsconf so the cert can be changed
parent
3a63a373
No related branches found
No related tags found
4 merge requests
!47
Project/https support
,
!46
Swap to using GetCertificate in tlsconf so the cert can be changed
,
!45
re-enable https for servewithweb, add function to provide certs when available
,
!39
Merge release into master
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
connect/comms.go
+30
-13
30 additions, 13 deletions
connect/comms.go
with
30 additions
and
13 deletions
connect/comms.go
+
30
−
13
View file @
c1d9fafd
...
@@ -99,6 +99,8 @@ type ProtoComms struct {
...
@@ -99,6 +99,8 @@ type ProtoComms struct {
salt
[]
byte
salt
[]
byte
httpsCredChan
chan
tls
.
Certificate
httpsCredChan
chan
tls
.
Certificate
httpsCertificate
*
tls
.
Certificate
httpsCertificateLock
sync
.
RWMutex
// -------------------------------------------------------------------------
// -------------------------------------------------------------------------
}
}
...
@@ -260,24 +262,20 @@ func (c *ProtoComms) ServeWithWeb() {
...
@@ -260,24 +262,20 @@ func (c *ProtoComms) ServeWithWeb() {
c
.
httpsCredChan
=
make
(
chan
tls
.
Certificate
,
1
)
c
.
httpsCredChan
=
make
(
chan
tls
.
Certificate
,
1
)
wg
.
Done
()
wg
.
Done
()
creds
:=
<-
c
.
httpsCredChan
creds
:=
<-
c
.
httpsCredChan
var
err
error
tlsConf
.
Certificate
s
=
make
([]
tls
.
Certificate
,
1
)
c
.
https
Certificate
=
&
creds
tlsConf
.
Certificate
s
[
0
]
=
creds
tlsConf
.
Get
Certificate
=
c
.
GetCertificateFunc
()
var
serverName
string
var
serverName
string
if
tlsConf
.
Certificates
[
0
]
.
Leaf
==
nil
{
cert
,
err
:=
x509
.
ParseCertificate
(
creds
.
Certificate
[
0
])
var
cert
*
x509
.
Certificate
cert
,
err
=
x509
.
ParseCertificate
(
creds
.
Certificate
[
0
])
if
err
!=
nil
{
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to load TLS certificate: %+v"
,
err
)
jww
.
FATAL
.
Panicf
(
"Failed to load TLS certificate: %+v"
,
err
)
}
}
serverName
=
cert
.
DNSNames
[
0
]
serverName
=
cert
.
DNSNames
[
0
]
}
else
{
serverName
=
tlsConf
.
Certificates
[
0
]
.
Leaf
.
DNSNames
[
0
]
}
tlsConf
.
ServerName
=
serverName
tlsConf
.
ServerName
=
serverName
go
c
.
startUpdateCertificate
()
tlsLis
:=
tls
.
NewListener
(
l
,
tlsConf
)
tlsLis
:=
tls
.
NewListener
(
l
,
tlsConf
)
if
err
:=
http
.
Serve
(
tlsLis
,
httpServer
);
err
!=
nil
{
if
err
:=
http
.
Serve
(
tlsLis
,
httpServer
);
err
!=
nil
{
// Cannot panic here due to shared net.Listener
// Cannot panic here due to shared net.Listener
...
@@ -383,6 +381,25 @@ func (c *ProtoComms) Stream(host *Host, f func(conn Connection) (
...
@@ -383,6 +381,25 @@ func (c *ProtoComms) Stream(host *Host, f func(conn Connection) (
return
c
.
transmit
(
host
,
f
)
return
c
.
transmit
(
host
,
f
)
}
}
func
(
c
*
ProtoComms
)
GetCertificateFunc
()
func
(
*
tls
.
ClientHelloInfo
)
(
*
tls
.
Certificate
,
error
)
{
return
func
(
clientHello
*
tls
.
ClientHelloInfo
)
(
*
tls
.
Certificate
,
error
)
{
c
.
httpsCertificateLock
.
RLock
()
defer
c
.
httpsCertificateLock
.
RUnlock
()
return
c
.
httpsCertificate
,
nil
}
}
func
(
c
*
ProtoComms
)
startUpdateCertificate
()
{
for
{
select
{
case
creds
:=
<-
c
.
httpsCredChan
:
c
.
httpsCertificateLock
.
Lock
()
c
.
httpsCertificate
=
&
creds
c
.
httpsCertificateLock
.
Unlock
()
}
}
}
// returns true if the connection error is one of the connection errors which
// returns true if the connection error is one of the connection errors which
// should be retried
// should be retried
func
isConnError
(
err
error
)
bool
{
func
isConnError
(
err
error
)
bool
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment