MCPcopy Create free account
hub / github.com/cloudflare/cfssl / New

Function New

initca/initca.go:48–102  ·  view source on GitHub ↗

New creates a new root certificate from the certificate request.

(req *csr.CertificateRequest)

Source from the content-addressed store, hash-verified

46
47// New creates a new root certificate from the certificate request.
48func New(req *csr.CertificateRequest) (cert, csrPEM, key []byte, err error) {
49 policy := CAPolicy()
50 if req.CA != nil {
51 if req.CA.Expiry != "" {
52 policy.Default.ExpiryString = req.CA.Expiry
53 policy.Default.Expiry, err = time.ParseDuration(req.CA.Expiry)
54 if err != nil {
55 return
56 }
57 }
58
59 if req.CA.Backdate != "" {
60 policy.Default.Backdate, err = time.ParseDuration(req.CA.Backdate)
61 if err != nil {
62 return
63 }
64 }
65
66 policy.Default.CAConstraint.MaxPathLen = req.CA.PathLength
67 if req.CA.PathLength != 0 && req.CA.PathLenZero {
68 log.Infof("ignore invalid 'pathlenzero' value")
69 } else {
70 policy.Default.CAConstraint.MaxPathLenZero = req.CA.PathLenZero
71 }
72 }
73
74 if req.CRL != "" {
75 policy.Default.CRL = req.CRL
76 }
77
78 g := &csr.Generator{Validator: validator}
79 csrPEM, key, err = g.ProcessRequest(req)
80 if err != nil {
81 log.Errorf("failed to process request: %v", err)
82 key = nil
83 return
84 }
85
86 priv, err := helpers.ParsePrivateKeyPEM(key)
87 if err != nil {
88 log.Errorf("failed to parse private key: %v", err)
89 return
90 }
91
92 s, err := local.NewSigner(priv, nil, signer.DefaultSigAlgo(priv), policy)
93 if err != nil {
94 log.Errorf("failed to create signer: %v", err)
95 return
96 }
97
98 signReq := signer.SignRequest{Hosts: req.Hosts, Request: string(csrPEM)}
99 cert, err = s.Sign(signReq)
100
101 return
102}
103
104// NewFromPEM creates a new root certificate from the key file passed in.
105func NewFromPEM(req *csr.CertificateRequest, keyFile string) (cert, csrPEM []byte, err error) {

Callers 8

NewFunction · 0.92
TestLoadSignerFunction · 0.92
genkeyMainFunction · 0.92
gencertMainFunction · 0.92
initialCAHandlerFunction · 0.92
TestInitCAFunction · 0.70
TestInvalidCAConfigFunction · 0.70
TestInvalidCryptoParamsFunction · 0.70

Calls 7

ProcessRequestMethod · 0.95
SignMethod · 0.95
InfofFunction · 0.92
ErrorfFunction · 0.92
ParsePrivateKeyPEMFunction · 0.92
NewSignerFunction · 0.92
DefaultSigAlgoFunction · 0.92

Tested by 4

TestLoadSignerFunction · 0.74
TestInitCAFunction · 0.56
TestInvalidCAConfigFunction · 0.56
TestInvalidCryptoParamsFunction · 0.56