Skip to content

Commit e8790ac

Browse files
authored
fix: use consistent cert common name (#166)
Use the hex-encoded asset name as the TLS cert common name both when generating the cert and when populating the CRL Signed-off-by: Aurora Gaffney <aurora@blinklabs.io>
1 parent 05b62e7 commit e8790ac

3 files changed

Lines changed: 5 additions & 16 deletions

File tree

internal/ca/ca.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ func (c *Ca) loadKey(cfg *config.Config) error {
124124

125125
func (c *Ca) GenerateClientCert(clientName string) (*ClientCert, error) {
126126
// Generate cert serial number from client name
127-
clientSerial := ClientNameToSerialNumber([]byte(clientName))
127+
clientSerial := ClientNameToSerialNumber(clientName)
128128
// Cert template
129129
cert := &x509.Certificate{
130130
SerialNumber: clientSerial,
@@ -212,10 +212,10 @@ func (c *Ca) GenerateCRL(
212212
return ret, nil
213213
}
214214

215-
func ClientNameToSerialNumber(clientName []byte) *big.Int {
215+
func ClientNameToSerialNumber(clientName string) *big.Int {
216216
// Hash client name using blake2b-160 to use as cert serial number
217217
hasher, _ := blake2b.New(20, nil)
218-
hasher.Write(clientName)
218+
hasher.Write([]byte(clientName))
219219
clientNameHash := hasher.Sum(nil)
220220
return new(big.Int).SetBytes(clientNameHash)
221221
}

internal/client/client.go

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
s3types "github.com/aws/aws-sdk-go-v2/service/s3/types"
2929
"github.com/blinklabs-io/vpn-indexer/internal/ca"
3030
"github.com/blinklabs-io/vpn-indexer/internal/config"
31-
"golang.org/x/crypto/blake2b"
3231
)
3332

3433
const profileTemplate = `
@@ -56,7 +55,6 @@ type Client struct {
5655
config *config.Config
5756
ca *ca.Ca
5857
assetName []byte
59-
id string
6058
}
6159

6260
func New(cfg *config.Config, caObj *ca.Ca, assetName []byte) *Client {
@@ -179,14 +177,5 @@ func (c *Client) createS3Client() (*s3.Client, error) {
179177
}
180178

181179
func (c *Client) identifier() string {
182-
// Returned cached response
183-
if c.id != "" {
184-
return c.id
185-
}
186-
// Create blake2b-256 hash from client name and encode as hex
187-
hasher, _ := blake2b.New(32, nil)
188-
hasher.Write(c.assetName)
189-
hash := hasher.Sum(nil)
190-
c.id = hex.EncodeToString(hash)
191-
return c.id
180+
return hex.EncodeToString(c.assetName)
192181
}

internal/crl/crl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (c *Crl) updateConfigMap() error {
114114
revokedCerts = append(
115115
revokedCerts,
116116
pkix.RevokedCertificate{
117-
SerialNumber: ca.ClientNameToSerialNumber(client.AssetName),
117+
SerialNumber: ca.ClientNameToSerialNumber(hex.EncodeToString(client.AssetName)),
118118
RevocationTime: client.Expiration,
119119
},
120120
)

0 commit comments

Comments
 (0)