Package ca-certificates.crt
This commit is contained in:
3517
ca-certificates.crt
Normal file
3517
ca-certificates.crt
Normal file
File diff suppressed because it is too large
Load Diff
21
voter.go
21
voter.go
@@ -2,6 +2,9 @@ package elect
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/hmac"
|
"crypto/hmac"
|
||||||
|
"crypto/tls"
|
||||||
|
"crypto/x509"
|
||||||
|
_ "embed"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"log"
|
"log"
|
||||||
"time"
|
"time"
|
||||||
@@ -38,9 +41,13 @@ type voteResponse struct {
|
|||||||
ResponseSent time.Time `json:"responseSent"`
|
ResponseSent time.Time `json:"responseSent"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//go:embed ca-certificates.crt
|
||||||
|
var caCertificates []byte
|
||||||
|
|
||||||
func NewVoter(url string, signingKey string) *Voter {
|
func NewVoter(url string, signingKey string) *Voter {
|
||||||
v := &Voter{
|
v := &Voter{
|
||||||
client: resty.New().
|
client: resty.New().
|
||||||
|
SetTLSClientConfig(getTLSClientConfig()).
|
||||||
SetCloseConnection(true).
|
SetCloseConnection(true).
|
||||||
SetBaseURL(url),
|
SetBaseURL(url),
|
||||||
signingKey: []byte(signingKey),
|
signingKey: []byte(signingKey),
|
||||||
@@ -167,3 +174,17 @@ func (v *Voter) sendVote() {
|
|||||||
func (v *Voter) log(format string, args ...any) {
|
func (v *Voter) log(format string, args ...any) {
|
||||||
log.Printf("[voter] "+format, args...)
|
log.Printf("[voter] "+format, args...)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getTLSClientConfig() *tls.Config {
|
||||||
|
pool := x509.NewCertPool()
|
||||||
|
|
||||||
|
ok := pool.AppendCertsFromPEM(caCertificates)
|
||||||
|
if !ok {
|
||||||
|
panic("invalid ca-certificates")
|
||||||
|
}
|
||||||
|
|
||||||
|
return &tls.Config{
|
||||||
|
MinVersion: tls.VersionTLS12,
|
||||||
|
RootCAs: pool,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user