diff --git a/hsm_utils/import_asymmetric_key.c b/hsm_utils/import_asymmetric_key.c index fe35f79..d669d3a 100644 --- a/hsm_utils/import_asymmetric_key.c +++ b/hsm_utils/import_asymmetric_key.c @@ -26,7 +26,7 @@ #include "simplecmd.h" -#define PUB_KEY_FILE "/opt/nfast/work/rsa-pub-key2048.der" +#define PUB_KEY_FILE "/opt/nfast/work/rsa-priv-key2048.der" #define MODULE_ID 1 #define DATA_LEN 256 // bytes @@ -86,7 +86,7 @@ int my_bignumsendlenupcall( struct NFast_Application *app, const M_Bignum *bignum, int *nbytes_r ) { char *ptr = (char*)bignum; - printf( "%08X\n", ptr ); + printf( "%08X\n", (unsigned int)ptr ); while( *ptr ) printf( "%02X ", *(ptr++) ); @@ -113,7 +113,7 @@ int main( int argc, char *argv[] ) rand_size = atoi( argv[1] ); // load rsa data(public) - RSA *pubkey = NULL; + RSA *privkey = NULL; FILE *fp; fp = fopen( PUB_KEY_FILE, "rb" ); if ( !fp ) @@ -122,14 +122,14 @@ int main( int argc, char *argv[] ) return 0; } - printf( "before : %08X\n", pubkey ); - pubkey = d2i_RSA_PUBKEY_fp( fp, NULL ); - if ( !pubkey ) + printf( "before : %08X\n", privkey ); + privkey = d2i_RSAPrivateKey_fp( fp, NULL ); + if ( !privkey ) { - printf( "error : d2i_RSA_PUBKEY_fp\n" ); + printf( "error : d2i_RSAPrivateKey_fp\n" ); return 0; } - printf( "after : %08X\n", pubkey ); + printf( "after : %08X\n", privkey ); // init nFast NFastAppInitArgs app_init_args; @@ -286,12 +286,13 @@ int main( int argc, char *argv[] ) } // import key - NFKM_KeyIdent keyident = { (char*)"custom", (char*)"rsa-import-pubkey" }; + NFKM_KeyIdent keyident = { (char*)"simple", (char*)"rsa-import-privkey" }; tc.cmd.cmd = Cmd_Import; tc.cmd.args.import.module = MODULE_ID; - tc.cmd.args.import.data.type = KeyType_RSAPublic; - tc.cmd.args.import.data.data.rsapublic.e = (M_Bignum)pubkey->e; // Public exponent of the RSA keypair - tc.cmd.args.import.data.data.rsapublic.n = (M_Bignum)pubkey->n; // Modules of the RSA keypair + tc.cmd.args.import.data.type = KeyType_RSAPrivate; + tc.cmd.args.import.data.data.rsaprivate.p = + tc.cmd.args.import.data.data.rsapublic.e = (M_Bignum)privkey->e; // Public exponent of the RSA keypair + tc.cmd.args.import.data.data.rsapublic.n = (M_Bignum)privkey->n; // Modules of the RSA keypair result = NFastApp_Transact( nc, NULL, &(tc.cmd), &(tc.reply), NULL ); if ( result != Status_OK ) { @@ -347,7 +348,7 @@ int main( int argc, char *argv[] ) #endif // find key - NFKM_KeyIdent ki_v = { (char*)"custom", (char*)"rsa-import-pubkey" }; + NFKM_KeyIdent ki_v = { (char*)"custom", (char*)"rsa-import-privkey" }; printf( "appname : %s, ident : %s\n", ki_v.appname, ki_v.ident );