forked from decred/politeia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcert.go
33 lines (27 loc) · 757 Bytes
/
cert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Copyright (c) 2017 The Decred developers
// Use of this source code is governed by an ISC
// license that can be found in the LICENSE file.
package util
import (
"crypto/elliptic"
"os"
"time"
"github.com/decred/dcrd/certgen"
)
// GenCertPair generates a key/cert pair to the paths provided.
func GenCertPair(curve elliptic.Curve, org, certFile, keyFile string) error {
validUntil := time.Now().Add(10 * 365 * 24 * time.Hour)
cert, key, err := certgen.NewTLSCertPair(curve, org, validUntil, nil)
if err != nil {
return err
}
// Write cert and key files.
if err = os.WriteFile(certFile, cert, 0666); err != nil {
return err
}
if err = os.WriteFile(keyFile, key, 0600); err != nil {
os.Remove(certFile)
return err
}
return nil
}