Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change serial number in certif #391

Merged
merged 2 commits into from
Jan 6, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions pkg/certificate/certificate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"crypto"
"crypto/rand"
"crypto/rsa"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"crypto/x509/pkix"
Expand Down Expand Up @@ -57,12 +58,12 @@ func GenerateTLS(hello *tls.ClientHelloInfo) (*tls.Certificate, error) {
return nil, wrapAndPrint("while getting mkcert CA root path", err)
}

caCertificate, err := LoadCertificate(caPath + "/rootCA.pem")
caCertificate, err := LoadCertificate(filepath.Join(caPath, "rootCA.pem"))
SebastienValla marked this conversation as resolved.
Show resolved Hide resolved
if err != nil {
return nil, wrapAndPrint("while loading CA certificate", err)
}

caPrivateKey, err := LoadPrivateKey(caPath + "/rootCA-key.pem")
caPrivateKey, err := LoadPrivateKey(filepath.Join(caPath, "rootCA-key.pem"))
if err != nil {
return nil, wrapAndPrint("while loading CA key", err)
}
Expand Down Expand Up @@ -90,9 +91,12 @@ func GenerateSignedCertificate(
return nil, nil, errors.New("while generating certificate: server name is empty")
}

SHA256serverNameEncrypted := sha256.New().Sum([]byte(serverName))
SebastienValla marked this conversation as resolved.
Show resolved Hide resolved

//nolint:exhaustruct
template := &x509.Certificate{
SerialNumber: &big.Int{}, // mandatory, but useless as it should be a unique id given to the certificate by the CA
//nolint:lll
SerialNumber: new(big.Int).SetBytes(SHA256serverNameEncrypted), // in order to have an unique ID for each website Name, we hash the website name
SebastienValla marked this conversation as resolved.
Show resolved Hide resolved
Subject: pkix.Name{ // not necessary, but cool to have if the user ask for certificate details.
CommonName: serverName,
Organization: []string{"thyra dynamically generated"},
Expand Down