/* Example: * * /// <summary>Class with sensitive property.</summary> * public class ClassName * { * /// <summary>Sensitive Property.</summary> * public string Password * { * get { return SecurityHelper.GetSecureStringValue(_Password); } * set { SecurityHelper.SetSecureStringValue(ref _Password, value); } * } * SecureString _Password; * * ~ClassName() * { * SecurityHelper.SetSecureStringValue(ref _Password, null); * } * } * */ #endregion /// <summary> /// The following method is invoked by the RemoteCertificateValidationDelegate. /// Net.ServicePointManager.ServerCertificateValidationCallback = AddressOf ValidateServerCertificate /// </summary> /// <remarks> /// Add "AllowCertificateErrors" to allow certificate errors: request.Headers.Add("AllowCertificateErrors"); /// </remarks> public static bool ValidateServerCertificate(object sender, System.Security.Cryptography.X509Certificates.X509Certificate certificate, System.Security.Cryptography.X509Certificates.X509Chain chain, System.Net.Security.SslPolicyErrors sslPolicyErrors) { // No errors were found. if (sslPolicyErrors == System.Net.Security.SslPolicyErrors.None) { // Allow this client to communicate with unauthenticated servers. return(true); } var sp = new Configuration.SettingsParser("CertificateErrors_"); var allow = sp.Parse("Allow", false); var notify = sp.Parse("Notify", true); string message = string.Format("Certificate error: {0}", sslPolicyErrors); message += allow ? " Allow this client to communicate with unauthenticated server." : " The underlying connection was closed."; var ex = new Exception("Validate server certificate error"); ex.Data.Add("AllowCertificateErrors", allow); if (sender != null && sender is System.Net.HttpWebRequest) { //var request = (System.Net.HttpWebRequest)sender; // Allow certificate errors if request contains "AllowCertificateErrors" key. //AllowCertificateErrors = request.Headers.AllKeys.Contains("AllowCertificateErrors"); var hr = (System.Net.HttpWebRequest)sender; ex.Data.Add("sender.OriginalString", hr.Address.OriginalString); } if (certificate != null) { ex.Data.Add("Certificate.Issuer", certificate.Issuer); ex.Data.Add("Certificate.Subject", certificate.Subject); } if (chain != null) { for (int i = 0; i < chain.ChainStatus.Length; i++) { ex.Data.Add("Chain.ChainStatus(" + i + ")", string.Format("{0}, {1}", chain.ChainStatus[i].Status, chain.ChainStatus[i].StatusInformation)); } } if (notify) { Runtime.LogHelper.Current.ProcessException(ex); } // Allow (or not allow depending on setting value) this client to communicate with unauthenticated servers. return(allow); }
void _Init() { LogFileEnabled = _SP.Parse("LogFileEnabled", false); if (!LogFileEnabled) { return; } _LogFileAutoFlush = _SP.Parse("LogFileAutoFlush", false); // File reset options. LogFileTimeout = _SP.Parse <TimeSpan>("LogFileTimeout"); LogFileName = _SP.Parse("LogFileName", ""); // Enable rolling by default if file name looks like daily. var defaultRolling = LogFileName.Contains("MMdd}"); LogFileRolling = _SP.Parse("LogFileRolling", defaultRolling); if (string.IsNullOrEmpty(LogFileName)) { // Suffix pattern. var defautlSuffix = LogFileRolling // Rolling resets daily by default. ? "{0:yyyyMMdd}.txt" // Use current date when creating new file. : "{0:yyyyMMdd_HHmmss}.txt"; // File prefix to make it unique. var defaultPrefix = string.IsNullOrEmpty(_SP.ConfigPrefix) ? GetAssemblyName() : _SP.ConfigPrefix; // Generate unique file name. var fileName = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}{2}", GetLogFolder(), defaultPrefix, defautlSuffix ); LogFileName = fileName; } }