AddCertificate adds the given certificate to the agent.
(subject string, cert *ssh.Certificate, priv interface{})
| 243 | |
| 244 | // AddCertificate adds the given certificate to the agent. |
| 245 | func (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 | } |
no test coverage detected