这篇教程C++ BIO_s_file函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中BIO_s_file函数的典型用法代码示例。如果您正苦于以下问题:C++ BIO_s_file函数的具体用法?C++ BIO_s_file怎么用?C++ BIO_s_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了BIO_s_file函数的30个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: strcpystatic ASN1_INTEGER *load_serial(char *CAfile, char *serialfile, int create) { char *buf = NULL, *p; MS_STATIC char buf2[1024]; ASN1_INTEGER *bs = NULL, *bs2 = NULL; BIO *io = NULL; BIGNUM *serial = NULL; buf=OPENSSL_malloc( ((serialfile == NULL) ?(strlen(CAfile)+strlen(POSTFIX)+1) :(strlen(serialfile)))+1); if (buf == NULL) { BIO_printf(bio_err,"out of mem/n"); goto end; } if (serialfile == NULL) { strcpy(buf,CAfile); for (p=buf; *p; p++) if (*p == '.') { *p='/0'; break; } strcat(buf,POSTFIX); } else strcpy(buf,serialfile); serial=BN_new(); bs=ASN1_INTEGER_new(); if ((serial == NULL) || (bs == NULL)) { ERR_print_errors(bio_err); goto end; } io=BIO_new(BIO_s_file()); if (io == NULL) { ERR_print_errors(bio_err); goto end; } if (BIO_read_filename(io,buf) <= 0) { if (!create) { perror(buf); goto end; } else { ASN1_INTEGER_set(bs,1); BN_one(serial); } } else { if (!a2i_ASN1_INTEGER(io,bs,buf2,sizeof buf2)) { BIO_printf(bio_err,"unable to load serial number from %s/n",buf); ERR_print_errors(bio_err); goto end; } else { serial=BN_bin2bn(bs->data,bs->length,serial); if (serial == NULL) { BIO_printf(bio_err,"error converting bin 2 bn"); goto end; } } } if (!BN_add_word(serial,1)) { BIO_printf(bio_err,"add_word failure/n"); goto end; } if (!(bs2 = BN_to_ASN1_INTEGER(serial, NULL))) { BIO_printf(bio_err,"error converting bn 2 asn1_integer/n"); goto end; } if (BIO_write_filename(io,buf) <= 0) { BIO_printf(bio_err,"error attempting to write serial number file/n"); perror(buf); goto end; } i2a_ASN1_INTEGER(io,bs2); BIO_puts(io,"/n"); BIO_free(io); if (buf) OPENSSL_free(buf); ASN1_INTEGER_free(bs2); BN_free(serial); io=NULL; return bs; end: if (buf) OPENSSL_free(buf); BIO_free(io); ASN1_INTEGER_free(bs); BN_free(serial); return NULL; }
开发者ID:xyzy,项目名称:mips-openssl_0.9.7,代码行数:100,
示例2: mainint main(int argc, char *argv[]){ BN_CTX *ctx = NULL; int ret = 1; BIO *out; CRYPTO_malloc_debug_init(); CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);# ifdef OPENSSL_SYS_WIN32 CRYPTO_malloc_init();# endif RAND_seed(rnd_seed, sizeof rnd_seed); out = BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); BIO_set_fp(out, stdout, BIO_NOCLOSE); if ((ctx = BN_CTX_new()) == NULL) goto err; /* NIST PRIME CURVES TESTS */ if (!test_ecdh_curve (NID_X9_62_prime192v1, "NIST Prime-Curve P-192", ctx, out)) goto err; if (!test_ecdh_curve(NID_secp224r1, "NIST Prime-Curve P-224", ctx, out)) goto err; if (!test_ecdh_curve (NID_X9_62_prime256v1, "NIST Prime-Curve P-256", ctx, out)) goto err; if (!test_ecdh_curve(NID_secp384r1, "NIST Prime-Curve P-384", ctx, out)) goto err; if (!test_ecdh_curve(NID_secp521r1, "NIST Prime-Curve P-521", ctx, out)) goto err;# ifndef OPENSSL_NO_EC2M /* NIST BINARY CURVES TESTS */ if (!test_ecdh_curve(NID_sect163k1, "NIST Binary-Curve K-163", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect163r2, "NIST Binary-Curve B-163", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect233k1, "NIST Binary-Curve K-233", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect233r1, "NIST Binary-Curve B-233", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect283k1, "NIST Binary-Curve K-283", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect283r1, "NIST Binary-Curve B-283", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect409k1, "NIST Binary-Curve K-409", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect409r1, "NIST Binary-Curve B-409", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect571k1, "NIST Binary-Curve K-571", ctx, out)) goto err; if (!test_ecdh_curve(NID_sect571r1, "NIST Binary-Curve B-571", ctx, out)) goto err;# endif if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP256r1", 256)) goto err; if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP384r1", 384)) goto err; if (!test_ecdh_kat(out, "Brainpool Prime-Curve brainpoolP512r1", 512)) goto err; ret = 0; err: ERR_print_errors_fp(stderr); if (ctx) BN_CTX_free(ctx); BIO_free(out); CRYPTO_cleanup_all_ex_data(); ERR_remove_thread_state(NULL); CRYPTO_mem_leaks_fp(stderr); EXIT(ret); return (ret);}
开发者ID:Orav,项目名称:kbengine,代码行数:80,
示例3: MAINint MAIN(int argc, char **argv){ ENGINE *e = NULL; int ret = 1; DSA *dsa = NULL; int i, badops = 0; const EVP_CIPHER *enc = NULL; BIO *in = NULL, *out = NULL; int informat, outformat, text = 0, noout = 0; int pubin = 0, pubout = 0; char *infile, *outfile, *prog;# ifndef OPENSSL_NO_ENGINE char *engine;# endif char *passargin = NULL, *passargout = NULL; char *passin = NULL, *passout = NULL; int modulus = 0; int pvk_encr = 2; apps_startup(); if (bio_err == NULL) if ((bio_err = BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end;# ifndef OPENSSL_NO_ENGINE engine = NULL;# endif infile = NULL; outfile = NULL; informat = FORMAT_PEM; outformat = FORMAT_PEM; prog = argv[0]; argc--; argv++; while (argc >= 1) { if (strcmp(*argv, "-inform") == 0) { if (--argc < 1) goto bad; informat = str2fmt(*(++argv)); } else if (strcmp(*argv, "-outform") == 0) { if (--argc < 1) goto bad; outformat = str2fmt(*(++argv)); } else if (strcmp(*argv, "-in") == 0) { if (--argc < 1) goto bad; infile = *(++argv); } else if (strcmp(*argv, "-out") == 0) { if (--argc < 1) goto bad; outfile = *(++argv); } else if (strcmp(*argv, "-passin") == 0) { if (--argc < 1) goto bad; passargin = *(++argv); } else if (strcmp(*argv, "-passout") == 0) { if (--argc < 1) goto bad; passargout = *(++argv); }# ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv, "-engine") == 0) { if (--argc < 1) goto bad; engine = *(++argv); }# endif else if (strcmp(*argv, "-pvk-strong") == 0) pvk_encr = 2; else if (strcmp(*argv, "-pvk-weak") == 0) pvk_encr = 1; else if (strcmp(*argv, "-pvk-none") == 0) pvk_encr = 0; else if (strcmp(*argv, "-noout") == 0) noout = 1; else if (strcmp(*argv, "-text") == 0) text = 1; else if (strcmp(*argv, "-modulus") == 0) modulus = 1; else if (strcmp(*argv, "-pubin") == 0) pubin = 1; else if (strcmp(*argv, "-pubout") == 0) pubout = 1; else if ((enc = EVP_get_cipherbyname(&(argv[0][1]))) == NULL) { BIO_printf(bio_err, "unknown option %s/n", *argv); badops = 1; break; } argc--; argv++; } if (badops) { bad://.........这里部分代码省略.........
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:101,
示例4: MAINint MAIN(int argc, char **argv) {#ifndef OPENSSL_NO_ENGINE ENGINE *e = NULL;#endif int ret=1; RSA *rsa=NULL; int i,num=DEFBITS; long l; const EVP_CIPHER *enc=NULL; unsigned long f4=RSA_F4; char *outfile=NULL; char *passargout = NULL, *passout = NULL;#ifndef OPENSSL_NO_ENGINE char *engine=NULL;#endif char *inrand=NULL; BIO *out=NULL; apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto err; if ((out=BIO_new(BIO_s_file())) == NULL) { BIO_printf(bio_err,"unable to create BIO for output/n"); goto err; } argv++; argc--; for (;;) { if (argc <= 0) break; if (strcmp(*argv,"-out") == 0) { if (--argc < 1) goto bad; outfile= *(++argv); } else if (strcmp(*argv,"-3") == 0) f4=3; else if (strcmp(*argv,"-F4") == 0 || strcmp(*argv,"-f4") == 0) f4=RSA_F4;#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv,"-engine") == 0) { if (--argc < 1) goto bad; engine= *(++argv); }#endif else if (strcmp(*argv,"-rand") == 0) { if (--argc < 1) goto bad; inrand= *(++argv); }#ifndef OPENSSL_NO_DES else if (strcmp(*argv,"-des") == 0) enc=EVP_des_cbc(); else if (strcmp(*argv,"-des3") == 0) enc=EVP_des_ede3_cbc();#endif#ifndef OPENSSL_NO_IDEA else if (strcmp(*argv,"-idea") == 0) enc=EVP_idea_cbc();#endif#ifndef OPENSSL_NO_AES else if (strcmp(*argv,"-aes128") == 0) enc=EVP_aes_128_cbc(); else if (strcmp(*argv,"-aes192") == 0) enc=EVP_aes_192_cbc(); else if (strcmp(*argv,"-aes256") == 0) enc=EVP_aes_256_cbc();#endif else if (strcmp(*argv,"-passout") == 0) { if (--argc < 1) goto bad; passargout= *(++argv); } else break; argv++; argc--; } if ((argc >= 1) && ((sscanf(*argv,"%d",&num) == 0) || (num < 0))) {bad: BIO_printf(bio_err,"usage: genrsa [args] [numbits]/n"); BIO_printf(bio_err," -des encrypt the generated key with DES in cbc mode/n"); BIO_printf(bio_err," -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)/n");#ifndef OPENSSL_NO_IDEA BIO_printf(bio_err," -idea encrypt the generated key with IDEA in cbc mode/n");#endif#ifndef OPENSSL_NO_AES BIO_printf(bio_err," -aes128, -aes192, -aes256/n"); BIO_printf(bio_err," encrypt PEM output with cbc aes/n");#endif//.........这里部分代码省略.........
开发者ID:FelipeFernandes1988,项目名称:Alice-1121-Modem,代码行数:101,
示例5: MAINint MAIN(int argc, char **argv) { DSA *dsa=NULL; int ret=1; char *outfile=NULL; char *inrand=NULL,*dsaparams=NULL; char *passargout = NULL, *passout = NULL; BIO *out=NULL,*in=NULL; const EVP_CIPHER *enc=NULL;#ifndef OPENSSL_NO_ENGINE char *engine=NULL;#endif apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,OPENSSL_TYPE__FILE_STDERR,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; argv++; argc--; for (;;) { if (argc <= 0) break; if (TINYCLR_SSL_STRCMP(*argv,"-out") == 0) { if (--argc < 1) goto bad; outfile= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-passout") == 0) { if (--argc < 1) goto bad; passargout= *(++argv); }#ifndef OPENSSL_NO_ENGINE else if (TINYCLR_SSL_STRCMP(*argv,"-engine") == 0) { if (--argc < 1) goto bad; engine= *(++argv); }#endif else if (TINYCLR_SSL_STRCMP(*argv,"-rand") == 0) { if (--argc < 1) goto bad; inrand= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-") == 0) goto bad;#ifndef OPENSSL_NO_DES else if (TINYCLR_SSL_STRCMP(*argv,"-des") == 0) enc=EVP_des_cbc(); else if (TINYCLR_SSL_STRCMP(*argv,"-des3") == 0) enc=EVP_des_ede3_cbc();#endif#ifndef OPENSSL_NO_IDEA else if (TINYCLR_SSL_STRCMP(*argv,"-idea") == 0) enc=EVP_idea_cbc();#endif#ifndef OPENSSL_NO_SEED else if (TINYCLR_SSL_STRCMP(*argv,"-seed") == 0) enc=EVP_seed_cbc();#endif#ifndef OPENSSL_NO_AES else if (TINYCLR_SSL_STRCMP(*argv,"-aes128") == 0) enc=EVP_aes_128_cbc(); else if (TINYCLR_SSL_STRCMP(*argv,"-aes192") == 0) enc=EVP_aes_192_cbc(); else if (TINYCLR_SSL_STRCMP(*argv,"-aes256") == 0) enc=EVP_aes_256_cbc();#endif#ifndef OPENSSL_NO_CAMELLIA else if (TINYCLR_SSL_STRCMP(*argv,"-camellia128") == 0) enc=EVP_camellia_128_cbc(); else if (TINYCLR_SSL_STRCMP(*argv,"-camellia192") == 0) enc=EVP_camellia_192_cbc(); else if (TINYCLR_SSL_STRCMP(*argv,"-camellia256") == 0) enc=EVP_camellia_256_cbc();#endif else if (**argv != '-' && dsaparams == NULL) { dsaparams = *argv; } else goto bad; argv++; argc--; } if (dsaparams == NULL) {bad: BIO_printf(bio_err,"usage: gendsa [args] dsaparam-file/n"); BIO_printf(bio_err," -out file - output the key to 'file'/n");#ifndef OPENSSL_NO_DES BIO_printf(bio_err," -des - encrypt the generated key with DES in cbc mode/n"); BIO_printf(bio_err," -des3 - encrypt the generated key with DES in ede cbc mode (168 bit key)/n");#endif//.........这里部分代码省略.........
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:101,
示例6: mainint main(int argc, char *argv[]) { BN_CTX *ctx; BIO *out; char *outfile=NULL; results = 0; RAND_seed(rnd_seed, sizeof rnd_seed); /* or BN_generate_prime may fail */ argc--; argv++; while (argc >= 1) { if (strcmp(*argv,"-results") == 0) results=1; else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) break; outfile= *(++argv); } argc--; argv++; } ctx=BN_CTX_new(); if (ctx == NULL) EXIT(1); out=BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); if (outfile == NULL) { BIO_set_fp(out,stdout,BIO_NOCLOSE); } else { if (!BIO_write_filename(out,outfile)) { perror(outfile); EXIT(1); } } if (!results) BIO_puts(out,"obase=16/nibase=16/n"); message(out,"BN_add"); if (!test_add(out)) goto err; BIO_flush(out); message(out,"BN_sub"); if (!test_sub(out)) goto err; BIO_flush(out); message(out,"BN_lshift1"); if (!test_lshift1(out)) goto err; BIO_flush(out); message(out,"BN_lshift (fixed)"); if (!test_lshift(out,ctx,BN_bin2bn(lst,sizeof(lst)-1,NULL))) goto err; BIO_flush(out); message(out,"BN_lshift"); if (!test_lshift(out,ctx,NULL)) goto err; BIO_flush(out); message(out,"BN_rshift1"); if (!test_rshift1(out)) goto err; BIO_flush(out); message(out,"BN_rshift"); if (!test_rshift(out,ctx)) goto err; BIO_flush(out); message(out,"BN_sqr"); if (!test_sqr(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mul"); if (!test_mul(out)) goto err; BIO_flush(out); message(out,"BN_div"); if (!test_div(out,ctx)) goto err; BIO_flush(out); message(out,"BN_div_recp"); if (!test_div_recp(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod"); if (!test_mod(out,ctx)) goto err; BIO_flush(out); message(out,"BN_mod_mul"); if (!test_mod_mul(out,ctx)) goto err; BIO_flush(out);//.........这里部分代码省略.........
开发者ID:froggatt,项目名称:edimax-br-6528n,代码行数:101,
示例7: add_certs_from_file * * Read a list of certificates to be checked from a file. * * Results: * number of certs added if successful, -1 if not. *---------------------------------------------------------------------- */static int add_certs_from_file(STACK_OF(X509) *stack, char *certfile) { BIO *in=NULL; int count=0; int ret= -1; STACK_OF(X509_INFO) *sk=NULL; X509_INFO *xi; in=BIO_new(BIO_s_file()); if ((in == NULL) || (BIO_read_filename(in,certfile) <= 0)) { BIO_printf(bio_err,"error opening the file, %s/n",certfile); goto end; } /* This loads from a file, a stack of x509/crl/pkey sets */ sk=PEM_X509_INFO_read_bio(in,NULL,NULL,NULL); if (sk == NULL) { BIO_printf(bio_err,"error reading the file, %s/n",certfile); goto end; } /* scan over it and pull out the CRL's */ while (sk_X509_INFO_num(sk))
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:31,
示例8: gendh_mainintgendh_main(int argc, char **argv){ BN_GENCB cb; DH *dh = NULL; int ret = 1, num = DEFBITS; int g = 2; char *outfile = NULL;#ifndef OPENSSL_NO_ENGINE char *engine = NULL;#endif BIO *out = NULL; BN_GENCB_set(&cb, dh_cb, bio_err); if (!load_config(bio_err, NULL)) goto end; argv++; argc--; for (;;) { if (argc <= 0) break; if (strcmp(*argv, "-out") == 0) { if (--argc < 1) goto bad; outfile = *(++argv); } else if (strcmp(*argv, "-2") == 0) g = 2; /* * else if (strcmp(*argv,"-3") == 0) g=3; */ else if (strcmp(*argv, "-5") == 0) g = 5;#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv, "-engine") == 0) { if (--argc < 1) goto bad; engine = *(++argv); }#endif else break; argv++; argc--; } if ((argc >= 1) && ((sscanf(*argv, "%d", &num) == 0) || (num < 0))) {bad: BIO_printf(bio_err, "usage: gendh [args] [numbits]/n"); BIO_printf(bio_err, " -out file - output the key to 'file/n"); BIO_printf(bio_err, " -2 - use 2 as the generator value/n"); /* * BIO_printf(bio_err," -3 - use 3 as the generator * value/n"); */ BIO_printf(bio_err, " -5 - use 5 as the generator value/n");#ifndef OPENSSL_NO_ENGINE BIO_printf(bio_err, " -engine e - use engine e, possibly a hardware device./n");#endif goto end; }#ifndef OPENSSL_NO_ENGINE setup_engine(bio_err, engine, 0);#endif out = BIO_new(BIO_s_file()); if (out == NULL) { ERR_print_errors(bio_err); goto end; } if (outfile == NULL) { BIO_set_fp(out, stdout, BIO_NOCLOSE); } else { if (BIO_write_filename(out, outfile) <= 0) { perror(outfile); goto end; } } BIO_printf(bio_err, "Generating DH parameters, %d bit long safe prime, generator %d/n", num, g); BIO_printf(bio_err, "This is going to take a long time/n"); if (((dh = DH_new()) == NULL) || !DH_generate_parameters_ex(dh, num, g, &cb)) goto end; if (!PEM_write_bio_DHparams(out, dh)) goto end; ret = 0;end: if (ret != 0) ERR_print_errors(bio_err); if (out != NULL) BIO_free_all(out); if (dh != NULL) DH_free(dh); return (ret);}
开发者ID:randombit,项目名称:hacrypto,代码行数:98,
示例9: certfingerprintstatic int certfingerprint(char *file,void *out){ int r=FILEFAIL; int len; BIO *cert; X509 *x509; EVP_PKEY *key; RSA *rsa=NULL; EC_KEY *ec=NULL; unsigned char bfr[2048]; unsigned char *p=bfr; if(!(cert=BIO_new(BIO_s_file())))goto err1; if(BIO_read_filename(cert,file)<=0)goto err2; r=CRYPTOFAIL; if(!(x509=PEM_read_bio_X509_AUX(cert,NULL,NULL,NULL)))goto err2; if(!(key=X509_get_pubkey(x509)))goto err3;#if OPENSSL_VERSION_NUMBER >= 0x1010000fL if(EVP_PKEY_get0_RSA(key)) { if(!(rsa=EVP_PKEY_get1_RSA(key)))goto err4; if((len=i2d_RSA_PUBKEY(rsa,NULL))>sizeof(bfr))goto err5; if(i2d_RSA_PUBKEY(rsa,&p)!=len)goto err5; } else if(EVP_PKEY_get0_EC_KEY(key)) { if(!(ec=EVP_PKEY_get1_EC_KEY(key)))goto err4; if((len=i2d_EC_PUBKEY(ec,NULL))>sizeof(bfr))goto err5; if(i2d_EC_PUBKEY(ec,&p)!=len)goto err5; } else goto err4;#else switch(EVP_PKEY_type(key->type)) { case EVP_PKEY_RSA: if(!(rsa=EVP_PKEY_get1_RSA(key)))goto err4; if((len=i2d_RSA_PUBKEY(rsa,NULL))>sizeof(bfr))goto err5; if(i2d_RSA_PUBKEY(rsa,&p)!=len)goto err5; break; case EVP_PKEY_EC: if(!(ec=EVP_PKEY_get1_EC_KEY(key)))goto err4; if((len=i2d_EC_PUBKEY(ec,NULL))>sizeof(bfr))goto err5; if(i2d_EC_PUBKEY(ec,&p)!=len)goto err5; break; default:goto err4; }#endif if(out)sha256(bfr,len,out); r=OK;err5: if(rsa)RSA_free(rsa); if(ec)EC_KEY_free(ec);err4: EVP_PKEY_free(key);err3: X509_free(x509);err2: BIO_free(cert);err1: return r;}
开发者ID:not1337,项目名称:pam_pivcard,代码行数:62,
示例10: mainint main(int argc, char **argv) { XSECCryptoKey * key = NULL; DSIGKeyInfoX509 * keyInfoX509 = NULL; OpenSSLCryptoX509 * certs[128]; int certCount = 0; int paramCount; bool clearKeyInfo = false; // Initialise the XML system try { XMLPlatformUtils::Initialize();#ifndef XSEC_NO_XALAN XPathEvaluator::initialize(); XalanTransformer::initialize();#endif XSECPlatformUtils::Initialise(); } catch (const XMLException &e) { cerr << "Error during initialisation of Xerces" << endl; cerr << "Error Message = : " << e.getMessage() << endl; } // Initialise OpenSSL ERR_load_crypto_strings(); BIO * bio_err; if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (argc < 2) { printUsage(); exit (1); } paramCount = 1; while (paramCount < argc - 1) { // Run through all parameters if (stricmp(argv[paramCount], "--dsakey") == 0 || stricmp(argv[paramCount], "-d") == 0 || stricmp(argv[paramCount], "--rsakey") == 0 || stricmp(argv[paramCount], "-r") == 0) { // DSA or RSA Key if (paramCount + 3 >= argc) { printUsage(); exit (1); } if (key != 0) { cerr << "/nError loading RSA or DSA key - another key already loaded/n/n"; printUsage(); exit(1); } // Load the signing key // For now just read a particular file BIO * bioKey; if ((bioKey = BIO_new(BIO_s_file())) == NULL) { cerr << "Error opening private key file/n/n"; exit (1); } if (BIO_read_filename(bioKey, argv[paramCount + 1]) <= 0) { cerr << "Error opening private key file/n/n"; exit (1); } EVP_PKEY * pkey; pkey = PEM_read_bio_PrivateKey(bioKey,NULL,NULL,argv[paramCount + 2]); if (pkey == NULL) { cerr << "Error loading private key/n/n"; ERR_print_errors(bio_err); exit (1); } if (stricmp(argv[paramCount], "--dsakey") == 0 || stricmp(argv[paramCount], "-d") == 0) {//.........这里部分代码省略.........
开发者ID:mvancompernolle,项目名称:ai_project,代码行数:101,
示例11: sign_reqstatic voidsign_req (int fd, void *unused){ char thefile[80], cmd_buf[300], p7[3000]; int i, num; unsigned char *data, *asn1; int32_t msglen; BIO *bio = NULL; FILE *fp; struct stat blah; X509_REQ *req = NULL; EVP_ENCODE_CTX ctx; if (recv(fd, (char *)&msglen, sizeof(int32_t), MSG_WAITALL) < sizeof(int32_t)) { return; } msglen = ntohl(msglen); if (msglen > 3000) { return; } if ((data = (unsigned char *)malloc(msglen)) == NULL) { return; } if ((asn1 = (unsigned char *)malloc(msglen)) == NULL) { free(data); return; } if (recv(fd, (char *)data, msglen, MSG_WAITALL) < msglen) { free(data); return; } EVP_DecodeInit(&ctx); EVP_DecodeUpdate(&ctx, asn1, &i, data, msglen); num = i; EVP_DecodeFinal(&ctx, &(asn1[i]), &i); num += i; free(data); if ((bio = BIO_new_mem_buf(asn1, num)) == NULL) { free(asn1); goto no_cert; } if ((req = d2i_X509_REQ_bio(bio, NULL)) == NULL) { free(asn1); goto no_cert; } free(asn1); BIO_free(bio); bio = NULL; unique++; memset(thefile, 0, sizeof(thefile)); snprintf(thefile, sizeof(thefile), "%dreq.pem", unique); if ((fp = fopen(thefile, "w+")) == NULL) { goto no_cert; } if ((bio = BIO_new(BIO_s_file())) == NULL) { fprintf(stderr, "unable to create bio for CSR/n"); goto no_cert; } BIO_set_fp(bio, fp, BIO_NOCLOSE); PEM_write_bio_X509_REQ(bio, req); (void)BIO_flush(bio); BIO_free(bio); bio = NULL; fclose(fp); snprintf(cmd_buf, sizeof(cmd_buf), "openssl ca " "-policy policy_anything -batch -notext " "-config ./conf/openssl.cnf " "-out %dcert.pem -in %dreq.pem", unique, unique); system(cmd_buf); unlink(thefile); snprintf(thefile, sizeof(thefile), "%dcert.pem", unique); if ((stat(thefile, &blah) < 0) || (blah.st_size < 1)) { goto no_cert; } snprintf(cmd_buf, sizeof(cmd_buf), "openssl crl2pkcs7 " "-certfile %dcert.pem -outform DER -out %dder.p7 -nocrl", unique, unique); system(cmd_buf); unlink(thefile); snprintf(thefile, sizeof(thefile), "%dder.p7", unique); if (stat(thefile, &blah) < 0) { goto no_cert; } i = blah.st_size; printf("DER-encoded P7 is %d bytes/n", i); if ((data = (unsigned char *)malloc(blah.st_size*2)) == NULL) { goto no_cert; } if ((fp = fopen(thefile, "r")) == NULL) { free(data); goto no_cert; } if (fread(p7, 1, sizeof(p7), fp) < blah.st_size) {//.........这里部分代码省略.........
开发者ID:danharkins,项目名称:est,代码行数:101,
示例12: prime_mainintprime_main(int argc, char **argv){ BIGNUM *bn = NULL; char *prime = NULL; BIO *bio_out; char *s; int ret = 1; memset(&prime_config, 0, sizeof(prime_config)); /* Default iterations for Miller-Rabin probabilistic primality test. */ prime_config.checks = 20; if (options_parse(argc, argv, prime_options, &prime, NULL) != 0) { prime_usage(); return (1); } if (prime == NULL && prime_config.generate == 0) { BIO_printf(bio_err, "No prime specified./n"); prime_usage(); return (1); } if ((bio_out = BIO_new(BIO_s_file())) == NULL) { ERR_print_errors(bio_err); return (1); } BIO_set_fp(bio_out, stdout, BIO_NOCLOSE); if (prime_config.generate != 0) { if (prime_config.bits == 0) { BIO_printf(bio_err, "Specify the number of bits./n"); goto end; } bn = BN_new(); if (!bn) { BIO_printf(bio_err, "Out of memory./n"); goto end; } if (!BN_generate_prime_ex(bn, prime_config.bits, prime_config.safe, NULL, NULL, NULL)) { BIO_printf(bio_err, "Prime generation error./n"); goto end; } s = prime_config.hex ? BN_bn2hex(bn) : BN_bn2dec(bn); if (s == NULL) { BIO_printf(bio_err, "Out of memory./n"); goto end; } BIO_printf(bio_out, "%s/n", s); free(s); } else { if (prime_config.hex) { if (!BN_hex2bn(&bn, prime)) { BIO_printf(bio_err, "%s is an invalid hex " "value./n", prime); goto end; } } else { if (!BN_dec2bn(&bn, prime)) { BIO_printf(bio_err, "%s is an invalid decimal " "value./n", prime); goto end; } } BN_print(bio_out, bn); BIO_printf(bio_out, " is %sprime/n", BN_is_prime_ex(bn, prime_config.checks, NULL, NULL) ? "" : "not "); } ret = 0;end: BN_free(bn); BIO_free_all(bio_out); return (ret);}
开发者ID:Heratom,项目名称:Firefly-project,代码行数:82,
示例13: MAINint MAIN(int argc, char **argv) { PKCS7 *p7=NULL; int i,badops=0; BIO *in=NULL,*out=NULL; int informat,outformat; char *infile,*outfile,*prog; int print_certs=0,text=0,noout=0,p7_print=0; int ret=1;#ifndef OPENSSL_NO_ENGINE char *engine=NULL;#endif apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,OPENSSL_TYPE__FILE_STDERR,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; infile=NULL; outfile=NULL; informat=FORMAT_PEM; outformat=FORMAT_PEM; prog=argv[0]; argc--; argv++; while (argc >= 1) { if (TINYCLR_SSL_STRCMP(*argv,"-inform") == 0) { if (--argc < 1) goto bad; informat=str2fmt(*(++argv)); } else if (TINYCLR_SSL_STRCMP(*argv,"-outform") == 0) { if (--argc < 1) goto bad; outformat=str2fmt(*(++argv)); } else if (TINYCLR_SSL_STRCMP(*argv,"-in") == 0) { if (--argc < 1) goto bad; infile= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-out") == 0) { if (--argc < 1) goto bad; outfile= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-noout") == 0) noout=1; else if (TINYCLR_SSL_STRCMP(*argv,"-text") == 0) text=1; else if (TINYCLR_SSL_STRCMP(*argv,"-print") == 0) p7_print=1; else if (TINYCLR_SSL_STRCMP(*argv,"-print_certs") == 0) print_certs=1;#ifndef OPENSSL_NO_ENGINE else if (TINYCLR_SSL_STRCMP(*argv,"-engine") == 0) { if (--argc < 1) goto bad; engine= *(++argv); }#endif else { BIO_printf(bio_err,"unknown option %s/n",*argv); badops=1; break; } argc--; argv++; } if (badops) {bad: BIO_printf(bio_err,"%s [options] <infile >outfile/n",prog); BIO_printf(bio_err,"where options are/n"); BIO_printf(bio_err," -inform arg input format - DER or PEM/n"); BIO_printf(bio_err," -outform arg output format - DER or PEM/n"); BIO_printf(bio_err," -in arg input file/n"); BIO_printf(bio_err," -out arg output file/n"); BIO_printf(bio_err," -print_certs print any certs or crl in the input/n"); BIO_printf(bio_err," -text print full details of certificates/n"); BIO_printf(bio_err," -noout don't output encoded data/n");#ifndef OPENSSL_NO_ENGINE BIO_printf(bio_err," -engine e use engine e, possibly a hardware device./n");#endif ret = 1; goto end; } ERR_load_crypto_strings();#ifndef OPENSSL_NO_ENGINE setup_engine(bio_err, engine, 0);//.........这里部分代码省略.........
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:101,
示例14: MAIN//.........这里部分代码省略......... if (!extsect) { extsect = NCONF_get_string(extconf, "default", "extensions"); if (!extsect) { ERR_clear_error(); extsect = "default"; } } X509V3_set_ctx_test(&ctx2); X509V3_set_nconf(&ctx2, extconf); if (!X509V3_EXT_add_nconf(extconf, &ctx2, extsect, NULL)) { BIO_printf(bio_err, "Error Loading extension section %s/n", extsect); ERR_print_errors(bio_err); goto end; } } if (reqfile) { EVP_PKEY *pkey; X509_CINF *ci; BIO *in; if (!sign_flag && !CA_flag) { BIO_printf(bio_err,"We need a private key to sign with/n"); goto end; } in=BIO_new(BIO_s_file()); if (in == NULL) { ERR_print_errors(bio_err); goto end; } if (infile == NULL) BIO_set_fp(in,stdin,BIO_NOCLOSE|BIO_FP_TEXT); else { if (BIO_read_filename(in,infile) <= 0) { perror(infile); BIO_free(in); goto end; } } req=PEM_read_bio_X509_REQ(in,NULL,NULL,NULL); BIO_free(in); if (req == NULL) { ERR_print_errors(bio_err); goto end; } if ( (req->req_info == NULL) || (req->req_info->pubkey == NULL) || (req->req_info->pubkey->public_key == NULL) || (req->req_info->pubkey->public_key->data == NULL)) { BIO_printf(bio_err,"The certificate request appears to corrupted/n");
开发者ID:xyzy,项目名称:mips-openssl_0.9.7,代码行数:67,
示例15: definedBIO *BIO_new_file(const char *filename, const char *mode){ BIO *ret; FILE *file = NULL;# if defined(_WIN32) && defined(CP_UTF8) int sz, len_0 = (int)strlen(filename) + 1; DWORD flags; /* * Basically there are three cases to cover: a) filename is * pure ASCII string; b) actual UTF-8 encoded string and * c) locale-ized string, i.e. one containing 8-bit * characters that are meaningful in current system locale. * If filename is pure ASCII or real UTF-8 encoded string, * MultiByteToWideChar succeeds and _wfopen works. If * filename is locale-ized string, chances are that * MultiByteToWideChar fails reporting * ERROR_NO_UNICODE_TRANSLATION, in which case we fall * back to fopen... */ if ((sz = MultiByteToWideChar(CP_UTF8, (flags = MB_ERR_INVALID_CHARS), filename, len_0, NULL, 0)) > 0 || (GetLastError() == ERROR_INVALID_FLAGS && (sz = MultiByteToWideChar(CP_UTF8, (flags = 0), filename, len_0, NULL, 0)) > 0) ) { WCHAR wmode[8]; WCHAR *wfilename = _alloca(sz * sizeof(WCHAR)); if (MultiByteToWideChar(CP_UTF8, flags, filename, len_0, wfilename, sz) && MultiByteToWideChar(CP_UTF8, 0, mode, strlen(mode) + 1, wmode, OSSL_NELEM(wmode)) && (file = _wfopen(wfilename, wmode)) == NULL && (errno == ENOENT || errno == EBADF) ) { /* * UTF-8 decode succeeded, but no file, filename * could still have been locale-ized... */ file = fopen(filename, mode); } } else if (GetLastError() == ERROR_NO_UNICODE_TRANSLATION) { file = fopen(filename, mode); }# else file = fopen(filename, mode);# endif if (file == NULL) { SYSerr(SYS_F_FOPEN, get_last_sys_error()); ERR_add_error_data(5, "fopen('", filename, "','", mode, "')"); if (errno == ENOENT) BIOerr(BIO_F_BIO_NEW_FILE, BIO_R_NO_SUCH_FILE); else BIOerr(BIO_F_BIO_NEW_FILE, ERR_R_SYS_LIB); return (NULL); } if ((ret = BIO_new(BIO_s_file())) == NULL) { fclose(file); return (NULL); } BIO_clear_flags(ret, BIO_FLAGS_UPLINK); /* we did fopen -> we disengage * UPLINK */ BIO_set_fp(ret, file, BIO_CLOSE); return (ret);}
开发者ID:AimaTeam-hehai,项目名称:openssl,代码行数:68,
示例16: MAINint MAIN(int argc, char **argv) { ENGINE *e = NULL; int i,ret=1, badarg = 0; int purpose = -1; char *CApath=NULL,*CAfile=NULL; char *untfile = NULL, *trustfile = NULL; STACK_OF(X509) *untrusted = NULL, *trusted = NULL; X509_STORE *cert_ctx=NULL; X509_LOOKUP *lookup=NULL; X509_VERIFY_PARAM *vpm = NULL;#ifndef OPENSSL_NO_ENGINE char *engine=NULL;#endif cert_ctx=X509_STORE_new(); if (cert_ctx == NULL) goto end; X509_STORE_set_verify_cb_func(cert_ctx,cb); ERR_load_crypto_strings(); apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; argc--; argv++; for (;;) { if (argc >= 1) { if (strcmp(*argv,"-CApath") == 0) { if (argc-- < 1) goto end; CApath= *(++argv); } else if (strcmp(*argv,"-CAfile") == 0) { if (argc-- < 1) goto end; CAfile= *(++argv); } else if (args_verify(&argv, &argc, &badarg, bio_err, &vpm)) { if (badarg) goto end; continue; } else if (strcmp(*argv,"-untrusted") == 0) { if (argc-- < 1) goto end; untfile= *(++argv); } else if (strcmp(*argv,"-trusted") == 0) { if (argc-- < 1) goto end; trustfile= *(++argv); }#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv,"-engine") == 0) { if (--argc < 1) goto end; engine= *(++argv); }#endif else if (strcmp(*argv,"-help") == 0) goto end; else if (strcmp(*argv,"-verbose") == 0) v_verbose=1; else if (argv[0][0] == '-') goto end; else break; argc--; argv++; } else break; }#ifndef OPENSSL_NO_ENGINE e = setup_engine(bio_err, engine, 0);#endif if (vpm) X509_STORE_set1_param(cert_ctx, vpm); lookup=X509_STORE_add_lookup(cert_ctx,X509_LOOKUP_file()); if (lookup == NULL) abort(); if (CAfile) { i=X509_LOOKUP_load_file(lookup,CAfile,X509_FILETYPE_PEM); if(!i) { BIO_printf(bio_err, "Error loading file %s/n", CAfile); ERR_print_errors(bio_err); goto end;//.........这里部分代码省略.........
开发者ID:RafaelRMachado,项目名称:MinnowBoard,代码行数:101,
示例17: enc_main//.........这里部分代码省略......... if (enc_config.bufsize != NULL) { char *p = enc_config.bufsize; unsigned long n; /* XXX - provide an OPTION_ARG_DISKUNIT. */ for (n = 0; *p != '/0'; p++) { i = *p; if ((i <= '9') && (i >= '0')) n = n * 10 + i - '0'; else if (i == 'k') { n *= 1024; p++; break; } } if (*p != '/0') { BIO_printf(bio_err, "invalid 'bufsize' specified./n"); goto end; } /* It must be large enough for a base64 encoded line. */ if (enc_config.base64 && n < 80) n = 80; bsize = (int)n; if (enc_config.verbose) BIO_printf(bio_err, "bufsize=%d/n", bsize); } strbuf = malloc(SIZE); buff = malloc(EVP_ENCODE_LENGTH(bsize)); if ((buff == NULL) || (strbuf == NULL)) { BIO_printf(bio_err, "malloc failure %ld/n", (long) EVP_ENCODE_LENGTH(bsize)); goto end; } in = BIO_new(BIO_s_file()); out = BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) { ERR_print_errors(bio_err); goto end; } if (enc_config.debug) { BIO_set_callback(in, BIO_debug_callback); BIO_set_callback(out, BIO_debug_callback); BIO_set_callback_arg(in, (char *) bio_err); BIO_set_callback_arg(out, (char *) bio_err); } if (enc_config.inf == NULL) { if (enc_config.bufsize != NULL) setvbuf(stdin, (char *) NULL, _IONBF, 0); BIO_set_fp(in, stdin, BIO_NOCLOSE); } else { if (BIO_read_filename(in, enc_config.inf) <= 0) { perror(enc_config.inf); goto end; } } if (!enc_config.keystr && enc_config.passarg) { if (!app_passwd(bio_err, enc_config.passarg, NULL, &pass, NULL)) { BIO_printf(bio_err, "Error getting password/n"); goto end; } enc_config.keystr = pass; } if (enc_config.keystr == NULL && enc_config.cipher != NULL && enc_config.hkey == NULL) {
开发者ID:LucaBongiorni,项目名称:nextgen,代码行数:67,
示例18: openssl_x509_crlvoid openssl_x509_crl(){ RSA *r; BIO *bp; int len; FILE *fp; BIGNUM *bne; X509_CRL *crl; EVP_PKEY *pkey; X509_NAME *issuer; ASN1_INTEGER *serial; X509_REVOKED *revoked; ASN1_TIME *lastUpdate, *nextUpdate, *rvTime; unsigned char *buf, *p, tmp[MAX1_LEN] = "crl cert"; printf("/nX509_CRL info:/n"); bne = BN_new(); BN_set_word(bne, RSA_3); r = RSA_new(); RSA_generate_key_ex(r, MAX1_LEN, bne, NULL); pkey = EVP_PKEY_new(); EVP_PKEY_assign_RSA(pkey, r); crl = X509_CRL_new(); X509_CRL_set_version(crl, 3); issuer = X509_NAME_new(); X509_NAME_add_entry_by_NID(issuer, NID_commonName, V_ASN1_PRINTABLESTRING, tmp, 10, -1, 0); X509_CRL_set_issuer_name(crl, issuer); lastUpdate = ASN1_TIME_new(); ASN1_TIME_set(lastUpdate, time(NULL)); X509_CRL_set_lastUpdate(crl, lastUpdate); nextUpdate = ASN1_TIME_new(); ASN1_TIME_set(nextUpdate, time(NULL) + 1280); X509_CRL_set_nextUpdate(crl, nextUpdate); revoked = X509_REVOKED_new(); serial = ASN1_INTEGER_new(); ASN1_INTEGER_set(serial, 1280); X509_REVOKED_set_serialNumber(revoked, serial); rvTime = ASN1_TIME_new(); ASN1_TIME_set(rvTime, time(NULL) + 2000); X509_CRL_set_nextUpdate(crl, rvTime); X509_REVOKED_set_revocationDate(revoked, rvTime); X509_CRL_add0_revoked(crl, revoked); X509_CRL_sort(crl); X509_CRL_sign(crl, pkey, EVP_md5()); bp = BIO_new(BIO_s_file()); BIO_set_fp(bp, stdout, BIO_NOCLOSE); X509_CRL_print(bp, crl); len = i2d_X509_CRL(crl, NULL); buf = (unsigned char *)malloc(len + 10); p = buf; len = i2d_X509_CRL(crl, &p); fp = fopen("/tmp/crl.crl", "wb"); fwrite(buf, 1, len, fp); fclose(fp); free(buf); BIO_free(bp); X509_CRL_free(crl);}
开发者ID:beike2020,项目名称:source,代码行数:68,
示例19: mainint main(int argc, char *argv[]){ BN_GENCB *_cb = NULL; DH *a = NULL; DH *b = NULL; BIGNUM *ap = NULL, *ag = NULL, *bp = NULL, *bg = NULL, *apub_key = NULL; BIGNUM *bpub_key = NULL, *priv_key = NULL; char buf[12] = {0}; unsigned char *abuf = NULL; unsigned char *bbuf = NULL; int i, alen, blen, aout, bout; int ret = 1; BIO *out = NULL; CRYPTO_set_mem_debug(1); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); RAND_seed(rnd_seed, sizeof rnd_seed); out = BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); _cb = BN_GENCB_new(); if (_cb == NULL) goto err; BN_GENCB_set(_cb, &cb, out); if (((a = DH_new()) == NULL) || (!DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, _cb))) goto err; if (!DH_check(a, &i)) goto err; if (i & DH_CHECK_P_NOT_PRIME) BIO_puts(out, "p value is not prime/n"); if (i & DH_CHECK_P_NOT_SAFE_PRIME) BIO_puts(out, "p value is not a safe prime/n"); if (i & DH_UNABLE_TO_CHECK_GENERATOR) BIO_puts(out, "unable to check the generator value/n"); if (i & DH_NOT_SUITABLE_GENERATOR) BIO_puts(out, "the g value is not a generator/n"); DH_get0_pqg(a, &ap, NULL, &ag); BIO_puts(out, "/np ="); BN_print(out, ap); BIO_puts(out, "/ng ="); BN_print(out, ag); BIO_puts(out, "/n"); b = DH_new(); if (b == NULL) goto err; bp = BN_dup(ap); bg = BN_dup(ag); if ((bp == NULL) || (bg == NULL) || !DH_set0_pqg(b, bp, NULL, bg)) goto err; bp = bg = NULL; if (!DH_generate_key(a)) goto err; DH_get0_key(a, &apub_key, &priv_key); BIO_puts(out, "pri 1="); BN_print(out, priv_key); BIO_puts(out, "/npub 1="); BN_print(out, apub_key); BIO_puts(out, "/n"); if (!DH_generate_key(b)) goto err; DH_get0_key(b, &bpub_key, &priv_key); BIO_puts(out, "pri 2="); BN_print(out, priv_key); BIO_puts(out, "/npub 2="); BN_print(out, bpub_key); BIO_puts(out, "/n"); alen = DH_size(a); abuf = OPENSSL_malloc(alen); if (abuf == NULL) goto err; aout = DH_compute_key(abuf, bpub_key, a); BIO_puts(out, "key1 ="); for (i = 0; i < aout; i++) { sprintf(buf, "%02X", abuf[i]); BIO_puts(out, buf); } BIO_puts(out, "/n"); blen = DH_size(b); bbuf = OPENSSL_malloc(blen); if (bbuf == NULL) goto err; bout = DH_compute_key(bbuf, apub_key, b); BIO_puts(out, "key2 =");//.........这里部分代码省略.........
开发者ID:1234-,项目名称:openssl,代码行数:101,
示例20: mainint main (int Argc, char *ARGV[]){ ARGS arg;#define PROG_NAME_SIZE 39 char pname[PROG_NAME_SIZE + 1]; FUNCTION f, *fp; MS_STATIC const char *prompt; MS_STATIC char buf[1024]; char *to_free = NULL; int n, i, ret = 0; int argc; char **argv, *p; LHASH_OF (FUNCTION) * prog = NULL; long errline;#if defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64) /* 2011-03-22 SMS. * If we have 32-bit pointers everywhere, then we're safe, and * we bypass this mess, as on non-VMS systems. (See ARGV, * above.) * Problem 1: Compaq/HP C before V7.3 always used 32-bit * pointers for argv[]. * Fix 1: For a 32-bit argv[], when we're using 64-bit pointers * everywhere else, we always allocate and use a 64-bit * duplicate of argv[]. * Problem 2: Compaq/HP C V7.3 (Alpha, IA64) before ECO1 failed * to NULL-terminate a 64-bit argv[]. (As this was written, the * compiler ECO was available only on IA64.) * Fix 2: Unless advised not to (VMS_TRUST_ARGV), we test a * 64-bit argv[argc] for NULL, and, if necessary, use a * (properly) NULL-terminated (64-bit) duplicate of argv[]. * The same code is used in either case to duplicate argv[]. * Some of these decisions could be handled in preprocessing, * but the code tends to get even uglier, and the penalty for * deciding at compile- or run-time is tiny. */ char **Argv = NULL; int free_Argv = 0; if ((sizeof (_Argv) < 8) /* 32-bit argv[]. */# if !defined( VMS_TRUST_ARGV) || (_Argv[Argc] != NULL) /* Untrusted argv[argc] not NULL. */# endif ) { int i; Argv = OPENSSL_malloc ((Argc + 1) * sizeof (char *)); if (Argv == NULL) { ret = -1; goto end; } for (i = 0; i < Argc; i++) Argv[i] = _Argv[i]; Argv[Argc] = NULL; /* Certain NULL termination. */ free_Argv = 1; } else { /* Use the known-good 32-bit argv[] (which needs the * type cast to satisfy the compiler), or the trusted or * tested-good 64-bit argv[] as-is. */ Argv = (char **) _Argv; }#endif /* defined( OPENSSL_SYS_VMS) && (__INITIAL_POINTER_SIZE == 64) */ arg.data = NULL; arg.count = 0; if (bio_err == NULL) if ((bio_err = BIO_new (BIO_s_file ())) != NULL) BIO_set_fp (bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); if (getenv ("OPENSSL_DEBUG_MEMORY") != NULL) /* if not defined, use compiled-in library defaults */ { if (!(0 == strcmp (getenv ("OPENSSL_DEBUG_MEMORY"), "off"))) { CRYPTO_malloc_debug_init (); CRYPTO_set_mem_debug_options (V_CRYPTO_MDEBUG_ALL); } else { /* OPENSSL_DEBUG_MEMORY=off */ CRYPTO_set_mem_debug_functions (0, 0, 0, 0, 0); } } CRYPTO_mem_ctrl (CRYPTO_MEM_CHECK_ON);#if 0//.........这里部分代码省略.........
开发者ID:274914765,项目名称:C,代码行数:101,
示例21: MAINint MAIN(int argc, char **argv) { int i,badops=0; BIO *in=NULL,*out=NULL; int informat,outformat; char *infile,*outfile,*prog,*certfile; PKCS7 *p7 = NULL; PKCS7_SIGNED *p7s = NULL; X509_CRL *crl=NULL; STACK_OF(OPENSSL_STRING) *certflst=NULL; STACK_OF(X509_CRL) *crl_stack=NULL; STACK_OF(X509) *cert_stack=NULL; int ret=1,nocrl=0; apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,OPENSSL_TYPE__FILE_STDERR,BIO_NOCLOSE|BIO_FP_TEXT); infile=NULL; outfile=NULL; informat=FORMAT_PEM; outformat=FORMAT_PEM; prog=argv[0]; argc--; argv++; while (argc >= 1) { if (TINYCLR_SSL_STRCMP(*argv,"-inform") == 0) { if (--argc < 1) goto bad; informat=str2fmt(*(++argv)); } else if (TINYCLR_SSL_STRCMP(*argv,"-outform") == 0) { if (--argc < 1) goto bad; outformat=str2fmt(*(++argv)); } else if (TINYCLR_SSL_STRCMP(*argv,"-in") == 0) { if (--argc < 1) goto bad; infile= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-nocrl") == 0) { nocrl=1; } else if (TINYCLR_SSL_STRCMP(*argv,"-out") == 0) { if (--argc < 1) goto bad; outfile= *(++argv); } else if (TINYCLR_SSL_STRCMP(*argv,"-certfile") == 0) { if (--argc < 1) goto bad; if(!certflst) certflst = sk_OPENSSL_STRING_new_null(); sk_OPENSSL_STRING_push(certflst,*(++argv)); } else { BIO_printf(bio_err,"unknown option %s/n",*argv); badops=1; break; } argc--; argv++; } if (badops) {bad: BIO_printf(bio_err,"%s [options] <infile >outfile/n",prog); BIO_printf(bio_err,"where options are/n"); BIO_printf(bio_err," -inform arg input format - DER or PEM/n"); BIO_printf(bio_err," -outform arg output format - DER or PEM/n"); BIO_printf(bio_err," -in arg input file/n"); BIO_printf(bio_err," -out arg output file/n"); BIO_printf(bio_err," -certfile arg certificates file of chain to a trusted CA/n"); BIO_printf(bio_err," (can be used more than once)/n"); BIO_printf(bio_err," -nocrl no crl to load, just certs from '-certfile'/n"); ret = 1; goto end; } ERR_load_crypto_strings(); in=BIO_new(BIO_s_file()); out=BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) { ERR_print_errors(bio_err); goto end; } if (!nocrl) { if (infile == NULL) BIO_set_fp(in,OPENSSL_TYPE__FILE_STDIN,BIO_NOCLOSE);//.........这里部分代码省略.........
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:101,
示例22: genrsa_mainintgenrsa_main(int argc, char **argv){ BN_GENCB cb; int ret = 1; int i, num = DEFBITS; long l; const EVP_CIPHER *enc = NULL; unsigned long f4 = RSA_F4; char *outfile = NULL; char *passargout = NULL, *passout = NULL; BIO *out = NULL; BIGNUM *bn = BN_new(); RSA *rsa = NULL; if (single_execution) { if (pledge("stdio cpath wpath rpath tty", NULL) == -1) { perror("pledge"); exit(1); } } if (!bn) goto err; BN_GENCB_set(&cb, genrsa_cb, bio_err); if ((out = BIO_new(BIO_s_file())) == NULL) { BIO_printf(bio_err, "unable to create BIO for output/n"); goto err; } argv++; argc--; for (;;) { if (argc <= 0) break; if (strcmp(*argv, "-out") == 0) { if (--argc < 1) goto bad; outfile = *(++argv); } else if (strcmp(*argv, "-3") == 0) f4 = 3; else if (strcmp(*argv, "-F4") == 0 || strcmp(*argv, "-f4") == 0) f4 = RSA_F4;#ifndef OPENSSL_NO_DES else if (strcmp(*argv, "-des") == 0) enc = EVP_des_cbc(); else if (strcmp(*argv, "-des3") == 0) enc = EVP_des_ede3_cbc();#endif#ifndef OPENSSL_NO_IDEA else if (strcmp(*argv, "-idea") == 0) enc = EVP_idea_cbc();#endif#ifndef OPENSSL_NO_AES else if (strcmp(*argv, "-aes128") == 0) enc = EVP_aes_128_cbc(); else if (strcmp(*argv, "-aes192") == 0) enc = EVP_aes_192_cbc(); else if (strcmp(*argv, "-aes256") == 0) enc = EVP_aes_256_cbc();#endif#ifndef OPENSSL_NO_CAMELLIA else if (strcmp(*argv, "-camellia128") == 0) enc = EVP_camellia_128_cbc(); else if (strcmp(*argv, "-camellia192") == 0) enc = EVP_camellia_192_cbc(); else if (strcmp(*argv, "-camellia256") == 0) enc = EVP_camellia_256_cbc();#endif else if (strcmp(*argv, "-passout") == 0) { if (--argc < 1) goto bad; passargout = *(++argv); } else break; argv++; argc--; } if ((argc >= 1) && ((sscanf(*argv, "%d", &num) == 0) || (num < 0))) { bad: BIO_printf(bio_err, "usage: genrsa [args] [numbits]/n"); BIO_printf(bio_err, " -des encrypt the generated key with DES in cbc mode/n"); BIO_printf(bio_err, " -des3 encrypt the generated key with DES in ede cbc mode (168 bit key)/n");#ifndef OPENSSL_NO_IDEA BIO_printf(bio_err, " -idea encrypt the generated key with IDEA in cbc mode/n");#endif#ifndef OPENSSL_NO_AES BIO_printf(bio_err, " -aes128, -aes192, -aes256/n"); BIO_printf(bio_err, " encrypt PEM output with cbc aes/n");#endif#ifndef OPENSSL_NO_CAMELLIA BIO_printf(bio_err, " -camellia128, -camellia192, -camellia256/n"); BIO_printf(bio_err, " encrypt PEM output with cbc camellia/n");#endif BIO_printf(bio_err, " -out file output the key to 'file/n"); BIO_printf(bio_err, " -passout arg output file pass phrase source/n"); BIO_printf(bio_err, " -f4 use F4 (0x10001) for the E value/n"); BIO_printf(bio_err, " -3 use 3 for the E value/n"); goto err;//.........这里部分代码省略.........
开发者ID:bbbrumley,项目名称:openbsd,代码行数:101,
示例23: MAINint MAIN(int argc, char **argv){#ifndef OPENSSL_NO_ENGINE ENGINE *e = NULL;#endif static const char magic[]="Salted__"; char mbuf[sizeof magic-1]; char *strbuf=NULL; unsigned char *buff=NULL,*bufsize=NULL; int bsize=BSIZE,verbose=0; int ret=1,inl; int nopad = 0; unsigned char key[EVP_MAX_KEY_LENGTH],iv[EVP_MAX_IV_LENGTH]; unsigned char salt[PKCS5_SALT_LEN]; char *str=NULL, *passarg = NULL, *pass = NULL; char *hkey=NULL,*hiv=NULL,*hsalt = NULL; char *md=NULL; int enc=1,printkey=0,i,base64=0; int debug=0,olb64=0,nosalt=0; const EVP_CIPHER *cipher=NULL,*c; EVP_CIPHER_CTX *ctx = NULL; char *inf=NULL,*outf=NULL; BIO *in=NULL,*out=NULL,*b64=NULL,*benc=NULL,*rbio=NULL,*wbio=NULL;#define PROG_NAME_SIZE 39 char pname[PROG_NAME_SIZE+1];#ifndef OPENSSL_NO_ENGINE char *engine = NULL;#endif const EVP_MD *dgst=NULL; apps_startup(); if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; /* first check the program name */ program_name(argv[0],pname,sizeof pname); if (strcmp(pname,"base64") == 0) base64=1; cipher=EVP_get_cipherbyname(pname); if (!base64 && (cipher == NULL) && (strcmp(pname,"enc") != 0)) { BIO_printf(bio_err,"%s is an unknown cipher/n",pname); goto bad; } argc--; argv++; while (argc >= 1) { if (strcmp(*argv,"-e") == 0) enc=1; else if (strcmp(*argv,"-in") == 0) { if (--argc < 1) goto bad; inf= *(++argv); } else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) goto bad; outf= *(++argv); } else if (strcmp(*argv,"-pass") == 0) { if (--argc < 1) goto bad; passarg= *(++argv); }#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv,"-engine") == 0) { if (--argc < 1) goto bad; engine= *(++argv); }#endif else if (strcmp(*argv,"-d") == 0) enc=0; else if (strcmp(*argv,"-p") == 0) printkey=1; else if (strcmp(*argv,"-v") == 0) verbose=1; else if (strcmp(*argv,"-nopad") == 0) nopad=1; else if (strcmp(*argv,"-salt") == 0) nosalt=0; else if (strcmp(*argv,"-nosalt") == 0) nosalt=1; else if (strcmp(*argv,"-debug") == 0) debug=1; else if (strcmp(*argv,"-P") == 0) printkey=2; else if (strcmp(*argv,"-A") == 0) olb64=1; else if (strcmp(*argv,"-a") == 0) base64=1;//.........这里部分代码省略.........
开发者ID:kuailexs,项目名称:symbiandump-os2,代码行数:101,
示例24: mainint main(int argc, char *argv[]){ BN_GENCB _cb; DH *a; DH *b = NULL; char buf[12]; unsigned char *abuf = NULL, *bbuf = NULL; int i, alen, blen, aout, bout, ret = 1; BIO *out; CRYPTO_malloc_debug_init(); CRYPTO_dbg_set_options(V_CRYPTO_MDEBUG_ALL); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON);# ifdef OPENSSL_SYS_WIN32 CRYPTO_malloc_init();# endif RAND_seed(rnd_seed, sizeof rnd_seed); out = BIO_new(BIO_s_file()); if (out == NULL) EXIT(1); BIO_set_fp(out, stdout, BIO_NOCLOSE); BN_GENCB_set(&_cb, &cb, out); if (((a = DH_new()) == NULL) || !DH_generate_parameters_ex(a, 64, DH_GENERATOR_5, &_cb)) goto err; if (!DH_check(a, &i)) goto err; if (i & DH_CHECK_P_NOT_PRIME) BIO_puts(out, "p value is not prime/n"); if (i & DH_CHECK_P_NOT_SAFE_PRIME) BIO_puts(out, "p value is not a safe prime/n"); if (i & DH_UNABLE_TO_CHECK_GENERATOR) BIO_puts(out, "unable to check the generator value/n"); if (i & DH_NOT_SUITABLE_GENERATOR) BIO_puts(out, "the g value is not a generator/n"); BIO_puts(out, "/np ="); BN_print(out, a->p); BIO_puts(out, "/ng ="); BN_print(out, a->g); BIO_puts(out, "/n"); b = DH_new(); if (b == NULL) goto err; b->p = BN_dup(a->p); b->g = BN_dup(a->g); if ((b->p == NULL) || (b->g == NULL)) goto err; /* Set a to run with normal modexp and b to use constant time */ a->flags &= ~DH_FLAG_NO_EXP_CONSTTIME; b->flags |= DH_FLAG_NO_EXP_CONSTTIME; if (!DH_generate_key(a)) goto err; BIO_puts(out, "pri 1="); BN_print(out, a->priv_key); BIO_puts(out, "/npub 1="); BN_print(out, a->pub_key); BIO_puts(out, "/n"); if (!DH_generate_key(b)) goto err; BIO_puts(out, "pri 2="); BN_print(out, b->priv_key); BIO_puts(out, "/npub 2="); BN_print(out, b->pub_key); BIO_puts(out, "/n"); alen = DH_size(a); abuf = (unsigned char *)OPENSSL_malloc(alen); aout = DH_compute_key(abuf, b->pub_key, a); BIO_puts(out, "key1 ="); for (i = 0; i < aout; i++) { snprintf(buf, sizeof(buf), "%02X",abuf[i]); BIO_puts(out, buf); } BIO_puts(out, "/n"); blen = DH_size(b); bbuf = (unsigned char *)OPENSSL_malloc(blen); bout = DH_compute_key(bbuf, a->pub_key, b); BIO_puts(out, "key2 ="); for (i = 0; i < bout; i++) { snprintf(buf, sizeof(buf), "%02X",bbuf[i]); BIO_puts(out, buf); } BIO_puts(out, "/n"); if ((aout < 4) || (bout != aout) || (memcmp(abuf, bbuf, aout) != 0)) { fprintf(stderr, "Error in DH routines/n");//.........这里部分代码省略.........
开发者ID:Henauxg,项目名称:minix,代码行数:101,
示例25: rand_mainintrand_main(int argc, char **argv){ char *num_bytes = NULL; int ret = 1; int badopt = 0; int num = -1; int i, r; BIO *out = NULL; memset(&rand_config, 0, sizeof(rand_config)); if (options_parse(argc, argv, rand_options, &num_bytes, NULL) != 0) { rand_usage(); return (1); } if (num_bytes != NULL) { r = sscanf(num_bytes, "%d", &num); if (r == 0 || num < 0) badopt = 1; } else badopt = 1; if (rand_config.hex && rand_config.base64) badopt = 1; if (badopt) { rand_usage(); goto err; }#ifndef OPENSSL_NO_ENGINE setup_engine(bio_err, rand_config.engine, 0);#endif out = BIO_new(BIO_s_file()); if (out == NULL) goto err; if (rand_config.outfile != NULL) r = BIO_write_filename(out, rand_config.outfile); else r = BIO_set_fp(out, stdout, BIO_NOCLOSE | BIO_FP_TEXT); if (r <= 0) goto err; if (rand_config.base64) { BIO *b64 = BIO_new(BIO_f_base64()); if (b64 == NULL) goto err; out = BIO_push(b64, out); } while (num > 0) { unsigned char buf[4096]; int chunk; chunk = num; if (chunk > (int) sizeof(buf)) chunk = sizeof(buf); arc4random_buf(buf, chunk); if (rand_config.hex) { for (i = 0; i < chunk; i++) BIO_printf(out, "%02x", buf[i]); } else BIO_write(out, buf, chunk); num -= chunk; } if (rand_config.hex) BIO_puts(out, "/n"); (void) BIO_flush(out); ret = 0;err: ERR_print_errors(bio_err); if (out) BIO_free_all(out); return (ret);}
开发者ID:Heratom,项目名称:Firefly-project,代码行数:81,
示例26: main//.........这里部分代码省略......... f = fopen(argv[4], "w+"); print_hex_data(f, signature); fclose(f); } } else if (!strcmp(argv[1], "-convkey")) { if (argc < 6) { usage(); exit(1); } if (strcmp(argv[2], "b2o") == 0) { b2o = true; } else if (strcmp(argv[2], "o2b") == 0) { b2o = false; } else { die("either 'o2b' or 'b2o' must be defined for -convkey/n"); } if (strcmp(argv[3], "pub") == 0) { kpriv = false; } else if (strcmp(argv[3], "priv") == 0) { kpriv = true; } else { die("either 'pub' or 'priv' must be defined for -convkey/n"); } OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); ENGINE_load_builtin_engines(); if (bio_err == NULL) { bio_err = BIO_new_fp(stdout, BIO_NOCLOSE); } //enc=EVP_get_cipherbyname("des"); //if (enc == NULL) // die("could not get cypher./n"); // no encription yet. bio_out=BIO_new(BIO_s_file()); if (BIO_write_filename(bio_out,argv[5]) <= 0) { perror(argv[5]); die("could not create output file./n"); } if (b2o) { rsa_key_ = RSA_new(); if (kpriv) { fpriv = fopen(argv[4], "r"); if (!fpriv) { die("fopen"); } scan_key_hex(fpriv, (KEY*)&private_key, sizeof(private_key)); fclose(fpriv); private_to_openssl(private_key, &rsa_key); //i = PEM_write_bio_RSAPrivateKey(bio_out, &rsa_key, // enc, NULL, 0, pass_cb, NULL); // no encryption yet. //i = PEM_write_bio_RSAPrivateKey(bio_out, &rsa_key, // NULL, NULL, 0, pass_cb, NULL); fpriv = fopen(argv[5], "w+"); PEM_write_RSAPrivateKey(fpriv, &rsa_key, NULL, NULL, 0, 0, NULL); fclose(fpriv); //if (i == 0) { // ERR_print_errors(bio_err); // die("could not write key file./n"); //} } else { fpub = fopen(argv[4], "r"); if (!fpub) { die("fopen");
开发者ID:keyz182,项目名称:BOINC-7.0,代码行数:67,
示例27: MAINint MAIN(int argc, char **argv) { ENGINE *e = NULL; unsigned char *buf=NULL; int i,err=0; const EVP_MD *md=NULL,*m; BIO *in=NULL,*inp; BIO *bmd=NULL; BIO *out = NULL; const char *name;#define PROG_NAME_SIZE 39 char pname[PROG_NAME_SIZE+1]; int separator=0; int debug=0; int keyform=FORMAT_PEM; const char *outfile = NULL, *keyfile = NULL; const char *sigfile = NULL, *randfile = NULL; int out_bin = -1, want_pub = 0, do_verify = 0; EVP_PKEY *sigkey = NULL; unsigned char *sigbuf = NULL; int siglen = 0; char *passargin = NULL, *passin = NULL;#ifndef OPENSSL_NO_ENGINE char *engine=NULL;#endif char *hmac_key=NULL; apps_startup(); if ((buf=(unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL) { BIO_printf(bio_err,"out of memory/n"); goto end; } if (bio_err == NULL) if ((bio_err=BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err,stderr,BIO_NOCLOSE|BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; /* first check the program name */ program_name(argv[0],pname,sizeof pname); md=EVP_get_digestbyname(pname); argc--; argv++; while (argc > 0) { if ((*argv)[0] != '-') break; if (strcmp(*argv,"-c") == 0) separator=1; else if (strcmp(*argv,"-rand") == 0) { if (--argc < 1) break; randfile=*(++argv); } else if (strcmp(*argv,"-out") == 0) { if (--argc < 1) break; outfile=*(++argv); } else if (strcmp(*argv,"-sign") == 0) { if (--argc < 1) break; keyfile=*(++argv); } else if (!strcmp(*argv,"-passin")) { if (--argc < 1) break; passargin=*++argv; } else if (strcmp(*argv,"-verify") == 0) { if (--argc < 1) break; keyfile=*(++argv); want_pub = 1; do_verify = 1; } else if (strcmp(*argv,"-prverify") == 0) { if (--argc < 1) break; keyfile=*(++argv); do_verify = 1; } else if (strcmp(*argv,"-signature") == 0) { if (--argc < 1) break; sigfile=*(++argv); } else if (strcmp(*argv,"-keyform") == 0) { if (--argc < 1) break; keyform=str2fmt(*(++argv)); }#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv,"-engine") == 0) {//.........这里部分代码省略.........
开发者ID:siredblood,项目名称:tree-bumpkin-project,代码行数:101,
示例28: MAINint MAIN(int argc, char **argv){ ENGINE *e = NULL, *impl = NULL; unsigned char *buf = NULL; int i, err = 1; const EVP_MD *md = NULL, *m; BIO *in = NULL, *inp; BIO *bmd = NULL; BIO *out = NULL;#define PROG_NAME_SIZE 39 char pname[PROG_NAME_SIZE + 1]; int separator = 0; int debug = 0; int keyform = FORMAT_PEM; const char *outfile = NULL, *keyfile = NULL; const char *sigfile = NULL, *randfile = NULL; int out_bin = -1, want_pub = 0, do_verify = 0; EVP_PKEY *sigkey = NULL; unsigned char *sigbuf = NULL; int siglen = 0; char *passargin = NULL, *passin = NULL;#ifndef OPENSSL_NO_ENGINE char *engine = NULL; int engine_impl = 0;#endif char *hmac_key = NULL; char *mac_name = NULL; int non_fips_allow = 0; STACK_OF(OPENSSL_STRING) *sigopts = NULL, *macopts = NULL; apps_startup(); if ((buf = (unsigned char *)OPENSSL_malloc(BUFSIZE)) == NULL) { BIO_printf(bio_err, "out of memory/n"); goto end; } if (bio_err == NULL) if ((bio_err = BIO_new(BIO_s_file())) != NULL) BIO_set_fp(bio_err, stderr, BIO_NOCLOSE | BIO_FP_TEXT); if (!load_config(bio_err, NULL)) goto end; /* first check the program name */ program_name(argv[0], pname, sizeof pname); md = EVP_get_digestbyname(pname); argc--; argv++; while (argc > 0) { if ((*argv)[0] != '-') break; if (strcmp(*argv, "-c") == 0) separator = 1; else if (strcmp(*argv, "-r") == 0) separator = 2; else if (strcmp(*argv, "-rand") == 0) { if (--argc < 1) break; randfile = *(++argv); } else if (strcmp(*argv, "-out") == 0) { if (--argc < 1) break; outfile = *(++argv); } else if (strcmp(*argv, "-sign") == 0) { if (--argc < 1) break; keyfile = *(++argv); } else if (!strcmp(*argv, "-passin")) { if (--argc < 1) break; passargin = *++argv; } else if (strcmp(*argv, "-verify") == 0) { if (--argc < 1) break; keyfile = *(++argv); want_pub = 1; do_verify = 1; } else if (strcmp(*argv, "-prverify") == 0) { if (--argc < 1) break; keyfile = *(++argv); do_verify = 1; } else if (strcmp(*argv, "-signature") == 0) { if (--argc < 1) break; sigfile = *(++argv); } else if (strcmp(*argv, "-keyform") == 0) { if (--argc < 1) break; keyform = str2fmt(*(++argv)); }#ifndef OPENSSL_NO_ENGINE else if (strcmp(*argv, "-engine") == 0) { if (--argc < 1) break; engine = *(++argv); e = setup_engine(bio_err, engine, 0); } else if (strcmp(*argv, "-engine_impl") == 0)//.........这里部分代码省略.........
开发者ID:AshKarath,项目名称:bumo,代码行数:101,
示例29: crl_mainintcrl_main(int argc, char **argv){ unsigned long nmflag = 0; X509_CRL *x = NULL; char *CAfile = NULL, *CApath = NULL; int ret = 1, i, num, badops = 0; BIO *out = NULL; int informat, outformat; char *infile = NULL, *outfile = NULL; int hash = 0, issuer = 0, lastupdate = 0, nextupdate = 0, noout = 0, text = 0;#ifndef OPENSSL_NO_MD5 int hash_old = 0;#endif int fingerprint = 0, crlnumber = 0; const char **pp; X509_STORE *store = NULL; X509_STORE_CTX ctx; X509_LOOKUP *lookup = NULL; X509_OBJECT xobj; EVP_PKEY *pkey; int do_ver = 0; const EVP_MD *md_alg, *digest = EVP_sha1(); if (!load_config(bio_err, NULL)) goto end; if (bio_out == NULL) if ((bio_out = BIO_new(BIO_s_file())) != NULL) { BIO_set_fp(bio_out, stdout, BIO_NOCLOSE); } informat = FORMAT_PEM; outformat = FORMAT_PEM; argc--; argv++; num = 0; while (argc >= 1) {#ifdef undef if (strcmp(*argv, "-p") == 0) { if (--argc < 1) goto bad; if (!args_from_file(++argv, Nargc, Nargv)) { goto end; } }#endif if (strcmp(*argv, "-inform") == 0) { if (--argc < 1) goto bad; informat = str2fmt(*(++argv)); } else if (strcmp(*argv, "-outform") == 0) { if (--argc < 1) goto bad; outformat = str2fmt(*(++argv)); } else if (strcmp(*argv, "-in") == 0) { if (--argc < 1) goto bad; infile = *(++argv); } else if (strcmp(*argv, "-out") == 0) { if (--argc < 1) goto bad; outfile = *(++argv); } else if (strcmp(*argv, "-CApath") == 0) { if (--argc < 1) goto bad; CApath = *(++argv); do_ver = 1; } else if (strcmp(*argv, "-CAfile") == 0) { if (--argc < 1) goto bad; CAfile = *(++argv); do_ver = 1; } else if (strcmp(*argv, "-verify") == 0) do_ver = 1; else if (strcmp(*argv, "-text") == 0) text = 1; else if (strcmp(*argv, "-hash") == 0) hash = ++num;#ifndef OPENSSL_NO_MD5 else if (strcmp(*argv, "-hash_old") == 0) hash_old = ++num;#endif else if (strcmp(*argv, "-nameopt") == 0) { if (--argc < 1) goto bad; if (!set_name_ex(&nmflag, *(++argv))) goto bad; } else if (strcmp(*argv, "-issuer") == 0) issuer = ++num; else if (strcmp(*argv, "-lastupdate") == 0) lastupdate = ++num; else if (strcmp(*argv, "-nextupdate") == 0) nextupdate = ++num; else if (strcmp(*argv, "-noout") == 0) noout = ++num; else if (strcmp(*argv, "-fingerprint") == 0) fingerprint = ++num; else if (strcmp(*argv, "-crlnumber") == 0)//.........这里部分代码省略.........
开发者ID:DiamondLovesYou,项目名称:libressl-pnacl-sys,代码行数:101,
示例30: ec_main//.........这里部分代码省略......... "supported by OpenSSL can be used/n"); BIO_printf(bio_err, " -text print the key/n"); BIO_printf(bio_err, " -noout don't print key out/n"); BIO_printf(bio_err, " -param_out print the elliptic " "curve parameters/n"); BIO_printf(bio_err, " -conv_form arg specifies the " "point conversion form /n"); BIO_printf(bio_err, " possible values:" " compressed/n"); BIO_printf(bio_err, " " " uncompressed (default)/n"); BIO_printf(bio_err, " " " hybrid/n"); BIO_printf(bio_err, " -param_enc arg specifies the way" " the ec parameters are encoded/n"); BIO_printf(bio_err, " in the asn1 der " "encoding/n"); BIO_printf(bio_err, " possible values:" " named_curve (default)/n"); BIO_printf(bio_err, " " "explicit/n"); goto end; } ERR_load_crypto_strings();#ifndef OPENSSL_NO_ENGINE setup_engine(bio_err, engine, 0);#endif if (!app_passwd(bio_err, passargin, passargout, &passin, &passout)) { BIO_printf(bio_err, "Error getting passwords/n"); goto end; } in = BIO_new(BIO_s_file()); out = BIO_new(BIO_s_file()); if ((in == NULL) || (out == NULL)) { ERR_print_errors(bio_err); goto end; } if (infile == NULL) BIO_set_fp(in, stdin, BIO_NOCLOSE); else { if (BIO_read_filename(in, infile) <= 0) { perror(infile); goto end; } } BIO_printf(bio_err, "read EC key/n"); if (informat == FORMAT_ASN1) { if (pubin) eckey = d2i_EC_PUBKEY_bio(in, NULL); else eckey = d2i_ECPrivateKey_bio(in, NULL); } else if (informat == FORMAT_PEM) { if (pubin) eckey = PEM_read_bio_EC_PUBKEY(in, NULL, NULL, NULL); else eckey = PEM_read_bio_ECPrivateKey(in, NULL, NULL, passin); } else { BIO_printf(bio_err, "bad input format specified for key/n"); goto end; } if (eckey == NULL) {
开发者ID:benwh4,项目名称:libressl,代码行数:67,
注:本文中的BIO_s_file函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ BIO_set_close函数代码示例 C++ BIO_reset函数代码示例 |