From ebf59663edcae70046bb53af4ea4447c16f6e990 Mon Sep 17 00:00:00 2001 From: n2460 Date: Thu, 10 Oct 2013 07:26:03 +0000 Subject: [PATCH] =?UTF-8?q?hsm=5Futils/import=5Fras=5Fkeypair:getopt=5Flon?= =?UTF-8?q?g=20=E3=82=92=E5=B0=8E=E5=85=A5=E3=81=97=E5=A4=96=E9=83=A8?= =?UTF-8?q?=E3=81=8B=E3=82=89=E4=BB=BB=E6=84=8F=E3=81=AE=E9=8D=B5=E3=82=92?= =?UTF-8?q?=E6=8C=87=E5=AE=9A=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86?= =?UTF-8?q?=E3=81=AB=E3=81=97=E3=81=9F=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@231 ff987cc8-cf2f-4642-8568-d52cce064691 --- trunk/hsm_utils/import_rsa_keypair.c | 63 ++++++++++++++++++++++++---- 1 file changed, 56 insertions(+), 7 deletions(-) diff --git a/trunk/hsm_utils/import_rsa_keypair.c b/trunk/hsm_utils/import_rsa_keypair.c index 32f650a..82f57f5 100644 --- a/trunk/hsm_utils/import_rsa_keypair.c +++ b/trunk/hsm_utils/import_rsa_keypair.c @@ -5,6 +5,7 @@ #include #include #include +#include // openssl #include @@ -25,8 +26,8 @@ #include "my_hsm_bignum.h" #include "my_hsm_alloc.h" -#define PRIV_KEY_FILE "./test_key/test-rsa-privkey2048.der" -#define PUB_KEY_FILE "./test_key/test-rsa-pubkey2048.der" +#define DEFAULT_PRIV_KEY_FILE_PATH "./test_key/test-rsa-privkey2048.der" +#define DEFAULT_PUB_KEY_FILE_PATH "./test_key/test-rsa-pubkey2048.der" #define MODULE_ID 1 #define DATA_LEN 256 // bytes @@ -65,6 +66,9 @@ const NFKM_KeyIdent pub_keyident = { (char*)"simple", (char*)"test-rsa-pubkey204 unsigned char save_enc[DATA_LEN]; +char *privKeyFilePath = DEFAULT_PRIV_KEY_FILE_PATH; +char *pubKeyFilePath = DEFAULT_PUB_KEY_FILE_PATH; + // function int importRSAPrivate( NFKM_KeyIdent keyident ); int importRSAPublic( NFKM_KeyIdent keyident ); @@ -98,10 +102,10 @@ int importRSAPrivate( NFKM_KeyIdent keyident ) memset( &privBn, 0, sizeof( privBn ) ); // key data open - fp = fopen( PRIV_KEY_FILE, "rb" ); + fp = fopen( privKeyFilePath, "rb" ); if ( !fp ) { - printf( "error : open %s file\n", PRIV_KEY_FILE ); + printf( "error : open %s file\n", privKeyFilePath ); return 1; } privkey = d2i_RSAPrivateKey_fp( fp, NULL ); @@ -409,10 +413,10 @@ int importRSAPublic( NFKM_KeyIdent keyident ) memset( &pubBn, 0, sizeof( pubBn ) ); // key data open - fp = fopen( PUB_KEY_FILE, "rb" ); + fp = fopen( pubKeyFilePath, "rb" ); if ( !fp ) { - printf( "error : open %s file\n", PUB_KEY_FILE ); + printf( "error : open %s file\n", pubKeyFilePath ); return 1; } pubkey = d2i_RSA_PUBKEY_fp( fp, NULL ); @@ -809,7 +813,52 @@ int main( int argc, char *argv[] ) memset( &cmd, 0, sizeof( cmd ) ); memset( &reply, 0, sizeof( reply ) ); - + + int opt = 0; + while (1) + { + int optionIndex = 0; + static struct option longOptions[] = + { + { "priv", required_argument, 0, 0 }, + { "pub", required_argument, 0, 0 }, + { 0, 0, 0, 0 } + }; + // - によるオプション禁止、 -- のみ認める + opt = getopt_long(argc, argv, "", longOptions, &optionIndex); + if (opt == -1) + { + break; + } + + switch (opt) + { + case 0 : // long arg + { + switch (optionIndex) + { + case 0 : // priv + { + privKeyFilePath = optarg; + } break; + case 1 : // pub + { + pubKeyFilePath = optarg; + } break; + } + } break; + } + } + printf( "HSM import RSA Key Sample.\n" ); + printf( " --priv filename : specify private RSA key(DER format)\n" ); + printf( " Default=%s\n", DEFAULT_PRIV_KEY_FILE_PATH ); + printf( " --pub filename : specify public RSA key(DER format)\n" ); + printf( " Default=%s\n", DEFAULT_PUB_KEY_FILE_PATH ); + printf( "\n" ); + printf( "----- start -----\n" ); + printf( "import privkey=%s\n", privKeyFilePath ); + printf( "import pubkey=%s\n", pubKeyFilePath ); + // init nFast result = NFastApp_InitEx( &handle, NULL, NULL ); if ( result != Status_OK )