| 66 | } |
| 67 | |
| 68 | func CertConfigFromModule(prefix string, m session.SessionModule) (cfg CertConfig, err error) { |
| 69 | if err, cfg.Bits = m.IntParam(prefix + ".certificate.bits"); err != nil { |
| 70 | return cfg, err |
| 71 | } else if err, cfg.Country = m.StringParam(prefix + ".certificate.country"); err != nil { |
| 72 | return cfg, err |
| 73 | } else if err, cfg.Locality = m.StringParam(prefix + ".certificate.locality"); err != nil { |
| 74 | return cfg, err |
| 75 | } else if err, cfg.Organization = m.StringParam(prefix + ".certificate.organization"); err != nil { |
| 76 | return cfg, err |
| 77 | } else if err, cfg.OrganizationalUnit = m.StringParam(prefix + ".certificate.organizationalunit"); err != nil { |
| 78 | return cfg, err |
| 79 | } else if err, cfg.CommonName = m.StringParam(prefix + ".certificate.commonname"); err != nil { |
| 80 | return cfg, err |
| 81 | } |
| 82 | return cfg, err |
| 83 | } |
| 84 | |
| 85 | func CreateCertificate(cfg CertConfig, ca bool) (*rsa.PrivateKey, []byte, error) { |
| 86 | priv, err := rsa.GenerateKey(rand.Reader, cfg.Bits) |