authReq is the common logic for AuthSign and AuthInfo -- perform the given request, and return the resultant certificate. The target is either 'sign' or 'info'.
(req, ID []byte, provider auth.Provider, target string)
| 205 | // request, and return the resultant certificate. |
| 206 | // The target is either 'sign' or 'info'. |
| 207 | func (srv *server) authReq(req, ID []byte, provider auth.Provider, target string) ([]byte, error) { |
| 208 | url := srv.getURL("auth" + target) |
| 209 | |
| 210 | token, err := provider.Token(req) |
| 211 | if err != nil { |
| 212 | return nil, errors.Wrap(errors.APIClientError, errors.AuthenticationFailure, err) |
| 213 | } |
| 214 | |
| 215 | aReq := &auth.AuthenticatedRequest{ |
| 216 | Timestamp: time.Now().Unix(), |
| 217 | RemoteAddress: ID, |
| 218 | Token: token, |
| 219 | Request: req, |
| 220 | } |
| 221 | |
| 222 | jsonData, err := json.Marshal(aReq) |
| 223 | if err != nil { |
| 224 | return nil, errors.Wrap(errors.APIClientError, errors.JSONError, err) |
| 225 | } |
| 226 | |
| 227 | response, err := srv.post(url, jsonData) |
| 228 | if err != nil { |
| 229 | return nil, err |
| 230 | } |
| 231 | |
| 232 | result, ok := response.Result.(map[string]interface{}) |
| 233 | if !ok { |
| 234 | return nil, errors.New(errors.APIClientError, errors.JSONError) |
| 235 | } |
| 236 | |
| 237 | cert, ok := result["certificate"].(string) |
| 238 | if !ok { |
| 239 | return nil, errors.New(errors.APIClientError, errors.JSONError) |
| 240 | } |
| 241 | |
| 242 | return []byte(cert), nil |
| 243 | } |
| 244 | |
| 245 | // Sign sends a signature request to the remote CFSSL server, |
| 246 | // receiving a signed certificate or an error in response. |