/// <summary> /// Retrieves the OrderID from the cookie if available; otherwise a -1 is returned /// </summary> /// <returns>OrderID if found in cookie; otherwise a -1 is returned.</returns> private int GetOrderIDFromCookie() { int orderID = Null.NullInteger; HttpCookie cookie = HttpContext.Current.Request.Cookies[CookieKey]; if ((cookie != null) && (cookie["OrderID"] != null)) { string cookieValue = cookie["OrderID"]; if (string.IsNullOrEmpty(cookieValue) == false) { int value; // If it's NOT an integer, try to decrypt the value if (int.TryParse(cookieValue, out value) == false) { string decrypted = SymmetricHelper.Decrypt(cookieValue); orderID = int.Parse(decrypted); } else { orderID = value; } } } return(orderID); }
private static string GetCartID(int portalID, bool secureCookie) { string cartID = null; // Get cart ID from cookie HttpCookie cartCookie = HttpContext.Current.Request.Cookies[CookieKey(portalID)]; if (cartCookie != null) { cartID = cartCookie["CartID"]; if (!string.IsNullOrEmpty(cartID) && secureCookie && SymmetricHelper.CanSafelyEncrypt) { try { cartID = SymmetricHelper.Decrypt(cartID); } catch (FormatException) { // Do nothing in this case it's probably throwed // because the CartID is not encrypted! } } else { // Verify if it's a valid GUID, otherwise try to decrypt the value if (!CheckGuid(cartID)) { cartID = SymmetricHelper.Decrypt(cartID); } } } // Do we need to verify? if (!string.IsNullOrEmpty(cartID) && !_isCartVerified) { _isCartVerified = (Controller.GetCart(cartID, portalID) != null); if (!_isCartVerified) { cartID = null; } } // Do we need to create a new cart? if (string.IsNullOrEmpty(cartID)) { cartID = CreateCart(portalID); SetCartID(portalID, cartID, secureCookie); } return(cartID); }
public ConnectionRequestConfirmReplyMessage(byte[] data, IEndPointFactory endPointFactory, ISymmetricKey key) { var dataReader = new BigEndianBinaryReader(new MemoryStream(SymmetricHelper.Decrypt(key, data))); NewId = dataReader.ReadUInt16(); NewEndPoint = endPointFactory.DeserializeEndPoint(dataReader.ReadBytes(dataReader.ReadUInt16())); var clientCount = dataReader.ReadUInt16(); for (var i = 0; i < clientCount; i++) { Clients.Add(new DnmpNode { Id = dataReader.ReadUInt16(), ParentId = dataReader.ReadUInt16(), EndPoint = endPointFactory.DeserializeEndPoint(dataReader.ReadBytes(dataReader.ReadUInt16())), CustomData = dataReader.ReadBytes(dataReader.ReadUInt16()) }); } }
private void ReceiveCallback(byte[] data, IEndPoint source) { try { var message = new BaseMessage(data); if (message.MessageType.ShouldBeEncrypted() && (!realClient.ClientsById.ContainsKey(message.MessageType.OnlyBroadcasted() ? message.RealSourceId : message.SourceId) || !message.MessageType.ShouldBeEncrypted())) { return; } if (message.MessageType.ShouldBeEncrypted()) { var realSourceId = message.MessageFlags.HasFlag(MessageFlags.IsRedirected) ? message.RealSourceId : message.SourceId; var client = realClient.ClientsById[realSourceId]; var key = client.MainKey; if (key == null) { throw new DnmpException("Selected client key is null"); } message.Payload = SymmetricHelper.Decrypt(key, message.Payload); message.ReceivedHash = message.Payload.Take(HashUtil.GetHashSize()).ToArray(); message.Payload = message.Payload.Skip(HashUtil.GetHashSize()).ToArray(); if (!message.SecurityHash.SequenceEqual(message.ReceivedHash)) { throw new DnmpException("Hash of packets is not equal"); } } lock (receivedReliableMessages) { if (message.MessageType.IsReliable() && !receivedReliableMessages.Contains(message.Guid)) { if (!message.Hash.SequenceEqual(message.RealHash)) { return; } receivedReliableMessages.Add(message.Guid); SendBaseMessage( new BaseMessage(new ReliableConfirmMessage(message.Guid), realClient.SelfClient?.Id ?? 0xFFFF, message.MessageFlags.HasFlag(MessageFlags.IsRedirected) ? message.RealSourceId : message.SourceId), source); } else if (message.MessageType.IsReliable()) { return; } } if (realClient.ClientsById.ContainsKey(message.SourceId) && realClient.ClientsById[message.SourceId].EndPoint.Equals(source)) { realClient.ClientsById[message.SourceId].BytesReceived += message.TotalLength; } if (message.MessageType == MessageType.ReliableConfirm) { var decodedMessage = new ReliableConfirmMessage(message.Payload); if (!reliableMessages.ContainsKey(decodedMessage.MessageId)) { return; } EventQueue.RemoveEvent(decodedMessage.MessageId); reliableMessages.TryRemove(decodedMessage.MessageId, out _); } else { realClient.MessageHandler.ProcessMessage(message, source); } } catch (Exception e) { logger.Error(e, "Exception on receivng message"); } }
void IHttpHandler.ProcessRequest(HttpContext context) { PortalSettings portalSettings = PortalController.Instance.GetCurrentPortalSettings(); UserInfo user = (UserInfo)context.Items["UserInfo"]; if (user != null && user.UserID != Null.NullInteger) { // Init params int currentUserID = user.UserID; int portalID = portalSettings.PortalId; string key = context.Request.QueryString["KEY"]; key = SymmetricHelper.Decrypt(key); string[] values = key.Split(','); int orderDetailID = int.Parse(values[0]); int userID = int.Parse(values[1]); ProductInfo product = null; // Get the requested order detail row OrderController orderControler = new OrderController(); OrderDetailInfo orderDetail = orderControler.GetOrderDetail(orderDetailID); if (orderDetail != null) { // Get the corresponding product ProductController productControler = new ProductController(); product = productControler.GetProduct(portalID, orderDetail.ProductID); } // If user authentication and product are valid if (currentUserID == userID && product != null) { // Is download allowed? if (product.AllowedDownloads == Null.NullInteger || orderDetail.Downloads < product.AllowedDownloads) { // Update download counter then download file int downloads = orderDetail.Downloads; if (downloads == Null.NullInteger) { downloads = 1; } else { downloads += 1; } orderControler.UpdateOrderDetail(orderDetail.OrderDetailID, orderDetail.OrderID, orderDetail.ProductID, orderDetail.Quantity, orderDetail.UnitCost, orderDetail.RoleID, downloads); IFileInfo file = FileManager.Instance.GetFile(product.VirtualFileID); FileManager.Instance.WriteFileToResponse(file, ContentDisposition.Attachment); } // The following code is NEVER reached when download succeed! } // Redirect to the product detail page or the store page StoreInfo storeInfo = StoreController.GetStoreInfo(portalSettings.PortalId); CatalogNavigation catNav = new CatalogNavigation { TabID = storeInfo.StorePageID }; if (product != null) { catNav.CategoryID = product.CategoryID; catNav.ProductID = product.ProductID; } context.Response.Redirect(catNav.GetNavigationUrl()); } else { // Try to authenticate the user then retry download string returnUrl = context.Request.RawUrl; int posReturn = returnUrl.IndexOf("?returnurl="); if (posReturn != Null.NullInteger) { returnUrl = returnUrl.Substring(0, posReturn); } returnUrl = "returnurl=" + context.Server.UrlEncode(returnUrl); if (portalSettings.LoginTabId != Null.NullInteger && context.Request["override"] == null) { context.Response.Redirect(Globals.NavigateURL(portalSettings.LoginTabId, "", returnUrl), true); } else { if (portalSettings.HomeTabId != Null.NullInteger) { context.Response.Redirect(Globals.NavigateURL(portalSettings.HomeTabId, "Login", returnUrl), true); } else { context.Response.Redirect(Globals.NavigateURL(portalSettings.ActiveTab.TabID, "Login", returnUrl), true); } } } }