summarylogtreecommitdiffstats
path: root/PluginSecurityManager.cs.patch
blob: 8044cd7bbe09a3161791f7537a2229ed30162a0f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
*** PluginSecurityManager.cs_	2017-07-23 02:13:15.000000000 -0400
--- PluginSecurityManager.cs	2017-08-05 19:55:29.509988589 -0400
***************
*** 117,123 ****
          /// <returns>Task{MBRegistrationRecord}.</returns>
          public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
          {
!             return GetRegistrationStatusInternal(feature, mb2Equivalent);
          }
  
          /// <summary>
--- 117,123 ----
          /// <returns>Task{MBRegistrationRecord}.</returns>
          public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent = null)
          {
!             return GetRegistrationStatusInternal();
          }
  
          /// <summary>
***************
*** 129,140 ****
          /// <returns>Task{MBRegistrationRecord}.</returns>
          public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version)
          {
!             return GetRegistrationStatusInternal(feature, mb2Equivalent, version);
          }
  
          private Task<MBRegistrationRecord> GetSupporterRegistrationStatus()
          {
!             return GetRegistrationStatusInternal("MBSupporter", null, _appHost.ApplicationVersion.ToString());
          }
  
          /// <summary>
--- 129,140 ----
          /// <returns>Task{MBRegistrationRecord}.</returns>
          public Task<MBRegistrationRecord> GetRegistrationStatus(string feature, string mb2Equivalent, string version)
          {
!             return GetRegistrationStatusInternal();
          }
  
          private Task<MBRegistrationRecord> GetSupporterRegistrationStatus()
          {
!             return GetRegistrationStatusInternal();
          }
  
          /// <summary>
***************
*** 241,334 ****
              }
          }
  
!         private async Task<MBRegistrationRecord> GetRegistrationStatusInternal(string feature,
!             string mb2Equivalent = null,
!             string version = null)
          {
!             var regInfo = LicenseFile.GetRegInfo(feature);
!             var lastChecked = regInfo == null ? DateTime.MinValue : regInfo.LastChecked;
!             var expDate = regInfo == null ? DateTime.MinValue : regInfo.ExpirationDate;
! 
!             var maxCacheDays = 14;
!             var nextCheckDate = new [] { expDate, lastChecked.AddDays(maxCacheDays) }.Min();
! 
!             if (nextCheckDate > DateTime.UtcNow.AddDays(maxCacheDays))
!             {
!                 nextCheckDate = DateTime.MinValue;
!             }
! 
!             //check the reg file first to alleviate strain on the MB admin server - must actually check in every 30 days tho
!             var reg = new RegRecord
!             {
!                 // Cache the result for up to a week
!                 registered = regInfo != null && nextCheckDate >= DateTime.UtcNow && expDate >= DateTime.UtcNow,
!                 expDate = expDate
!             };
! 
!             var success = reg.registered;
! 
!             if (!(lastChecked > DateTime.UtcNow.AddDays(-1)) || !reg.registered)
!             {
!                 var data = new Dictionary<string, string>
!                 {
!                     { "feature", feature }, 
!                     { "key", SupporterKey }, 
!                     { "mac", _appHost.SystemId }, 
!                     { "systemid", _appHost.SystemId }, 
!                     { "mb2equiv", mb2Equivalent }, 
!                     { "ver", version }, 
!                     { "platform", _appHost.OperatingSystemDisplayName }
!                 };
! 
!                 try
!                 {
!                     var options = new HttpRequestOptions
!                     {
!                         Url = MBValidateUrl,
! 
!                         // Seeing block length errors
!                         EnableHttpCompression = false,
!                         BufferContent = false
!                     };
! 
!                     options.SetPostData(data);
! 
!                     using (var json = (await _httpClient.Post(options).ConfigureAwait(false)).Content)
!                     {
!                         reg = _jsonSerializer.DeserializeFromStream<RegRecord>(json);
!                         success = true;
!                     }
! 
!                     if (reg.registered)
!                     {
!                         _logger.Info("Registered for feature {0}", feature);
!                         LicenseFile.AddRegCheck(feature, reg.expDate);
!                     }
!                     else
!                     {
!                         _logger.Info("Not registered for feature {0}", feature);
!                         LicenseFile.RemoveRegCheck(feature);
!                     }
! 
!                 }
!                 catch (Exception e)
!                 {
!                     _logger.ErrorException("Error checking registration status of {0}", e, feature);
!                 }
!             }
! 
!             var record = new MBRegistrationRecord
              {
!                 IsRegistered = reg.registered,
!                 ExpirationDate = reg.expDate,
                  RegChecked = true,
!                 RegError = !success
              };
- 
-             record.TrialVersion = IsInTrial(reg.expDate, record.RegChecked, record.IsRegistered);
-             record.IsValid = !record.RegChecked || record.IsRegistered || record.TrialVersion;
- 
-             return record;
          }
  
          private bool IsInTrial(DateTime expirationDate, bool regChecked, bool isRegistered)
--- 241,256 ----
              }
          }
  
!         private async Task<MBRegistrationRecord> GetRegistrationStatusInternal()
          {
!             return new MBRegistrationRecord
              {
!                 IsRegistered = true,
                  RegChecked = true,
!                 TrialVersion = false,
!                 IsValid = true,
!                 RegError = false
              };
          }
  
          private bool IsInTrial(DateTime expirationDate, bool regChecked, bool isRegistered)