diff options
-rw-r--r-- | base/native-tools/src/tkstool/file.c | 25 | ||||
-rw-r--r-- | base/native-tools/src/tkstool/tkstool.c | 64 | ||||
-rw-r--r-- | base/native-tools/src/tkstool/tkstool.h | 2 |
3 files changed, 70 insertions, 21 deletions
diff --git a/base/native-tools/src/tkstool/file.c b/base/native-tools/src/tkstool/file.c index d757225fc..6e95f03fa 100644 --- a/base/native-tools/src/tkstool/file.c +++ b/base/native-tools/src/tkstool/file.c @@ -516,3 +516,28 @@ destroyHexWrappedKey: return status; } +SECStatus +TKS_WriteSharedKeyIntoOutputFile( char *output ) +{ + SECStatus status = SECSuccess; + PRFileDesc *fd = NULL; + PRInt32 r = 0; + + fd = PR_Open( output, ( PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE ), 0600 ); + if( !fd ) { + status = SECFailure; + goto done; + } + + r = PR_Write( fd, "<SharedKey></SharedKey>\n", 24 ); + if( r < 0 ) { + status = SECFailure; + goto close; + } + +close: + PR_Close( fd ); + +done: + return status; +} diff --git a/base/native-tools/src/tkstool/tkstool.c b/base/native-tools/src/tkstool/tkstool.c index 5368b2e7b..c11151e1c 100644 --- a/base/native-tools/src/tkstool/tkstool.c +++ b/base/native-tools/src/tkstool/tkstool.c @@ -356,7 +356,7 @@ main( int argc, char **argv ) /* the "-U" command */ if( tkstool.options[opt_InFile].activated && !tkstool.commands[cmd_UnWrapMasterKey].activated ) { - PR_fprintf( PR_STDERR, + PR_fprintf( PR_STDERR, "%s -%c: the \"-i infile\" option may only be " "specified with one of the following command(s):\n\n", progName, @@ -392,10 +392,11 @@ main( int argc, char **argv ) } /* the "-o outfile" command option may ONLY be used with */ - /* the "-W" command */ - if( tkstool.options[opt_OutFile].activated && - !tkstool.commands[cmd_WrapMasterKey].activated ) { - PR_fprintf( PR_STDERR, + /* the "-T" and "-W" command */ + if( tkstool.options[opt_OutFile].activated && + ! ( tkstool.commands[cmd_WrapMasterKey].activated || + tkstool.commands[cmd_GenTransportKey].activated ) ) { + PR_fprintf( PR_STDERR, "%s -%c: the \"-o outfile\" option may only be " "specified with one of the following command(s):\n\n", progName, @@ -1019,25 +1020,26 @@ main( int argc, char **argv ) } - /***********************************/ - /* Clear screen and wait for user. */ - /***********************************/ + if( ! tkstool.options[opt_OutFile].activated ) { + /***********************************/ + /* Clear screen and wait for user. */ + /***********************************/ - TKS_ClearScreen(); + TKS_ClearScreen(); - if( tkstool.commands[cmd_GenTransportKey].activated ) { - PR_fprintf( PR_STDOUT, - "\nThe next screen generates the " - "first session key share . . .\n" ); - } else { - /* ( tkstool.commands[cmd_InputGenTransportKey].activated ) */ - PR_fprintf( PR_STDOUT, - "\nUse the next screen to input the " - "first session key share . . .\n" ); - } - - TKS_TypeProceedToContinue(); + if( tkstool.commands[cmd_GenTransportKey].activated ) { + PR_fprintf( PR_STDOUT, + "\nThe next screen generates the " + "first session key share . . .\n" ); + } else { + /* ( tkstool.commands[cmd_InputGenTransportKey].activated ) */ + PR_fprintf( PR_STDOUT, + "\nUse the next screen to input the " + "first session key share . . .\n" ); + } + TKS_TypeProceedToContinue(); + } /******************************************************************/ /* Input ("-I"), or Generate ("-T"), the first session key share. */ @@ -1097,6 +1099,26 @@ main( int argc, char **argv ) DES_LENGTH ); #endif + if( tkstool.options[opt_OutFile].activated ) { + /**************************************************************/ + /* Write the wrapped master key to the specified output file. */ + /**************************************************************/ + + PR_fprintf( PR_STDOUT, + "Writing shared keys into the file called\n\"%s\" . . .\n\n", + output ); + rv = TKS_WriteSharedKeyIntoOutputFile( output ); + if( rv != SECSuccess ) { + PR_fprintf( PR_STDERR, + "%s -%c: %s: %d\n", + progName, + commandToRun, + "unable to save the shared keys", + PR_GetError() ); + goto shutdown; + } + goto shutdown; + } /***********************************/ /* Clear screen and wait for user. */ diff --git a/base/native-tools/src/tkstool/tkstool.h b/base/native-tools/src/tkstool/tkstool.h index 3b0407227..0a509a49f 100644 --- a/base/native-tools/src/tkstool/tkstool.h +++ b/base/native-tools/src/tkstool/tkstool.h @@ -171,6 +171,8 @@ TKS_WriteSECItemIntoOutputFile( SECItem *wrappedKey, int hexInternalKeyKCVLength, char *output ); +SECStatus +TKS_WriteSharedKeyIntoOutputFile( char *output ); /**********/ /* find.c */ |