OSDN Git Service

na-get-lib,"セキュリティプロトコル設定の確認"を追加。SSLv3を無効化し、使用可能ならばTLSv1.1とTLSv1.2を有効にする
authorttp <ttp@users.sourceforge.jp>
Mon, 9 Oct 2017 14:39:26 +0000 (23:39 +0900)
committerttp <ttp@users.sourceforge.jp>
Mon, 9 Oct 2017 14:41:20 +0000 (23:41 +0900)
na-get-lib/NaGet.SubCommands.SubTask/SecurityProtocolConfigSubTask.cs [new file with mode: 0644]
na-get-lib/NaGet.SubCommands/NaGetDownloadToCache2.cs
na-get-lib/NaGet.SubCommands/NaGetInstall2.cs
na-get-lib/NaGet.SubCommands/NaGetUpdate2.cs
na-get-lib/na-get-lib.csproj

diff --git a/na-get-lib/NaGet.SubCommands.SubTask/SecurityProtocolConfigSubTask.cs b/na-get-lib/NaGet.SubCommands.SubTask/SecurityProtocolConfigSubTask.cs
new file mode 100644 (file)
index 0000000..fdfc096
--- /dev/null
@@ -0,0 +1,41 @@
+using System;
+using System.Net;
+using NaGet.Tasks;
+
+namespace NaGet.SubCommands.SubTask
+{
+       public class SecurityProtocolConfigSubTask : NaGetSubTask
+       {       
+               public SecurityProtocolConfigSubTask()
+               {
+               }
+               
+               public override void Run()
+               {
+                       NotifyStarted();
+                       RaiseTaskSetEvent(TaskEventType.STARTED, "セキュリティプロトコル設定の確認", 0);
+                       
+                       if ((ServicePointManager.SecurityProtocol & SecurityProtocolType.Ssl3) != 0) {
+                               ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
+                               RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 33);
+                       }
+                       
+                       try {
+                               ServicePointManager.SecurityProtocol |= (SecurityProtocolType)768; // SecurityProtocolType.Tls11
+                               RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 66);
+                       } catch (NotSupportedException) {
+                               RaiseTaskSetEvent(TaskEventType.WARNING, "TLSv1.1は有効ではありません", 66);
+                       }
+                       
+                       try {
+                               ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
+                               RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 99);
+                       } catch (NotSupportedException) {
+                               RaiseTaskSetEvent(TaskEventType.WARNING, "TLSv1.2は有効ではありません", 99);
+                       }
+                       
+                       RaiseTaskSetEvent(TaskEventType.COMPLETED, "セキュリティプロトコル設定の確認", 100);
+                       NotifyCompleted();
+               }
+       }
+}
index 94cfe29..a435685 100644 (file)
@@ -41,6 +41,8 @@ namespace NaGet.SubCommands
                        
                        // taskセットの初期化
                        initSubTask();
+                       registSubTask("セキュリティプロトコル設定の確認",
+                                     new SecurityProtocolConfigSubTask());
                        foreach (Installation inst in installations) {
                                DownloadSubTask dlSTask = new DownloadSubTask(inst.InstallerURL, inst.InstallerFile);
                                VirusScanSubTask scanSTask = new VirusScanSubTask(scanner, inst.InstallerFile, inst.InstallerURL);
index 9e215e0..514896a 100644 (file)
@@ -49,6 +49,8 @@ namespace NaGet.SubCommands
                {
                        // taskセットの初期化
                        initSubTask();
+                       registSubTask("セキュリティプロトコル設定の確認",
+                                     new SecurityProtocolConfigSubTask());
                        foreach (Installation inst in installations) {
                                VirusScanSubTask scanSTask = new VirusScanSubTask(scanner, inst.InstallerFile, inst.InstallerURL);
                                
index 8ea2c4a..9b84cc8 100644 (file)
@@ -40,6 +40,8 @@ namespace NaGet.SubCommands
                        
                        // taskセットの初期化
                        initSubTask();
+                       registSubTask("セキュリティプロトコル設定の確認",
+                                     new SecurityProtocolConfigSubTask());
                        if (this.downloadPackageLists) {
                                // repos.list.xmlがあるとき、そこからよみとる。
                                repoList = NaGet.Utils.GetDeserializedObject<RepositoriesList>(NaGet.Env.RepositoriesListFile);
index a11dd1c..324536b 100644 (file)
@@ -77,6 +77,7 @@
     <Compile Include="NaGet.SubCommands.SubTask\DownloadSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\LocalUpdateSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\NaGetSubTask.cs" />\r
+    <Compile Include="NaGet.SubCommands.SubTask\SecurityProtocolConfigSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\VerifyInstallerFileSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands.SubTask\VirusScanSubTask.cs" />\r
     <Compile Include="NaGet.SubCommands\NaGetDownloadToCache2.cs" />\r