Browse Source

Removed unused Logout Session manager middleware

Teknikode 2 months ago
parent
commit
0597455180

+ 4
- 0
Teknik.sln View File

@@ -17,6 +17,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
17 17
 		.gitattributes = .gitattributes
18 18
 		.gitignore = .gitignore
19 19
 		global.json = global.json
20
+		Performance1.psess = Performance1.psess
20 21
 		README.md = README.md
21 22
 	EndProjectSection
22 23
 EndProject
@@ -29,6 +30,9 @@ EndProject
29 30
 Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ServiceWorker", "ServiceWorker\ServiceWorker.csproj", "{0B712243-994C-4AC3-893C-B86B59F63F53}"
30 31
 EndProject
31 32
 Global
33
+	GlobalSection(Performance) = preSolution
34
+		HasPerformanceSessions = true
35
+	EndGlobalSection
32 36
 	GlobalSection(SolutionConfigurationPlatforms) = preSolution
33 37
 		Debug|Any CPU = Debug|Any CPU
34 38
 		Release|Any CPU = Release|Any CPU

+ 1
- 4
Teknik/Areas/User/Controllers/UserController.cs View File

@@ -49,11 +49,8 @@ namespace Teknik.Areas.Users.Controllers
49 49
         private readonly IHttpContextAccessor _httpContextAccessor;
50 50
         private ISession _session => _httpContextAccessor.HttpContext.Session;
51 51
 
52
-        private readonly LogoutSessionManager _logoutSessions;
53
-
54
-        public UserController(ILogger<Logger> logger, Config config, TeknikEntities dbContext, LogoutSessionManager logoutSessions, IHttpContextAccessor httpContextAccessor) : base(logger, config, dbContext)
52
+        public UserController(ILogger<Logger> logger, Config config, TeknikEntities dbContext, IHttpContextAccessor httpContextAccessor) : base(logger, config, dbContext)
55 53
         {
56
-            _logoutSessions = logoutSessions;
57 54
             _httpContextAccessor = httpContextAccessor;
58 55
         }
59 56
 

+ 2
- 5
Teknik/Security/CookieEventHandler.cs View File

@@ -13,13 +13,10 @@ namespace Teknik.Security
13 13
 {
14 14
     public class CookieEventHandler : CookieAuthenticationEvents
15 15
     {
16
-        public CookieEventHandler(LogoutSessionManager logoutSessions)
16
+        public CookieEventHandler()
17 17
         {
18
-            _LogoutSessions = logoutSessions;
19 18
         }
20
-
21
-        private static LogoutSessionManager _LogoutSessions;
22
-
19
+        
23 20
         public override async Task RedirectToAccessDenied(RedirectContext<CookieAuthenticationOptions> context)
24 21
         {
25 22
             context.Response.StatusCode = 403;

+ 0
- 36
Teknik/Security/LogoutSessionManager.cs View File

@@ -1,36 +0,0 @@
1
-using System;
2
-using System.Collections.Generic;
3
-using System.Linq;
4
-using System.Threading.Tasks;
5
-
6
-namespace Teknik.Security
7
-{
8
-    public class LogoutSessionManager
9
-    {
10
-        private static List<Session> _sessions = new List<Session>();
11
-
12
-        public void Add(string sub, string sid)
13
-        {
14
-            _sessions.Add(new Session { Sub = sub, Sid = sid });
15
-        }
16
-
17
-        public bool IsLoggedOut(string sub, string sid)
18
-        {
19
-            var matches = _sessions.Any(s => s.IsMatch(sub, sid));
20
-            return matches;
21
-        }
22
-
23
-        private class Session
24
-        {
25
-            public string Sub { get; set; }
26
-            public string Sid { get; set; }
27
-
28
-            public bool IsMatch(string sub, string sid)
29
-            {
30
-                return (Sid == sid && Sub == sub) ||
31
-                       (Sid == sid && Sub == null) ||
32
-                       (Sid == null && Sub == sub);
33
-            }
34
-        }
35
-    }
36
-}

+ 11
- 9
Teknik/Startup.cs View File

@@ -136,7 +136,7 @@ namespace Teknik
136 136
             });
137 137
 
138 138
             // Sessions
139
-            services.AddResponseCaching();
139
+            //services.AddResponseCaching();
140 140
             services.AddMemoryCache();
141 141
             services.AddSession();
142 142
 
@@ -153,7 +153,6 @@ namespace Teknik
153 153
             services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);
154 154
 
155 155
             services.AddTransient<CookieEventHandler>();
156
-            services.AddSingleton<LogoutSessionManager>();
157 156
 
158 157
             services.AddAuthentication(options =>
159 158
             {
@@ -285,6 +284,15 @@ namespace Teknik
285 284
                 }
286 285
             });
287 286
 
287
+            // Compress Reponse
288
+            //app.UseResponseCompression();
289
+
290
+            // Cache Responses
291
+            //app.UseResponseCaching();
292
+
293
+            // Force a HTTPS redirection (301)
294
+            app.UseHttpsRedirection();
295
+
288 296
             // Use Exception Handling
289 297
             app.UseErrorHandler(config);
290 298
 
@@ -297,13 +305,7 @@ namespace Teknik
297 305
             app.UseCSP();
298 306
             app.UseSecurityHeaders();
299 307
 
300
-            // Cache Responses
301
-            app.UseResponseCaching();
302
-
303
-            // Force a HTTPS redirection (301)
304
-            app.UseHttpsRedirection();
305
-
306
-            // Setup static files anc cache them client side
308
+            // Setup static files and cache them client side
307 309
             app.UseStaticFiles(new StaticFileOptions
308 310
             {
309 311
                 OnPrepareResponse = ctx =>

+ 4
- 1
Utilities/Cryptography/AesCounterMode.cs View File

@@ -101,6 +101,9 @@ namespace Teknik.Utilities.Cryptography
101 101
 
102 102
             _SymmetricAlgorithm = symmetricAlgorithm;
103 103
 
104
+            // Initialize the encrypted counter
105
+            _EncryptedCounter = new byte[_SymmetricAlgorithm.BlockSize / 8];
106
+
104 107
             _IV = new byte[iv.Length];
105 108
             iv.CopyTo(_IV, 0);
106 109
 
@@ -157,7 +160,7 @@ namespace Teknik.Utilities.Cryptography
157 160
         public void EncryptCounter()
158 161
         {
159 162
             // Clear the encrypted counter
160
-            _EncryptedCounter = new byte[_SymmetricAlgorithm.BlockSize / 8];
163
+            Array.Clear(_EncryptedCounter, 0, _EncryptedCounter.Length);
161 164
 
162 165
             // Encrypt the current counter to the encrypted counter
163 166
             _CounterEncryptor.TransformBlock(_Counter, 0, _Counter.Length, _EncryptedCounter, 0);

Loading…
Cancel
Save