简体   繁体   English

服务器在Openssl初始化时失败

[英]Server Fails on Openssl Initialization

I am working on a win32 file server that was coded using Visual Studio 6.0. 我正在使用Visual Studio 6.0编码的win32文件服务器上工作。 It had SSL configured and working back in 2000, but hasn't been used since. 它已配置SSL并在2000年开始工作,但此后一直未使用。

Now, we want to use SSL (Opensll), so I've updated the libraries, etc and have the server working with SSLv3 and TLS when the server is run as a console app. 现在,我们要使用SSL(Opensll),因此我已经更新了库等,并在服务器作为控制台应用程序运行时让服务器使用SSLv3和TLS。

As soon as I run the server as a windows service, the ssl initialization routine crashes without any error messages. 一旦我将服务器作为Windows服务运行,ssl初始化例程就会崩溃,而不会出现任何错误消息。 Here is the code that is causing all of the grief. 这是引起所有悲伤的代码。

int SwiftSSL::Initialize()
{
  SSLeay_add_ssl_algorithms();
  SSL_load_error_strings();

  ctx_ = SSL_CTX_new( SSLv23_server_method() );

  if(!ctx_) {
    LogEvent( "SSL_CTX is bad.");
    return false;
  }

  LogEvent( "Before using cert and private key file.");

  if ( SSL_CTX_use_certificate_file( ctx_, CERT_FILE, SSL_FILETYPE_PEM ) == 1 ) {
  LogEvent( "SUCCESS SSL_CTX_use_certificate_file." );
  }
  else {
    LogEvent( "FAILED SSL_CTX_use_certificate_file." );
    return false;
  }

  if ( SSL_CTX_use_PrivateKey_file( ctx_, KEY_FILE, SSL_FILETYPE_PEM ) == 0 ) { 
  LogEvent( "Failed SSL_CTX_use_PrivateKey_file." );
    return false;
  }
  else {
    LogEvent( "SUCCESSFUL SSL_CTX_use_PrivateKey_file." );
  }

  if ( SSL_CTX_check_private_key( ctx_ ) == 0 ) {
    ERR_print_errors_fp( stderr );
    LogEvent( "Failed SSL_CTX_check_private_key" );
    return false;
  }

  LogEvent( "Successfully used cert and private key file."); 

  return true;
}

When run as a Windows Service, the only message logged is: "Before using cert and private key file." 当作为Windows服务运行时,记录的唯一消息是:“使用证书和私钥文件之前”。

Nothing else is logged. 没有其他记录。 That, to me, means that the command SSL_CTX_use_certificate_file( ctx_, CERT_FILE, SSL_FILETYPE_PEM ) is crashing. 对我来说,这意味着命令SSL_CTX_use_certificate_file(ctx_,CERT_FILE,SSL_FILETYPE_PEM)崩溃。

But why would it work with no issues when the same program is run as a console? 但是,当同一程序作为控制台运行时,为什么它不会出现问题呢?

This is the information that I found in event viewer: 这是我在事件查看器中找到的信息:

The description for Event ID ( 0 ) in Source ( OPENSSL ) cannot be found. 找不到源(OPENSSL)中事件ID(0)的描述。 The local computer may not have the necessary registry information or message DLL files to display messages from a remote computer. 本地计算机可能没有必要的注册表信息或消息DLL文件来显示来自远程计算机的消息。 The following information is part of the event: OPENSSL_Uplink(00341000,08): no OPENSSL_Applink 以下信息是事件的一部分:OPENSSL_Uplink(00341000,08):否OPENSSL_Applink

Any help will be appreciated. 任何帮助将不胜感激。

Ok. 好。 I woke up this morning with the solution to this situation. 今天早上,我醒了,解决了这种情况。 As it turns out, the Windows Service did not know where to find the CERT_FILE or the KEY_FILE. 事实证明,Windows服务不知道在哪里可以找到CERT_FILE或KEY_FILE。 Apps running as a Windows Service will look for files in the %WinDir%\\System32 directory. 作为Windows服务运行的应用程序将在%WinDir%\\ System32目录中查找文件。 I have the files in the app directory, so I simply had to add the actual path to the files when calling SSL_CTX_use_certificate_file and SSL_CTX_use_PrivateKey_file. 我在app目录中有文件,因此在调用SSL_CTX_use_certificate_file和SSL_CTX_use_PrivateKey_file时,只需要将实际路径添加到文件中。

It now works fine. 现在可以正常工作了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM