@@ -17,6 +17,7 @@ import (
17
17
18
18
// Certificate hold certificate information
19
19
type Certificate struct {
20
+ SerialNumber * big.Int
20
21
Subject pkix.Name
21
22
NotBefore time.Time
22
23
NotAfter time.Time
@@ -25,12 +26,15 @@ type Certificate struct {
25
26
IsCA bool
26
27
Parent * x509.Certificate
27
28
ParentPrivateKey interface {}
29
+ KeyUsage x509.KeyUsage
28
30
ExtentedKeyUsage []x509.ExtKeyUsage
31
+ SubjectKeyId []byte
29
32
}
30
33
31
34
// Result hold created certificate in []byte format
32
35
type Result struct {
33
- Certificate []byte
36
+ ByteCert []byte
37
+ Cert * x509.Certificate
34
38
}
35
39
36
40
// GetSerial returns serial and an error
@@ -44,17 +48,19 @@ func GetSerial() (*big.Int, error) {
44
48
}
45
49
46
50
// SetTemplate set template for x509.Certificate from given Certificate struct
47
- func (c * Certificate ) SetTemplate (serial * big. Int ) x509.Certificate {
51
+ func (c * Certificate ) SetTemplate () x509.Certificate {
48
52
return x509.Certificate {
49
- SerialNumber : serial ,
53
+ SerialNumber : c . SerialNumber ,
50
54
Subject : c .Subject ,
51
55
NotBefore : c .NotBefore ,
52
56
NotAfter : c .NotAfter ,
53
57
ExtKeyUsage : c .ExtentedKeyUsage ,
58
+ KeyUsage : c .KeyUsage ,
54
59
IsCA : c .IsCA ,
55
60
IPAddresses : c .IPAddress ,
56
61
DNSNames : c .DNSNames ,
57
62
BasicConstraintsValid : true ,
63
+ SubjectKeyId : c .SubjectKeyId ,
58
64
}
59
65
}
60
66
@@ -65,7 +71,8 @@ func (c *Certificate) GetCertificate(pkey *ecdsa.PrivateKey) (*Result, error) {
65
71
return nil , err
66
72
}
67
73
68
- template := c .SetTemplate (serial )
74
+ c .SerialNumber = serial
75
+ template := c .SetTemplate ()
69
76
70
77
if c .Parent == nil {
71
78
c .Parent = & template
@@ -80,7 +87,7 @@ func (c *Certificate) GetCertificate(pkey *ecdsa.PrivateKey) (*Result, error) {
80
87
return nil , err
81
88
}
82
89
83
- return & Result {Certificate : der }, nil
90
+ return & Result {ByteCert : der , Cert : c . Parent }, nil
84
91
}
85
92
86
93
// String returns certificate in string format
@@ -89,7 +96,7 @@ func (r *Result) String() string {
89
96
90
97
if err := pem .Encode (& w , & pem.Block {
91
98
Type : "CERTIFICATE" ,
92
- Bytes : r .Certificate ,
99
+ Bytes : r .ByteCert ,
93
100
}); err != nil {
94
101
return ""
95
102
}
0 commit comments