///////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////// private static AnonymousIdData GetDecodedValue(string data) { if (data == null || data.Length < 1 || data.Length > MAX_ENCODED_COOKIE_STRING) { return(null); } try { byte [] bBlob = CookieProtectionHelper.Decode(s_Protection, data, Purpose.AnonymousIdentificationModule_Ticket); if (bBlob == null || bBlob.Length < 13) { return(null); } DateTime expireDate = DateTime.FromFileTimeUtc(BitConverter.ToInt64(bBlob, 0)); if (expireDate < DateTime.UtcNow) { return(null); } int len = BitConverter.ToInt32(bBlob, 8); if (len < 0 || len > bBlob.Length - 12) { return(null); } string id = Encoding.UTF8.GetString(bBlob, 12, len); if (id.Length > MAX_ID_LENGTH) { return(null); } return(new AnonymousIdData(id, expireDate)); } catch {} return(null); }
private static AnonymousIdData GetDecodedValue(string data) { if (((data != null) && (data.Length >= 1)) && (data.Length <= 0x200)) { try { byte[] buffer = CookieProtectionHelper.Decode(s_Protection, data); if ((buffer == null) || (buffer.Length < 13)) { return(null); } DateTime dt = DateTime.FromFileTimeUtc(BitConverter.ToInt64(buffer, 0)); if (dt < DateTime.UtcNow) { return(null); } int count = BitConverter.ToInt32(buffer, 8); if ((count < 0) || (count > (buffer.Length - 12))) { return(null); } string id = Encoding.UTF8.GetString(buffer, 12, count); if (id.Length > 0x80) { return(null); } return(new AnonymousIdData(id, dt)); } catch { } } return(null); }
private void InitFromEncryptedTicket(string encryptedTicket) { if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest); } if (!string.IsNullOrEmpty(encryptedTicket)) { byte[] buffer = CookieProtectionHelper.Decode(Roles.CookieProtectionValue, encryptedTicket); if (buffer != null) { RolePrincipal principal = null; MemoryStream serializationStream = null; try { serializationStream = new MemoryStream(buffer); principal = new BinaryFormatter().Deserialize(serializationStream) as RolePrincipal; } catch { } finally { serializationStream.Close(); } if (((principal != null) && StringUtil.EqualsIgnoreCase(principal._Username, this._Identity.Name)) && (StringUtil.EqualsIgnoreCase(principal._ProviderName, this._ProviderName) && (DateTime.UtcNow <= principal._ExpireDate))) { this._Version = principal._Version; this._ExpireDate = principal._ExpireDate; this._IssueDate = principal._IssueDate; this._IsRoleListCached = principal._IsRoleListCached; this._CachedListChanged = false; this._Username = principal._Username; this._Roles = principal._Roles; this.RenewIfOld(); if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, "RolePrincipal", this._Identity.Name); } return; } } } this.Init(); this._CachedListChanged = true; if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(4, 8)) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, "RolePrincipal", this._Identity.Name); } }
private void InitFromEncryptedTicket(string encryptedTicket) { if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_BEGIN, HttpContext.Current.WorkerRequest); } if (string.IsNullOrEmpty(encryptedTicket)) { goto Exit; } byte[] bTicket = CookieProtectionHelper.Decode(Roles.CookieProtectionValue, encryptedTicket, Purpose.RolePrincipal_Ticket); if (bTicket == null) { goto Exit; } RolePrincipal rp = null; MemoryStream ms = null; try{ ms = new System.IO.MemoryStream(bTicket); rp = (new BinaryFormatter()).Deserialize(ms) as RolePrincipal; } catch { } finally { ms.Close(); } if (rp == null) { goto Exit; } if (!StringUtil.EqualsIgnoreCase(rp._Username, _Identity.Name)) { goto Exit; } if (!StringUtil.EqualsIgnoreCase(rp._ProviderName, _ProviderName)) { goto Exit; } if (DateTime.UtcNow > rp._ExpireDate) { goto Exit; } _Version = rp._Version; _ExpireDate = rp._ExpireDate; _IssueDate = rp._IssueDate; _IsRoleListCached = rp._IsRoleListCached; _CachedListChanged = false; _Username = rp._Username; _Roles = rp._Roles; // will it be the case that _Identity.Name != _Username? RenewIfOld(); if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, "RolePrincipal", _Identity.Name); } return; Exit: Init(); _CachedListChanged = true; if (HostingEnvironment.IsHosted && EtwTrace.IsTraceEnabled(EtwTraceLevel.Information, EtwTraceFlags.AppSvc) && HttpContext.Current != null) { EtwTrace.Trace(EtwTraceType.ETW_TYPE_ROLE_END, HttpContext.Current.WorkerRequest, "RolePrincipal", _Identity.Name); } return; }