-
Notifications
You must be signed in to change notification settings - Fork 402
/
templates.go
47 lines (39 loc) · 1.33 KB
/
templates.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
35
36
37
38
39
40
41
42
43
44
45
46
47
// Copyright (C) 2019 Storj Labs, Inc.
// See LICENSE for copying information.
package peertls
import (
"crypto/x509"
"crypto/x509/pkix"
)
// CATemplate returns x509.Certificate template for certificate authority
func CATemplate() (*x509.Certificate, error) {
serialNumber, err := newSerialNumber()
if err != nil {
return nil, ErrTLSTemplate.Wrap(err)
}
template := &x509.Certificate{
SerialNumber: serialNumber,
KeyUsage: x509.KeyUsageCertSign,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth},
BasicConstraintsValid: true,
IsCA: true,
Subject: pkix.Name{Organization: []string{"Storj"}},
}
return template, nil
}
// LeafTemplate returns x509.Certificate template for signing and encrypting
func LeafTemplate() (*x509.Certificate, error) {
serialNumber, err := newSerialNumber()
if err != nil {
return nil, ErrTLSTemplate.Wrap(err)
}
template := &x509.Certificate{
SerialNumber: serialNumber,
KeyUsage: x509.KeyUsageDigitalSignature | x509.KeyUsageKeyEncipherment,
ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageServerAuth, x509.ExtKeyUsageClientAuth},
BasicConstraintsValid: true,
IsCA: false,
Subject: pkix.Name{Organization: []string{"Storj"}},
}
return template, nil
}