@@ -20,6 +20,7 @@ import (
2020const (
2121 certExtension string = ".crt"
2222 csrExtension string = ".csr"
23+ crlExtension string = ".crl"
2324)
2425
2526// A Identity represents the Certificate Authority Identity Information
@@ -43,6 +44,7 @@ type CAData struct {
4344 PublicKey string
4445 CSR string
4546 Certificate string
47+ CRL string
4648 privateKey rsa.PrivateKey
4749 certificate * x509.Certificate
4850 publicKey rsa.PublicKey
@@ -77,6 +79,7 @@ func (c *CA) create(commonName string, id Identity) error {
7779 publicKeyString []byte
7880 csrString []byte
7981 certString []byte
82+ crlString []byte
8083 )
8184
8285 if id .Organization == "" || id .OrganizationalUnit == "" || id .Country == "" || id .Locality == "" || id .Province == "" {
@@ -125,6 +128,7 @@ func (c *CA) create(commonName string, id Identity) error {
125128
126129 caData .certificate = certificate
127130 caData .Certificate = string (certString )
131+
128132 crlBytes , err := cert .RevokeCertificate (c .CommonName , []pkix.RevokedCertificate {}, certificate , privKey )
129133 if err != nil {
130134 crl , err := x509 .ParseCRL (crlBytes )
@@ -133,6 +137,12 @@ func (c *CA) create(commonName string, id Identity) error {
133137 }
134138 }
135139
140+ if crlString , err = storage .LoadFile (caDir + "/" + commonName + crlExtension ); err != nil {
141+ crlString = []byte {}
142+ }
143+
144+ c .Data .CRL = string (crlString )
145+
136146 } else {
137147 csrBytes , err := cert .CreateCSR (commonName , commonName , id .Country , id .Province , id .Locality , id .Organization , id .OrganizationalUnit , id .EmailAddresses , id .DNSNames , privKey , storage .CreationTypeCA )
138148 if err != nil {
@@ -373,6 +383,8 @@ func (c *CA) loadCertificate(commonName string) (certificate Certificate, err er
373383func (c * CA ) revokeCertificate (certificate * x509.Certificate ) error {
374384
375385 var revokedCerts []pkix.RevokedCertificate
386+ var caDir string = "/" + c .CommonName + "/ca"
387+ var crlString []byte
376388
377389 if c .Data .crl != nil {
378390 revokedCerts = c .Data .crl .TBSCertList .RevokedCertificates
@@ -396,5 +408,12 @@ func (c *CA) revokeCertificate(certificate *x509.Certificate) error {
396408 }
397409 c .Data .crl = crl
398410
411+ var crlFile string = caDir + "/" + c .CommonName + crlExtension
412+ if crlString , err = storage .LoadFile (crlFile ); err != nil {
413+ crlString = []byte {}
414+ }
415+
416+ c .Data .CRL = string (crlString )
417+
399418 return nil
400419}
0 commit comments