Problem making shared library with openssl
Hello: I have a source files that use openssl functionality. I want to make a shared library to use this with Java. I did this following steps: 1º Compile sources: gcc -fPIC -g -c -Wall -I/usr/local/java/include \ -I/usr/local/java/include/linux \ -I/usr/local/ssl/include \ -L/usr/local/ssl/lib -ssl -lcrypto *.c 2º Make a shared library: gcc -shared -Wl,-soname,TTP.so -o TTP.so *.o -lc But when I use this shared library TTP.so, my java program not found openssl functions. I obtain this error: java.lang.UnsatisfiedLinkError: /usr/local/jakarta-tomcat-4.1.12/webapps/pseudomatic/TTP/TTP.so: /usr/local/jakarta-tomcat-4.1.12/webapps/pseudomatic/TTP/TTP.so: undefined symbol: PEM_write_DSA_PUBKEY I think that the problem is in the compilate phase, but I don´t know what is wrong. Somebody can help me?. Thanks. Regards. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
OpenSSL use into java applet
Hello: Sorry for my english. I have a native methods written in C that use openssl functions. This native methods are invoke into java applet throught JNI, but it don´t work. I think that my applet don´t find some .dll or .lib from OpenSSL, but I don´t know how do it. I use Microsoft Visual Studio 6.0 to do my native methods, and here I set the library modules libeay32.lib and ssleay32.lib; the additional library path D:\openssl-0.9.7e\out32dll; and the additional include directory D:\openssl-0.9.7e\inc32. Then, I build a dll that is load from my java applet. The whole program works fine from an java application that use JNI to invoke this native methods, but from an applet don´t work. Somebody can help me?. Thanks. Regards. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: OpenSSL use into java applet
Hello: I use various jar files because I use a jar with the code of my program, and others jar files from libraries that my code use. My html code is: applet code=org.ubisec.anonymity.AppletParteI.class archive=parteI.jar,base-core.jar,base-opt.jar,pcsc-wrapper-2.0.jar,referenc e-services.jar width=325 height=325 /applet The file parteI.jar is my code, and the others are from OpenCard. I have signed this jar files to allow the execution and not have security restrictions. What do you suggest me? Regards. - Original Message - From: Dominique Lohez [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Tuesday, September 13, 2005 10:42 AM Subject: Re: OpenSSL use into java applet Angel Martinez Gonzalez wrote: Hello: Sorry for my english. I have a native methods written in C that use openssl functions. This native methods are invoke into java applet throught JNI, but it don´t work. I think that my applet don´t find some .dll or .lib from OpenSSL, but I don´t know how do it. I use Microsoft Visual Studio 6.0 to do my native methods, and here I set the library modules libeay32.lib and ssleay32.lib; the additional library path D:\openssl-0.9.7e\out32dll; and the additional include directory D:\openssl-0.9.7e\inc32. Then, I build a dll that is load from my java applet. The whole program works fine from an java application that use JNI to invoke this native methods, but from an applet don´t work. This sounds as a security restriction related the use of an applet. This can be come around by puting in an UNIQUE jar file all the programs needed to run the applet. Dominique LOHEZ Somebody can help me?. Thanks. Regards. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] -- Dr Dominique LOHEZ ISEN 41, Bd Vauban F59046 LILLE France Phone : +33 (0)3 20 30 40 71 Email: [EMAIL PROTECTED] __ 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: OpenSSL use into java applet
Hello: Well, I can use JNI and web applet when I signed this applet. I don´t have problem with JNI and web applet. The problem is when I use openssl functionsin my native code. IfI don´t use openssl it work fine. Iread some articles about the incompatibilityJNI and web-loaded applets, but It work. Regards. Ángel Martínez - Original Message - From: Bhupendra K Joshi To: openssl-users@openssl.org Sent: Tuesday, September 13, 2005 12:55 PM Subject: Re: OpenSSL use into java applet Hi Angel, JNI and web-loaded Applets are incompatible, even if you sign them or jump through incredible hoops. You must use a Signed Applet to install an second signed one on the client's local hard disk, and then use that second Applet to do your JNI work. Even then loadLibrary is unreliable. I can't gurantee that but it may work for you. Regards, Bhupendra K JoshiAngel Martinez Gonzalez [EMAIL PROTECTED] wrote: Hello:I use various jar files because I use a jar with the code of my program, andothers jar files from libraries that my code use.My html code is: archive="parteI.jar,base-core.jar,base-opt.jar,pcsc-wrapper-2.0.jar,reference-services.jar" width=325 height=325>The file "parteI.jar" is my code, and the others are from OpenCard.I have signed this jar files to allow the execution and not have securityrestrictions.What do you suggest me?Regards.- Original Message - From: "Dominique Lohez" <[EMAIL PROTECTED]>To:Sent: Tuesday, September 13, 2005 10:42 AMSubject: Re: OpenSSL use into java appletAngel Martinez Gonzalez wrote:Hello:Sorry for my english.I have a native methods written in C that use openssl functions. Thisnativemethods are invoke into java applet throught JNI, but it don´t work. Ithinkthat my applet don´t find some .dll or .lib from OpenSSL, but I don´t knowhow do it.I use Micro soft Visual Studio 6.0 to do my native methods, and here I setthe library modules "libeay32.lib" and "ssleay32.lib"; the additionallibrary path "D:\openssl-0.9.7e\out32dll"; and the additional includedirectory "D:\openssl-0.9.7e\inc32". Then, I build a dll that is load frommy java applet.The whole program works fine from an java application that use JNI toinvokethis native methods, but from an applet don´t work.This sounds as a security restriction related the use of an applet.This can be come around by puting in an UNIQUE jar fileall the programs needed to run the applet.Dominique LOHEZSomebody can help me?. Thanks.Regards.__OpenSSL Project http://www.openssl.orgUser Support Mailing List openssl-users@openssl.orgAutomated List Manager [EMAIL PROTECTED]-- Dr Dominique LOHEZISEN41, Bd VaubanF59046 LILLEFrancePhone : +33 (0)3 20 30 40 71Email: [EMAIL PROTECTED]__OpenSSL Project http://www.openssl.orgUser Support Mailing List openssl-users@openssl.orgAutomated List Manager [EMAIL PROTECTED]__OpenSSL Project http://www.openssl.orgUser Support Mailing List openssl-users@openssl.orgAutomated List Manager [EMAIL PROTECTED] Yahoo! for GoodClick here to donate to the Hurricane Katrina relief effort.
Get public key from a certificate
Hello: I have a certificate in char * format, and I want to get his public key. Are there an OpenSSL function to do this?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Get public key from X509 certificate
Hello: I want to get the RSA public key from a X509 certificate. Are there some function to do this?. I know this function: EVP_PKEY *509_get_pubkey(cert) But I want obtain a RSA *. Thanks __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Strange error when I read a certificate
Hello: I want read a certificate, and I use the function PEM_read_X509. Then, I get the serial number and the subject name. I have done it with success reading a certain certificate, but when I read other certificate I have get a read error. And this certificate it´s ok. Both certificates are in format .crt. This is the funcion that I use to read the certificates: BIGNUM *ClavePublicaCertificado(char *certificado) { BIO *out; FILE *fp; X509 *cert; X509_NAME *asunto; ASN1_INTEGER *bs; char *serialHex; BIGNUM *serialBN = NULL; int error; // abre la salida estandar // if (!(out = BIO_new_fp (stdout, BIO_NOCLOSE))) printf(Error creating stdout BIO\n); if (!(fp = fopen(certificado, r))) printf (Error lectura certificado (%s)\n, certificado); if (!(cert = PEM_read_X509(fp, NULL, NULL, NULL))) printf (Error leyendo certificado (%s)\n, certificado); fclose(fp); bs = X509_get_serialNumber(cert); serialBN = ASN1_INTEGER_to_BN(bs,NULL); serialHex = BN_bn2hex(serialBN); asunto = X509_get_subject_name(cert); X509_NAME_print (out, asunto, 0); return (serialBN); } What is the problem?. Is the problem the certificate, o is this code? Thanks a lot. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
How initialize the PRNG using RAND_seed ?
Hello: I need initialize the PRNG to can generate keys and performing public key encryption. I want use one of this functions: void RAND_seed(const void *buf, int num); void RAND_add(const void *buf, int num, double entropy); But I don´t know what parameters I have to use. Somebody can send me a example to use this functions?. Thanks a lot. Regards. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: How initialize the PRNG using RAND_seed ?
Hello: Thanks for your help, but I don´t know what buffer and num I must use. How I can generate this buffer of random data?. And, num is the entropy, but, what is it?. How I obtain this entropy?. I use Windows. Thanks. Ragards. - Original Message - From: Bernhard Froehlich [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Thursday, June 23, 2005 10:17 AM Subject: Re: How initialize the PRNG using RAND_seed ? Angel Martinez Gonzalez wrote: Hello: I need initialize the PRNG to can generate keys and performing public key encryption. I want use one of this functions: void RAND_seed(const void *buf, int num); void RAND_add(const void *buf, int num, double entropy); But I don´t know what parameters I have to use. Somebody can send me a example to use this functions?. See http://www.openssl.org/docs/crypto/RAND_add.html You usually use RAND_seed with a buffer of good random data. Hope it helps, Ted ;) -- PGP Public Key Information Download complete Key from http://www.convey.de/ted/tedkey_convey.asc Key fingerprint = 31B0 E029 BCF9 6605 DAC1 B2E1 0CC8 70F4 7AFB 8D26 __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Read a Bignum from file
Hello: I wrote a BIGNUM into a file using the function: int BN_print_fp(FILE *fp, const BIGNUM *a); But, How I can read this bignum from this file?. I don´t know a openssl function to read a bignum from a file. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Get Serial number from a cert
Hello: I want to get the serial number from a certificate. I use this function: X509_get_serialNumber(). This function returns a ASN1_INTEGER struct, with the field length, type, data and flag. I suppose that the serial number is stored in the data field of the struct. But I can´t get it. My code is the following: char *CERTIFICADO_TTP = cacert.pem; FILE *fp; X509 *cert; int serialNumber; ASN1_INTEGER *bs; if (!(fp = fopen(CERTIFICADO_TTP, r))) printf (Error\n); if (!(cert = PEM_read_X509(fp, NULL, NULL, NULL))) printf (Error\n); fclose(fp); bs = X509_get_serialNumber(cert); printf (Serial number: %s \n, bs-data); What is wrong?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Get an attribute from a certificate
Hello: I am newby with the certificates in OpenSSL. I want to get an attribute from a certificate, that I have stored in a local file .cer. What functions I have to use? Can somebody help me? Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Problem at RSA decrypt: block type is not 02
Hello: I want to cypher/decrypt messages with RSA. I use this functions to cypher and decypher: int CifradoClavePublica(RSA *claveRSA, char *texto, char **textocifrado) { int size = RSA_size(claveRSA); int blksize = size - 12; int length = strlen(texto); int blocks = length/blksize; int rest = length%blksize; int i; int tamano_datos_cifrados; int longitud_datos_cifrados = 0; if (rest == 0) *textocifrado = malloc(blocks*size+1); else *textocifrado = malloc((blocks+1)*size+1); for (i=0; iblocks; i++) { tamano_datos_cifrados = RSA_public_encrypt(blksize, texto+i*blksize, *textocifrado+i*size, claveRSA, RSA_PKCS1_PADDING); longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados; } if (rest != 0) { tamano_datos_cifrados = RSA_public_encrypt(rest, texto+blocks*blksize, *textocifrado+blocks*size, claveRSA, RSA_PKCS1_PADDING); longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados; } return (longitud_datos_cifrados); } This function returns the size of the encrypted data. claveRSA is the public key RSA, texto is the message to cypher, and textocifrado stores the ciphertext. To decypher, I use this function: char *DescifradoClavePrivada(RSA *claveRSA, char *texto, int longitud_datos_cifrados) { int size = RSA_size(claveRSA); int blksize = size-12; int length = longitud_datos_cifrados; int blocks = length/size; int i, error; int written = 0; char *textoclaro; int tamano_datos_descifrados; char *fileError = error.txt; FILE *fp; textoclaro = malloc(blocks*blksize+1); for (i=0; iblocks; i++) { printf (bucle %i\n,i); tamano_datos_descifrados = RSA_private_decrypt(blksize, texto+i*size, textoclaro+written, claveRSA, RSA_PKCS1_PADDING); ERR_load_crypto_strings(); error = ERR_get_error(); printf (Library: %s\n, ERR_lib_error_string(error)); printf (Function: %s\n, ERR_func_error_string(error)); printf (Reason: %s\n, ERR_reason_error_string(error)); written = written + tamano_datos_descifrados; } return (textoclaro); } This function returns the plain text. claveRSA is the private key RSA, texto is the cyphertext to decrypt, and longitud_datos_cifrados is the size of the encrypted data texto. And when I run this function, I obtain this error message: Library: rsa routines Function: RSA_padding_check_PKCS1_type_2 Reason: block type is not 02 What meaning this error?, What it is wrong?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: Problem at RSA decrypt: block type is not 02
Yes, I agree with you. The message that I want to cypher, is not a real message. I want to cypher a struct with two fields: - A symmetric key, and - A integer with a special meaning for my application. And this struct have a size bigger than RSA key size, and I need use blocks. And, I think that it is a correct use of the RSA cypher/decypher method, isn´t you?. Regards. - Original Message - From: Eduardo Pérez [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Monday, May 16, 2005 10:40 AM Subject: Re: Problem at RSA decrypt: block type is not 02 What are you trying to do? (give some details if you want any help) Using RSA directly on the message is almost never a good idea. (Correct me if I'm wrong but that's what you seem to be doing) You should be using an intermediate symmetric cipher or just let openssl or gnupg do its job and forget about the internal specifics of key selection and protocol. Eduardo On 2005-05-16 07:21:25 UTC, Angel Martinez Gonzalez wrote: I want to cypher/decrypt messages with RSA. I use this functions to cypher and decypher: int CifradoClavePublica(RSA *claveRSA, char *texto, char **textocifrado) { int size = RSA_size(claveRSA); int blksize = size - 12; int length = strlen(texto); int blocks = length/blksize; int rest = length%blksize; int i; int tamano_datos_cifrados; int longitud_datos_cifrados = 0; if (rest == 0) *textocifrado = malloc(blocks*size+1); else *textocifrado = malloc((blocks+1)*size+1); for (i=0; iblocks; i++) { tamano_datos_cifrados = RSA_public_encrypt(blksize, texto+i*blksize, *textocifrado+i*size, claveRSA, RSA_PKCS1_PADDING); longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados; } if (rest != 0) { tamano_datos_cifrados = RSA_public_encrypt(rest, texto+blocks*blksize, *textocifrado+blocks*size, claveRSA, RSA_PKCS1_PADDING); longitud_datos_cifrados = longitud_datos_cifrados + tamano_datos_cifrados; } return (longitud_datos_cifrados); } This function returns the size of the encrypted data. claveRSA is the public key RSA, texto is the message to cypher, and textocifrado stores the ciphertext. To decypher, I use this function: char *DescifradoClavePrivada(RSA *claveRSA, char *texto, int longitud_datos_cifrados) { int size = RSA_size(claveRSA); int blksize = size-12; int length = longitud_datos_cifrados; int blocks = length/size; int i, error; int written = 0; char *textoclaro; int tamano_datos_descifrados; char *fileError = error.txt; FILE *fp; textoclaro = malloc(blocks*blksize+1); for (i=0; iblocks; i++) { printf (bucle %i\n,i); tamano_datos_descifrados = RSA_private_decrypt(blksize, texto+i*size, textoclaro+written, claveRSA, RSA_PKCS1_PADDING); ERR_load_crypto_strings(); error = ERR_get_error(); printf (Library: %s\n, ERR_lib_error_string(error)); printf (Function: %s\n, ERR_func_error_string(error)); printf (Reason: %s\n, ERR_reason_error_string(error)); written = written + tamano_datos_descifrados; } return (textoclaro); } This function returns the plain text. claveRSA is the private key RSA, texto is the cyphertext to decrypt, and longitud_datos_cifrados is the size of the encrypted data texto. And when I run this function, I obtain this error message: Library: rsa routines Function: RSA_padding_check_PKCS1_type_2 Reason: block type is not 02 What meaning this error?, What it is wrong?. Thanks. __ 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]
How to cypher a struct with RSA_public_encrypt
Hello: I want to cypher a struct like this: struct { DES_cblock *key; int id; } Request; but, the RSA_public_encrypt function receive as parameter unsigned char *from, no a struct: int RSA_public_encrypt(int flen, unsigned char *from, unsigned char *to, RSA *rsa, int padding); How I do to cypher my struct?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: No show errors with ERR_print_errors_fp()
Hello: I tried your advice but I obtain the same result. I have tried the following: ERR_load_crypto_strings(); printf (error: %i\n,ERR_get_error()); printf(ERR_error_string(ERR_get_error(), NULL)); printf(ERR_lib_error_string(ERR_get_error())); printf(ERR_func_error_string(ERR_get_error())); printf(ERR_reason_error_string(ERR_get_error())); fflush(stdout); This code only show: error: 0 error::lib(0):func(0):reason(0) But it not show a human-readable string representing the error code. Why?. I have load the OpenSSL error strings by calling: ERR_load_crypto_strings(); Why it not show the string representing the error code?. Thanks for you help. - Original Message - From: Andreas Hoffmann [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Wednesday, May 11, 2005 8:13 PM Subject: Re: No show errors with ERR_print_errors_fp() Hi I want to obtain the errors that I have, and I use the function ERR_print_errors_fp(). But , this give a empty file. And I have errors ... My code: ERR_load_crypto_strings(); fp = fopen(fileError, w); ERR_print_errors_fp(fp); fclose(fp); Have you tried to direct the errors to stderr? using: ERR_print_errors_fp (stderr); Do you do multiple fopen ... fclose in your code? Then you should use fp = fopen(fileError,a); as the w option overwrites the file contents. So may be your last write contained no errors. I hope this helps. Andreas __ 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: Loading RSA keys from file.
Hello: I send you a function that read RSA public and private key from a file: RSA *RecuperaClavesRSA(int type, char *pemfile){ FILE *fp; RSA *key=NULL; switch (type){ case READPUB: if((fp = fopen(pemfile,"r")) == NULL) { fprintf(stderr,"Error: Public Key file doesn't exists.\n"); exit(EXIT_FAILURE); } if((key = PEM_read_RSAPublicKey(fp,NULL,NULL,NULL)) == NULL) { fprintf(stderr,"Error: problems while reading Public Key.\n"); exit(EXIT_FAILURE); } fclose(fp); printf("RSA size: %d", RSA_size(key)); return key; break; case READSEC: if((fp = fopen(pemfile,"r")) == NULL) { fprintf(stderr,"Error: Private Key file doesn't exists.\n"); exit(EXIT_FAILURE); } if((key = PEM_read_RSAPrivateKey(fp,NULL,NULL,NULL)) == NULL) { fprintf(stderr,"Error: problmes while reading Private Key. %d %s\n",type,pemfile); exit(EXIT_FAILURE); } fclose(fp); if(RSA_check_key(key) == -1) { fprintf(stderr,"Error: Problems while reading RSA Private Key in \ '%s' file.\n",pemfile); exit(EXIT_FAILURE); } else if(RSA_check_key(key) == 0) { fprintf(stderr,"Error: Bad RSA Private Key readed in '%s' \ file.\n",pemfile); exit(EXIT_FAILURE); } else return key; break; } return key;} If the parameter "type" is "READPUB" it read the public key from the file "pemfile", and if this parameter is "READSEC", it read the private key. Too, this function show RSA size correctly. I hope this function solve your problem. Regards. P.D.: Your name remember me a very famous song of Eric Clapton ... ;-) - Original Message - From: Layla To: openssl-users@openssl.org Sent: Tuesday, May 10, 2005 3:55 PM Subject: Re: Loading RSA keys from file. Hi Angel, Thank you for your response. I have changed my code with accordance to your suggestion but I'm still getting a runtime error when attempting to read the key from its file. So far I'm having trouble with 1- reading the key from file, and 2- RSA_size() , this function generates a runtime error when encountered as well. I can't think of anything since I'm initializing my RSA object. Suggestions ? Angel Martinez Gonzalez [EMAIL PROTECTED] wrote: Hello Layla: Maybe, your error disapear if you will change the following: apub = PEM_read_RSAPublicKey(f, NULL, NULL, NULL); Regards. - Original Message - From: Layla To: openssl-users@openssl.org Sent: Tuesday, May 10, 2005 9:30 AM Subject: Loading RSA keys from file. I'm still not able to load the key from its file and I'm still encountering an error when I use RSA_size();a run time error occured when I try to print the returned size. I'm including a segment of my code after modification: RSA *apub; FILE *f; seed_prng(); // my function for seeding PRNG //Allocating apub apub = RSA_new(); if ( apub == NULL) //print error mesage //open key file f= fopen ("a_rsa_public","r"); if (f == NULL) //print error message //Loading key apub = PEM_read_RSAPublicKey(f, apub, 0,0); //a run time error occurs here if (apub == NULL) { // print error message return -1; } /* if I try the following line after the allocation of the RSA object I get a runtime error as well*/ printf("RSA size: %d", RSA_size(apub); *** I'm thankful for any help I can get. Sebastian [EMAIL PROTECTED] wrote: Hmm,take a look at routines like RSA_new() to create RSA structures. As you coded 'sizeof apub', this will return the size of a _pointer_ - assuming a 32-bit architecture you will get round about four bytes ;-).See: http://www.openssl.org/docs/crypto/RSA_new.htmlThe runtime error is caused by calling RSA_size() with a null pointer - unfortnunfortunately RSA_size() doesn't like null pointers.See: http://www.openssl.org/docs/crypto/RSA_size.htmlGood luck,Sebastian Hi all, I'm trying to develop a C++ application to encrypt and decrypt data using RSA public key cryptography scheme. I have generated the public/private keys using OpenSSL command line tool. The following C++ code should read a public key, encrypt data, read private key and decrypt the data: #include #include #include #include #include
Re: Problem to cipher/decypher a struct with RSA
Hello: Thanks Nils for you help, but I obtain the problem. I have tried your advice: RSA_public_encrypt(sizeof(texto)+1, texto, textocifrado, claveRSA, RSA_PKCS1_PADDING); but the problem is the same. - Original Message - From: Nils Larsch [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Thursday, May 12, 2005 9:51 AM Subject: Re: Problem to cipher/decypher a struct with RSA Angel Martinez Gonzalez wrote: Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, I wouldn't use strlen(), sizeof() might be more appropriate Nils __ 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]
No show errors with ERR_print_errors_fp()
Hello: I want to obtain the errors that I have, and I use the function ERR_print_errors_fp(). But , this give a empty file. And I have errors ... My code: ERR_load_crypto_strings(); fp = fopen(fileError, w); ERR_print_errors_fp(fp); fclose(fp); Can somebody help me? Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: Loading RSA keys from file.
Hello Layla: Maybe, your error disapear if you will change the following: apub = PEM_read_RSAPublicKey(f, NULL, NULL, NULL); Regards. - Original Message - From: Layla To: openssl-users@openssl.org Sent: Tuesday, May 10, 2005 9:30 AM Subject: Loading RSA keys from file. I'm still not able to load the key from its file and I'm still encountering an error when I use RSA_size();a run time error occured when I try to print the returned size. I'm including a segment of my code after modification: RSA *apub; FILE *f; seed_prng(); // my function for seeding PRNG //Allocating apub apub = RSA_new(); if ( apub == NULL) //print error mesage //open key file f= fopen ("a_rsa_public","r"); if (f == NULL) //print error message //Loading key apub = PEM_read_RSAPublicKey(f, apub, 0,0); //a run time error occurs here if (apub == NULL) { // print error message return -1; } /* if I try the following line after the allocation of the RSA object I get a runtime error as well*/ printf("RSA size: %d", RSA_size(apub); *** I'm thankful for any help I can get. Sebastian [EMAIL PROTECTED] wrote: Hmm,take a look at routines like RSA_new() to create RSA structures. As you coded 'sizeof apub', this will return the size of a _pointer_ - assuming a 32-bit architecture you will get round about four bytes ;-).See: http://www.openssl.org/docs/crypto/RSA_new.htmlThe runtime error is caused by calling RSA_size() with a null pointer - unfortnunfortunately RSA_size() doesn't like null pointers.See: http://www.openssl.org/docs/crypto/RSA_size.htmlGood luck,Sebastian Hi all, I'm trying to develop a C++ application to encrypt and decrypt data using RSA public key cryptography scheme. I have generated the public/private keys using OpenSSL command line tool. The following C++ code should read a public key, encrypt data, read private key and decrypt the data: #include #include #include #include #includeint main() { char *message ="Hello World!"; RSA *apub; RSA *aprivate; FILE *f; int ret; unsigned char *buf; unsigned char *e_data; unsigned char *clear_text; //Get key f= fopen("a_rsa_public","rb"); if(f == NULL) { printf("\nError opening public key file"); return -1; } else printf("\n Public key file opened"); //load the key if ( fread(apub,sizeof apub,1,f) != 1) { printf("\nError reading public key"); return -1; } else printf("\nPublic key read"); //close the key file fclose(f); buf = (unsigned char *) malloc(strlen(message)); memcpy(buf,message,strlen(message)); e_data = (unsigned char *) malloc(RSA_size(apub)); // THIS is where i get a run time error //encrypt data RSA_public_encrypt(strlen(message),buf, e_data, apub, RSA_PKCS1_OAEP_PADDING); //--decrypt //Get key f= fopen("a_rsa_private","rb"); if(f == NULL) { printf("\nError opening private key file"); return -1; } //load the key ret = fread(aprivate,sizeof(aprivate),1,f); //close the key file fclose(f); //make sure we loaded ok if(ret != 1) { printf("\nError reading private key"); return -1; } clear_text= (unsigned char *) malloc(strlen(message)); RSA_private_decrypt(strlen((char*)e _data), e_data, clear_text, aprivate, RSA_PKCS1_OAEP_PADDING); return 0; } *** At first I used to get a run time error in the RSA_public_encrypt(...); and I figured caused I had e_data initialized as: e_data = (unsigned char *) malloc(strlen(message)*4); So instead I used : e_data = (unsigned char *) malloc(RSA_size(apub)); and now I'm getting a run time as this line is encountered. I'm sure someone with experience would be able to spot my mistake. I thank you all in advance for your help. __ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com __OpenSSL Project http://www.openssl.orgUser Support Mailing List openssl-users@openssl.orgAutomated List Manager [EMAIL PROTECTED] Yahoo! Mail MobileTake Yahoo! Mail with you! Check email on your mobile phone.
Problem to cipher/decypher a struct with RSA
Hello: I want to cypher/decypher an struct: struct PeticionSeudonimo { char *mensaje; int id_peticion; DES_cblock *clave_simetrica; }peticion_seudonimo; To do this, I first convert this struct to char *: char *ptrPeticionSeudonimo = (char *)peticion_seudonimo; Then I use this function to cipher: char *CifradoClavePublica(RSA *claveRSA, char *texto) { char *textocifrado; textocifrado =malloc(RSA_size(claveRSA)); RSA_public_encrypt(strlen(texto)+1, texto, textocifrado, claveRSA, RSA_PKCS1_PADDING); return (textocifrado); } and I call this function at this way: solicitudCifrada = CifradoClavePublica(clavePublicaRSA_TTP, ptrPeticionSeudonimo); Then, I decipher (solicitudCifrada) using this function: char *DescifradoClavePrivada(RSA *claveRSA, char *texto) { char *textoclaro; textoclaro = malloc(RSA_size(claveRSA)); RSA_private_decrypt(RSA_size(claveRSA), texto, textoclaro, claveRSA, RSA_PKCS1_PADDING); return (textoclaro); } and I call this function at this way: solicitudDescifrada = DescifradoClavePrivada(clavePrivadaRSA_TTP, solicitudCifrada); Finally, I convert solicitudDescifrada from char * to struct: peticion_seudonimo_descifrada = (struct PeticionSeudonimo *)solicitudDescifrada; But, when I want to show the fields of this struct peticion_seudonimo_descifrada, I only obtain the first field (char *mensaje), the others fileds are missing. I obtain an error at execution time. This fields are disappear. What is wrong?. Thanks for your help. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Error using BN_rand_range() function
Hello: I want to generate a random number making use of BN_rand_range() function. But I obtain an error at execution time. This is my code: error = BN_rand_range(A, claveDSA_TTP-q); if (error == 1) printf (A obtenido correctamente\n); else printf (Error al obtener A\n); printf (A: %s\n, BN_bn2dec(A)); The error that I obtained is this: The instruction in 0x1002a31a make a reference to memory in 0xd4c0ada7. The memory can not be read. I send, too, an image of the error. What is the problem?. Thanks. attachment: error.jpg
Re: Problem with BN_rand_range
Hello: The error that I obtained is at execution time: The instruction in 0x1002a31a make a reference to memory in 0xd4c0ada7. The memory can not be read. I send, too, an image of the error. Thanks. - Original Message - From: Nils Larsch [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Friday, April 22, 2005 9:52 PM Subject: Re: Problem with BN_rand_range Angel Martinez Gonzalez wrote: Hello: I want to generate a random number making use of BN_rand_range() function. But I obtain an error at execution time. This is my code: error = BN_rand_range(A, claveDSA_TTP-q); if (error == 1) printf (A obtenido correctamente\n); else printf (Error al obtener A\n); printf (A: %s\n, BN_bn2dec(A)); What is the problem? what error message does ERR_print_errors() give you ? Nils __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] attachment: error.jpg
Problem with BN_rand_range
Hello: I want to generate a random number making use of BN_rand_range() function. But I obtain an error at execution time. This is my code: error = BN_rand_range(A, claveDSA_TTP-q); if (error == 1) printf (A obtenido correctamente\n); else printf (Error al obtener A\n); printf (A: %s\n, BN_bn2dec(A)); What is the problem? Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Re: Error with PEM_write_RSAPrivateKey function
Hello: This is the error message that I obtained: The instruction in 0x78468216 refers to memory in 0x0010. Memory can not written. I send you a image with this error message. Thanks. - Original Message - From: Nils Larsch [EMAIL PROTECTED] To: openssl-users@openssl.org Sent: Tuesday, April 19, 2005 9:40 PM Subject: Re: Error with PEM_write_RSAPrivateKey function Angel Martinez Gonzalez wrote: Hello: I use this function to generate a RSA pair key and write the public and private key in a files. But this function have a error at execution time. what kind or error (error message) ? Nils __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED] attachment: error.jpg
Generate RSA key
Hello: I want to generate a RSA pair key. I do the following: RSA *claveRSA; int num = 1024; // Tamaño del módulo. unsigned long e = 3; // Exponente público RAND_screen(); claveRSA = RSA_new(); claveRSA = RSA_generate_key(num, e, NULL, NULL); But I obtain the same key allways. When I show the public modulus I obtain the same: printf (public modulus: %i, *(claveRSA-n)); I use VC++ in Windows 2000. What is wrong?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Error with PEM_write_RSAPrivateKey function
Hello: I use this function to generate a RSA pair key and write the public and private key in a files. But this function have a error at execution time. I think that the problem is on the function: PEM_write_RSAPrivateKey(fp,key,NULL,NULL,0,NULL,NULL) But I don´t know what is wrong. The function is the following: void AlmacenaClavesRSA(char *secfile, char *pubfile) { RSA *key=NULL; FILE *fp; int size = 1024; printf(Generating RSA keys[%d bits].\n, size); if (size 64) { fprintf(stderr, Error: RSA Key pair size too small.\n); fprintf(stderr, size = 64\n); exit(EXIT_FAILURE); } if((key = RSA_generate_key(size,3,NULL,NULL)) == NULL) { fprintf(stderr,%s\n,ERR_error_string(ERR_get_error(),NULL)); exit(EXIT_FAILURE); } if(RSA_check_key(key) 1) { fprintf(stderr,Error: Problems while generating RSA Key.\n \ Retry.\n); exit(EXIT_FAILURE); } printf (clave generada\n); // Guarda la clave privada fp=fopen(secfile,w); if(PEM_write_RSAPrivateKey(fp,key,NULL,NULL,0,NULL,NULL) == 0) { fprintf(stderr,Error: problems while writing RSA Private \ Key.\n); exit(EXIT_FAILURE); } fclose(fp); // Guarda la clave publica fp=fopen(pubfile,w); if(PEM_write_RSAPublicKey(fp,key) == 0) { fprintf(stderr,Error: problems while writing RSA Public Key.\n); exit(EXIT_FAILURE); } fclose(fp); RSA_free(key); printf(Done.\n); return; } Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Error to sign with OpenSSL
Hello: I want sign with OpenSSL, and I use the RSA_sign fuction: void Firmar(char *mdigest, int longmdigest, RSA *claveRSA) { int error; char *firma; firma = malloc(RSA_size(claveRSA)); error = RSA_sign(NID_sha1, mdigest, longmdigest, firma, strlen(firma), claveRSA); if (error == 1) printf (Firma realizada con exito\n); else printf (Error en el firmado\n); } And I call to this funcion Firmar with this code: Firmar(messagedigest, longitudMensajeDigest, parClaves); Where: unsigned char messagedigest[EVP_MAX_MD_SIZE]; int longitudMensajeDigest; RSA *parClaves; and this variables have a valid value. But I have an error in execution time. What is wrong?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Generate symmetric key DES3
Hello: I want to generate a symmetric key with DES. But I don´t know very well, how do it. I tried the following: void GenerateKey() { DES_cblock *ret ; RAND_screen(); printf(Staus of PRNG: %i\n,RAND_status()); DES_random_key(ret); printf(key: %i\n,ret); } But I obtained an error of execution. What I do wrong?. How I can generate a DES symmetric key?. Thanks. __ OpenSSL Project http://www.openssl.org User Support Mailing Listopenssl-users@openssl.org Automated List Manager [EMAIL PROTECTED]
Request Setup error
Hello: I´m trying to initializate OpenCA. In Request Setup of Phase 1, I enter this DN: C=ES, ST=Valladolid, L=Boecillo, O=Telefonica I+D, OU=Casa Domotica, CN=domolinux.hi.inet/[EMAIL PROTECTED] obtained from this OpenSSL certificate: Certificate: Data: Version: 1 (0x0) Serial Number: 0 (0x0) Signature Algorithm: md5WithRSAEncryption Issuer: C=ES, ST=Valladolid, L=Boecillo, O=Telefonica I+D, OU=Casa Domotica, CN=domolinux.hi.inet/[EMAIL PROTECTED] Validity Not Before: Jun 28 11:30:55 2004 GMT Not After : Jun 28 11:30:55 2005 GMT Subject: C=ES, ST=Valladolid, L=Boecillo, O=Telefonica I+D, OU=Casa Domotica, CN=domolinux.hi.inet/[EMAIL PROTECTED] Subject Public Key Info: Public Key Algorithm: rsaEncryption RSA Public Key: (1024 bit) Modulus (1024 bit): 00:b0:31:94:3a:60:28:6a:04:65:25:74:43:e2:8a: ae:92:50:a4:61:d3:4d:a3:5c:ca:20:63:8f:48:ac: b2:c1:2d:e9:f3:72:cb:97:9d:3a:72:7b:ae:97:8d: 51:76:34:32:6c:39:ca:71:5e:09:83:b2:36:a8:9c: e2:c6:77:78:a2:01:19:06:af:ed:cd:81:0e:96:b5: ec:48:af:0b:c1:76:04:5e:7a:6a:7e:b4:f4:44:58: a1:0f:b7:79:e1:a9:ef:7f:09:b4:67:00:9d:d4:7f: 42:32:0a:64:30:67:57:5d:8c:49:94:29:ef:8f:92: 02:7e:16:28:9f:5a:d9:c3:c3 Exponent: 65537 (0x10001) Signature Algorithm: md5WithRSAEncryption 20:f1:44:48:64:ae:b7:6b:9d:e9:e6:38:54:d6:f8:69:c8:c6: 59:63:c9:0a:61:23:99:a0:c4:13:65:e6:9b:8f:34:59:07:75: 13:de:a8:06:6e:9e:1f:06:d0:66:78:c6:e2:a9:58:cb:ea:21: 63:6a:95:64:5f:28:89:ba:32:dd:f5:36:29:6c:f8:0d:7b:f1: d6:31:1d:63:b5:a8:e3:ac:34:74:be:46:0b:57:31:3f:cd:9b: 86:fe:55:4d:b0:c9:9e:ba:66:e7:20:ec:b7:d9:b3:32:35:fc: 11:fd:df:cb:a4:a6:71:b3:63:1b:cd:6b:41:10:67:95:e9:e7: 20:6f But I havethis error: Error 7712013 General Error. OpenCA::OpenSSL failed.OpenCA::OpenSSL-genReq: Cannot build X500::DN-object from subject C=ES, ST=Valladolid, L=Boecillo, O=Telefonica I+D, OU=Casa Domotica, CN=domolinux.hi.inet/[EMAIL PROTECTED] Somebody can help me? Thanks.