[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 3160
  • Last Modified:

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

0
rbhargaw
Asked:
rbhargaw
  • 6
1 Solution
 
rbhargawAuthor Commented:
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      
0
 
rbhargawAuthor Commented:
My sample application is in VC ++ .NET 2005 ( unmanaged code) while downloading OpenSSL, I installed
Visual C++ 2008 Redistributables also .
0
 
alb66Commented:
Does fopen() return correctly ( != NULL ) ?
0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
rbhargawAuthor Commented:
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

0
 
rbhargawAuthor Commented:
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

0
 
rbhargawAuthor Commented:
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()       

0
 
rbhargawAuthor Commented:
Finally found out the solution:

* According to a bug in OpenSSL (current: 0.9.8j) under Win32 some
statements which are used in wsse-sample (wssedemo.c) can't be used.

   PEM_read_PrivateKey() and PEM_read_X509() will crash on Win32.

   Use following instead:

   BIO* pBio = BIO_new(BIO_s_file());
   BIO_read_filename(pBio, "server.pem");
   EVP_KEY* pRsaPrvKey = PEM_read_bio_PrivateKey(pBio, NULL, NULL,
(void*)"keyfilepassword");
   EVP_KEY* pCert = PEM_read_bio_X509(pBio, NULL, NULL, NULL);
   BIO_free(pBio);
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now