Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // original: openssl/demos/cms/cms_ver.c
- // g++ test_verify.cpp -lcrypto -o test_verify
- #include <iostream>
- #include <string>
- #include <openssl/bio.h>
- #include <openssl/err.h>
- #include <openssl/ssl.h>
- #include <openssl/pkcs7.h>
- #include <openssl/safestack.h>
- #include <openssl/x509.h>
- #include <openssl/x509v3.h> /* X509_PURPOSE_ANY */
- #include <openssl/x509_vfy.h>
- #include <openssl/cms.h>
- #include <openssl/pem.h>
- std::string get_bio_str(BIO* bio) {
- char* data;
- BIO_get_mem_data(bio, &data);
- return data;
- }
- void print_openssl_errors() {
- ERR_print_errors_fp(stderr);
- }
- void exit_openssl_error() {
- print_openssl_errors();
- exit(1);
- }
- int main(int argc, char* argv[]) {
- if (argc < 2) {
- std::cerr << argv[0] << " target-file" << std::endl;
- return 1;
- }
- const char* target_file_path = argv[1];
- OpenSSL_add_all_algorithms();
- ERR_load_crypto_strings();
- X509_STORE *st = X509_STORE_new();
- if (!X509_STORE_set_default_paths(st))
- exit_openssl_error();
- BIO *in = BIO_new_file(target_file_path, "r");
- if (!in)
- exit_openssl_error();
- BIO *cont = NULL;
- CMS_ContentInfo *cms = SMIME_read_CMS(in, &cont);
- if (!cms)
- exit_openssl_error();
- BIO *out = BIO_new(BIO_s_mem());
- if (!out)
- exit_openssl_error();
- if (!CMS_verify(cms, NULL, st, cont, out, 0))
- exit_openssl_error();
- std::cout << "Verify OK" << std::endl;
- std::cout << "---" << std::endl;
- std::cout << get_bio_str(out) << std::endl;
- CMS_ContentInfo_free(cms);
- BIO_free(in);
- BIO_free(out);
- return 0;
- }
Add Comment
Please, Sign In to add comment