I just tried redirecting the output of the write functions to stdout, it
dumped the private and public keys, atleast I hope it did, I have nt had any
luck with these functions so I am not sure if this is the correct keys that
it dumped but atleast it gave some output, the only way I can test this key
for correctness is, if I can dump it to a file, read it back and then use it
to verify a signature. Any pointers as to why the function is able to write
to stdout but not to the given files ?

Thanks for all the help

-----BEGIN PUBLIC KEY-----
MIIBtzCCASsGByqGSM44BAEwggEeAoGBAO9Wbg5xRfu7KdglgYqbB7N3lu2jz5Pd
pw6BfqHR56GGq+gKu8Hmy8KI73ayAGz49lxXpI0MBQPP5wv5Xqfj+qs8T35JBnua
A0/lV9cIyEHlMAMALGTkzwkgBPkLGrfc9Z2pH/XyinhuM/EtVT5XoZu1pSjyClZg
fXAvZI8jAL0bAhUAqLuLfv5Ptva/0ehhh9T8529sk50CgYAtjo1pBrWTcqHAPS+Q
/ozF3BN4LLaxR2nbHefj1jHd9XrgMkCQNf5HNUvboWVBloJDJQaiJ9D/6KBP4235
PBeEGYz9N1sGDlyzpom94ZExuLFq/8b8647mlJxFVUFoU5SlUAqb6JwSJXe+YIf6
1gAJ1Co7OD4FrXUYF+F/Bf+0oAOBhQACgYEAijFfCkNXqOoRyiTyBl5MQomeQ1aK
4vC1bFcy2GL4O6RkHQ39QLLWV9fS2J+K7k4zabwhoPUJEW1Q0UydGfHCy2Na9U0z
7TbN5Ei19ZioRixajF8bogHawi0jWE+NONotXwSQXZtYOzWPwUP+JALfGkjoCHil
ppyKzspOe3zJ1bY=
-----END PUBLIC KEY-----



On Sat, Jun 21, 2008 at 1:57 PM, Siddhartha Chhabra <
[EMAIL PROTECTED]> wrote:

> Hi Thomas,
>
> Thanks for your email, I tried using EVP_PKEY_set1_DSA(), that doesnt work
> either. I also tried using thePEM_write_DSAPrivateKey() and
> PEM_write_DSA_PUBKEY() functions, however the files still stay empty. I dont
> know, its seemingly a straightforward thing but it just isnt working,
> between I am using 0.9.8.e, any known bugs there? Anything else that I can
> try to get my private and public keys stored and used later on for
> verification.
>
> Thanks in advance.
>
> Regards,
> Sid
>
>
> On Sat, Jun 21, 2008 at 1:47 PM, Thomas Mangold <[EMAIL PROTECTED]>
> wrote:
>
>> Hi Siddhartha,
>>
>> the problem is the line
>> EVP_PKEY_assign_DSA(pkey, dsa);
>> you should use
>> EVP_PKEY_set1_DSA()
>> if you want to use the DSA structure later on.
>> Why don't you write out the keys directly with
>> PEM_write_DSAPrivateKey() and PEM_write_DSA_PUBKEY() ?
>>
>> Thomas
>>
>>
>>
>> Siddhartha Chhabra wrote:
>>
>>> Hi,
>>>
>>> After trying to figure out the problem with the macros, I found the
>>> following two macros already in the OpenSSL set
>>>
>>> PEM_write_PrivateKey and PEM_write_DSA_PUBKEY and their corresponding
>>> read functions
>>>
>>> Now I do the following in my code
>>>
>>>    fptr = fopen("Pub","w");
>>>    fpriv = fopen("Priv","w");
>>>    EVP_PKEY *pkey = EVP_PKEY_new();
>>>    dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb,bio_err);
>>>    if( DSA_generate_key(dsa) == 1)
>>>    {
>>>        EVP_PKEY_assign_DSA(pkey, dsa);      }
>>>    i = PEM_write_PrivateKey(fpriv, pkey, NULL, NULL, 0, NULL, NULL);
>>>  j = PEM_write_DSA_PUBKEY(fptr, dsa);
>>> After this I hoped the files Pub and Priv to have the public and private
>>> key counterparts of the generated DSA keys. Both functions succeed returning
>>> a 1, however, the files are empty with nothing written to them. Do you see
>>> any potential problems with the code that I have above?
>>>
>>> Thanks again
>>>
>>>
>>>
>>> On Sat, Jun 21, 2008 at 8:15 AM, Bill Colvin <[EMAIL PROTECTED]<mailto:
>>> [EMAIL PROTECTED]>> wrote:
>>>
>>>    0.9.8 have used it with f, g and h
>>>
>>>
>>>    Bill
>>>
>>>
>>>    * From: * [EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>
>>>    [mailto:[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>] *On Behalf Of
>>>    *Siddhartha Chhabra
>>>    *Sent:* June 20, 2008 10:07 PM
>>>
>>>    *To:* [email protected] <mailto:[email protected]>
>>>    *Subject:* Re: DSA signing and verification
>>>
>>>
>>>    What version of the library are you using ?
>>>
>>>    On Fri, Jun 20, 2008 at 9:01 PM, Siddhartha Chhabra
>>>    <[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>> wrote:
>>>
>>>    I tried that but I think it has to do with the cast applied to the
>>>    functions as it says
>>>
>>>
>>>    cannot convert parameter 1 from 'int (__cdecl *)(void)' to
>>>    'i2d_of_void (__cdecl *)'
>>>            This conversion requires a reinterpret_cast, a C-style
>>>    cast or function-style cast
>>>
>>>    cannot convert parameter 1 from 'char *(__cdecl *)(void)' to
>>>    'd2i_of_void (__cdecl *)'
>>>            This conversion requires a reinterpret_cast, a C-style
>>>    cast or function-style cast
>>>
>>>    I will try it out and I hope once its typecasted I can use it for
>>>    my intended purposes. Let me know if you have any more comments.
>>>
>>>    Thanks alot for all the help...I can see some light at the end of
>>>    the tunnel now
>>>
>>>
>>>    On Fri, Jun 20, 2008 at 5:55 PM, Bill Colvin
>>>    <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
>>>    wrote:
>>>
>>>    Check your include statements.  You might need either or both of:
>>>
>>>
>>>    #include <openssl/evp.h>
>>>
>>>    #include <openssl/pem.h>
>>>
>>>
>>>    Bill
>>>
>>>    * From: * [EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>
>>>    [mailto:[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>] *On Behalf Of
>>>    *Siddhartha Chhabra
>>>    *Sent:* June 20, 2008 8:39 PM
>>>
>>>
>>>    *To:* [email protected] <mailto:[email protected]>
>>>
>>>    * Subject: * Re: DSA signing and verification
>>>
>>>
>>>    On trying the macros, it gives the following errors
>>>
>>>
>>>  c:\se_simulation2\verificationserver\verifier\verifier\verifier.cpp(201)
>>>    : error C2664: 'PEM_ASN1_write' : cannot convert parameter 1 from
>>>    'int (__cdecl *)(void)' to 'i2d_of_void (__cdecl *)'
>>>            This conversion requires a reinterpret_cast, a C-style
>>>    cast or function-style cast
>>>
>>>  c:\se_simulation2\verificationserver\verifier\verifier\verifier.cpp(264)
>>>    : error C2664: 'PEM_ASN1_read' : cannot convert parameter 1 from
>>>    'char *(__cdecl *)(void)' to 'd2i_of_void (__cdecl *)'
>>>            This conversion requires a reinterpret_cast, a C-style
>>>    cast or function-style cast
>>>
>>>    I believe its more of a coding problem now, to typecast the
>>>    pointers properly rather than anything else, but still I am
>>>    wondering if you faced the same issues or not ?
>>>
>>>    On Fri, Jun 20, 2008 at 5:00 PM, Siddhartha Chhabra
>>>    <[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>> wrote:
>>>
>>>    I will try the method that Bill just mentioned and hope that it
>>>    works, Thanks again, but I would still like to know the problem
>>>    with the way I am trying to do stuff.
>>>
>>>    Thanks
>>>
>>>
>>>    On Fri, Jun 20, 2008 at 4:58 PM, Siddhartha Chhabra
>>>    <[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>> wrote:
>>>
>>>    Thanks for your quick replies, however, I did not understand it
>>>    clearly, I am very new to OpenSSL
>>>
>>>    Here is what I am doing in my code
>>>
>>>    dsa=DSA_generate_parameters(1024,seed,20,&counter,&h,cb,bio_err);
>>>    DSA_generate_key(dsa)
>>>
>>>    Now I have the keys generated. Now if I say
>>>        SHA1(sigbuf,11,dgst);
>>>        //Generate a signature
>>>            if (1 == DSA_sign(0, dgst, sizeof(dgst), signature, &siglen,
>>> dsa))
>>>        {
>>>            printf("Succeeded\n");
>>>        }
>>>                if( 1 ==
>>> DSA_verify(0,dgst,sizeof(dgst),signature,siglen,dsa))
>>>        {
>>>            printf("Succeeded\n");
>>>        }
>>>
>>>
>>>    This works fine. But When I try to save everything in structure
>>>    dsa to another structure dsa2, barring the private key, to use it
>>>    at the server for verification, it fails. I am developing a
>>>    prototype which has exactly these requirements, I do not want the
>>>    public key to be signed by a CA, just a client signing data X and
>>>    the server be able to verify it.
>>>
>>>    Can you please say whats wrong with the above code?
>>>
>>>    Thanks a ton
>>>
>>>
>>>    On Fri, Jun 20, 2008 at 4:50 PM, Bill Colvin
>>>    <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
>>>    wrote:
>>>
>>>    I had a similar problem.  I found I had to define my own macros
>>>    for this as they were not in the OpenSSL set.
>>>
>>>
>>>    #define PEM_write_DSAPublicKey(fp,x) \
>>>
>>>            PEM_ASN1_write((int (*)())i2d_DSAPublicKey,\
>>>
>>>                PEM_STRING_DSA_PUBLIC,fp,(char *)x,NULL,NULL,0,NULL,NULL)
>>>
>>>
>>>    #define PEM_read_DSAPublicKey(fp,x,cb,u) (DSA *)PEM_ASN1_read( \
>>>
>>>        (char *(*)())d2i_DSAPublicKey,PEM_STRING_DSA_PUBLIC,fp,(char
>>>    **)x,cb,u)
>>>
>>>
>>>
>>>    /* Then to save the public key to a file referenced by fptr */
>>>
>>>
>>>            DSA         *dsa_E=NULL;
>>>
>>>
>>>    /*  Generate your DSA key somewhere in here */
>>>
>>>
>>>            i = PEM_write_DSAPublicKey(fptr, dsa_E );
>>>
>>>
>>>    /*  Transfer the public key file to the remote */
>>>
>>>    /*  where the remote does the following assuming that fptr
>>>    references the public key file  */
>>>
>>>
>>>            dsa_E = PEM_read_DSAPublicKey( fptr, NULL, NULL, NULL );
>>>
>>>
>>>
>>>    Bill
>>>
>>>    * From: * [EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>
>>>    [mailto:[EMAIL PROTECTED]
>>>    <mailto:[EMAIL PROTECTED]>] *On Behalf Of
>>>    *Siddhartha Chhabra
>>>    *Sent:* June 20, 2008 7:37 PM
>>>    *To:* [email protected] <mailto:[email protected]>
>>>    *Subject:* DSA signing and verification
>>>
>>>
>>>    Hi all,
>>>
>>>    I am trying to use DSA_sign and DSA_verify functions to generate a
>>>    signature and verify it. If I do this in the same file, that is
>>>    signing and then verifying using the public key, things go on
>>>    smoothly. However, if I try to save the DSA structure, that is by
>>>    saving each of the values other than the private key, which I can
>>>    later restore and use as a public key to verify the signature, the
>>>    verification fails.
>>>
>>>    How can I generate a signature at one place (say the client) and
>>>    verify it on another process (say a server)? Essentially how can I
>>>    save the public key counterpart of the private key that was used
>>>    to sign in the first place.
>>>
>>>    Thanks for the help
>>>
>>>
>>>
>>>
>>>
>>>
>>>
>>>  ______________________________________________________________________
>> OpenSSL Project                                 http://www.openssl.org
>> User Support Mailing List                    [email protected]
>> Automated List Manager                           [EMAIL PROTECTED]
>>
>
>

Reply via email to