Changeset 325 for binary-improvements/MapRendering/Web/OpenID.cs
- Timestamp:
- Sep 4, 2018, 1:00:48 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
binary-improvements/MapRendering/Web/OpenID.cs
r318 r325 5 5 using System.Net; 6 6 using System.Net.Security; 7 using System.Reflection; 8 using System.Security.Cryptography.X509Certificates; 7 9 using System.Text; 8 10 using System.Text.RegularExpressions; 9 using System.Security.Cryptography.X509Certificates; 10 using System.Reflection; 11 12 namespace AllocsFixes.NetConnections.Servers.Web 13 { 11 12 namespace AllocsFixes.NetConnections.Servers.Web { 14 13 public static class OpenID { 15 14 private const string STEAM_LOGIN = "https://steamcommunity.com/openid/login"; 16 private static Regex steamIdUrlMatcher = new Regex (@"^https?:\/\/steamcommunity\.com\/openid\/id\/([0-9]{17,18})"); 17 18 private static readonly X509Certificate2 caCert = new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/steam-rootca.cer"); 19 private static readonly X509Certificate2 caIntermediateCert = new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + "/steam-intermediate.cer"); 15 16 private static readonly Regex steamIdUrlMatcher = 17 new Regex (@"^https?:\/\/steamcommunity\.com\/openid\/id\/([0-9]{17,18})"); 18 19 private static readonly X509Certificate2 caCert = 20 new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + 21 "/steam-rootca.cer"); 22 23 private static readonly X509Certificate2 caIntermediateCert = 24 new X509Certificate2 (Path.GetDirectoryName (Assembly.GetExecutingAssembly ().Location) + 25 "/steam-intermediate.cer"); 20 26 21 27 private static readonly bool verboseSsl = false; 22 public static bool debugOpenId = false;28 public static bool debugOpenId; 23 29 24 30 static OpenID () { 25 for (int i = 0; i < System.Environment.GetCommandLineArgs ().Length; i++) {26 if ( System.Environment.GetCommandLineArgs () [i].EqualsCaseInsensitive ("-debugopenid")) {31 for (int i = 0; i < Environment.GetCommandLineArgs ().Length; i++) { 32 if (Environment.GetCommandLineArgs () [i].EqualsCaseInsensitive ("-debugopenid")) { 27 33 debugOpenId = true; 28 34 } … … 34 40 Log.Out ("Steam certificate: No error (1)"); 35 41 } 42 36 43 return true; 37 44 } … … 49 56 Log.Out ("Steam certificate: No error (2)"); 50 57 } 58 51 59 return true; 52 60 } … … 58 66 Log.Out ("Steam certificate: No error (3)"); 59 67 } 68 60 69 return true; 61 70 } … … 66 75 Log.Out ("Validating cert: " + chainEl.Certificate.Subject); 67 76 } 77 68 78 // Iterate all status flags of the current cert 69 79 foreach (X509ChainStatus chainStatus in chainEl.ChainElementStatus) { … … 71 81 Log.Out (" Status: " + chainStatus.Status); 72 82 } 83 73 84 if (chainStatus.Status == X509ChainStatusFlags.NoError) { 74 85 // This status is not an error, skip 75 86 continue; 76 87 } 88 77 89 if (chainStatus.Status == X509ChainStatusFlags.UntrustedRoot && chainEl.Certificate == caCert) { 78 90 // This status is about the cert being an untrusted root certificate but the certificate is one of those we added, ignore 79 91 continue; 80 92 } 93 81 94 // This status is an error, print information 82 Log.Warning ("Steam certificate error: " + chainEl.Certificate.Subject + " ### Error: " + chainStatus.Status); 95 Log.Warning ("Steam certificate error: " + chainEl.Certificate.Subject + " ### Error: " + 96 chainStatus.Status); 83 97 privateChain.Reset (); 84 98 return false; … … 87 101 88 102 foreach (X509ChainStatus chainStatus in privateChain.ChainStatus) { 89 if (chainStatus.Status != X509ChainStatusFlags.NoError && chainStatus.Status != X509ChainStatusFlags.UntrustedRoot) { 103 if (chainStatus.Status != X509ChainStatusFlags.NoError && 104 chainStatus.Status != X509ChainStatusFlags.UntrustedRoot) { 90 105 Log.Warning ("Steam certificate error: " + chainStatus.Status); 91 106 privateChain.Reset (); … … 99 114 Log.Out ("Steam certificate: No error (4)"); 100 115 } 116 101 117 return true; 102 118 }; 103 104 119 } 105 120 … … 123 138 return 0; 124 139 } 140 125 141 if (mode == "error") { 126 142 Log.Warning ("Steam OpenID login error: " + getValue (_req, "openid.error")); … … 128 144 PrintOpenIdResponse (_req); 129 145 } 146 130 147 return 0; 131 148 } 149 132 150 string steamIdString = getValue (_req, "openid.claimed_id"); 133 151 ulong steamId = 0; … … 140 158 PrintOpenIdResponse (_req); 141 159 } 160 142 161 return 0; 143 162 } … … 161 180 162 181 byte[] postData = Encoding.ASCII.GetBytes (buildUrlParams (queryParams)); 163 HttpWebRequest request = (HttpWebRequest) WebRequest.Create (STEAM_LOGIN);182 HttpWebRequest request = (HttpWebRequest) WebRequest.Create (STEAM_LOGIN); 164 183 request.Method = "POST"; 165 184 request.ContentType = "application/x-www-form-urlencoded"; … … 170 189 } 171 190 172 HttpWebResponse response = (HttpWebResponse) request.GetResponse ();191 HttpWebResponse response = (HttpWebResponse) request.GetResponse (); 173 192 string responseString = null; 174 193 using (Stream st = response.GetResponseStream ()) { … … 180 199 if (responseString.ToLower ().Contains ("is_valid:true")) { 181 200 return steamId; 182 } else {183 Log.Warning ("Steam OpenID login failed: {0}", responseString); 184 return 0;185 }201 } 202 203 Log.Warning ("Steam OpenID login failed: {0}", responseString); 204 return 0; 186 205 } 187 206 … … 192 211 paramsArr [i++] = kvp.Key + "=" + Uri.EscapeDataString (kvp.Value); 193 212 } 213 194 214 return string.Join ("&", paramsArr); 195 215 } … … 200 220 throw new MissingMemberException ("OpenID parameter \"" + _name + "\" missing"); 201 221 } 222 202 223 return nvc [_name]; 203 224 } … … 209 230 } 210 231 } 211 212 232 } 213 233 } 214
Note:
See TracChangeset
for help on using the changeset viewer.