MCPcopy
hub / github.com/smallstep/cli / AddCertificate

Method AddCertificate

internal/sshutil/agent.go:245–271  ·  view source on GitHub ↗

AddCertificate adds the given certificate to the agent.

(subject string, cert *ssh.Certificate, priv interface{})

Source from the content-addressed store, hash-verified

243
244// AddCertificate adds the given certificate to the agent.
245func (a *Agent) AddCertificate(subject string, cert *ssh.Certificate, priv interface{}) error {
246 var (
247 lifetime uint64
248 now = cast.Uint64(time.Now().Unix())
249 )
250 switch {
251 case cert.ValidBefore == ssh.CertTimeInfinity:
252 // 0 indicates that the certificate should never expire from the agent.
253 lifetime = 0
254 case cert.ValidBefore <= now:
255 return errors.New("error adding certificate to ssh agent - certificate is already expired")
256 default:
257 lifetime = cert.ValidBefore - now
258 }
259
260 // Windows SSH agent fails with a lifetime
261 if runtime.GOOS == "windows" {
262 lifetime = 0
263 }
264
265 return errors.Wrap(a.Add(agent.AddedKey{
266 PrivateKey: priv,
267 Certificate: cert,
268 Comment: subject,
269 LifetimeSecs: cast.Uint32(lifetime),
270 }), "error adding key to agent")
271}

Callers 4

doLoginIfNeededFunction · 0.80
loginOnUnauthorizedFunction · 0.80
loginActionFunction · 0.80
certificateActionFunction · 0.80

Calls 2

Uint64Function · 0.92
Uint32Function · 0.92

Tested by

no test coverage detected