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
a942768a
Commit
a942768a
authored
Dec 20, 2022
by
Jonah Husson
Browse files
Options
Downloads
Patches
Plain Diff
Make ServeHTTPS take in tls.Certificate
parent
a1eb3c8a
Branches
Branches containing commit
Tags
Tags containing commit
2 merge requests
!58
Add GetServerCert for getting certificate of server from web hosts
,
!39
Merge release into master
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
connect/comms.go
+10
-9
10 additions, 9 deletions
connect/comms.go
connect/connection_test.go
+12
-3
12 additions, 3 deletions
connect/connection_test.go
with
22 additions
and
12 deletions
connect/comms.go
+
10
−
9
View file @
a942768a
...
...
@@ -465,7 +465,7 @@ func parseTlsPacket(r io.Reader) (*tlshacks.ClientHelloInfo, bool) {
// not be usable until this has been called at least once, unblocking the
// listenHTTP func in ServeWithWeb. Future calls will be handled by the
// startUpdateCertificate thread.
func
(
c
*
ProtoComms
)
ServeHttps
(
cert
,
key
[]
by
te
)
error
{
func
(
c
*
ProtoComms
)
ServeHttps
(
keyPair
tls
.
Certifica
te
)
error
{
if
c
.
mux
==
nil
{
return
errors
.
New
(
"mux does not exist; is https enabled?"
)
}
...
...
@@ -477,16 +477,17 @@ func (c *ProtoComms) ServeHttps(cert, key []byte) error {
httpL
:=
c
.
mux
.
Match
(
c
.
matchWebTls
)
grpcServer
:=
c
.
grpcServer
keyPair
,
err
:=
tls
.
X509KeyPair
(
cert
,
key
)
if
err
!=
nil
{
return
errors
.
WithMessage
(
err
,
"cert & key could not be parsed to valid tls certificate"
)
}
parsedLeafCert
,
err
:=
x509
.
ParseCertificate
(
keyPair
.
Certificate
[
0
])
var
parsedLeafCert
*
x509
.
Certificate
var
err
error
if
keyPair
.
Leaf
==
nil
{
parsedLeafCert
,
err
=
x509
.
ParseCertificate
(
keyPair
.
Certificate
[
0
])
if
err
!=
nil
{
jww
.
FATAL
.
Panicf
(
"Failed to load TLS certificate: %+v"
,
err
)
}
}
else
{
parsedLeafCert
=
keyPair
.
Leaf
}
c
.
httpsX509
=
parsedLeafCert
listenHTTPS
:=
func
(
l
net
.
Listener
)
{
...
...
This diff is collapsed.
Click to expand it.
connect/connection_test.go
+
12
−
3
View file @
a942768a
...
...
@@ -2,6 +2,7 @@ package connect
import
(
"context"
"crypto/tls"
"fmt"
"gitlab.com/xx_network/comms/connect/token"
pb
"gitlab.com/xx_network/comms/messages"
...
...
@@ -174,7 +175,11 @@ func TestWebConnection_TLS(t *testing.T) {
pb
.
RegisterGenericServer
(
pc
.
grpcServer
,
&
TestGenericServer
{
resp
:
expectedResponse
})
pc
.
ServeWithWeb
()
err
=
pc
.
ServeHttps
(
httpsCertBytes
,
httpsKeyBytes
)
tlsKeypair
,
err
:=
tls
.
X509KeyPair
(
httpsCertBytes
,
httpsKeyBytes
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
pc
.
ServeHttps
(
tlsKeypair
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
@@ -209,7 +214,7 @@ func TestWebConnection_TLS(t *testing.T) {
t
.
Errorf
(
"Did not receive expected payload"
)
}
_
,
err
:
=
h
.
GetServerCert
()
_
,
err
=
h
.
GetServerCert
()
if
err
!=
nil
{
t
.
Errorf
(
"Did not receive cert: %+v"
,
err
)
}
...
...
@@ -266,7 +271,11 @@ func TestServeWeb_Matchers(t *testing.T) {
hostParams
:=
GetDefaultHostParams
()
hostParams
.
ConnectionType
=
ct
pc
.
ServeWithWeb
()
err
=
pc
.
ServeHttps
(
httpsCertBytes
,
httpsKeyBytes
)
tlsKeypair
,
err
:=
tls
.
X509KeyPair
(
httpsCertBytes
,
httpsKeyBytes
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
err
=
pc
.
ServeHttps
(
tlsKeypair
)
if
err
!=
nil
{
t
.
Fatal
(
err
)
}
...
...
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