forked from TrueCloudLab/certificates
Renew identity certificate in /ssh/rekey and /ssh/renew
This commit is contained in:
parent
0b5d37b284
commit
a6deea7d8d
2 changed files with 35 additions and 5 deletions
|
@ -31,6 +31,7 @@ func (s *SSHRekeyRequest) Validate() error {
|
||||||
// SSHRekeyResponse is the response object that returns the SSH certificate.
|
// SSHRekeyResponse is the response object that returns the SSH certificate.
|
||||||
type SSHRekeyResponse struct {
|
type SSHRekeyResponse struct {
|
||||||
Certificate SSHCertificate `json:"crt"`
|
Certificate SSHCertificate `json:"crt"`
|
||||||
|
IdentityCertificate []Certificate `json:"identityCrt,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSHRekey is an HTTP handler that reads an RekeySSHRequest with a one-time-token
|
// SSHRekey is an HTTP handler that reads an RekeySSHRequest with a one-time-token
|
||||||
|
@ -72,7 +73,14 @@ func (h *caHandler) SSHRekey(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
JSONStatus(w, &SSHSignResponse{
|
identity, err := h.renewIdentityCertificate(r)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, errs.Forbidden(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
JSONStatus(w, &SSHRekeyResponse{
|
||||||
Certificate: SSHCertificate{newCert},
|
Certificate: SSHCertificate{newCert},
|
||||||
|
IdentityCertificate: identity,
|
||||||
}, http.StatusCreated)
|
}, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,6 +27,7 @@ func (s *SSHRenewRequest) Validate() error {
|
||||||
// SSHRenewResponse is the response object that returns the SSH certificate.
|
// SSHRenewResponse is the response object that returns the SSH certificate.
|
||||||
type SSHRenewResponse struct {
|
type SSHRenewResponse struct {
|
||||||
Certificate SSHCertificate `json:"crt"`
|
Certificate SSHCertificate `json:"crt"`
|
||||||
|
IdentityCertificate []Certificate `json:"identityCrt,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// SSHRenew is an HTTP handler that reads an RenewSSHRequest with a one-time-token
|
// SSHRenew is an HTTP handler that reads an RenewSSHRequest with a one-time-token
|
||||||
|
@ -62,7 +63,28 @@ func (h *caHandler) SSHRenew(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
identity, err := h.renewIdentityCertificate(r)
|
||||||
|
if err != nil {
|
||||||
|
WriteError(w, errs.Forbidden(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
JSONStatus(w, &SSHSignResponse{
|
JSONStatus(w, &SSHSignResponse{
|
||||||
Certificate: SSHCertificate{newCert},
|
Certificate: SSHCertificate{newCert},
|
||||||
|
IdentityCertificate: identity,
|
||||||
}, http.StatusCreated)
|
}, http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// renewIdentityCertificate request the client TLS certificate if present.
|
||||||
|
func (h *caHandler) renewIdentityCertificate(r *http.Request) ([]Certificate, error) {
|
||||||
|
if r.TLS == nil || len(r.TLS.PeerCertificates) == 0 {
|
||||||
|
return nil, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
certChain, err := h.Authority.Renew(r.TLS.PeerCertificates[0])
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
|
return certChainToPEM(certChain), nil
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue