File tree Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Expand file tree Collapse file tree 1 file changed +11
-0
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import (
1313 "os"
1414 "os/user"
1515 "path"
16+ "slices"
1617 "strings"
1718 "syscall"
1819
@@ -141,6 +142,8 @@ func main() {
141142 }
142143 defer tpm .Close ()
143144
145+ supportedECCBitsizes := key .SupportedECCAlgorithms (tpm )
146+
144147 if listsupported {
145148 fmt .Printf ("ecdsa bit lengths:" )
146149 for _ , alg := range key .SupportedECCAlgorithms (tpm ) {
@@ -207,6 +210,11 @@ func main() {
207210 case "ecdsa" :
208211 tpmkeyType = tpm2 .TPMAlgECC
209212 filename = "id_ecdsa"
213+
214+ if ! slices .Contains (supportedECCBitsizes , bits ) {
215+ log .Fatalf ("invalid ecdsa key length: TPM does not support %v bits" , bits )
216+ }
217+
210218 case "rsa" :
211219 tpmkeyType = tpm2 .TPMAlgRSA
212220 filename = "id_rsa"
@@ -257,6 +265,9 @@ func main() {
257265 switch key := rawKey .(type ) {
258266 case * ecdsa.PrivateKey :
259267 toImportKey = * key
268+ if ! slices .Contains (supportedECCBitsizes , key .Params ().BitSize ) {
269+ log .Fatalf ("invalid ecdsa key length: TPM does not support %v bits" , key .Params ().BitSize )
270+ }
260271 case * rsa.PrivateKey :
261272 if key .N .BitLen () != 2048 {
262273 log .Fatal ("can only support 2048 bit RSA" )
You can’t perform that action at this time.
0 commit comments