Hi,
i tried to modify demos/sign, which reads private key from pem file and
public key from x509 certificate in pem file, to a version which instead
read public from pem file (not a certificate).
my 2 pem files are generate using RSA_generate_key, PEM_write_RSAPrivateKey,
PEM_write_RSAPublicKey fuctions.
here the code of sign.c changed by me:
#include <stdio.h>
#include <openssl/rsa.h>
#include <openssl/evp.h>
#include <openssl/objects.h>
#include <openssl/x509.h>
#include <openssl/err.h>
#include <openssl/pem.h>
#include <openssl/ssl.h>
int main ()
{
int err;
int sig_len;
unsigned char sig_buf [4096];
static char certfile[] = "pubkey.pem";
static char keyfile[] = "privkey.pem";
static char data[] = "I owe you...";
EVP_MD_CTX md_ctx;
EVP_PKEY * pkey;
FILE * fp;
/* Just load the crypto library error strings,
* SSL_load_error_strings() loads the crypto AND the SSL ones */
/* SSL_load_error_strings();*/
ERR_load_crypto_strings();
/* Read private key */
fp = fopen (keyfile, "r");
if (fp == NULL) exit (1);
pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);
fclose (fp);
if (pkey == NULL) {
ERR_print_errors_fp (stderr);
exit (1);
}
/* Do the signature */
EVP_SignInit (&md_ctx, EVP_sha1());
EVP_SignUpdate (&md_ctx, data, strlen(data));
sig_len = sizeof(sig_buf);
err = EVP_SignFinal (&md_ctx, sig_buf, &sig_len, pkey);
if (err != 1) {
ERR_print_errors_fp(stderr);
exit (1);
}
EVP_PKEY_free (pkey);
/* Read public key */
fp = fopen (certfile, "r");
if (fp == NULL) exit (1);
pkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL);
fclose (fp);
if (pkey == NULL) {
ERR_print_errors_fp (stderr);
exit (1);
}
/* Verify the signature */
EVP_VerifyInit (&md_ctx, EVP_sha1());
EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));
err = EVP_VerifyFinal (&md_ctx, sig_buf, sig_len, pkey);
EVP_PKEY_free (pkey);
if (err != 1) {
ERR_print_errors_fp (stderr);
exit (1);
}
printf ("Signature Verified Ok.\n");
return(0);
}
it's return the following error:
1883:error:0906D06C:PEM routines:PEM_read_bio:no start
line:/export/builds/onnv_101a/usr/src/common/openssl/crypto/pem/pem_lib.c:644:Expecting:
PUBLIC KEY
Can somebody plz help me ?
TNX
--
------------------------------------------------------------------
Marco Sommella
marco.s...@gmail.com (E-Mail & MSN)
------------------------------------------------------------------
------=_Part_12058_26001910.1228336035290
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
Hi,<br>i tried to modify demos/sign, which reads private key from pem file and public key from x509 certificate in pem file, to a version which instead read public from pem file (not a certificate).<br><br>my 2 pem files are generate using RSA_generate_key, PEM_write_RSAPrivateKey, PEM_write_RSAPublicKey fuctions.<br>
<br>here the code of sign.c changed by me:<br><br>#include <stdio.h><br>#include <openssl/rsa.h><br>#include <openssl/evp.h><br>#include <openssl/objects.h><br>#include <openssl/x509.h><br>#include <openssl/err.h><br>
#include <openssl/pem.h><br>#include <openssl/ssl.h><br><br>int main ()<br>{<br> int err;<br> int sig_len;<br> unsigned char sig_buf [4096];<br> static char certfile[] = "pubkey.pem";<br> static char keyfile[] = "privkey.pem";<br>
static char data[] = "I owe you...";<br> EVP_MD_CTX md_ctx;<br> EVP_PKEY * pkey;<br> FILE * fp;<br><br> /* Just load the crypto library error strings,<br> * SSL_load_error_strings() loads the crypto AND the SSL ones */<br>
/* SSL_load_error_strings();*/<br> ERR_load_crypto_strings();<br> <br> /* Read private key */<br> <br> fp = fopen (keyfile, "r");<br> if (fp == NULL) exit (1);<br> pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);<br>
fclose (fp);<br><br> if (pkey == NULL) { <br> ERR_print_errors_fp (stderr);<br> exit (1);<br> }<br> <br> /* Do the signature */<br> <br> EVP_SignInit (&md_ctx, EVP_sha1());<br> EVP_SignUpdate (&md_ctx, data, strlen(data));<br>
sig_len = sizeof(sig_buf);<br> err = EVP_SignFinal (&md_ctx, sig_buf, &sig_len, pkey);<br><br> if (err != 1) {<br> ERR_print_errors_fp(stderr);<br> exit (1);<br> }<br><br> EVP_PKEY_free (pkey);<br> <br>
/* Read public key */<br> <br> fp = fopen (certfile, "r");<br> if (fp == NULL) exit (1);<br> pkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL);<br> fclose (fp);<br> <br> if (pkey == NULL) { <br> ERR_print_errors_fp (stderr);<br>
exit (1);<br> }<br><br> /* Verify the signature */<br> <br> EVP_VerifyInit (&md_ctx, EVP_sha1());<br> EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));<br> err = EVP_VerifyFinal (&md_ctx, sig_buf, sig_len, pkey);<br>
EVP_PKEY_free (pkey);<br><br> if (err != 1) {<br> ERR_print_errors_fp (stderr);<br> exit (1);<br> }<br> printf ("Signature Verified Ok.\n");<br> return(0);<br>}<br><br>it's return the following error:<br>
1883:error:0906D06C:PEM routines:PEM_read_bio:no start line:/export/builds/onnv_101a/usr/src/common/openssl/crypto/pem/pem_lib.c:644:Expecting: PUBLIC KEY<br><br>Can somebody plz help me ?<br>TNX<br clear="all"><br>-- <br>
------------------------------------------------------------------<br>Marco Sommella<br><a href="mailto:marco.s...@gmail.com">marco.s...@gmail.com</a> (E-Mail & MSN)<br>------------------------------------------------------------------<br>
------=_Part_12058_26001910.1228336035290--
______________________________________________________________________
OpenSSL Project http://www.openssl.org
User Support Mailing List openss...@openssl.org
Automated List Manager majo...@openssl.org
> fp = fopen (certfile, "r");
> if (fp == NULL) exit (1);
> pkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL);
> fclose (fp);
Is certfile actually a X.509 certificate file or a public key file?
What are the contents of your certfile?
--- Kah
> marco.somme...@gmail.com (E-Mail & MSN)
> ------------------------------------------------------------------
>
> ------=_Part_12058_26001910.1228336035290
> Content-Type: text/html; charset=ISO-8859-1
> Content-Transfer-Encoding: 7bit
> Content-Disposition: inline
>
> Hi,<br>i tried to modify demos/sign, which reads private key from pem file and public key from x509 certificate in pem file, to a version which instead read public from pem file (not a certificate).<br><br>my 2 pem files are generate using RSA_generate_key, PEM_write_RSAPrivateKey, PEM_write_RSAPublicKey fuctions.<br>
> <br>here the code of sign.c changed by me:<br><br>#include <stdio.h><br>#include <openssl/rsa.h><br>#include <openssl/evp.h><br>#include <openssl/objects.h><br>#include <openssl/x509.h><br>#include <openssl/err.h><br>
> #include <openssl/pem.h><br>#include <openssl/ssl.h><br><br>int main ()<br>{<br> int err;<br> int sig_len;<br> unsigned char sig_buf [4096];<br> static char certfile[] = "pubkey.pem";<br> static char keyfile[] = "privkey.pem";<br>
> static char data[] = "I owe you...";<br> EVP_MD_CTX md_ctx;<br> EVP_PKEY * pkey;<br> FILE * fp;<br><br> /* Just load the crypto library error strings,<br> * SSL_load_error_strings() loads the crypto AND the SSL ones */<br>
> /* SSL_load_error_strings();*/<br> ERR_load_crypto_strings();<br> <br> /* Read private key */<br> <br> fp = fopen (keyfile, "r");<br> if (fp == NULL) exit (1);<br> pkey = PEM_read_PrivateKey(fp, NULL, NULL, NULL);<br>
> fclose (fp);<br><br> if (pkey == NULL) { <br> ERR_print_errors_fp (stderr);<br> exit (1);<br> }<br> <br> /* Do the signature */<br> <br> EVP_SignInit (&md_ctx, EVP_sha1());<br> EVP_SignUpdate (&md_ctx, data, strlen(data));<br>
> sig_len = sizeof(sig_buf);<br> err = EVP_SignFinal (&md_ctx, sig_buf, &sig_len, pkey);<br><br> if (err != 1) {<br> ERR_print_errors_fp(stderr);<br> exit (1);<br> }<br><br> EVP_PKEY_free (pkey);<br> <br>
> /* Read public key */<br> <br> fp = fopen (certfile, "r");<br> if (fp == NULL) exit (1);<br> pkey = PEM_read_PUBKEY(fp, NULL, NULL, NULL);<br> fclose (fp);<br> <br> if (pkey == NULL) { <br> ERR_print_errors_fp (stderr);<br>
> exit (1);<br> }<br><br> /* Verify the signature */<br> <br> EVP_VerifyInit (&md_ctx, EVP_sha1());<br> EVP_VerifyUpdate (&md_ctx, data, strlen((char*)data));<br> err = EVP_VerifyFinal (&md_ctx, sig_buf, sig_len, pkey);<br>
> EVP_PKEY_free (pkey);<br><br> if (err != 1) {<br> ERR_print_errors_fp (stderr);<br> exit (1);<br> }<br> printf ("Signature Verified Ok.\n");<br> return(0);<br>}<br><br>it's return the following error:<br>
> 1883:error:0906D06C:PEM routines:PEM_read_bio:no start line:/export/builds/onnv_101a/usr/src/common/openssl/crypto/pem/pem_lib.c:644:Expecting: PUBLIC KEY<br><br>Can somebody plz help me ?<br>TNX<br clear="all"><br>-- <br>
> ------------------------------------------------------------------<br>Marco Sommella<br><a href="mailto:marco.somme...@gmail.com">marco.somme...@gmail.com</a> (E-Mail & MSN)<br>------------------------------------------------------------------<br>
>
> ------=_Part_12058_26001910.1228336035290--
> ______________________________________________________________________
> OpenSSL Project http://www.openssl.org
> User Support Mailing List openssl-us...@openssl.org
> Automated List Manager majord...@openssl.org