RE: Reading certificate and public key from memory

2008-10-03 Thread Ajeet kumar.S
Hi Dan,
Please try like:

 

char *key = -BEGIN RSA PRIVATE KEY- \n\
jGK1T++C+Np4As+ KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU\n\
  ..

  .

 

 Drys2uVaAzmRhS6tGJ2fdwPnlSLJrQbHuP938BkyxNhdYN8drfqb\n\
 -END RSA PRIVATE KEY-\n;   

 

BIO *bio = BIO_new_mem_buf(key, -1);



SSL_CTX  *sslctx;
EVP_PKEY *pktmp = NULL;

  If key don't have password protcted
 pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);
if your key having in PKCS12 format and password protected.  Please try
like This

pktmp = PEM_read_bio_PrivateKey(bio,0,sslctx-default_passwd_callback,
sslctx-default_passwd_callback_userdata);


if (pktmp == NULL) {
char buffer[120];

ERR_error_string(ERR_get_error(), buffer);
fprintf(stderr, OpenSSL error: %s, buffer);
}



 SSL_CTX_use_PrivateKey(sslctx,  pktmp);

 EVP_PKEY_free(pktmp);

Please try above. If you are again facing problem. Then please read key
using file pointer using fread(char *key will point private key) and please
compare to hardcode key pointer and key pointer from file.Beasause it is
working.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

  _  

From: Dan Ribe [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, October 01, 2008 5:41 PM
To: Ajeet kumar.S
Subject: Re: Reading certificate and public key from memory

 

Hey,

How are u doing ?

Was trying to read my private key from the mem buffer like :

char *key = -BEGIN RSA PRIVATE KEY-
jGK1T++C+Np4As+

KoaO2NCiCBN5UQJRzXBsZvLDoN6IcfxJwXklp560jrKiIZ8VU
N2AZVq28yjqt3RYaRPn0xhbmLfWH/o+wzlg58wIDAQABAoIBAAHEep7qWWMFWsbc
 

..
 

..

  DwiD1OKnxTlAvZPkTSCS+QKBgDkXMM+2jyeRPwpUEyZjqYveVb5zc3HJMMGbpI/p
09dirkd+sRoXWShF8ctVVb4B1PAFTOBEa8diickehnAyEq6KhzLWpQqhqCnylETw
Drys2uVaAzmRhS6tGJ2fdwPnlSLJrQbHuP938BkyxNhdYN8drfqb
-END RSA PRIVATE KEY-;

int keyLength = strlen(key);
BIO *bio = BIO_new_mem_buf(key, keyLength);

EVP_PKEY *pktmp = NULL;
pktmp = PEM_read_bio_PrivateKey(bio, NULL, NULL, NULL);

if (pktmp == NULL) {
char buffer[120];

ERR_error_string(ERR_get_error(), buffer);
fprintf(stderr, OpenSSL error: %s, buffer);
}

But PEM_read_bio_PrivateKey() always returns an error like : 

OpenSSL error: error:0906D06C:PEM routines:PEM_read_bio:no start line

Any Help ?

Thanks much.

Cheers !

 

On Tue, Sep 30, 2008 at 2:33 PM, Ajeet kumar.S
[EMAIL PROTECTED] wrote:

Hi Dan,

I am solving this issue. I will get you back soon. It is not required to
change in other format.  You can use .PEM format.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

  _  

From: Dan Ribe [mailto:[EMAIL PROTECTED] 
Sent: Monday, September 29, 2008 2:34 PM
To: [EMAIL PROTECTED]
Subject: Re: Reading certificate and public key from memory

 

Hi Ajeet,

Just wondering whether you was able to solve this one or not. Actually I
have similar problem in front of me. I want to read the private key directly
from the memory buffer. Currently I have the private key in form of a file
(.pem) on disk. I want to hard code its contents in my code  read them
directly from there. Doing so because I don't want to distribute the private
key with my product.

If you have already done this. Please share following information. 
1. How to hard code the value in some string buffer (how to convert the .pem
file to the required format).
2. How to read the key informaiton from the memory buffer. Please give me
some sample code, that will make my life much easiler.

Hoping for a prompt reply from your side. thanks much

Cheers !

On Mon, Sep 15, 2008 at 10:11 AM, Ajeet kumar.S
[EMAIL PROTECTED] wrote:

Dear All,

  In open ssl I saw we were passing file name of certificate and
public key. In openssl we used this name and reading certificates  keys
from that file. If instead of file name we want to pass char pointer which
point to address of certificate and public key respectively.

Is it possible? Actually I don't want to read certificates and keys from
file .I want to pass one memory pointer for each certificate and keys
respectively which stored both certificate and keys respectively.

Please tell me how to possible.

 

Thank you.

Regards,

--Ajeet  Kumar  Singh

 

 

 

 

 

image002.jpgimage003.jpg

Re: Reading certificate and public key from memory

2008-09-17 Thread Goetz Babin-Ebell

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

biswatosh chakraborty wrote:
| I dont think so. The actual content is wrapped within the headers and
| footers and
| how can your buffer contain them as well? U have to extract the main
| content out.

Why do you think that can't be done ?
everything that you can read from a file you also can read from memory
(using something like BIO_new_mem_buf())

But reading key / cert from memory is simpler by storing it in binary
and read the data with the d2i_* functions...

It is even possible to use openssl x509 -C ...  to generate
C structure data that you can use directly in your programs...

Unfortunately such parameter seems not to be available with the rsa,...
sub commands...

Goetz

- --
DMCA: The greed of the few outweighs the freedom of the many
-BEGIN PGP SIGNATURE-
Version: GnuPG v2.0.4-svn0 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFI0Nxs2iGqZUF3qPYRAkGVAJ9x09DmJZUB0XdfTRodAYFILDtlagCfW5LQ
ikiamD6CzVtNuT8fKjqPyBU=
=rHC9
-END PGP SIGNATURE-
__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Reading certificate and public key from memory

2008-09-17 Thread Kyle Hamilton
Since the OP is looking to embed a certificate (which contains a
public key), and the certificate is already in X.509 format, using
'openssl x509 -C' would resolve the problem nicely.

-Kyle H

On Wed, Sep 17, 2008 at 3:31 AM, Goetz Babin-Ebell [EMAIL PROTECTED] wrote:
 -BEGIN PGP SIGNED MESSAGE-
 Hash: SHA1

 biswatosh chakraborty wrote:
 | I dont think so. The actual content is wrapped within the headers and
 | footers and
 | how can your buffer contain them as well? U have to extract the main
 | content out.

 Why do you think that can't be done ?
 everything that you can read from a file you also can read from memory
 (using something like BIO_new_mem_buf())

 But reading key / cert from memory is simpler by storing it in binary
 and read the data with the d2i_* functions...

 It is even possible to use openssl x509 -C ...  to generate
 C structure data that you can use directly in your programs...

 Unfortunately such parameter seems not to be available with the rsa,...
 sub commands...

 Goetz

 - --
 DMCA: The greed of the few outweighs the freedom of the many
 -BEGIN PGP SIGNATURE-
 Version: GnuPG v2.0.4-svn0 (GNU/Linux)
 Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

 iD8DBQFI0Nxs2iGqZUF3qPYRAkGVAJ9x09DmJZUB0XdfTRodAYFILDtlagCfW5LQ
 ikiamD6CzVtNuT8fKjqPyBU=
 =rHC9
 -END PGP SIGNATURE-
 __
 OpenSSL Project http://www.openssl.org
 User Support Mailing Listopenssl-users@openssl.org
 Automated List Manager   [EMAIL PROTECTED]

__
OpenSSL Project http://www.openssl.org
User Support Mailing Listopenssl-users@openssl.org
Automated List Manager   [EMAIL PROTECTED]


Re: Reading certificate and public key from memory

2008-09-16 Thread biswatosh chakraborty
I dont think so. The actual content is wrapped within the headers and
footers and
how can your buffer contain them as well? U have to extract the main content
out.
For help, see the test programs in openssl.

Phir bhi nehi hotaa hei, to mail ki-jiye!!!

Dhanyavad

Biswatosh

On Mon, Sep 15, 2008 at 10:11 AM, Ajeet kumar.S 
[EMAIL PROTECTED] wrote:

  Dear All,

   In open ssl I saw we were passing file name of certificate
 and public key. In openssl we used this name and reading certificates  keys
 from that file. If instead of file name we want to pass char pointer which
 point to address of certificate and public key respectively.

 Is it possible? Actually I don't want to read certificates and keys from
 file .I want to pass one memory pointer for each certificate and keys
 respectively which stored both certificate and keys respectively.

 Please tell me how to possible.



 Thank you.

 Regards,

 --Ajeet  Kumar  Singh







image001.jpg