public string RSAReadPrivateKey(string filename, string password) { try { string PKey; byte[] IVCipher; byte[] IV; byte[] Cipher; byte[] Passkey = AESCreateKey(password); PKey = File.ReadAllText(filename); PKey = RemoveWhitespace(PKey); PKey = PKey.Replace("BEGINPRIVATEKEY", String.Empty); PKey = PKey.Replace("ENDPRIVATEKEY", String.Empty); PKey = PKey.Replace("-", String.Empty); IVCipher = Convert.FromBase64String(PKey); IV = GetIVfromIVCipher(IVCipher); Cipher = GetCipherfromIVCipher(IVCipher); return(Encoding.UTF8.GetString(AESDecrypt(Cipher, Passkey, IV))); } catch { return(String.Empty); } }
public static TOut Resolve <TIn, TOut>(TIn target, Expression <Func <T, TOut> > property) { var name = property.Body as MemberExpression; var key = new PKey(target.GetType(), name.Member.Name); Expression e; if (_getters.TryGetValue(key, out e)) { var param = Expression.Parameter(typeof(TIn), "x"); var expression = Expression.Invoke(e, Expression.Convert(param, target.GetType())); var lambda = Expression.Lambda <Func <TIn, TOut> > (expression, param); var compiled = lambda.Compile(); return(compiled.Invoke(target)); } return(default(TOut)); }
public WSStatus regStatistics(HttpContext context) { WSStatus status = WSStatus.NONE_Copy(); try { string httpSession = string.Empty; string urlQuery = string.Empty; string postParams = string.Empty; string routeData = string.Empty; System.Text.StringBuilder request = new System.Text.StringBuilder(); Guid errorKey = Guid.NewGuid(); #region STANDARD_ASP_URL_PARAMS string[] STANDARD_ASP_URL_PARAMS = new string[] { "__utma", "__utmb", "__utmc", "__utmz", //"ASP.NET_SessionId", "fbm_876939902336614", "fbm_881650921865512", "fbsr_881650921865512", "ALL_HTTP", "ALL_RAW", "APPL_MD_PATH", //"APPL_PHYSICAL_PATH", //"AUTH_TYPE", //"AUTH_USER", "AUTH_PASSWORD", //"LOGON_USER", //"REMOTE_USER", "CERT_COOKIE", "CERT_FLAGS", "CERT_ISSUER", "CERT_KEYSIZE", "CERT_SECRETKEYSIZE", "CERT_SERIALNUMBER", "CERT_SERVER_ISSUER", "CERT_SERVER_SUBJECT", "CERT_SUBJECT", "CONTENT_LENGTH", //"CONTENT_TYPE", "GATEWAY_INTERFACE", "HTTPS", "HTTPS_KEYSIZE", "HTTPS_SECRETKEYSIZE", "HTTPS_SERVER_ISSUER", "HTTPS_SERVER_SUBJECT", "INSTANCE_ID", "INSTANCE_META_PATH", //"LOCAL_ADDR", //"PATH_INFO", //"PATH_TRANSLATED", //"QUERY_STRING", //"REMOTE_ADDR", //"REMOTE_HOST", //"REMOTE_PORT", //"REQUEST_METHOD", "SCRIPT_NAME", //"SERVER_NAME", //"SERVER_PORT", "SERVER_PORT_SECURE", //"SERVER_PROTOCOL", "SERVER_SOFTWARE", //"URL", "HTTP_CONNECTION", "HTTP_CONTENT_LENGTH", "HTTP_CONTENT_TYPE", "HTTP_ACCEPT", "HTTP_ACCEPT_ENCODING", "HTTP_ACCEPT_LANGUAGE", "HTTP_COOKIE", //"HTTP_HOST", //"HTTP_REFERER", //"HTTP_USER_AGENT", //"HTTP_ORIGIN", "HTTP_X_REQUESTED_WITH", "HTTP_DNT", "AspSessionIDManagerInitializeRequestCalled", //"AspSession" }; #endregion string SecurityKey = string.Empty; string referrer = (context.Request.UrlReferrer == null ? "" : context.Request.UrlReferrer.AbsoluteUri); new OBMWS.WSConverter().ToMd5Hash("Sdk1RtmB" + DateTime.Now.ToString("yyyyMMddhhmm"), out SecurityKey); #region READ 'postParams' PARAMETERS try { Dictionary <string, string> items = new Dictionary <string, string>(); string[] PKeys = context.Request.Params.AllKeys.Where(x => !STANDARD_ASP_URL_PARAMS.Select(p => p.ToLower()).Contains(x.ToLower()) && !x.StartsWith("_")).ToArray(); foreach (var PKey in PKeys) { if (PKey != null) { try { items.Add(PKey, context.Request.Params[PKey]); } catch (Exception) { } } } postParams = (items != null && items.Any()) ? items.Select(i => "\"" + i.Key + "\":\"" + i.Value + "\"").Aggregate((a, b) => a + "," + b) : ""; } catch (Exception) { } #endregion #region READ 'httpSession' PARAMETERS try { Dictionary <string, string> items = new Dictionary <string, string>() { { "SessionID", context.Session.SessionID } }; System.Collections.Specialized.NameObjectCollectionBase.KeysCollection PKeys = context.Session.Keys; foreach (var PKey in PKeys) { if (PKey != null) { try { items.Add(PKey.ToString(), context.Session[PKey.ToString()].ToString()); } catch (Exception) { } } } httpSession = "{\"Session\":{" + ((items != null && items.Any()) ? items.Select(i => "\"" + i.Key + "\":\"" + i.Value + "\"").Aggregate((a, b) => a + "," + b) : "") + "}}"; } catch (Exception) { } #endregion #region READ 'urlQuery' PARAMETERS try { Dictionary <string, string> items = new Dictionary <string, string>(); foreach (var queryParam in context.Request.QueryString.Keys) { if (queryParam != null) { try { items.Add(queryParam.ToString(), context.Request.QueryString[queryParam.ToString()]); } catch (Exception) { } } } urlQuery = (items != null && items.Any()) ? items.Select(i => "\"" + i.Key + "\":\"" + i.Value + "\"").Aggregate((a, b) => a + "," + b) : ""; } catch (Exception) { } #endregion #region READ ROUTE-DATA PARAM try { Dictionary <string, string> items = new Dictionary <string, string>(); foreach (var urlParam in context.Request.RequestContext.RouteData.Values) { try { items.Add(urlParam.Key, urlParam.Value != null ? urlParam.Value.ToString() : ""); } catch (Exception) { } } routeData = (items != null && items.Any()) ? items.Select(i => "\"" + i.Key + "\":\"" + i.Value + "\"").Aggregate((a, b) => a + "," + b) : ""; } catch (Exception) { } #endregion #region Build 'Http_Request' object request.Append("{"); request.Append("\"ApplicationPath\":\"" + context.Request.ApplicationPath + "\","); #region Browser request.Append("\"Browser\":{"); if (context.Request.Browser != null) { request.Append("\"Browser\":\"" + context.Request.Browser.Browser + "\","); request.Append("\"Id\":\"" + context.Request.Browser.Id + "\","); request.Append("\"Type\":\"" + context.Request.Browser.Type + "\","); request.Append("\"Version\":\"" + context.Request.Browser.Version + "\","); request.Append("\"IsMobileDevice\":\"" + context.Request.Browser.IsMobileDevice + "\","); request.Append("\"Beta\":\"" + context.Request.Browser.Beta + "\","); request.Append("\"Platform\":\"" + context.Request.Browser.Platform + "\","); request.Append("\"ScreenPixelsHeight\":\"" + context.Request.Browser.ScreenPixelsHeight + "\","); request.Append("\"ScreenPixelsWidth\":\"" + context.Request.Browser.ScreenPixelsWidth + "\","); request.Append("\"SupportsCss\":\"" + context.Request.Browser.SupportsCss + "\","); request.Append("\"Cookies\":\"" + context.Request.Browser.Cookies + "\","); request.Append("\"SupportsCallback\":\"" + context.Request.Browser.SupportsCallback + "\","); request.Append("\"W3CDomVersion\":\"" + context.Request.Browser.W3CDomVersion + "\","); request.Append("\"Win16\":\"" + context.Request.Browser.Win16 + "\","); request.Append("\"Win32\":\"" + context.Request.Browser.Win32 + "\","); /********************************************************* * "\"Frames\":\"" + Request.Browser.Frames + "\"," + * "\"Tables\":\"" + Request.Browser.Tables + "\"," + * "\"UseOptimizedCacheKey\":\"" + Request.Browser.UseOptimizedCacheKey + "\"," + * "\"PreferredRequestEncoding\":\"" + Request.Browser.PreferredRequestEncoding + "\"," + * "\"PreferredResponseEncoding\":\"" + Request.Browser.PreferredResponseEncoding + "\"," + * "\"JScriptVersion\":\"" + (Request.Browser.JScriptVersion != null ? Request.Browser.JScriptVersion.Build : -1) + "\"," + * "\"VBScript\":\"" + Request.Browser.VBScript + "\"," + * "\"SupportsInputMode\":\"" + Request.Browser.SupportsInputMode + "\"," + * "\"SupportsItalic\":\"" + Request.Browser.SupportsItalic + "\"," + * "\"SupportsJPhoneMultiMediaAttributes\":\"" + Request.Browser.SupportsJPhoneMultiMediaAttributes + "\"," + * "\"SupportsJPhoneSymbols\":\"" + Request.Browser.SupportsJPhoneSymbols + "\"," + * "\"SupportsQueryStringInFormAction\":\"" + Request.Browser.SupportsQueryStringInFormAction + "\"," + * "\"SupportsRedirectWithCookie\":\"" + Request.Browser.SupportsRedirectWithCookie + "\"," + * "\"SupportsSelectMultiple\":\"" + Request.Browser.SupportsSelectMultiple + "\"," + * "\"SupportsUncheck\":\"" + Request.Browser.SupportsUncheck + "\"," + * "\"SupportsXmlHttp\":\"" + Request.Browser.SupportsXmlHttp + "\"," + * "\"SupportsDivAlign\":\"" + Request.Browser.SupportsDivAlign + "\"," + * "\"SupportsDivNoWrap\":\"" + Request.Browser.SupportsDivNoWrap + "\"," + * "\"SupportsEmptyStringInCookieValue\":\"" + Request.Browser.SupportsEmptyStringInCookieValue + "\"," + * "\"SupportsFontColor\":\"" + Request.Browser.SupportsFontColor + "\"," + * "\"SupportsFontName\":\"" + Request.Browser.SupportsFontName + "\"," + * "\"SupportsFontSize\":\"" + Request.Browser.SupportsFontSize + "\"," + * "\"SupportsInputIStyle\":\"" + Request.Browser.SupportsInputIStyle + "\"," + * "\"SupportsImageSubmit\":\"" + Request.Browser.SupportsImageSubmit + "\"," + * "\"SupportsIModeSymbols\":\"" + Request.Browser.SupportsIModeSymbols + "\"," + * "\"ActiveXControls\":\"" + Request.Browser.ActiveXControls + "\"," + * "\"AOL\":\"" + Request.Browser.AOL + "\"," + * "\"BackgroundSounds\":\"" + Request.Browser.BackgroundSounds + "\"," + * "\"CanCombineFormsInDeck\":\"" + Request.Browser.CanCombineFormsInDeck + "\"," + * "\"CanInitiateVoiceCall\":\"" + Request.Browser.CanInitiateVoiceCall + "\"," + * "\"CanRenderAfterInputOrSelectElement\":\"" + Request.Browser.CanRenderAfterInputOrSelectElement + "\"," + * "\"CanRenderEmptySelects\":\"" + Request.Browser.CanRenderEmptySelects + "\"," + * "\"CanRenderInputAndSelectElementsTogether\":\"" + Request.Browser.CanRenderInputAndSelectElementsTogether + "\"," + * "\"CanRenderMixedSelects\":\"" + Request.Browser.CanRenderMixedSelects + "\"," + * "\"CanRenderOneventAndPrevElementsTogether\":\"" + Request.Browser.CanRenderOneventAndPrevElementsTogether + "\"," + * "\"CanRenderPostBackCards\":\"" + Request.Browser.CanRenderPostBackCards + "\"," + * "\"CanRenderSetvarZeroWithMultiSelectionList\":\"" + Request.Browser.CanRenderSetvarZeroWithMultiSelectionList + "\"," + * "\"CanSendMail\":\"" + Request.Browser.CanSendMail + "\"," + * "\"CDF\":\"" + Request.Browser.CDF + "\"," + * "\"Crawler\":\"" + Request.Browser.Crawler + "\"," + * "\"DefaultSubmitButtonLimit\":\"" + Request.Browser.DefaultSubmitButtonLimit + "\"," + * "\"EcmaScriptVersion\":\"" + Request.Browser.EcmaScriptVersion + "\"," + * "\"GatewayMajorVersion\":\"" + Request.Browser.GatewayMajorVersion + "\"," + * "\"GatewayMinorVersion\":\"" + Request.Browser.GatewayMinorVersion + "\"," + * "\"GatewayVersion\":\"" + Request.Browser.GatewayVersion + "\"," + * "\"HasBackButton\":\"" + Request.Browser.HasBackButton + "\"," + * "\"HidesRightAlignedMultiselectScrollbars\":\"" + Request.Browser.HidesRightAlignedMultiselectScrollbars + "\"," + * "\"HtmlTextWriter\":\"" + Request.Browser.HtmlTextWriter + "\"," + * "\"InputType\":\"" + Request.Browser.InputType + "\"," + * "\"IsColor\":\"" + Request.Browser.IsColor + "\"," + * "\"JavaApplets\":\"" + Request.Browser.JavaApplets + "\"," + * "\"MajorVersion\":\"" + Request.Browser.MajorVersion + "\"," + * "\"MaximumHrefLength\":\"" + Request.Browser.MaximumHrefLength + "\"," + * "\"MaximumRenderedPageSize\":\"" + Request.Browser.MaximumRenderedPageSize + "\"," + * "\"MaximumSoftkeyLabelLength\":\"" + Request.Browser.MaximumSoftkeyLabelLength + "\"," + * "\"MinorVersion\":\"" + Request.Browser.MinorVersion + "\"," + * "\"MinorVersionString\":\"" + Request.Browser.MinorVersionString + "\"," + * "\"MobileDeviceManufacturer\":\"" + Request.Browser.MobileDeviceManufacturer + "\"," + * "\"MobileDeviceModel\":\"" + Request.Browser.MobileDeviceModel + "\"," + * "\"Browser\":\"" + (Request.Browser.MSDomVersion!=null?Request.Browser.MSDomVersion.Build:-1) + "\"," + * "\"NumberOfSoftkeys\":\"" + Request.Browser.NumberOfSoftkeys + "\"," + * "\"PreferredImageMime\":\"" + Request.Browser.PreferredImageMime + "\"," + * "\"PreferredRenderingMime\":\"" + Request.Browser.PreferredRenderingMime + "\"," + * "\"PreferredRenderingType\":\"" + Request.Browser.PreferredRenderingType + "\"," + * "\"RendersBreakBeforeWmlSelectAndInput\":\"" + Request.Browser.RendersBreakBeforeWmlSelectAndInput + "\"," + * "\"RendersBreaksAfterHtmlLists\":\"" + Request.Browser.RendersBreaksAfterHtmlLists + "\"," + * "\"RendersBreaksAfterWmlAnchor\":\"" + Request.Browser.RendersBreaksAfterWmlAnchor + "\"," + * "\"RendersWmlDoAcceptsInline\":\"" + Request.Browser.RendersWmlDoAcceptsInline + "\"," + * "\"RendersWmlSelectsAsMenuCards\":\"" + Request.Browser.RendersWmlSelectsAsMenuCards + "\"," + * "\"RequiredMetaTagNameValue\":\"" + Request.Browser.RequiredMetaTagNameValue + "\"," + * "\"RequiresAttributeColonSubstitution\":\"" + Request.Browser.RequiresAttributeColonSubstitution + "\"," + * "\"RequiresContentTypeMetaTag\":\"" + Request.Browser.RequiresContentTypeMetaTag + "\"," + * "\"RequiresControlStateInSession\":\"" + Request.Browser.RequiresControlStateInSession + "\"," + * "\"RequiresDBCSCharacter\":\"" + Request.Browser.RequiresDBCSCharacter + "\"," + * "\"RequiresHtmlAdaptiveErrorReporting\":\"" + Request.Browser.RequiresHtmlAdaptiveErrorReporting + "\"," + * "\"RequiresLeadingPageBreak\":\"" + Request.Browser.RequiresLeadingPageBreak + "\"," + * "\"RequiresNoBreakInFormatting\":\"" + Request.Browser.RequiresNoBreakInFormatting + "\"," + * "\"RequiresOutputOptimization\":\"" + Request.Browser.RequiresOutputOptimization + "\"," + * "\"RequiresPhoneNumbersAsPlainText\":\"" + Request.Browser.RequiresPhoneNumbersAsPlainText + "\"," + * "\"RequiresSpecialViewStateEncoding\":\"" + Request.Browser.RequiresSpecialViewStateEncoding + "\"," + * "\"RequiresUniqueFilePathSuffix\":\"" + Request.Browser.RequiresUniqueFilePathSuffix + "\"," + * "\"RequiresUniqueHtmlCheckboxNames\":\"" + Request.Browser.RequiresUniqueHtmlCheckboxNames + "\"," + * "\"RequiresUniqueHtmlInputNames\":\"" + Request.Browser.RequiresUniqueHtmlInputNames + "\"," + * "\"RequiresUrlEncodedPostfieldValues\":\"" + Request.Browser.RequiresUrlEncodedPostfieldValues + "\"," + * "\"ScreenBitDepth\":\"" + Request.Browser.ScreenBitDepth + "\"," + * "\"ScreenCharactersHeight\":\"" + Request.Browser.ScreenCharactersHeight + "\"," + * "\"ScreenCharactersWidth\":\"" + Request.Browser.ScreenCharactersWidth + "\"," + * "\"SupportsAccesskeyAttribute\":\"" + Request.Browser.SupportsAccesskeyAttribute + "\"," + * "\"SupportsBodyColor\":\"" + Request.Browser.SupportsBodyColor + "\"," + * "\"SupportsBold\":\"" + Request.Browser.SupportsBold + "\"," + * "\"SupportsCacheControlMetaTag\":\"" + Request.Browser.SupportsCacheControlMetaTag + "\"," + * ****************************************************************/ request.Append("\"Browser\":\"" + context.Request.Browser.ToString() + "\""); } request.Append("},"); #endregion request.Append("\"HttpMethod\":\"" + context.Request.HttpMethod + "\","); request.Append("\"IsSecureConnection\":\"" + context.Request.IsSecureConnection + "\","); request.Append("\"RequestType\":\"" + context.Request.RequestType + "\","); request.Append("\"UserAgent\":\"" + context.Request.UserAgent + "\","); request.Append("\"UserHostAddress\":\"" + context.Request.UserHostAddress + "\","); request.Append("\"UserHostName\":\"" + context.Request.UserHostName + "\","); request.Append("\"UserLanguages\":["); if (context.Request.UserLanguages != null && context.Request.UserLanguages.Any()) { request.Append(context.Request.UserLanguages.Select(l => "\"" + l + "\"").Aggregate((a, b) => a + "," + b)); } request.Append("],"); request.Append("\"UrlReferrer\":\"" + referrer + "\""); request.Append("}"); #endregion status = WSStatus.SUCCESS_Copy(); status.AddNote(registerHttpActivity(context.Request.Url.AbsoluteUri, context.Request.UserHostAddress, request.ToString(), httpSession, urlQuery, postParams, referrer, null, true)); } catch (Exception) { status = WSStatus.ERROR_Copy(); } return(status); }
public WSCall(HttpContext _InContext) { try { if (_InContext != null) { INPUT = new Dictionary <string, string>(); #region READ POST PARAMETERS if (_InContext.Request.HttpMethod.Equals("POST")) { #region READ FORM PARAMETERS foreach (string fKey in _InContext.Request.Form.AllKeys) { if (!string.IsNullOrEmpty(fKey)) { string fValue = _InContext.Request.Form[fKey]; INPUT.Save(fKey, fValue); } } #endregion string[] allKeys = _InContext.Request.Params.AllKeys; IEnumerable <string> actualKeys = allKeys.Where(x => x != null && !WSConstants.STANDARD_ASP_URL_PARAMS.Select(p => p.ToLower()).Contains(x.ToLower())); string[] PKeys = actualKeys.ToArray(); foreach (string PKey in _InContext.Request.Params) { if (!string.IsNullOrEmpty(PKey)) { if (!WSConstants.STANDARD_ASP_URL_PARAMS.Any(x => x.Equals(PKey))) { bool isValid = true; string PVal = _InContext.Request.Params[PKey]; if (PKey.ToLower().Equals("url")) { string RawUrl = _InContext.Request.RawUrl; if (PVal.Equals(RawUrl)) { isValid = false; } else { PVal = PVal.Split(new char[] { ',' }).FirstOrDefault(x => !x.ToLower().Equals(RawUrl.ToLower())); isValid = !string.IsNullOrEmpty(PVal); } } if (isValid) { INPUT.Save(PKey, PVal, false); } } } else { string jValue = _InContext.Request.Params[PKey]; status.AddNote("POST: try saving empty key {" + PKey + ":" + jValue + "}", WSConstants.ACCESS_LEVEL.READ); if (!string.IsNullOrEmpty(jValue)) { WSJson json = jValue.ToJson(); if (json == null) { status.AddNote("POST:failed convert json {" + jValue + "}. Try autoresolve.", WSConstants.ACCESS_LEVEL.READ); json = ("{data:" + jValue + "}").ToJson(); json = json != null && (json is WSJObject) ? ((WSJObject)json).Value[0].Value : null; } if (json == null) { status.AddNote("POST:failed convert json {" + jValue + "}", WSConstants.ACCESS_LEVEL.READ); } else { if (json is WSJArray) { WSJArray jArray = (WSJArray)json; foreach (WSJson innerJson in jArray.Value) { if (innerJson is WSJProperty) { WSJProperty jProp = (WSJProperty)innerJson; INPUT.Save(jProp.Key, jProp.Value.ToString(), false); } } } else if (json is WSJObject) { foreach (WSJProperty jProp in ((WSJObject)json).Value) { string jVal = Newtonsoft.Json.JsonConvert.SerializeObject(jProp.Value, new WSFilterConverter()); INPUT.Save(jProp.Key, jVal, false); } } else if (json is WSJProperty) { WSJProperty jProp = (WSJProperty)json; string jVal = Newtonsoft.Json.JsonConvert.SerializeObject(jProp.Value, new WSFilterConverter()); INPUT.Save(jProp.Key, jVal, false); } } } } } } #endregion #region READ QUERY-STRING PARAMETERS foreach (var queryParam in _InContext.Request.QueryString.Keys) { if (queryParam != null) { string qKey = queryParam.ToString(); string qValue = _InContext.Request.QueryString[qKey]; INPUT.Save(qKey, qValue); } } #endregion #region READ ROUTE-DATA PARAM foreach (var urlParam in _InContext.Request.RequestContext.RouteData.Values) { if (!WSConstants.STANDARD_ASP_URL_PARAMS.Select(p => p.ToLower()).Contains(urlParam.Key.ToLower())) { string uKey = urlParam.Key; string uValue = urlParam.Value.ToString(); INPUT.Save(uKey, uValue); } } #endregion SessionID = INPUT.Any(x => WSConstants.PARAMS.SESSIONID.Match(x.Key)) ? INPUT.FirstOrDefault(x => WSConstants.PARAMS.SESSIONID.Match(x.Key)).Value : string.Empty; if (string.IsNullOrEmpty(SessionID)) { if (_InContext.Session != null) { SessionID = _InContext.Session.SessionID; } else { SessionID = _InContext.Request.Params["ASP.NET_SessionId"]; } } IsLocal = _InContext.Request == null || _InContext.Request.IsLocal; UserHostAddress = _InContext.Request.UserHostAddress; HttpMethod = _InContext.Request.HttpMethod; Url = _InContext.Request.Url; Files = _InContext.Request.Files; } } catch (Exception) { } }