@@ -1526,6 +1526,58 @@ static int debug_unlock_token(int argc, char **argv)
15261526 return 0 ;
15271527}
15281528
1529+ #define CMD_DESC_CSR_GET "get Device ID Certificate Signing Request (CSR)"
1530+
1531+ static int csr_get (int argc , char * * argv )
1532+ {
1533+ int ret ;
1534+
1535+ const char * desc = CMD_DESC_CSR_GET "\n\n"
1536+ "This command can only be used in Main Firmware.\n\n"
1537+ "It gets the DevID Certificate Signing Request (CSR)"
1538+ "in DER format and save it to a specified file\n" ;
1539+
1540+ static struct {
1541+ struct switchtec_dev * dev ;
1542+ int csr_fd ;
1543+ const char * csr_file_name ;
1544+ int assume_yes ;
1545+ } cfg = {
1546+ .csr_fd = 0 ,
1547+ };
1548+ const struct argconfig_options opts [] = {
1549+ DEVICE_OPTION_MFG ,
1550+ {"csr_file" , .cfg_type = CFG_FD_WR , .value_addr = & cfg .csr_fd ,
1551+ .argument_type = optional_positional ,
1552+ .force_default = "devid_csr.der" ,
1553+ .help = "The CSR file to save to disk" },
1554+ {"yes" , 'y' , "" , CFG_NONE , & cfg .assume_yes , no_argument ,
1555+ "assume yes when prompted" },
1556+ {NULL }
1557+ };
1558+
1559+ argconfig_parse (argc , argv , desc , opts , & cfg , sizeof (cfg ));
1560+
1561+ if (switchtec_boot_phase (cfg .dev ) != SWITCHTEC_BOOT_PHASE_FW ) {
1562+ fprintf (stderr ,
1563+ "This command is only available in Main Firmware!\n" );
1564+ return -1 ;
1565+ }
1566+
1567+ ret = switchtec_csr_to_file (cfg .dev , cfg .csr_fd );
1568+ if (ret ) {
1569+ switchtec_perror ("mfg csr_get" );
1570+ close (cfg .csr_fd );
1571+ return ret ;
1572+ }
1573+
1574+ close (cfg .csr_fd );
1575+
1576+ fprintf (stderr , "\nCertificate Signing Request (CSR) saved to %s.\n" , cfg .csr_file_name );
1577+
1578+ return 0 ;
1579+ }
1580+
15291581static const struct cmd commands [] = {
15301582 CMD (ping , CMD_DESC_PING ),
15311583 CMD (info , CMD_DESC_INFO ),
@@ -1541,6 +1593,7 @@ static const struct cmd commands[] = {
15411593 CMD (debug_unlock_token , CMD_DESC_DEBUG_TOKEN ),
15421594 CMD (debug_unlock , CMD_DESC_DEBUG_UNLOCK ),
15431595 CMD (debug_lock_update , CMD_DESC_DEBUG_LOCK_UPDATE ),
1596+ CMD (csr_get , CMD_DESC_CSR_GET ),
15441597 {}
15451598};
15461599
0 commit comments