Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
G
go-common
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
ai3
go-common
Commits
e83b5f86
Commit
e83b5f86
authored
7 years ago
by
ale
Browse files
Options
Downloads
Patches
Plain Diff
Add client TLS helpers
parent
7aaddbf8
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
clientutil/tls.go
+37
-0
37 additions, 0 deletions
clientutil/tls.go
misc.go
+17
-0
17 additions, 0 deletions
misc.go
with
54 additions
and
0 deletions
clientutil/tls.go
0 → 100644
+
37
−
0
View file @
e83b5f86
package
clientutil
import
(
"crypto/tls"
common
"git.autistici.org/ai3/go-common"
)
// TLSClientConfig defines the TLS parameters for a client connection
// that should use a client X509 certificate for authentication.
type
TLSClientConfig
struct
{
Cert
string
`yaml:"cert"`
Key
string
`yaml:"key"`
CA
string
`yaml:"ca"`
}
// TLSConfig returns a tls.Config object with the current configuration.
func
(
c
*
TLSClientConfig
)
TLSConfig
()
(
*
tls
.
Config
,
error
)
{
cert
,
err
:=
tls
.
LoadX509KeyPair
(
c
.
Cert
,
c
.
Key
)
if
err
!=
nil
{
return
nil
,
err
}
tlsConf
:=
&
tls
.
Config
{
Certificates
:
[]
tls
.
Certificate
{
cert
},
}
if
c
.
CA
!=
""
{
cas
,
err
:=
common
.
LoadCA
(
c
.
CA
)
if
err
!=
nil
{
return
nil
,
err
}
tlsConf
.
RootCAs
=
cas
}
tlsConf
.
BuildNameToCertificate
()
return
tlsConf
,
nil
}
This diff is collapsed.
Click to expand it.
misc.go
0 → 100644
+
17
−
0
View file @
e83b5f86
package
common
import
(
"crypto/x509"
"io/ioutil"
)
// LoadCA loads a file containing CA certificates into a x509.CertPool.
func
LoadCA
(
path
string
)
(
*
x509
.
CertPool
,
error
)
{
data
,
err
:=
ioutil
.
ReadFile
(
path
)
if
err
!=
nil
{
return
nil
,
err
}
cas
:=
x509
.
NewCertPool
()
cas
.
AppendCertsFromPEM
(
data
)
return
cas
,
nil
}
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