arguments to pkcs8 application.
int topk8 = 0;
int pbe_nid = -1;
int iter = PKCS12_DEFAULT_ITER;
+ int informat, outformat;
int p8_broken = PKCS8_OK;
X509_SIG *p8;
PKCS8_PRIV_KEY_INFO *p8inf;
char pass[50];
int badarg = 0;
if (bio_err == NULL) bio_err = BIO_new_fp (stderr, BIO_NOCLOSE);
+ informat=FORMAT_PEM;
+ outformat=FORMAT_PEM;
ERR_load_crypto_strings();
SSLeay_add_all_algorithms();
args = argv + 1;
while (!badarg && *args && *args[0] == '-') {
- if (!strcmp (*args, "-topk8")) topk8 = 1;
+ if (!strcmp(*args,"-inform")) {
+ if (args[1]) {
+ args++;
+ informat=str2fmt(*args);
+ } else badarg = 1;
+ } else if (!strcmp(*args,"-outform")) {
+ if (args[1]) {
+ args++;
+ outformat=str2fmt(*args);
+ } else badarg = 1;
+ } else if (!strcmp (*args, "-topk8")) topk8 = 1;
else if (!strcmp (*args, "-noiter")) iter = 1;
else if (!strcmp (*args, "-nooct")) p8_broken = PKCS8_NO_OCTET;
else if (!strcmp (*args, "-in")) {
if (pbe_nid == -1) pbe_nid = NID_pbeWithMD5AndDES_CBC;
if (infile) {
- if (!(in = BIO_new_file (infile, "r"))) {
+ if (!(in = BIO_new_file (infile, "rb"))) {
BIO_printf (bio_err,
"Can't open input file %s\n", infile);
return (1);
} else in = BIO_new_fp (stdin, BIO_NOCLOSE);
if (outfile) {
- if (!(out = BIO_new_file (outfile, "w"))) {
+ if (!(out = BIO_new_file (outfile, "wb"))) {
BIO_printf (bio_err,
"Can't open output file %s\n", outfile);
return (1);
return (0);
}
- if (!(p8 = PEM_read_bio_PKCS8 (in, NULL, NULL))) {
+ if(informat == FORMAT_PEM)
+ p8 = PEM_read_bio_PKCS8(in, NULL, NULL);
+ else if(informat == FORMAT_ASN1)
+ p8 = d2i_PKCS8_bio(in, NULL);
+ else {
+ BIO_printf(bio_err, "Bad input format specified for key\n");
+ return (1);
+ }
+
+ if (!p8) {
BIO_printf (bio_err, "Error reading key\n", outfile);
ERR_print_errors(bio_err);
return (1);
#ifndef NO_DSA
DSA *d2i_DSAPrivateKey_fp(FILE *fp, DSA **dsa);
int i2d_DSAPrivateKey_fp(FILE *fp, DSA *dsa);
+X509_SIG *d2i_PKCS8_fp(FILE *fp,X509_SIG **p8);
+int i2d_PKCS8_fp(FILE *fp,X509_SIG *p8);
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
+ PKCS8_PRIV_KEY_INFO **p8inf);
+int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,PKCS8_PRIV_KEY_INFO *p8inf);
#endif
#endif
#ifndef NO_DSA
DSA *d2i_DSAPrivateKey_bio(BIO *bp, DSA **dsa);
int i2d_DSAPrivateKey_bio(BIO *bp, DSA *dsa);
+X509_SIG *d2i_PKCS8_bio(BIO *bp,X509_SIG **p8);
+int i2d_PKCS8_bio(BIO *bp,X509_SIG *p8);
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
+ PKCS8_PRIV_KEY_INFO **p8inf);
+int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,PKCS8_PRIV_KEY_INFO *p8inf);
#endif
#endif
(char *)data,md,len));
}
+
+#ifndef NO_FP_API
+X509_SIG *d2i_PKCS8_fp(FILE *fp, X509_SIG **p8)
+ {
+ return((X509_SIG *)ASN1_d2i_fp((char *(*)())X509_SIG_new,
+ (char *(*)())d2i_X509_SIG, (fp),(unsigned char **)(p8)));
+ }
+
+int i2d_PKCS8_fp(FILE *fp, X509_SIG *p8)
+ {
+ return(ASN1_i2d_fp(i2d_X509_SIG,fp,(unsigned char *)p8));
+ }
+#endif
+
+X509_SIG *d2i_PKCS8_bio(BIO *bp, X509_SIG **p8)
+ {
+ return((X509_SIG *)ASN1_d2i_bio((char *(*)())X509_SIG_new,
+ (char *(*)())d2i_X509_SIG, (bp),(unsigned char **)(p8)));
+ }
+
+int i2d_PKCS8_bio(BIO *bp, X509_SIG *p8)
+ {
+ return(ASN1_i2d_bio(i2d_X509_SIG,bp,(unsigned char *)p8));
+ }
+
+#ifndef NO_FP_API
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_fp(FILE *fp,
+ PKCS8_PRIV_KEY_INFO **p8inf)
+ {
+ return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_fp(
+ (char *(*)())PKCS8_PRIV_KEY_INFO_new,
+ (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (fp),
+ (unsigned char **)(p8inf)));
+ }
+
+int i2d_PKCS8_PRIV_KEY_INFO_fp(FILE *fp, PKCS8_PRIV_KEY_INFO *p8inf)
+ {
+ return(ASN1_i2d_fp(i2d_PKCS8_PRIV_KEY_INFO,fp,(unsigned char *)p8inf));
+ }
+#endif
+
+PKCS8_PRIV_KEY_INFO *d2i_PKCS8_PRIV_KEY_INFO_bio(BIO *bp,
+ PKCS8_PRIV_KEY_INFO **p8inf)
+ {
+ return((PKCS8_PRIV_KEY_INFO *)ASN1_d2i_bio(
+ (char *(*)())PKCS8_PRIV_KEY_INFO_new,
+ (char *(*)())d2i_PKCS8_PRIV_KEY_INFO, (bp),
+ (unsigned char **)(p8inf)));
+ }
+
+int i2d_PKCS8_PRIV_KEY_INFO_bio(BIO *bp, PKCS8_PRIV_KEY_INFO *p8inf)
+ {
+ return(ASN1_i2d_bio(i2d_PKCS8_PRIV_KEY_INFO,bp,(unsigned char *)p8inf));
+ }