Link to home
Start Free TrialLog in
Avatar of rbhargaw
rbhargawFlag for United States of America

asked on

Microsoft Visual Studio C Run Time Fatal Error, openSSL, wsse, gsoap, VC++

I am trying to use OpenSSL in an sample VC++ application. The test application compiles and links properly.
But I run the application I receive an "Microsoft Visual Studio C Run Time Fatal Error" on the following line
I have copied wsseapi.cpp and wsseapi.h from C:\gsoap-win32-2.7\plugin folder.

1. rsa_private_key = PEM_read_PrivateKey(fd, NULL, NULL, "password");
2. X509 *cert = PEM_read_X509(fd, NULL, NULL, NULL);      

Let me know whats wrong in this?
fd = fopen("C:/clientPriv.pk8", "r");
	rsa_private_key = PEM_read_PrivateKey(fd, NULL, NULL, "password");
	if (!rsa_private_key) {ERR_print_errors_fp(stderr);	exit(1); }
	fclose(fd);
	fd = fopen("C:/clientCert.pem", "r");
	X509 *cert = PEM_read_X509(fd, NULL, NULL, NULL);
	if (!cert) {ERR_print_errors_fp(stderr);	exit(1); }
	fclose(fd);

Open in new window

Avatar of rbhargaw
rbhargaw
Flag of United States of America image

ASKER

Call Stack error:

      msvcr90.dll!_crt_debugger_hook()       
       [Frames below may be incorrect and/or missing, no symbols loaded for msvcr90.dll]      
       msvcr90.dll!_invalid_parameter()  + 0x1f bytes      
       msvcr90.dll!_setmode()  + 0x49 bytes      
       libeay32.dll!BIO_s_file()  + 0x2be bytes      
       libeay32.dll!BIO_ctrl()  + 0x4f bytes      
My sample application is in VC ++ .NET 2005 ( unmanaged code) while downloading OpenSSL, I installed
Visual C++ 2008 Redistributables also .
Does fopen() return correctly ( != NULL ) ?
I did tried       
fd = fopen("C:/clientPriv.pk8", "r");
      if ((fd = fopen("C:/clientPriv.pk8", "r")) != NULL)
      {
            printLine("\n\tYeah","");
      }
It is printing the comment.

I have built the project as "Multithreaded DLL         /MD"       for  OpenSSL . The compile and linking are going properly.

I have put few more codes..Let me know if you need more details.
int main(int argc, char ** argv[])
{
SSL_load_error_strings() 
OpenSSL_add_all_algorithms() 
 
FILE *fd = NULL;
EVP_PKEY *rsa_private_key;
fd = fopen("C:/clientPriv.pk8", "r");
	if ((fd = fopen("C:/clientPriv.pk8", "r")) != NULL) 
	{
		printLine("\n\tYeah","");
	}
	rsa_private_key = PEM_read_PrivateKey(fd, NULL, NULL, "password");
	if (!rsa_private_key) {ERR_print_errors_fp(stderr);	exit(1); }
	fclose(fd);
	fd = fopen("C:/clientCert.pem", "r");
	X509 *cert = PEM_read_X509(fd, NULL, NULL, NULL);
	if (!cert) {ERR_print_errors_fp(stderr);	exit(1); }
	fclose(fd);
 
}

Open in new window

I tried the following statements under       main :
RSA_generate_key works but PEM_write_RSA_PUBKEY fails

Error: Microsoft Visual Studio C Runtime Library has detected a fatal error


---------------------------------------------------------------------

OpenSSL_add_all_algorithms() ;

RSA *rsa=NULL;

//Generate the keys
if ((rsa=RSA_generate_key(2048,65537,NULL,NULL)) == NULL){
      printLine("\n\tCreated","");
}
else
{
      printLine("\n\sucess","");
}
FILE *fp;
 
fp = fopen("server_public.key","w");
 if (!PEM_write_RSA_PUBKEY(fp, rsa )){
           printLine("\n\fail","");
}
else{
         printLine("\n\sucess","");
}
fclose(fp);
------------------------------------------------------------------------------------
Output
----------------------------------------------------
 
'VFS-UT-SIG.exe': Loaded 'C:\VfsDev gSoap\VFS-UT-SIG\VFS-UT-SIG\debug\VFS-UT-SIG.exe', Symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\ntdll.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\kernel32.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\VfsDev gSoap\VFS-UT-SIG\VFS-UT-SIG\debug\ssleay32.dll', Binary was not built with debug information.
'VFS-UT-SIG.exe': Loaded 'C:\VfsDev gSoap\VFS-UT-SIG\VFS-UT-SIG\debug\libeay32.dll', Binary was not built with debug information.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\wsock32.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\ws2_32.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\msvcrt.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\ws2help.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\advapi32.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\rpcrt4.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\secur32.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\gdi32.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\user32.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC90.CRT_1fc8b3b9a1e18e3b_9.0.30729.1_x-ww_6f74963e\msvcr90.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.CRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_6b128700\msvcr80.dll', Symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcp80d.dll', Symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\WinSxS\x86_Microsoft.VC80.DebugCRT_1fc8b3b9a1e18e3b_8.0.50727.762_x-ww_5490cd9f\msvcr80d.dll', Symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\EntAPI.dll', No symbols loaded.
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\psapi.dll', Symbols loaded (source information stripped).
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\netapi32.dll', No symbols loaded.
'VFS-UT-SIG.exe': Unloaded 'C:\WINDOWS\system32\EntAPI.dll'
'VFS-UT-SIG.exe': Unloaded 'C:\WINDOWS\system32\netapi32.dll'
'VFS-UT-SIG.exe': Unloaded 'C:\WINDOWS\system32\psapi.dll'
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\netapi32.dll', No symbols loaded.
'VFS-UT-SIG.exe': Unloaded 'C:\WINDOWS\system32\netapi32.dll'
'VFS-UT-SIG.exe': Loaded 'C:\WINDOWS\system32\rsaenh.dll', Symbols loaded (source information stripped).
Microsoft Visual Studio C Runtime Library has detected a fatal error in VFS-UT-SIG.exe.

Open in new window

Call Stack
----------------------------------------------------
       msvcr90.dll!785912e1()       
       [Frames below may be incorrect and/or missing, no symbols loaded for msvcr90.dll]      
       msvcr90.dll!7858c93d()       
       msvcr90.dll!7858c149()       
       libeay32.dll!0050098e()       
       libeay32.dll!004ff5ff()       
       libeay32.dll!00529fe1()       
       libeay32.dll!0052a633()       
>      VFS-UT-SIG.exe!main(int argc=1, char * * * argv=0x003f6c88)  Line 281 + 0xd bytes      C++
       VFS-UT-SIG.exe!__tmainCRTStartup()  Line 597 + 0x17 bytes      C
       kernel32.dll!7c816fd7()       

ASKER CERTIFIED SOLUTION
Avatar of rbhargaw
rbhargaw
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial