@@ -52,8 +52,9 @@ type Certificate struct {
52
52
NotAfter * time.Time `yaml:"not_after"`
53
53
54
54
// generated at runtime, not read from yaml
55
- Key crypto.Signer `yaml:"-"`
56
- Cert []byte `yaml:"-"`
55
+ Key crypto.Signer `yaml:"-"`
56
+ Cert []byte `yaml:"-"`
57
+ Generated bool `hash:"-"`
57
58
}
58
59
59
60
// getKeyUsage converts key usage string representation to x509.KeyUsage
@@ -247,6 +248,9 @@ func (c *Certificate) Generate(ca *Certificate) error {
247
248
248
249
c .Cert , err = x509 .CreateCertificate (rand .Reader , template , issuerCert , c .Key .Public (), issuerKey )
249
250
251
+ // Mark the state as valid
252
+ c .Generated = true
253
+
250
254
return err
251
255
}
252
256
@@ -311,16 +315,27 @@ func (c *Certificate) Load(srcdir string) error {
311
315
return err
312
316
}
313
317
decoded , _ = pem .Decode (buf )
314
- if decoded == nil || decoded .Type != "PRIVATE KEY" {
318
+ if decoded == nil {
319
+ return fmt .Errorf ("Error while decoding %s" , keyFilename )
320
+ }
321
+
322
+ var key interface {}
323
+ if decoded .Type == "PRIVATE KEY" {
324
+ key , err = x509 .ParsePKCS8PrivateKey (decoded .Bytes )
325
+ } else if decoded .Type == "RSA PRIVATE KEY" {
326
+ key , err = x509 .ParsePKCS1PrivateKey (decoded .Bytes )
327
+ } else {
315
328
return fmt .Errorf ("Error while decoding %s" , keyFilename )
316
329
}
317
330
318
- key , err := x509 .ParsePKCS8PrivateKey (decoded .Bytes )
319
331
if err != nil {
320
332
return err
321
333
}
322
334
c .Key = key .(crypto.Signer )
323
335
336
+ // Mark the state as valid
337
+ c .Generated = true
338
+
324
339
return nil
325
340
}
326
341
0 commit comments