OSDN Git Service

na-get-lib,"セキュリティプロトコル設定の確認"を追加。SSLv3を無効化し、使用可能ならばTLSv1.1とTLSv1.2を有効にする
[applistation/AppliStation.git] / na-get-lib / NaGet.SubCommands.SubTask / SecurityProtocolConfigSubTask.cs
1 using System;
2 using System.Net;
3 using NaGet.Tasks;
4
5 namespace NaGet.SubCommands.SubTask
6 {
7         public class SecurityProtocolConfigSubTask : NaGetSubTask
8         {       
9                 public SecurityProtocolConfigSubTask()
10                 {
11                 }
12                 
13                 public override void Run()
14                 {
15                         NotifyStarted();
16                         RaiseTaskSetEvent(TaskEventType.STARTED, "セキュリティプロトコル設定の確認", 0);
17                         
18                         if ((ServicePointManager.SecurityProtocol & SecurityProtocolType.Ssl3) != 0) {
19                                 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
20                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 33);
21                         }
22                         
23                         try {
24                                 ServicePointManager.SecurityProtocol |= (SecurityProtocolType)768; // SecurityProtocolType.Tls11
25                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 66);
26                         } catch (NotSupportedException) {
27                                 RaiseTaskSetEvent(TaskEventType.WARNING, "TLSv1.1は有効ではありません", 66);
28                         }
29                         
30                         try {
31                                 ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
32                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 99);
33                         } catch (NotSupportedException) {
34                                 RaiseTaskSetEvent(TaskEventType.WARNING, "TLSv1.2は有効ではありません", 99);
35                         }
36                         
37                         RaiseTaskSetEvent(TaskEventType.COMPLETED, "セキュリティプロトコル設定の確認", 100);
38                         NotifyCompleted();
39                 }
40         }
41 }