-
Notifications
You must be signed in to change notification settings - Fork 1
/
cert.go
34 lines (28 loc) · 786 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
34
// Copyright (c) 2017 The Fonero 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"
"io/ioutil"
"os"
"time"
"github.com/fonero-project/fnod/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 = ioutil.WriteFile(certFile, cert, 0666); err != nil {
return err
}
if err = ioutil.WriteFile(keyFile, key, 0600); err != nil {
os.Remove(certFile)
return err
}
return nil
}