OSDN Git Service

na-get-lib,"セキュリティプロトコル設定の確認"を追加。SSLv3を無効化し、使用可能ならばTLSv1.1とTLSv1.2を有効にする
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / SecurityProtocolConfigSubTask.cs
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();
+               }
+       }
+}