handleCAInfo returns information about a particular CA by its ID. If the CA ID is the default, then the CA will be provisioned if it has not already been. Other CA IDs will return an error if they have not been previously provisioned.
(w http.ResponseWriter, r *http.Request)
| 92 | // provisioned if it has not already been. Other CA IDs will return an |
| 93 | // error if they have not been previously provisioned. |
| 94 | func (a *adminAPI) handleCAInfo(w http.ResponseWriter, r *http.Request) error { |
| 95 | if r.Method != http.MethodGet { |
| 96 | return caddy.APIError{ |
| 97 | HTTPStatus: http.StatusMethodNotAllowed, |
| 98 | Err: fmt.Errorf("method not allowed: %v", r.Method), |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | ca, err := a.getCAFromAPIRequestPath(r) |
| 103 | if err != nil { |
| 104 | return err |
| 105 | } |
| 106 | |
| 107 | rootCert, interCert, err := rootAndIntermediatePEM(ca) |
| 108 | if err != nil { |
| 109 | return caddy.APIError{ |
| 110 | HTTPStatus: http.StatusInternalServerError, |
| 111 | Err: fmt.Errorf("failed to get root and intermediate cert for CA %s: %v", ca.ID, err), |
| 112 | } |
| 113 | } |
| 114 | |
| 115 | repl := ca.newReplacer() |
| 116 | |
| 117 | response := caInfo{ |
| 118 | ID: ca.ID, |
| 119 | Name: ca.Name, |
| 120 | RootCN: repl.ReplaceAll(ca.RootCommonName, ""), |
| 121 | IntermediateCN: repl.ReplaceAll(ca.IntermediateCommonName, ""), |
| 122 | RootCert: string(rootCert), |
| 123 | IntermediateCert: string(interCert), |
| 124 | } |
| 125 | |
| 126 | encoded, err := json.Marshal(response) |
| 127 | if err != nil { |
| 128 | return caddy.APIError{ |
| 129 | HTTPStatus: http.StatusInternalServerError, |
| 130 | Err: err, |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | w.Header().Set("Content-Type", "application/json") |
| 135 | _, _ = w.Write(encoded) |
| 136 | |
| 137 | return nil |
| 138 | } |
| 139 | |
| 140 | // handleCACerts returns the certificate chain for a particular |
| 141 | // CA by its ID. If the CA ID is the default, then the CA will be |
no test coverage detected