2 Copyright (C) 2021 Sergey Matveev <stargrave@stargrave.org>
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, version 3 of the License.
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
13 You should have received a copy of the GNU General Public License
14 along with this program. If not, see <http://www.gnu.org/licenses/>.
33 cert *x509.Certificate
38 hostCerts = make(map[string]*Keypair)
45 max = max.SetBit(max, 128, 1)
47 Serial, err = rand.Int(rand.Reader, max)
55 caCert *x509.Certificate,
56 caPrv crypto.PrivateKey,
58 prv, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
63 notBefore := time.Now()
64 notAfter := notBefore.Add(24 * time.Hour)
65 Serial = Serial.Add(Serial, big.NewInt(1))
66 template := x509.Certificate{
68 Subject: pkix.Name{CommonName: host},
69 DNSNames: []string{host},
73 certRaw, err := x509.CreateCertificate(
74 rand.Reader, &template, caCert, pub, caPrv,
79 cert, err := x509.ParseCertificate(certRaw)
83 return &Keypair{cert, prv}