mirror of
https://github.com/rvtr/ctr_eFuse.git
synced 2025-11-02 00:11:04 -04:00
hsm_utils/import_ras_keypair:getopt_long を導入し外部から任意の鍵を指定できるようにした。
git-svn-id: file:///Volumes/Transfer/gigaleak_20231201/2020-09-30%20-%20paladin.7z/paladin/ctr_eFuse@231 ff987cc8-cf2f-4642-8568-d52cce064691
This commit is contained in:
parent
ef3720f6a9
commit
ebf59663ed
@ -5,6 +5,7 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <getopt.h>
|
||||||
|
|
||||||
// openssl
|
// openssl
|
||||||
#include <openssl/err.h>
|
#include <openssl/err.h>
|
||||||
@ -25,8 +26,8 @@
|
|||||||
#include "my_hsm_bignum.h"
|
#include "my_hsm_bignum.h"
|
||||||
#include "my_hsm_alloc.h"
|
#include "my_hsm_alloc.h"
|
||||||
|
|
||||||
#define PRIV_KEY_FILE "./test_key/test-rsa-privkey2048.der"
|
#define DEFAULT_PRIV_KEY_FILE_PATH "./test_key/test-rsa-privkey2048.der"
|
||||||
#define PUB_KEY_FILE "./test_key/test-rsa-pubkey2048.der"
|
#define DEFAULT_PUB_KEY_FILE_PATH "./test_key/test-rsa-pubkey2048.der"
|
||||||
|
|
||||||
#define MODULE_ID 1
|
#define MODULE_ID 1
|
||||||
#define DATA_LEN 256 // bytes
|
#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];
|
unsigned char save_enc[DATA_LEN];
|
||||||
|
|
||||||
|
char *privKeyFilePath = DEFAULT_PRIV_KEY_FILE_PATH;
|
||||||
|
char *pubKeyFilePath = DEFAULT_PUB_KEY_FILE_PATH;
|
||||||
|
|
||||||
// function
|
// function
|
||||||
int importRSAPrivate( NFKM_KeyIdent keyident );
|
int importRSAPrivate( NFKM_KeyIdent keyident );
|
||||||
int importRSAPublic( NFKM_KeyIdent keyident );
|
int importRSAPublic( NFKM_KeyIdent keyident );
|
||||||
@ -98,10 +102,10 @@ int importRSAPrivate( NFKM_KeyIdent keyident )
|
|||||||
memset( &privBn, 0, sizeof( privBn ) );
|
memset( &privBn, 0, sizeof( privBn ) );
|
||||||
|
|
||||||
// key data open
|
// key data open
|
||||||
fp = fopen( PRIV_KEY_FILE, "rb" );
|
fp = fopen( privKeyFilePath, "rb" );
|
||||||
if ( !fp )
|
if ( !fp )
|
||||||
{
|
{
|
||||||
printf( "error : open %s file\n", PRIV_KEY_FILE );
|
printf( "error : open %s file\n", privKeyFilePath );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
privkey = d2i_RSAPrivateKey_fp( fp, NULL );
|
privkey = d2i_RSAPrivateKey_fp( fp, NULL );
|
||||||
@ -409,10 +413,10 @@ int importRSAPublic( NFKM_KeyIdent keyident )
|
|||||||
memset( &pubBn, 0, sizeof( pubBn ) );
|
memset( &pubBn, 0, sizeof( pubBn ) );
|
||||||
|
|
||||||
// key data open
|
// key data open
|
||||||
fp = fopen( PUB_KEY_FILE, "rb" );
|
fp = fopen( pubKeyFilePath, "rb" );
|
||||||
if ( !fp )
|
if ( !fp )
|
||||||
{
|
{
|
||||||
printf( "error : open %s file\n", PUB_KEY_FILE );
|
printf( "error : open %s file\n", pubKeyFilePath );
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
pubkey = d2i_RSA_PUBKEY_fp( fp, NULL );
|
pubkey = d2i_RSA_PUBKEY_fp( fp, NULL );
|
||||||
@ -810,6 +814,51 @@ int main( int argc, char *argv[] )
|
|||||||
memset( &cmd, 0, sizeof( cmd ) );
|
memset( &cmd, 0, sizeof( cmd ) );
|
||||||
memset( &reply, 0, sizeof( reply ) );
|
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
|
// init nFast
|
||||||
result = NFastApp_InitEx( &handle, NULL, NULL );
|
result = NFastApp_InitEx( &handle, NULL, NULL );
|
||||||
if ( result != Status_OK )
|
if ( result != Status_OK )
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user