Hi,

has anyone of you ever tried to link C++ stream with OpenSSL BIO ? What I mean is:
1. there is an istream object on input with PKCS#7 data to verify with PKCS7_verify function
2. Let's assume this stream has it's source in file and I do not want to read whole data into memory before calling PKCS7_verify function because it's likely large file.

Example class could look like this (obvious parts omitted :-) ):
//constructor
OpenSSLCService::OpenSSLCService()
        {
                OPENSSL_add_all_algorithms_noconf();
        }

//destructor
OpenSSLCService::~OpenSSLCService()
        {
                EVP_cleanup();
                CRYPTO_cleanup_all_ex_data();                
                ERR_remove_state(0);
        }

bool OpenSSLCService::verifyPKCS7(istream & indata)
{        
        X509_STORE *store = X509_STORE_new();
        int flags = PKCS7_NOVERIFY;

        /* How to avoid reading whole data into memory here... */
        ostrstream tmp;
        dane >> tmp.rdbuf();
        int size = tmp.pcount();
        BIO * in = BIO_new_mem_buf( (void *)tmp.str(), size );        
      /* ... to here */

        BIO * out  = BIO_new(BIO_s_mem());        
        PKCS7 * p7 = d2i_PKCS7_bio(in, NULL);
        bool ret = PKCS7_verify(p7, NULL, store, NULL, out, flags);
       
        PKCS7_free(p7);
        BIO_free(in);
        BIO_free(out);
        X509_STORE_free(store);
        tmp.freeze(0);
        return ret;
}

Thank  you in advance for any help
Regards
Andrzej

Reply via email to