@@ -24,9 +24,13 @@ import (
2424var Version string
2525
2626const usage = `Usage:
27- ssh-tpm-add [FILE ...]
27+ ssh-tpm-add [-c] [ FILE ...]
2828 ssh-tpm-add --ca [URL] --user [USER] --host [HOSTNAME]
2929
30+ Options:
31+ -c Require confirmation via SSH_ASKPASS before each
32+ use of the key for signing.
33+
3034Options for CA provisioning:
3135 --ca URL URL to the CA authority for CA key provisioning.
3236 --user USER Username of the ssh server user.
@@ -44,10 +48,12 @@ func main() {
4448 }
4549
4650 var caURL , host , user string
51+ var confirm bool
4752
4853 flag .StringVar (& caURL , "ca" , "" , "ca authority" )
4954 flag .StringVar (& host , "host" , "" , "ssh hot" )
5055 flag .StringVar (& user , "user" , "" , "remote ssh user" )
56+ flag .BoolVar (& confirm , "c" , false , "require confirmation before each use" )
5157 flag .Parse ()
5258
5359 socket := utils .EnvSocketPath ("" )
@@ -60,15 +66,15 @@ func main() {
6066
6167 var ignorefile bool
6268 var paths []string
63- if len ( os . Args ) == 1 {
69+ if flag . NArg ( ) == 0 && caURL == "" {
6470 sshdir := utils .SSHDir ()
6571 paths = []string {
6672 fmt .Sprintf ("%s/id_ecdsa.tpm" , sshdir ),
6773 fmt .Sprintf ("%s/id_rsa.tpm" , sshdir ),
6874 }
6975 ignorefile = true
70- } else if len ( os . Args ) != 1 {
71- paths = os .Args [ 1 :]
76+ } else {
77+ paths = flag .Args ()
7278 }
7379
7480 lsm .RestrictAdditionalPaths (
@@ -101,9 +107,10 @@ func main() {
101107
102108 sshagentclient := sshagent .NewClient (conn )
103109 addedkey := sshagent.AddedKey {
104- PrivateKey : k ,
105- Comment : k .Description ,
106- Certificate : cert ,
110+ PrivateKey : k ,
111+ Comment : k .Description ,
112+ Certificate : cert ,
113+ ConfirmBeforeUse : confirm ,
107114 }
108115
109116 _ , err = sshagentclient .Extension (agent .SSH_TPM_AGENT_ADD , agent .MarshalTPMKeyMsg (& addedkey ))
@@ -132,13 +139,17 @@ func main() {
132139
133140 if _ , err = client .Extension (agent .SSH_TPM_AGENT_ADD , agent .MarshalTPMKeyMsg (
134141 & sshagent.AddedKey {
135- PrivateKey : k ,
136- Comment : k .Description ,
142+ PrivateKey : k ,
143+ Comment : k .Description ,
144+ ConfirmBeforeUse : confirm ,
137145 },
138146 )); err != nil {
139147 log .Fatal (err )
140148 }
141149 fmt .Printf ("Identity added: %s (%s)\n " , path , k .Description )
150+ if confirm {
151+ fmt .Printf ("The user must confirm each use of the key\n " )
152+ }
142153
143154 certStr := fmt .Sprintf ("%s-cert.pub" , strings .TrimSuffix (path , filepath .Ext (path )))
144155 if _ , err := os .Stat (certStr ); ! errors .Is (err , os .ErrNotExist ) {
@@ -157,9 +168,10 @@ func main() {
157168 }
158169 if _ , err = client .Extension (agent .SSH_TPM_AGENT_ADD , agent .MarshalTPMKeyMsg (
159170 & sshagent.AddedKey {
160- PrivateKey : k ,
161- Certificate : cert ,
162- Comment : k .Description ,
171+ PrivateKey : k ,
172+ Certificate : cert ,
173+ Comment : k .Description ,
174+ ConfirmBeforeUse : confirm ,
163175 },
164176 )); err != nil {
165177 log .Fatal (err )
0 commit comments