Hi all, We are trying to use openssl 0.9.8g with our application on various platforms. we are facing an issue now.
while creating a keystore as shown in below function (I have included only relevant portions of the function) the application got crashed at free() (msvcr80.dll). what i feel is that it is because of either ERR_free_strings() or ERR_remove_state(0) or EVP_cleanup();. Please note that we are calling the below function from inside a loop in another function. the crash happens when the below code executes for the second time. Also the below functin will be resolved on a .dll which is loaded by a single threaded (C) application. Are we missing some thing or are we doing some thing really wrong here. ------------------------------------------------------------------------------------------------------------------------------ X509 *x = NULL; EVP_PKEY *pk = NULL; RSA *rsa = NULL; X509_NAME *cerName=NULL; /* Keystore */ PKCS12 *p12 = NULL; FILE *fp = NULL ; CRYPTO_malloc_init(); CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ON); SSLeay_add_all_algorithms(); ERR_load_crypto_strings(); /* Creates the key pairs and puts it into structure */ if ((rsa = RSA_generate_key(2048, RSA_F4, callback, NULL)) == NULL) { return -1; } if (!EVP_PKEY_assign_RSA(pk, rsa)) { return -1; } X509_set_version(x, 2); ASN1_INTEGER_set(X509_get_serialNumber(x), 0); X509_gmtime_adj(X509_get_notBefore(x), 0); X509_gmtime_adj(X509_get_notAfter(x), (long)60 * 60 * 24 * 365); X509_set_pubkey(x, pk); cerName = X509_get_subject_name(x); X509_NAME_add_entry_by_txt(cerName, "C", MBSTRING_ASC, countryName, -1, -1, 0); X509_NAME_add_entry_by_txt(cerName, "O", MBSTRING_ASC, orgName, -1, -1, 0); X509_NAME_add_entry_by_txt(cerName, "CN", MBSTRING_ASC, commonName, -1, -1, 0); X509_set_issuer_name(x, cerName); /* Add various extensions: standard extensions */ add_ext(x, NID_basic_constraints, "critical,CA:TRUE"); add_ext(x, NID_key_usage, "critical,keyCertSign,cRLSign"); add_ext(x, NID_subject_key_identifier, "hash"); if (!X509_sign(x, pk, EVP_md5())) { return -1; } if ((fp = fopen(path, "wb")) == NULL) { return -1; } if ((p12 = PKCS12_create((char *)pwd, friendlyName, pk, x, NULL, 0, 0, 0, 0, 0)) == NULL) { return -1; } /* Write Keystore */ i2d_PKCS12_fp(fp, p12); PKCS12_free(p12); fclose(fp); X509_free(x); EVP_PKEY_free(pk); CRYPTO_cleanup_all_ex_data(); ERR_free_strings(); ERR_remove_state(0); EVP_cleanup(); ------------------------------------------------------------------------------------------------------------------------------- Thanks in advance. -Sanjith