Skip to content

Commit b6f27c2

Browse files
committed
mitm: generate valid serial number
1 parent e3eddc0 commit b6f27c2

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

cert.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"crypto/x509/pkix"
1010
"encoding/pem"
1111
"errors"
12+
"fmt"
1213
"math/big"
1314
"time"
1415
)
@@ -31,8 +32,13 @@ func genCert(ca *tls.Certificate, names []string) (*tls.Certificate, error) {
3132
if !ca.Leaf.IsCA {
3233
return nil, errors.New("CA cert is not a CA")
3334
}
35+
serialNumberLimit := new(big.Int).Lsh(big.NewInt(1), 128)
36+
serialNumber, err := rand.Int(rand.Reader, serialNumberLimit)
37+
if err != nil {
38+
return nil, fmt.Errorf("failed to generate serial number: %s", err)
39+
}
3440
tmpl := &x509.Certificate{
35-
SerialNumber: big.NewInt(1),
41+
SerialNumber: serialNumber,
3642
Subject: pkix.Name{CommonName: names[0]},
3743
NotBefore: now,
3844
NotAfter: now.Add(leafMaxAge),

0 commit comments

Comments
 (0)