OSDN Git Service

na-get-lib,TLSv1.1/1.2使用不能時のメッセージをWARNINGから単なるINFOに変更
[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                         // SSLv3無効化
19                         if ((ServicePointManager.SecurityProtocol & SecurityProtocolType.Ssl3) != 0) {
20                                 ServicePointManager.SecurityProtocol &= ~SecurityProtocolType.Ssl3;
21                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 33);
22                         }
23                         
24                         // TLSv1.0有効化
25                         ServicePointManager.SecurityProtocol |= SecurityProtocolType.Tls;
26                         
27                         try {
28                                 ServicePointManager.SecurityProtocol |= (SecurityProtocolType)768; // SecurityProtocolType.Tls11
29                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 66);
30                         } catch (NotSupportedException) {
31                                 RaiseTaskSetEvent(TaskEventType.INFO, "TLSv1.1は有効ではありません", 66);
32                         }
33                         
34                         try {
35                                 ServicePointManager.SecurityProtocol |= (SecurityProtocolType)3072; // SecurityProtocolType.Tls12
36                                 RaiseTaskSetEvent(TaskEventType.PING, string.Empty, 99);
37                         } catch (NotSupportedException) {
38                                 RaiseTaskSetEvent(TaskEventType.INFO, "TLSv1.2は有効ではありません", 99);
39                         }
40                         
41                         RaiseTaskSetEvent(TaskEventType.COMPLETED, "セキュリティプロトコル設定の確認", 100);
42                         NotifyCompleted();
43                 }
44         }
45 }