@@ -26,7 +26,8 @@ func (s *SSHRenewRequest) Validate() error {
26
26
27
27
// SSHRenewResponse is the response object that returns the SSH certificate.
28
28
type SSHRenewResponse struct {
29
- Certificate SSHCertificate `json:"crt"`
29
+ Certificate SSHCertificate `json:"crt"`
30
+ IdentityCertificate []Certificate `json:"identityCrt,omitempty"`
30
31
}
31
32
32
33
// 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) {
62
63
return
63
64
}
64
65
66
+ identity , err := h .renewIdentityCertificate (r )
67
+ if err != nil {
68
+ WriteError (w , errs .Forbidden (err ))
69
+ return
70
+ }
71
+
65
72
JSONStatus (w , & SSHSignResponse {
66
- Certificate : SSHCertificate {newCert },
73
+ Certificate : SSHCertificate {newCert },
74
+ IdentityCertificate : identity ,
67
75
}, http .StatusCreated )
68
76
}
77
+
78
+ // renewIdentityCertificate request the client TLS certificate if present.
79
+ func (h * caHandler ) renewIdentityCertificate (r * http.Request ) ([]Certificate , error ) {
80
+ if r .TLS == nil || len (r .TLS .PeerCertificates ) == 0 {
81
+ return nil , nil
82
+ }
83
+
84
+ certChain , err := h .Authority .Renew (r .TLS .PeerCertificates [0 ])
85
+ if err != nil {
86
+ return nil , err
87
+ }
88
+
89
+ return certChainToPEM (certChain ), nil
90
+ }
0 commit comments