Any problem with this "C" code

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Any problem with this "C" code

madhu sudhan reddy-2

Hello All,

 

            I used following C code to sign the data and encode in DER format.

 

            But JAVA Crypto code is failed to parse the DER encoded PKCS#7 data. Following is the “C” code to sign the data.

            Is there any problem in my code?

 

            The certificate I used is self signed certificate.

 

            Char* PKI_Sign (char* inputData, char* pcCertName)

            {

                        int flags = PKCS7_DETACHED | PKCS7_NOCERTS;

                        X509 *pSignerCert = NULL;        

                        EVP_PKEY *pkey = NULL;

                        BIO *InputData = NULL;

                        Char TempAuthData[2048];

 

                        pSignerCert = GetCertifcateByCertName (pcCertName);

            if(!pSignerCert)

            {

                        g_pkiReasonCode = CMS_NO_CERTIFICATE;

                        return 0;

            }

           

            /* It searches key store and gets private key by its filename.*/

            pkey = GetRSAPrivateKeyByCertName(pcCertName);

            if(!pkey)

            {

                        g_pkiReasonCode = CMS_NO_CERTIFICATE;

                        return 0;

            }

 

                        InputData  = BIO_new_file(tempFilename, "r");

 

                        EVP_add_digest (EVP_sha1 ());

            EVP_add_digest_alias (SN_sha1,"ssl3-sha1");

            EVP_add_digest_alias (SN_sha1WithRSAEncryption, SN_sha1WithRSA);

            EVP_add_digest (EVP_dss1 ());

            EVP_add_digest_alias (SN_dsaWithSHA1, SN_dsaWithSHA1_2);

            EVP_add_digest_alias (SN_dsaWithSHA1,"DSS1");

            EVP_add_digest_alias (SN_dsaWithSHA1,"dss1");

 

            pkcs7 = PKCS7_sign (pSignerCert, pkey, NULL, InputData, flags);           

 

            usDataLength = ASN1_item_i2d(pkcs7, &TempAuthData,ASN1_ITEM_rptr(PKCS7));

           

            return TempAuthData;

}

 

 

Thanks in advance……

 

Madhu

 

 

 

 

#####################################################################
This Email Message is for the sole use of the intended recipient(s) and May contain CONFIDENTIAL and PRIVILEGED information.
LG Soft India will not be responisible for any viruses or defects or
any forwarded attachements emanating either from within
LG Soft India or outside. Any unauthorised review , use, disclosure or distribution is prohibited. If you are not intentded
recipient, please contact the sender by reply email and destroy all
copies of the original message.
#####################################################################
Reply | Threaded
Open this post in threaded view
|

Re: Any problem with this "C" code

Dr. Stephen Henson
On Fri, Jun 17, 2005, Madhu Sudhan Reddy wrote:

>
>             Is there any problem in my code?
>
>
>             usDataLength = ASN1_item_i2d(pkcs7,
> &TempAuthData,ASN1_ITEM_rptr(PKCS7));
>

The above command is broken for reasons mentioned in the manual pages and the
FAQ. Don't use ASN1_item_i2d() directly: use i2d_PKCS7 instead.

Steve.
--
Dr Stephen N. Henson. Email, S/MIME and PGP keys: see homepage
OpenSSL project core developer and freelance consultant.
Funding needed! Details on homepage.
Homepage: http://www.drh-consultancy.demon.co.uk
______________________________________________________________________
OpenSSL Project                                 http://www.openssl.org
User Support Mailing List                    [hidden email]
Automated List Manager                           [hidden email]