这篇教程C++ CMS_ContentInfo_free函数代码示例写得很实用,希望能帮到您。
本文整理汇总了C++中CMS_ContentInfo_free函数的典型用法代码示例。如果您正苦于以下问题:C++ CMS_ContentInfo_free函数的具体用法?C++ CMS_ContentInfo_free怎么用?C++ CMS_ContentInfo_free使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。 在下文中一共展示了CMS_ContentInfo_free函数的24个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。 示例1: openssl_cms_freestatic int openssl_cms_free(lua_State *L){ CMS_ContentInfo *cms = CHECK_OBJECT(1, CMS_ContentInfo, "openssl.cms"); CMS_ContentInfo_free(cms); return 0;}
开发者ID:witchu,项目名称:lua-openssl,代码行数:7,
示例2: CMS_ContentInfo_newCMS_ContentInfo *cms_DigestedData_create(const EVP_MD *md) { CMS_ContentInfo *cms; CMS_DigestedData *dd; cms = CMS_ContentInfo_new(); if (!cms) return NULL; dd = M_ASN1_new_of(CMS_DigestedData); if (!dd) goto err; cms->contentType = OBJ_nid2obj(NID_pkcs7_digest); cms->d.digestedData = dd; dd->version = 0; dd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); cms_DigestAlgorithm_set(dd->digestAlgorithm, md); return cms; err: if (cms) CMS_ContentInfo_free(cms); return NULL; }
开发者ID:EddieGarmon,项目名称:netduino-netmf,代码行数:30,
示例3: CMSerrCMS_ContentInfo *CMS_EncryptedData_encrypt(BIO *in, const EVP_CIPHER *cipher, const unsigned char *key, size_t keylen, unsigned int flags) { CMS_ContentInfo *cms; if (!cipher) { CMSerr(CMS_F_CMS_ENCRYPTEDDATA_ENCRYPT, CMS_R_NO_CIPHER); return NULL; } cms = CMS_ContentInfo_new(); if (!cms) return NULL; if (!CMS_EncryptedData_set1_key(cms, cipher, key, keylen)) return NULL; if(!(flags & CMS_DETACHED)) CMS_set_detached(cms, 0); if ((flags & (CMS_STREAM|CMS_PARTIAL)) || CMS_final(cms, in, NULL, flags)) return cms; CMS_ContentInfo_free(cms); return NULL; }
开发者ID:hlcherub,项目名称:src,代码行数:26,
示例4: ossl_cms_initializestatic VALUEossl_cms_initialize(int argc, VALUE *argv, VALUE self){ CMS_ContentInfo *cms, *out = DATA_PTR(self); BIO *in; VALUE arg; if(rb_scan_args(argc, argv, "01", &arg) == 0) return self; arg = ossl_to_der_if_possible(arg); in = ossl_obj2bio(arg); cms = PEM_read_bio_CMS(in, &out, NULL, NULL); if (!cms) { OSSL_BIO_reset(in); cms = d2i_CMS_bio(in, &out); if (!cms) { BIO_free(in); CMS_ContentInfo_free(out); DATA_PTR(self) = NULL; ossl_raise(rb_eArgError, "Could not parse the CMS"); } } DATA_PTR(self) = out; BIO_free(in); ossl_cms_set_data(self, Qnil); ossl_cms_set_err_string(self, Qnil); return self;}
开发者ID:sustr4,项目名称:rCMS,代码行数:33,
示例5: ossl_cms_s_read_cmsstatic VALUEossl_cms_s_read_cms(VALUE klass, VALUE arg){ BIO *in; CMS_ContentInfo *cms, *out; VALUE ret; arg = ossl_to_der_if_possible(arg); in = ossl_obj2bio(arg); out = CMS_ContentInfo_new(); cms = PEM_read_bio_CMS(in, &out, NULL, NULL); if (!cms) { OSSL_BIO_reset(in); cms = d2i_CMS_bio(in, &out); if (!cms) { BIO_free(in); CMS_ContentInfo_free(out); ossl_raise(rb_eArgError, "Could not parse the CMS"); } } WrapCMS(cCMS, ret, cms); BIO_free(in); ossl_cms_set_data(ret, Qnil); ossl_cms_set_err_string(ret, Qnil); return ret;}
开发者ID:sustr4,项目名称:rCMS,代码行数:30,
示例6: mainint main(int argc, char **argv) { BIO *in = NULL, *out = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; /* * On OpenSSL 0.9.9 only: * for streaming set CMS_STREAM */ int flags = CMS_STREAM; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Open content being compressed */ in = BIO_new_file("comp.txt", "r"); if (!in) goto err; /* compress content */ cms = CMS_compress(in, NID_zlib_compression, flags); if (!cms) goto err; out = BIO_new_file("smcomp.txt", "w"); if (!out) goto err; /* Write out S/MIME message */ if (!SMIME_write_CMS(out, cms, in, flags)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Compressing Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (in) BIO_free(in); if (out) BIO_free(out); return ret; }
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:56,
示例7: mainint main(int argc, char **argv) { BIO *in = NULL, *out = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Open compressed content */ in = BIO_new_file("smcomp.txt", "r"); if (!in) goto err; /* Sign content */ cms = SMIME_read_CMS(in, NULL); if (!cms) goto err; out = BIO_new_file("smuncomp.txt", "w"); if (!out) goto err; /* Uncompress S/MIME message */ if (!CMS_uncompress(cms, out, NULL, 0)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Uncompressing Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (in) BIO_free(in); if (out) BIO_free(out); return ret; }
开发者ID:0culus,项目名称:openssl,代码行数:51,
示例8: cms_Data_createCMS_ContentInfo *CMS_data_create(BIO *in, unsigned int flags) { CMS_ContentInfo *cms; cms = cms_Data_create(); if (!cms) return NULL; if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) return cms; CMS_ContentInfo_free(cms); return NULL; }
开发者ID:hlcherub,项目名称:src,代码行数:14,
示例9: EVP_sha1CMS_ContentInfo *CMS_digest_create(BIO *in, const EVP_MD *md, unsigned int flags) { CMS_ContentInfo *cms; if (!md) md = EVP_sha1(); cms = cms_DigestedData_create(md); if (!cms) return NULL; if(!(flags & CMS_DETACHED)) CMS_set_detached(cms, 0); if ((flags & CMS_STREAM) || CMS_final(cms, in, NULL, flags)) return cms; CMS_ContentInfo_free(cms); return NULL; }
开发者ID:hlcherub,项目名称:src,代码行数:19,
示例10: CMS_ContentInfo_newCMS_ContentInfo *CMS_EnvelopedData_create(const EVP_CIPHER *cipher){ CMS_ContentInfo *cms; CMS_EnvelopedData *env; cms = CMS_ContentInfo_new(); if (!cms) goto merr; env = cms_enveloped_data_init(cms); if (!env) goto merr; if (!cms_EncryptedContent_init(env->encryptedContentInfo, cipher, NULL, 0)) goto merr; return cms;merr: CMS_ContentInfo_free(cms); CMSerr(CMS_F_CMS_ENVELOPEDDATA_CREATE, ERR_R_MALLOC_FAILURE); return NULL;}
开发者ID:redshodan,项目名称:mosh-openssl,代码行数:19,
示例11: CMSerrCMS_ContentInfo *cms_CompressedData_create(int comp_nid) { CMS_ContentInfo *cms; CMS_CompressedData *cd; /* Will need something cleverer if there is ever more than one * compression algorithm or parameters have some meaning... */ if (comp_nid != NID_zlib_compression) { CMSerr(CMS_F_CMS_COMPRESSEDDATA_CREATE, CMS_R_UNSUPPORTED_COMPRESSION_ALGORITHM); return NULL; } cms = CMS_ContentInfo_new(); if (!cms) return NULL; cd = M_ASN1_new_of(CMS_CompressedData); if (!cd) goto err; cms->contentType = OBJ_nid2obj(NID_id_smime_ct_compressedData); cms->d.compressedData = cd; cd->version = 0; X509_ALGOR_set0(cd->compressionAlgorithm, OBJ_nid2obj(NID_zlib_compression), V_ASN1_UNDEF, NULL); cd->encapContentInfo->eContentType = OBJ_nid2obj(NID_pkcs7_data); return cms; err: if (cms) CMS_ContentInfo_free(cms); return NULL; }
开发者ID:002301,项目名称:node,代码行数:42,
示例12: ossl_cms_copystatic VALUEossl_cms_copy(VALUE self, VALUE other){ CMS_ContentInfo *a, *b, *cms; rb_check_frozen(self); if (self == other) return self; GetCMS(self, a); SafeGetCMS(other, b); cms = CMS_ContentInfo_dup(b); if (!cms) { ossl_raise(eCMSError, NULL); } DATA_PTR(self) = cms; CMS_ContentInfo_free(a); return self;}
开发者ID:sustr4,项目名称:rCMS,代码行数:20,
示例13: FuzzerTestOneInputint FuzzerTestOneInput(const uint8_t *buf, size_t len){ CMS_ContentInfo *cms; BIO *in; if (len == 0) return 0; in = BIO_new(BIO_s_mem()); OPENSSL_assert((size_t)BIO_write(in, buf, len) == len); cms = d2i_CMS_bio(in, NULL); if (cms != NULL) { BIO *out = BIO_new(BIO_s_null()); i2d_CMS_bio(out, cms); BIO_free(out); CMS_ContentInfo_free(cms); } BIO_free(in); ERR_clear_error(); return 0;}
开发者ID:Ana06,项目名称:openssl,代码行数:24,
示例14: swupdate_verify_fileint swupdate_verify_file(struct swupdate_digest *dgst, const char *sigfile, const char *file, const char *signer_name){ int status = -EFAULT; CMS_ContentInfo *cms = NULL; BIO *content_bio = NULL; /* Open CMS blob that needs to be checked */ BIO *sigfile_bio = BIO_new_file(sigfile, "rb"); if (!sigfile_bio) { ERROR("%s cannot be opened", sigfile); status = -EBADF; goto out; } /* Parse the DER-encoded CMS message */ cms = d2i_CMS_bio(sigfile_bio, NULL); if (!cms) { ERROR("%s cannot be parsed as DER-encoded CMS signature blob", sigfile); status = -EFAULT; goto out; } if (check_signer_name(cms, signer_name)) { ERROR("failed to verify signer name"); status = -EFAULT; goto out; } /* Open the content file (data which was signed) */ content_bio = BIO_new_file(file, "rb"); if (!content_bio) { ERROR("%s cannot be opened", file); status = -EBADF; goto out; } /* Then try to verify signature */ if (!CMS_verify(cms, NULL, dgst->certs, content_bio, NULL, CMS_BINARY)) { ERR_print_errors_fp(stderr); ERROR("Signature verification failed"); status = -EBADMSG; goto out; } TRACE("Verified OK"); /* Signature is valid */ status = 0;out: if (cms) { CMS_ContentInfo_free(cms); } if (content_bio) { BIO_free(content_bio); } if (sigfile_bio) { BIO_free(sigfile_bio); } return status;}
开发者ID:3mdeb,项目名称:swupdate,代码行数:63,
示例15: MAIN//.........这里部分代码省略......... /* NULL these because call absorbs them */ secret_key = NULL; secret_keyid = NULL; } if (pwri_pass) { pwri_tmp = (unsigned char *)BUF_strdup((char *)pwri_pass); if (!pwri_tmp) goto end; if (!CMS_add0_recipient_password(cms, -1, NID_undef, NID_undef, pwri_tmp, -1, NULL)) goto end; pwri_tmp = NULL; } if (!(flags & CMS_STREAM)) { if (!CMS_final(cms, in, NULL, flags)) goto end; } } else if (operation == SMIME_ENCRYPTED_ENCRYPT) { cms = CMS_EncryptedData_encrypt(in, cipher, secret_key, secret_keylen, flags); } else if (operation == SMIME_SIGN_RECEIPT) { CMS_ContentInfo *srcms = NULL; STACK_OF(CMS_SignerInfo) *sis; CMS_SignerInfo *si; sis = CMS_get0_SignerInfos(cms); if (!sis) goto end; si = sk_CMS_SignerInfo_value(sis, 0); srcms = CMS_sign_receipt(si, signer, key, other, flags); if (!srcms) goto end; CMS_ContentInfo_free(cms); cms = srcms; } else if (operation & SMIME_SIGNERS) { int i; /* * If detached data content we enable streaming if S/MIME output * format. */ if (operation == SMIME_SIGN) { if (flags & CMS_DETACHED) { if (outformat == FORMAT_SMIME) flags |= CMS_STREAM; } flags |= CMS_PARTIAL; cms = CMS_sign(NULL, NULL, other, in, flags); if (!cms) goto end; if (econtent_type) CMS_set1_eContentType(cms, econtent_type); if (rr_to) { rr = make_receipt_request(rr_to, rr_allorfirst, rr_from); if (!rr) { BIO_puts(bio_err, "Signed Receipt Request Creation Error/n"); goto end; } } } else flags |= CMS_REUSE_DIGEST; for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++) { CMS_SignerInfo *si;
开发者ID:davidlt,项目名称:openssl-fedora,代码行数:67,
示例16: main//.........这里部分代码省略......... if ( ! key ) FAIL( "reading private key", free_extra_cert_files ); X509 * key_cert = PEM_read_bio_X509( key_cert_file, NULL, NULL, NULL ); if ( ! key_cert ) FAIL( "reading signing cert", free_key ); STACK_OF(X509) * extra_certs = NULL; if ( num_extra_cert_files > 0 ) { int success = 1; extra_certs = sk_X509_new_null(); if ( ! extra_certs ) FAIL( "allocating stack for extra certs", free_key_cert ); for ( int i = 0; i < num_extra_cert_files; ++i ) { X509 * tmp = PEM_read_bio_X509( extra_cert_files[i], NULL, NULL, NULL ); if ( ! tmp ) { fprintf( stderr, "error reading '%s'/n", argv[ ARG_FIRST_EXTRA_CERT_FILE_IX + i ] ); success = 0; break; } if ( ! sk_X509_push( extra_certs, tmp ) ) { fprintf( stderr, "error pushing '%s'/n", argv[ ARG_FIRST_EXTRA_CERT_FILE_IX + i ] ); success = 0; X509_free( tmp ); break; } } if ( ! success ) FAIL( "could not read extra certs", free_extra_certs ); } CMS_ContentInfo * ci = CMS_sign( key_cert, key, extra_certs, in_data_file, CMS_DETACHED | CMS_BINARY ); /* if ( 1 != PEM_write_bio_CMS( out_sig_file, ci ) ) FAIL( "could not write signature in PEM", free_ci ); */ if ( 1 != i2d_CMS_bio( out_sig_file, ci ) ) FAIL( "could not write signature in DER", free_ci ); /* -------------------------------------------------------------- */ /* success */ exit_code = 0; /* -------------------------------------------------------------- */ /* cleanup */free_ci: CMS_ContentInfo_free( ci );free_extra_certs: sk_X509_pop_free( extra_certs, &X509_free );free_key_cert: X509_free( key_cert );free_key: EVP_PKEY_free( key );free_extra_cert_files: for ( int i = 0; i < num_extra_cert_files; ++i ) BIO_vfree( extra_cert_files[ i ] ); free( extra_cert_files );free_key_cert_file: BIO_vfree( key_cert_file );free_key_file: BIO_vfree( key_file );free_out_sig_file: BIO_vfree( out_sig_file );free_in_data_file: BIO_vfree( in_data_file ); ERR_print_errors_fp( stderr ); ERR_remove_state( /* pid= */ 0 ); ENGINE_cleanup(); CONF_modules_unload( /* all= */ 1 ); EVP_cleanup(); ERR_free_strings(); CRYPTO_cleanup_all_ex_data();end: return exit_code;}
开发者ID:Agnara,项目名称:openssl-pkcs11-samples,代码行数:101,
示例17: cms_main//.........这里部分代码省略......... /* NULL these because call absorbs them */ secret_key = NULL; secret_keyid = NULL; } if (pwri_pass) { pwri_tmp = (unsigned char *)OPENSSL_strdup((char *)pwri_pass); if (!pwri_tmp) goto end; if (!CMS_add0_recipient_password(cms, -1, NID_undef, NID_undef, pwri_tmp, -1, NULL)) goto end; pwri_tmp = NULL; } if (!(flags & CMS_STREAM)) { if (!CMS_final(cms, in, NULL, flags)) goto end; } } else if (operation == SMIME_ENCRYPTED_ENCRYPT) { cms = CMS_EncryptedData_encrypt(in, cipher, secret_key, secret_keylen, flags); } else if (operation == SMIME_SIGN_RECEIPT) { CMS_ContentInfo *srcms = NULL; STACK_OF(CMS_SignerInfo) *sis; CMS_SignerInfo *si; sis = CMS_get0_SignerInfos(cms); if (!sis) goto end; si = sk_CMS_SignerInfo_value(sis, 0); srcms = CMS_sign_receipt(si, signer, key, other, flags); if (!srcms) goto end; CMS_ContentInfo_free(cms); cms = srcms; } else if (operation & SMIME_SIGNERS) { int i; /* * If detached data content we enable streaming if S/MIME output * format. */ if (operation == SMIME_SIGN) { if (flags & CMS_DETACHED) { if (outformat == FORMAT_SMIME) flags |= CMS_STREAM; } flags |= CMS_PARTIAL; cms = CMS_sign(NULL, NULL, other, in, flags); if (!cms) goto end; if (econtent_type) CMS_set1_eContentType(cms, econtent_type); if (rr_to) { rr = make_receipt_request(rr_to, rr_allorfirst, rr_from); if (!rr) { BIO_puts(bio_err, "Signed Receipt Request Creation Error/n"); goto end; } } } else flags |= CMS_REUSE_DIGEST; for (i = 0; i < sk_OPENSSL_STRING_num(sksigners); i++) { CMS_SignerInfo *si;
开发者ID:Muffo,项目名称:openssl,代码行数:67,
示例18: mz_crypt_signint32_t mz_crypt_sign(uint8_t *message, int32_t message_size, uint8_t *cert_data, int32_t cert_data_size, const char *cert_pwd, uint8_t **signature, int32_t *signature_size){ PKCS12 *p12 = NULL; EVP_PKEY *evp_pkey = NULL; BUF_MEM *buf_mem = NULL; BIO *cert_bio = NULL; BIO *message_bio = NULL; BIO *signature_bio = NULL; CMS_ContentInfo *cms = NULL; CMS_SignerInfo *signer_info = NULL; STACK_OF(X509) *ca_stack = NULL; X509 *cert = NULL; int32_t result = 0; int32_t err = MZ_OK; if (message == NULL || cert_data == NULL || signature == NULL || signature_size == NULL) return MZ_PARAM_ERROR; mz_crypt_init(); *signature = NULL; *signature_size = 0; cert_bio = BIO_new_mem_buf(cert_data, cert_data_size); if (d2i_PKCS12_bio(cert_bio, &p12) == NULL) err = MZ_SIGN_ERROR; if (err == MZ_OK) result = PKCS12_parse(p12, cert_pwd, &evp_pkey, &cert, &ca_stack); if (result) { cms = CMS_sign(NULL, NULL, ca_stack, NULL, CMS_BINARY | CMS_PARTIAL); if (cms) signer_info = CMS_add1_signer(cms, cert, evp_pkey, EVP_sha256(), 0); if (signer_info == NULL) { err = MZ_SIGN_ERROR; } else { message_bio = BIO_new_mem_buf(message, message_size); signature_bio = BIO_new(BIO_s_mem()); result = CMS_final(cms, message_bio, NULL, CMS_BINARY); if (result) result = i2d_CMS_bio(signature_bio, cms); if (result) { BIO_flush(signature_bio); BIO_get_mem_ptr(signature_bio, &buf_mem); *signature_size = buf_mem->length; *signature = MZ_ALLOC(buf_mem->length); memcpy(*signature, buf_mem->data, buf_mem->length); }#if 0 BIO *yy = BIO_new_file("xyz", "wb"); BIO_write(yy, *signature, *signature_size); BIO_flush(yy); BIO_free(yy);#endif } } if (!result) err = MZ_SIGN_ERROR; if (cms) CMS_ContentInfo_free(cms); if (signature_bio) BIO_free(signature_bio); if (cert_bio) BIO_free(cert_bio); if (message_bio) BIO_free(message_bio); if (p12) PKCS12_free(p12); if (err != MZ_OK && *signature != NULL) { MZ_FREE(*signature); *signature = NULL; *signature_size = 0; } return err;}
开发者ID:mschmieder,项目名称:minizip,代码行数:90,
示例19: mainint main(int argc, char **argv) { BIO *in = NULL, *out = NULL, *tbio = NULL, *cont = NULL; X509_STORE *st = NULL; X509 *cacert = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Set up trusted CA certificate store */ st = X509_STORE_new(); /* Read in CA certificate */ tbio = BIO_new_file("cacert.pem", "r"); if (!tbio) goto err; cacert = PEM_read_bio_X509(tbio, NULL, 0, NULL); if (!cacert) goto err; if (!X509_STORE_add_cert(st, cacert)) goto err; /* Open message being verified */ in = BIO_new_file("smout.txt", "r"); if (!in) goto err; /* parse message */ cms = SMIME_read_CMS(in, &cont); if (!cms) goto err; /* File to output verified content to */ out = BIO_new_file("smver.txt", "w"); if (!out) goto err; if (!CMS_verify(cms, NULL, st, cont, out, 0)) { fprintf(stderr, "Verification Failure/n"); goto err; } fprintf(stderr, "Verification Successful/n"); ret = 0; err: if (ret) { fprintf(stderr, "Error Verifying Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (cacert) X509_free(cacert); if (in) BIO_free(in); if (out) BIO_free(out); if (tbio) BIO_free(tbio); return ret; }
开发者ID:0culus,项目名称:openssl,代码行数:82,
示例20: mainint main(int argc, char **argv){ BIO *in = NULL, *out = NULL, *tbio = NULL; X509 *scert = NULL; EVP_PKEY *skey = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; /* * For simple S/MIME signing use CMS_DETACHED. On OpenSSL 1.0.0 only: for * streaming detached set CMS_DETACHED|CMS_STREAM for streaming * non-detached set CMS_STREAM */ int flags = CMS_DETACHED | CMS_STREAM; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Read in signer certificate and private key */ tbio = BIO_new_file("signer.pem", "r"); if (!tbio) goto err; scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); BIO_reset(tbio); skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); if (!scert || !skey) goto err; /* Open content being signed */ in = BIO_new_file("sign.txt", "r"); if (!in) goto err; /* Sign content */ cms = CMS_sign(scert, skey, NULL, in, flags); if (!cms) goto err; out = BIO_new_file("smout.txt", "w"); if (!out) goto err; if (!(flags & CMS_STREAM)) BIO_reset(in); /* Write out S/MIME message */ if (!SMIME_write_CMS(out, cms, in, flags)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Signing Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (scert) X509_free(scert); EVP_PKEY_free(skey); BIO_free(in); BIO_free(out); BIO_free(tbio); return ret;}
开发者ID:Adallom,项目名称:openssl,代码行数:79,
示例21: mainint main(int argc, char **argv){ BIO *in = NULL, *out = NULL, *tbio = NULL; X509 *rcert = NULL; EVP_PKEY *rkey = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Read in recipient certificate and private key */ tbio = BIO_new_file("signer.pem", "r"); if (!tbio) goto err; rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); BIO_reset(tbio); rkey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); if (!rcert || !rkey) goto err; /* Open S/MIME message to decrypt */ in = BIO_new_file("smencr.txt", "r"); if (!in) goto err; /* Parse message */ cms = SMIME_read_CMS(in, NULL); if (!cms) goto err; out = BIO_new_file("decout.txt", "w"); if (!out) goto err; /* Decrypt S/MIME message */ if (!CMS_decrypt(cms, rkey, rcert, NULL, out, 0)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Decrypting Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (rcert) X509_free(rcert); if (rkey) EVP_PKEY_free(rkey); if (in) BIO_free(in); if (out) BIO_free(out); if (tbio) BIO_free(tbio); return ret;}
开发者ID:1Project,项目名称:SafeBoardMessenger,代码行数:73,
示例22: mainint main(int argc, char **argv) { BIO *in = NULL, *out = NULL, *tbio = NULL; X509 *scert = NULL, *scert2 = NULL; EVP_PKEY *skey = NULL, *skey2 = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); tbio = BIO_new_file("signer.pem", "r"); if (!tbio) goto err; scert = PEM_read_bio_X509(tbio, NULL, 0, NULL); BIO_reset(tbio); skey = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); BIO_free(tbio); tbio = BIO_new_file("signer2.pem", "r"); if (!tbio) goto err; scert2 = PEM_read_bio_X509(tbio, NULL, 0, NULL); BIO_reset(tbio); skey2 = PEM_read_bio_PrivateKey(tbio, NULL, 0, NULL); if (!scert2 || !skey2) goto err; in = BIO_new_file("sign.txt", "r"); if (!in) goto err; cms = CMS_sign(NULL, NULL, NULL, in, CMS_STREAM|CMS_PARTIAL); if (!cms) goto err; /* Add each signer in turn */ if (!CMS_add1_signer(cms, scert, skey, NULL, 0)) goto err; if (!CMS_add1_signer(cms, scert2, skey2, NULL, 0)) goto err; out = BIO_new_file("smout.txt", "w"); if (!out) goto err; /* NB: content included and finalized by SMIME_write_CMS */ if (!SMIME_write_CMS(out, cms, in, CMS_STREAM)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Signing Data/n"); ERR_print_errors_fp(stderr); } if (cms) CMS_ContentInfo_free(cms); if (scert) X509_free(scert); if (skey) EVP_PKEY_free(skey); if (scert2) X509_free(scert2); if (skey) EVP_PKEY_free(skey2); if (in) BIO_free(in); if (out) BIO_free(out); if (tbio) BIO_free(tbio); return ret; }
开发者ID:AustinWise,项目名称:Netduino-Micro-Framework,代码行数:98,
示例23: mz_crypt_sign_verifyint32_t mz_crypt_sign_verify(uint8_t *message, int32_t message_size, uint8_t *signature, int32_t signature_size){ CMS_ContentInfo *cms = NULL; STACK_OF(X509) *signers = NULL; STACK_OF(X509) *intercerts = NULL; X509_STORE *cert_store = NULL; X509_LOOKUP *lookup = NULL; X509_STORE_CTX *store_ctx = NULL; BIO *message_bio = NULL; BIO *signature_bio = NULL; BUF_MEM *buf_mem = NULL; int32_t signer_count = 0; int32_t result = 0; int32_t i = 0; int32_t err = MZ_SIGN_ERROR; if (message == NULL || message_size == 0 || signature == NULL || signature_size == 0) return MZ_PARAM_ERROR; mz_crypt_init(); cert_store = X509_STORE_new(); X509_STORE_load_locations(cert_store, "cacert.pem", NULL); X509_STORE_set_default_paths(cert_store);#if 0 BIO *yy = BIO_new_file("xyz", "wb"); BIO_write(yy, signature, signature_size); BIO_flush(yy); BIO_free(yy);#endif lookup = X509_STORE_add_lookup(cert_store, X509_LOOKUP_file()); if (lookup != NULL) X509_LOOKUP_load_file(lookup, "cacert.pem", X509_FILETYPE_PEM); lookup = X509_STORE_add_lookup(cert_store, X509_LOOKUP_hash_dir()); if (lookup != NULL) X509_LOOKUP_add_dir(lookup, NULL, X509_FILETYPE_DEFAULT); signature_bio = BIO_new_mem_buf(signature, signature_size); message_bio = BIO_new(BIO_s_mem()); cms = d2i_CMS_bio(signature_bio, NULL); if (cms) { result = CMS_verify(cms, NULL, cert_store, NULL, message_bio, CMS_NO_SIGNER_CERT_VERIFY | CMS_BINARY); if (result) signers = CMS_get0_signers(cms); if (signers) intercerts = CMS_get1_certs(cms); if (intercerts) { /* Verify signer certificates */ signer_count = sk_X509_num(signers); if (signer_count > 0) err = MZ_OK; for (i = 0; i < signer_count; i++) { store_ctx = X509_STORE_CTX_new(); X509_STORE_CTX_init(store_ctx, cert_store, sk_X509_value(signers, i), intercerts); result = X509_verify_cert(store_ctx); if (store_ctx) X509_STORE_CTX_free(store_ctx); if (!result) { err = MZ_SIGN_ERROR; break; } } } BIO_get_mem_ptr(message_bio, &buf_mem); if (err == MZ_OK) { /* Verify the message */ if (((int32_t)buf_mem->length != message_size) || (memcmp(buf_mem->data, message, message_size) != 0)) err = MZ_SIGN_ERROR; } }#if 0 if (!result) printf(ERR_error_string(ERR_get_error(), NULL));#endif if (cms) CMS_ContentInfo_free(cms); if (message_bio) BIO_free(message_bio); if (signature_bio) BIO_free(signature_bio); if (cert_store) X509_STORE_free(cert_store);//.........这里部分代码省略.........
开发者ID:mschmieder,项目名称:minizip,代码行数:101,
示例24: mainint main(int argc, char **argv){ BIO *in = NULL, *out = NULL, *tbio = NULL; X509 *rcert = NULL; STACK_OF(X509) *recips = NULL; CMS_ContentInfo *cms = NULL; int ret = 1; /* * On OpenSSL 1.0.0 and later only: * for streaming set CMS_STREAM */ int flags = CMS_STREAM; OpenSSL_add_all_algorithms(); ERR_load_crypto_strings(); /* Read in recipient certificate */ tbio = BIO_new_file("signer.pem", "r"); if (!tbio) goto err; rcert = PEM_read_bio_X509(tbio, NULL, 0, NULL); if (!rcert) goto err; /* Create recipient STACK and add recipient cert to it */ recips = sk_X509_new_null(); if (!recips || !sk_X509_push(recips, rcert)) goto err; /* * sk_X509_pop_free will free up recipient STACK and its contents so set * rcert to NULL so it isn't freed up twice. */ rcert = NULL; /* Open content being encrypted */ in = BIO_new_file("encr.txt", "r"); if (!in) goto err; /* encrypt content */ cms = CMS_encrypt(recips, in, EVP_des_ede3_cbc(), flags); if (!cms) goto err; out = BIO_new_file("smencr.txt", "w"); if (!out) goto err; /* Write out S/MIME message */ if (!SMIME_write_CMS(out, cms, in, flags)) goto err; ret = 0; err: if (ret) { fprintf(stderr, "Error Encrypting Data/n"); ERR_print_errors_fp(stderr); } CMS_ContentInfo_free(cms); X509_free(rcert); sk_X509_pop_free(recips, X509_free); BIO_free(in); BIO_free(out); BIO_free(tbio); return ret;}
开发者ID:Ana06,项目名称:openssl,代码行数:78,
注:本文中的CMS_ContentInfo_free函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 C++ CMSerr函数代码示例 C++ CMSG_SPACE函数代码示例 |