@@ -34,8 +34,12 @@ Options:
3434 -f Output keyfile.
3535 -N PIN for the key.
3636 -t ecdsa | rsa Specify the type of key to create. Defaults to ecdsa
37+ -b bits Number of bits in the key to create.
38+ rsa: 2048 (default)
39+ ecdsa: 256 (default) | 384 | 521
3740 -I, --import PATH Import existing key into ssh-tpm-agent.
3841 -A Generate host keys for all key types (rsa and ecdsa).
42+ --supported List the supported keys of the TPM.
3943
4044Generate new TPM sealed keys for ssh-tpm-agent.
4145
@@ -97,7 +101,9 @@ func main() {
97101 var (
98102 comment , outputFile , keyPin string
99103 keyType , importKey string
104+ bits int
100105 swtpmFlag , hostKeys bool
106+ listsupported bool
101107 )
102108
103109 defaultComment := func () string {
@@ -120,10 +126,12 @@ func main() {
120126 flag .StringVar (& outputFile , "f" , "" , "output keyfile" )
121127 flag .StringVar (& keyPin , "N" , "" , "new pin for the key" )
122128 flag .StringVar (& keyType , "t" , "ecdsa" , "key to create" )
129+ flag .IntVar (& bits , "b" , 0 , "number of bits" )
123130 flag .StringVar (& importKey , "I" , "" , "import key" )
124131 flag .StringVar (& importKey , "import" , "" , "import key" )
125132 flag .BoolVar (& swtpmFlag , "swtpm" , false , "use swtpm instead of actual tpm" )
126133 flag .BoolVar (& hostKeys , "A" , false , "generate host keys" )
134+ flag .BoolVar (& listsupported , "supported" , false , "list tpm caps" )
127135
128136 flag .Parse ()
129137
@@ -133,6 +141,16 @@ func main() {
133141 }
134142 defer tpm .Close ()
135143
144+ if listsupported {
145+ fmt .Printf ("ecdsa bit lengths:" )
146+ for _ , alg := range key .SupportedECCAlgorithms (tpm ) {
147+ fmt .Printf (" %d" , alg )
148+ }
149+ fmt .Println ()
150+ fmt .Println ("rsa bit lengths: 2048" )
151+ os .Exit (0 )
152+ }
153+
136154 // Generate host keys
137155 if hostKeys {
138156 // Mimics the `ssh-keygen -A -f ./something` behaviour
@@ -141,9 +159,12 @@ func main() {
141159 outputPath = path .Join (outputFile , outputPath )
142160 }
143161
144- lookup := map [string ]tpm2.TPMAlgID {
145- "rsa" : tpm2 .TPMAlgRSA ,
146- "ecdsa" : tpm2 .TPMAlgECDSA ,
162+ lookup := map [string ]struct {
163+ alg tpm2.TPMAlgID
164+ bits int
165+ }{
166+ "rsa" : {alg : tpm2 .TPMAlgRSA , bits : 2048 },
167+ "ecdsa" : {alg : tpm2 .TPMAlgECDSA , bits : 256 },
147168 }
148169 for n , t := range lookup {
149170 filename := fmt .Sprintf ("ssh_tpm_host_%s_key" , n )
@@ -156,7 +177,7 @@ func main() {
156177
157178 slog .Info ("Generating new host key" , slog .String ("algorithm" , strings .ToUpper (n )))
158179
159- k , err := key .CreateKey (tpm , t , []byte ("" ), []byte (defaultComment ))
180+ k , err := key .CreateKey (tpm , t . alg , t . bits , []byte ("" ), []byte (defaultComment ))
160181 if err != nil {
161182 log .Fatal (err )
162183 }
@@ -311,7 +332,7 @@ func main() {
311332 log .Fatal (err )
312333 }
313334 } else {
314- k , err = key .CreateKey (tpm , tpmkeyType , pin , []byte (comment ))
335+ k , err = key .CreateKey (tpm , tpmkeyType , bits , pin , []byte (comment ))
315336 if err != nil {
316337 log .Fatal (err )
317338 }
0 commit comments