| 1 |
package x509util |
| 2 |
|
| 3 |
import ( |
| 4 |
"crypto" |
| 5 |
"crypto/x509" |
| 6 |
"crypto/x509/pkix" |
| 7 |
"time" |
| 8 |
) |
| 9 |
|
| 10 |
|
| 11 |
var DefaultIntermediateCertValidity = time.Hour * 24 * 365 * 10 |
| 12 |
|
| 13 |
|
| 14 |
type Intermediate struct { |
| 15 |
base |
| 16 |
} |
| 17 |
|
| 18 |
|
| 19 |
func (i *Intermediate) DefaultDuration() time.Duration { |
| 20 |
return DefaultIntermediateCertValidity |
| 21 |
} |
| 22 |
|
| 23 |
|
| 24 |
func NewIntermediateProfile(name string, iss *x509.Certificate, issPriv crypto.PrivateKey, withOps ...WithOption) (Profile, error) { |
| 25 |
sub := defaultIntermediateTemplate(name) |
| 26 |
return newProfile(&Intermediate{}, sub, iss, issPriv, withOps...) |
| 27 |
} |
| 28 |
|
| 29 |
func defaultIntermediateTemplate(name string) *x509.Certificate { |
| 30 |
notBefore := time.Now() |
| 31 |
return &x509.Certificate{ |
| 32 |
IsCA: true, |
| 33 |
NotBefore: notBefore, |
| 34 |
NotAfter: notBefore.Add(DefaultIntermediateCertValidity), |
| 35 |
KeyUsage: x509.KeyUsageCertSign | x509.KeyUsageCRLSign, |
| 36 |
BasicConstraintsValid: true, |
| 37 |
MaxPathLen: 0, |
| 38 |
MaxPathLenZero: true, |
| 39 |
Issuer: pkix.Name{CommonName: name}, |
| 40 |
Subject: pkix.Name{CommonName: name}, |
| 41 |
} |
| 42 |
} |