On Fri, Jan 25, 2008, John T. Cox wrote:
>
> I have spent the past couple of days going back and redoing a couple days
> worth of work. I have run across what I hope is the last issue. I suspect I
> am missing or have one step wrong:
>
> /* most of the error handling removed for brevity */
> static int decrypt(char *data_in)
> {
> BIO *bio_in = NULL;
> BIO *b64 = NULL;
> RSA *rsa = get_priv_key();
> FILE *fp = NULL;
> char buf[81] = {'\0'};
> unsigned char *rsa_in = NULL;
> unsigned char *rsa_out = NULL;
> unsigned char pad = RSA_PKCS1_PADDING;
> int keysize = 0;
> int rsa_inlen = 0;
> int rsa_outlen = 0;
> int i = 0;
> int rt = 0;
>
> b64 = BIO_new(BIO_f_base64());
> bio_in = BIO_new_mem_buf(data_in, strlen(data_in));
> BIO_push(b64, bio_in);
> BIO_write(bio_in, data_in, strlen(data_in));
> keysize = RSA_size(rsa);
> rsa_in = OPENSSL_malloc(keysize * 2);
> rsa_out = OPENSSL_malloc(keysize);
> rsa_inlen = BIO_read(bio_in, rsa_in, keysize * 2);
> if (rsa_inlen <= 0)
> {
> rt = -1;
> goto end;
> }
> rsa_outlen = RSA_private_decrypt(rsa_inlen, rsa_in, rsa_out, rsa, pad);
> if (rsa_outlen <= 0)
> {
> rt = -1;
> goto end;
> }
>
> The RSA_private_decrypt call fails the following errors:
>
> 8381:error:2007507E:BIO routines:MEM_WRITE:write to read only
> BIO:bss_mem.c:187:
> 8381:error:0406506C:rsa routines:RSA_EAY_PRIVATE_DECRYPT:data greater than
> mod len:rsa_eay.c:489:
>
> rsa_inlen is set to 344
>
>
> If anyone can shed any insight on what I may have missed. I would be very
> grateful..
>
>
Well the call:
BIO_write(bio_in, data_in, strlen(data_in));
is wrong because you've already created a read only BIO with the call:
bio_in = BIO_new_mem_buf(data_in, strlen(data_in));
As for the decoded data is the wrong length. Check that the data_in is just
the appropriate base64 data. It should at most be the RSA_size() value.
Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List [email protected]
Automated List Manager [EMAIL PROTECTED]