|
7 | 7 | "crypto/x509" |
8 | 8 | "crypto/x509/pkix" |
9 | 9 | "encoding/pem" |
| 10 | + "fmt" |
10 | 11 | "math/big" |
11 | 12 | "net/url" |
12 | 13 | "os" |
@@ -38,7 +39,7 @@ func GenerateRootCertificate(addThumbPrintToName bool, commonName, country, orga |
38 | 39 | if addThumbPrintToName { |
39 | 40 | hash := sha256.New() |
40 | 41 | hash.Write(privateKey.PublicKey.N.Bytes()) // Simplified approach to get a thumbprint-like result |
41 | | - commonName += "-" + string(hash.Sum(nil)[:3]) |
| 42 | + commonName += "-" + fmt.Sprintf("%x", hash.Sum(nil)[:3]) |
42 | 43 | } |
43 | 44 |
|
44 | 45 | if country == "" { |
@@ -107,7 +108,7 @@ type CertAndKeyType struct { |
107 | 108 | Key *rsa.PrivateKey |
108 | 109 | } |
109 | 110 |
|
110 | | -func IssueWebServerCertificate(rootCert CertAndKeyType, addThumbPrintToName bool, commonName, country, organization string, extKeyUsage x509.ExtKeyUsage, strong bool) (*x509.Certificate, *rsa.PrivateKey, error) { |
| 111 | +func IssueWebServerCertificate(rootCert CertAndKeyType, addThumbPrintToName bool, commonName, country, organization string, strong bool) (*x509.Certificate, *rsa.PrivateKey, error) { |
111 | 112 | keyLength := 2048 |
112 | 113 | if strong { |
113 | 114 | keyLength = 3072 |
@@ -148,16 +149,18 @@ func IssueWebServerCertificate(rootCert CertAndKeyType, addThumbPrintToName bool |
148 | 149 | subject.CommonName += "-" + string(hash.Sum(nil)[:3]) |
149 | 150 | } |
150 | 151 |
|
151 | | - template := x509.Certificate{ |
152 | | - SerialNumber: serialNumber, |
153 | | - Subject: subject, |
154 | | - NotBefore: notBefore, |
155 | | - NotAfter: notAfter, |
156 | | - KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment, |
157 | | - ExtKeyUsage: []x509.ExtKeyUsage{extKeyUsage}, |
| 152 | + hash := sha256.Sum256(keys.PublicKey.N.Bytes()) |
158 | 153 |
|
| 154 | + template := x509.Certificate{ |
| 155 | + SerialNumber: serialNumber, |
| 156 | + Subject: subject, |
| 157 | + NotBefore: notBefore, |
| 158 | + NotAfter: notAfter, |
| 159 | + KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment | x509.KeyUsageCertSign | x509.KeyUsageDataEncipherment, |
| 160 | + ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth}, |
159 | 161 | BasicConstraintsValid: true, |
160 | 162 | IsCA: false, |
| 163 | + SubjectKeyId: hash[:], |
161 | 164 | } |
162 | 165 |
|
163 | 166 | // Subject Alternative Name |
|
0 commit comments