X-Git-Url: https://git.saurik.com/apple/security.git/blobdiff_plain/80e2389990082500d76eb566d4946be3e786c3ef..d8f41ccd20de16f8ebe2ccc84d47bf1cb2b26bbb:/SecurityTests/clxutils/p12/p12.cpp diff --git a/SecurityTests/clxutils/p12/p12.cpp b/SecurityTests/clxutils/p12/p12.cpp new file mode 100644 index 00000000..b877251d --- /dev/null +++ b/SecurityTests/clxutils/p12/p12.cpp @@ -0,0 +1,153 @@ +/* + * multipurpose pkcs12 tool. + */ +#include +#include +#include +#include +#include "p12.h" +#include + +static void usage(char **argv) +{ + printf("Usage:\n"); + printf(" %s p infile [options] parse\n", argv[0]); + printf(" %s d infile [options] decode\n", argv[0]); + printf(" %s e infile [options] decode-->encode\n", argv[0]); + printf(" %s i infile keychain import to keychain\n", argv[0]); + printf(" %s x outfile keychain export from keychain\n", argv[0]); + + printf("Options:\n"); + printf(" p=password\n"); + printf(" z=keychainPassword\n"); + printf(" P (use secure passphrase)\n"); + printf(" k=keychain\n"); + printf(" l=loops\n"); + printf(" n(o prompt; export only)\n"); + printf(" v(erbose)\n"); + /* others here */ + exit(1); +} + +typedef enum { + PR_Parse, + PR_Decode, + PR_Reencode, + PR_Import, + PR_Export +} P12op; + +int main(int argc, char **argv) +{ + char *inFile; + P12op op; + int minArgs = 1; + CFStringRef pwd = NULL; + bool verbose = false; + unsigned loops = 1; + char *kcName = NULL; + bool noPrompt = false; + char *kcPwd = NULL; + bool usePassKey = false; + + if(argc < 2) { + usage(argv); + } + switch(argv[1][0]) { + case 'p': + op = PR_Parse; + minArgs = 3; + break; + case 'd': + op = PR_Decode; + minArgs = 3; + break; + case 'e': + op = PR_Reencode; + minArgs = 3; + break; + case 'i': + op = PR_Import; + minArgs = 4; + break; + case 'x': + op = PR_Export; + minArgs = 4; + break; + default: + usage(argv); + } + if(argc < minArgs) { + usage(argv); + } + for(int arg=minArgs; arg