8383#define IMPORT_HASH (1 << 21)
8484#define DELETE_HASH (1 << 22)
8585#define VERBOSITY (1 << 23)
86+ #define TIMEOUT (1 << 24)
8687
8788#define DEFAULT_CRYPT_METHOD SHA512_BASED
8889#define DEFAULT_SALT_SIZE SHA512_SALT_MAX
@@ -156,6 +157,7 @@ print_help ()
156157 printf (" --kek\t\t\t\t\tList the keys in KEK\n" );
157158 printf (" --db\t\t\t\t\tList the keys in db\n" );
158159 printf (" --dbx\t\t\t\t\tList the keys in dbx\n" );
160+ printf (" --set-timeout <-1,0..0x7fff>\t\tSet the timeout for MOK prompt\n" );
159161 printf ("\n" );
160162 printf ("Supplimentary Options:\n" );
161163 printf (" --hash-file <hash file>\t\tUse the specific password hash\n" );
@@ -1977,6 +1979,33 @@ generate_pw_hash (const char *input_pw)
19771979 return 0 ;
19781980}
19791981
1982+ static int
1983+ set_timeout (char * t )
1984+ {
1985+ int timeout = strtol (t , NULL , 10 );
1986+
1987+ if (errno == ERANGE || timeout > 0x7fff )
1988+ timeout = 0x7fff ;
1989+ if (timeout < 0 )
1990+ timeout = -1 ;
1991+
1992+ if (timeout != 10 ) {
1993+ uint32_t attributes = EFI_VARIABLE_NON_VOLATILE
1994+ | EFI_VARIABLE_BOOTSERVICE_ACCESS
1995+ | EFI_VARIABLE_RUNTIME_ACCESS ;
1996+ if (efi_set_variable (efi_guid_shim , "MokTimeout" ,
1997+ & timeout , sizeof (timeout ),
1998+ attributes , S_IRUSR | S_IWUSR ) < 0 ) {
1999+ fprintf (stderr , "Failed to set MokTimeout\n" );
2000+ return -1 ;
2001+ }
2002+ } else {
2003+ return test_and_delete_var ("MokTimeout" );
2004+ }
2005+
2006+ return 0 ;
2007+ }
2008+
19802009static int
19812010set_verbosity (uint8_t verbosity )
19822011{
@@ -2026,6 +2055,7 @@ main (int argc, char *argv[])
20262055 char * hash_file = NULL ;
20272056 char * input_pw = NULL ;
20282057 char * hash_str = NULL ;
2058+ char * timeout = NULL ;
20292059 const char * option ;
20302060 int c , i , f_ind , total = 0 ;
20312061 unsigned int command = 0 ;
@@ -2073,6 +2103,7 @@ main (int argc, char *argv[])
20732103 {"kek" , no_argument , 0 , 0 },
20742104 {"db" , no_argument , 0 , 0 },
20752105 {"dbx" , no_argument , 0 , 0 },
2106+ {"timeout" , required_argument , 0 , 0 },
20762107 {0 , 0 , 0 , 0 }
20772108 };
20782109
@@ -2160,6 +2191,9 @@ main (int argc, char *argv[])
21602191 command |= LIST_ENROLLED ;
21612192 db_name = DBX ;
21622193 }
2194+ } else if (strcmp (option , "timeout" ) == 0 ) {
2195+ command |= TIMEOUT ;
2196+ timeout = strdup (optarg );
21632197 }
21642198
21652199 break ;
@@ -2419,6 +2453,9 @@ main (int argc, char *argv[])
24192453 case VERBOSITY :
24202454 ret = set_verbosity (verbosity );
24212455 break ;
2456+ case TIMEOUT :
2457+ ret = set_timeout (timeout );
2458+ break ;
24222459 default :
24232460 print_help ();
24242461 break ;
@@ -2431,6 +2468,9 @@ main (int argc, char *argv[])
24312468 free (files );
24322469 }
24332470
2471+ if (timeout )
2472+ free (timeout );
2473+
24342474 if (key_file )
24352475 free (key_file );
24362476
0 commit comments