Click here to Skip to main content
15,887,267 members
Articles / Containers / Docker
Tip/Trick

Challenges in Migrating ASP.NET Apps to Containers #3 – OpenSSL Issues

Rate me:
Please Sign up or sign in to vote.
5.00/5 (2 votes)
22 Mar 2024CPOL2 min read 2.3K   2   1
Configuring OpenSSL minimum version and legacy renogetiation
This post outlines challenges encountered during the migration of ASP.NET apps from Windows to Linux Docker containers, focusing on addressing issues related to SSL connections, particularly the OpenSSL Legacy Renegotiation, and provides a solution using Dockerfile modifications.

Introduction

During a recent project, there was a requirement to migrate existing ASP.NET apps hosted on Windows to Linux Docker containers. Throughout this migration, numerous challenges arose, and a significant amount of time was dedicated to the migration process. In this post, as well as in subsequent posts with similar titles, I will briefly outline some of the key challenges that were encountered. One of those challenges was OpenSSL Legacy Renegotiation.


Credits: https://turnoff.us/geek/we-need-to-talk-about-ssl/

TL;DR

Add the below lines to your Dockerfile on the target runtime container before running your application entry point to enable legacy SSL Renegotiation and change the minimum TLS version allowed.

BAT
RUN sed -i 's/CipherString = DEFAULT:@SECLEVEL=2/CipherString = DEFAULT:@SECLEVEL=1\n\
MinProtocol = TLSv1\n\
Options =UnsafeLegacyRenegotiation,UnsafeLegacyServerConnect\n\
/' /etc/ssl/openssl.cnf

Details

During the Linux migration of one of the ASP.NET Windows applications that connects to a large number of third parties, we encountered numerous issues while establishing connections with some of them. Most of these issues were showing SSL exceptions, and one of the major exceptions what we encountered was:

BAT
WebServiceException: The SSL connection could not be established, see inner exception.
---> System.Net.Http.HttpRequestException: The SSL connection could not be established, 
     see inner exception.
---> System.Security.Authentication.AuthenticationException: Authentication failed, 
     see inner exception.
---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
---> Interop+Crypto+OpenSslCryptographicException: 
     error:0A000152:SSL routines::unsafe legacy renegotiation disabled
--- End of inner exception stack trace ---
   at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, 
   ReadOnlySpan`1 input, Byte[]& sendBuf, Int32& sendCount)

After conducting a comprehensive investigation, we discovered that the issue was caused by certain third parties using legacy SSL protocols and configurations. To resolve this, we have to update our OpenSSL configuration to:

  1. Change the minimum supported TLS version to match your third-party requirements.
  2. Allow unsafe legacy connect and renegotiations.

To apply the above changes, you need to update OpenSSL configuration file, openssl.cnf, which resides in /etc/ssl/. Follow the steps below:

Locate and open /etc/ssl/openssl.cnf:

BAT
cd /etc/ssl
cat openssl.cnf

Scroll through the file to locate the relevant sections or configurations mentioned in the previous instructions, such as the minimum supported TLS version and the settings related to unsafe legacy connect and renegotiations.

A long file may appear on the screen, scroll through the file to find our target section, system_default_sect section.

BAT
[ssl_sect]
system_default = system_default_sect
[system_default_sect]
CipherString = DEFAULT:@SECLEVEL=2

Full explanation of configurations of this file can be found here: /docs/man1.1.1/man3/SSL_CONF_cmd.html (openssl.org)

Now the action starts, we need to add two configurations to the system_default_sect section:

BAT
MinProtocol = TLSv1
Options = UnsafeLegacyRenegotiation,UnsafeLegacyServerConnect

This can be easily achieved by using the sed stream editor command. The following lines will insert our configurations after the CipherString line:

BAT
sed -i 's/CipherString = DEFAULT:@SECLEVEL=2/CipherString = DEFAULT:@SECLEVEL=1\n\
MinProtocol = TLSv1\n\
Options = UnsafeLegacyRenegotiation,UnsafeLegacyServerConnect\n\
/' /etc/ssl/openssl.cnf

Now browse the openssl.cnf file again, you can see:

BAT
[system_default_sect]
CipherString = DEFAULT:@SECLEVEL=1
MinProtocol = TLSv1
Options = UnsafeLegacyRenegotiation,UnsafeLegacyServerConnect

No need to restart your container or take any additional action. Your configurations will be automatically applied to your next SSL request. Enjoy!

History

  • 22nd March, 2024: Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Technical Lead
Egypt Egypt
Mohammad Elsheimy is a developer, trainer, and technical writer currently hired by one of the leading fintech companies in Middle East, as a technical lead.

Mohammad is a MCP, MCTS, MCPD, MCSA, MCSE, and MCT expertized in Microsoft technologies, data management, analytics, Azure and DevOps solutions. He is also a Project Management Professional (PMP) and a Quranic Readings college (Al-Azhar) graduate specialized in Quranic readings, Islamic legislation, and the Arabic language.

Mohammad was born in Egypt. He loves his machine and his code more than anything else!

Currently, Mohammad runs two blogs: "Just Like [a] Magic" (http://JustLikeAMagic.com) and "مع الدوت نت" (http://WithdDotNet.net), both dedicated for programming and Microsoft technologies.

You can reach Mohammad at elsheimy[at]live[dot]com

Comments and Discussions

 
GeneralMy vote of 5 Pin
Ștefan-Mihai MOGA25-Mar-24 20:07
professionalȘtefan-Mihai MOGA25-Mar-24 20:07 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.