성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] 그냥 RSS Reader 기능과 약간의 UI 편의성 때문에 사용...
[이종효] 오래된 소프트웨어는 보안 위협이 되기도 합니다. 혹시 어떤 기능...
[정성태] @Keystroke IEEE의 문서를 소개해 주시다니... +_...
[손민수 (Keystroke)] 괜히 듀얼채널 구성할 때 한번에 같은 제품 사라고 하는 것이 아...
[정성태] 전각(Full-width)/반각(Half-width) 기능을 토...
[정성태] Vector에 대한 내용은 없습니다. Vector가 닷넷 BCL...
[orion] 글 읽고 찾아보니 디자인 타임에는 InitializeCompon...
[orion] 연휴 전에 재현 프로젝트 올리자 생각해 놓고 여의치 않아서 못 ...
[정성태] 아래의 글에 정리했으니 참고하세요. C# - Typed D...
[정성태] 간단한 재현 프로젝트라도 있을까요? 저런 식으로 설명만 해...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 - TLS 1.2 지원</h1> <p> 지난 글에서,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > C# - Ubuntu + Microsoft.Data.SqlClient + SQL Server 2008 R2 연결 방법 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/13364'>https://www.sysnet.pe.kr/2/0/13364</a> </pre> <br /> 리눅스 환경인 경우 <a target='tab' href='https://learn.microsoft.com/en-us/dotnet/api/microsoft.data.sqlclient.sqlconnection'>SqlConnection</a> 접속에서 TLS 1.2를 지원하지 않아 "<a target='tab' href='https://www.sysnet.pe.kr/2/0/12270'>CipherString = DEFAULT:@SECLEVEL</a>" 값을 재조정하는 것으로 해결했습니다.<br /> <br /> 하지만, 분명히 <a target='tab' href='https://techcommunity.microsoft.com/t5/sql-server-blog/tls-1-2-support-for-sql-server-2008-2008-r2-2012-and-2014/ba-p/384613'>문서상으로는 TLS 1.2를 지원</a>한다고 되어 있는데요, 어디... ^^ 정말 그런 것인지 테스트를 해볼까요?<br /> <br /> <hr style='width: 50%' /><br /> <br /> 초기 <a target='tab' href='https://www.sysnet.pe.kr/2/0/1835'>SQL Server 2008 R2는 TLS 1.2를 지원하지 않습니다.</a> 당연히 업데이트가 필요한데, 이를 위해 우선 <a target='tab' href='https://www.microsoft.com/en-us/download/details.aspx?id=44271'>(KB2979597에 해당하는) Service Pack 3을 설치</a>해야 합니다. 그럼 SQL Server 2008 R2 버전이 10.50.6000.34로 바뀝니다. (패치에 따른 버전 참조: <a target='tab' href='https://sqlserverbuilds.blogspot.com/2008/05/sql-server-2008-r2-versions.html'>Microsoft SQL Server 2008 R2 Versions</a>)<br /> <br /> 일단 SP3을 설치하면 이어서 KB3045316 중요 업데이트로 떠오르고, 이것을 완료하면 SQL Server 2008 R2 버전은 10.50.6220.0이 됩니다. 그리고 마침내, 우리가 원하는 TLS 1.2 지원 패치가 KB3135244에 해당하는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > KB3135244 - TLS 1.2 support for Microsoft SQL Server ; <a target='tab' href='https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe'>https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe</a> TLS 1.2 Support is available in the latest cumulative update for SQL Server 2008 R2 SP3 – KB4057113. </pre> <br /> 이것은 KB4057113 누적 업데이트에 포함됐다고 나옵니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Security Update for SQL Server 2008 R2 SP3 (KB4057113) ; <a target='tab' href='https://www.microsoft.com/en-us/download/details.aspx?id=56415'>https://www.microsoft.com/en-us/download/details.aspx?id=56415</a> </pre> <br /> 따라서 최종 준비는 위의 업데이트를 설치하는 것으로 마무리할 수 있습니다. 그리고 위의 업데이트를 설치하면 SQL Server 2008 R2의 버전이 10.50.6560.0으로 바뀝니다.<br /> <br /> 실제로 이 시점부터는, Windows 클라이언트에서의 "Microsoft.Data.SqlClient"로 접속했을 때 "<a target='tab' href='https://www.sysnet.pe.kr/2/0/13364#sec_warn_tls12'>Security Warning: The negotiated TLS 1.0 is an insecure protocol and is supported for backward compatibility only. The recommended protocol version is TLS 1.2 and later.</a>" 경고가 사라집니다.<br /> <br /> 결국 KB4057113으로 TLS 1.2 지원이 되는 것은 맞는 것 같습니다. 관련해 아래의 Q&A를 보면,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > KB3135244 - TLS 1.2 support for Microsoft SQL Server ; <a target='tab' href='https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe'>https://support.microsoft.com/en-us/topic/kb3135244-tls-1-2-support-for-microsoft-sql-server-e4472ef8-90a9-13c1-e4d8-44aad198cdbe</a> </pre> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Q: Will SQL Server 2005 be supported for TLS 1.2? A: TLS 1.2 support is offered only for SQL Server 2008 and later versions. Q: Which versions of Windows Server support TLS 1.2? A: Windows Server 2008 R2 and later versions support TLS 1.2. </pre> <br /> 분명하게 2008 버전부터 지원한다고 나옵니다. 단지, 여전히 Ubuntu에서의 연결은 SECLEVEL을 설정하지 않으면 아래의 예외가 발생하는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Unhandled exception. Microsoft.Data.SqlClient.SqlException (0x80131904): A connection was successfully established with the server, but then an error occurred during the pre-login handshake. (provider: SSL Provider, error: 31 - Encryption(ssl/tls) handshake failed) ---> System.IO.IOException: Received an unexpected EOF or 0 bytes from the transport stream. </pre> <br /> 도대체 왜 리눅스에서의 접근에는 오류가 발생하는 것일까요? ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> 이를 위해 우선 SECLEVEL의 의미부터 알아야 할 필요가 있습니다. 지난 글에 정리한 것처럼, Ubuntu 20.04의 경우 Level 1에서 정상 동작했으므로 기본값인 Level 2를 만족하지 못했다는 것인데요, 이것의 의미를 보면,<br /> <br /> <div style='BACKGROUND-COLOR: #ccffcc; padding: 10px 10px 5px 10px; MARGIN: 0px 10px 10px 10px; FONT-FAMILY: Malgun Gothic, Consolas, Verdana; COLOR: #005555'> Security level set to 112 bits of security. <span style='color: blue; font-weight: bold'>As a result RSA, DSA and DH keys shorter than 2048 bits</span> and ECC keys shorter than 224 bits are prohibited. In addition to the level 1 exclusions any cipher suite using RC4 is also prohibited. SSL version 3 is also not allowed. Compression is disabled. </div><br /> <a name='keylen_2048'></a> <br /> 2048비트보다 짧은 키 길이는 허용하지 않는다고 나옵니다. 그렇다면 아마도 <a target='tab' href='https://www.sysnet.pe.kr/2/0/13372'>SQL Server 2008 R2의 암호화에 사용하는 기본 인증서</a>가 2048보다 낮게 나온다고 추측할 수 있습니다. 확인을 위해 지난 글에 소개한 <a target='tab' href='https://www.sysnet.pe.kr/2/0/13368#get_tds_cert'>get_tds_cert.py</a>를 이용해 추출한 인증서를 보면,<br /> <br /> <img alt='sql2008_tls12_1.png' src='/SysWebRes/bbs/sql2008_tls12_1.png' /><br /> <br /> 오호~~~ 예상이 맞아떨어졌습니다. 실제로 <a target='tab' href='https://www.sysnet.pe.kr/2/0/13368#user_cert'>지난 글에 설명한 방법을 거쳐 2048비트의 키 길이를 갖는 인증서를 만들어 SQL Server 2008 R2에 제공</a>하면, SECLEVEL=2 상황에서도 SqlConnection 연결이 잘 되는 것을 확인할 수 있습니다. ^^<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // Ubuntu 22.04 환경 $ <span style='color: blue; font-weight: bold'>cat /etc/ssl/openssl.cnf</span> ...[생략]... [system_default_sect] <span style='color: blue; font-weight: bold'>CipherString = DEFAULT:@SECLEVEL=2</span> $ <span style='color: blue; font-weight: bold'>cat Program.cs</span> using Microsoft.Data.SqlClient; // Install-Package Microsoft.Data.SqlClient internal class Program { static void Main(string[] args) { SqlConnection conn = new SqlConnection("TrustServerCertificate=true; User ID=testusr;Password=testusr_pw;Persist Security Info=False;Initial Catalog=TestDB2;Data Source=testpc"); conn.Open(); Console.WriteLine(conn.ServerVersion); conn.Close(); } } $ <span style='color: blue; font-weight: bold'>dotnet run ConsoleApp1.csproj</span> 10.50.6560 </pre> <br /> 클라이언트마다 SECLEVEL을 조정하느냐, SQL 서버 측에 한 번의 인증서 설정을 하느냐는... 여러분이 선택하시면 되겠습니다. ^^<br /> </p><br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1243
(왼쪽의 숫자를 입력해야 합니다.)