mirror of https://github.com/winsw/winsw
				
				
				
			Merge pull request #394 from NextTurn/tls
Enable TLS 1.1/1.2 when using .NET2 and .NET4 packages on Windows 7 and Windows Server 2008 R2pull/397/head
						commit
						b36aff024e
					
				| 
						 | 
				
			
			@ -3,6 +3,9 @@ using System.IO;
 | 
			
		|||
using System.Net;
 | 
			
		||||
using System.Text;
 | 
			
		||||
using System.Xml;
 | 
			
		||||
#if !VNEXT
 | 
			
		||||
using log4net;
 | 
			
		||||
#endif
 | 
			
		||||
using winsw.Util;
 | 
			
		||||
 | 
			
		||||
namespace winsw
 | 
			
		||||
| 
						 | 
				
			
			@ -20,6 +23,10 @@ namespace winsw
 | 
			
		|||
            basic
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
#if !VNEXT
 | 
			
		||||
        private static readonly ILog Logger = LogManager.GetLogger(typeof(Download));
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        public readonly string From;
 | 
			
		||||
        public readonly string To;
 | 
			
		||||
        public readonly AuthType Auth = AuthType.none;
 | 
			
		||||
| 
						 | 
				
			
			@ -30,6 +37,28 @@ namespace winsw
 | 
			
		|||
 | 
			
		||||
        public string ShortId => $"(download from {From})";
 | 
			
		||||
 | 
			
		||||
#if !VNEXT
 | 
			
		||||
        static Download()
 | 
			
		||||
        {
 | 
			
		||||
            const SecurityProtocolType Tls12 = (SecurityProtocolType)0x00000C00;
 | 
			
		||||
            const SecurityProtocolType Tls11 = (SecurityProtocolType)0x00000300;
 | 
			
		||||
 | 
			
		||||
            // Windows 7 and Windows Server 2008 R2
 | 
			
		||||
            if (Environment.OSVersion.Version.Major == 6 && Environment.OSVersion.Version.Minor == 1)
 | 
			
		||||
            {
 | 
			
		||||
                try
 | 
			
		||||
                {
 | 
			
		||||
                    ServicePointManager.SecurityProtocol |= Tls11 | Tls12;
 | 
			
		||||
                    Logger.Info("TLS 1.1/1.2 enabled");
 | 
			
		||||
                }
 | 
			
		||||
                catch (NotSupportedException)
 | 
			
		||||
                {
 | 
			
		||||
                    Logger.Info("TLS 1.1/1.2 disabled");
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        // internal
 | 
			
		||||
        public Download(
 | 
			
		||||
            string from,
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue