Wednesday, September 29, 2010

Bypass SSL Certificate Validation Programmatically

In a .NET development, if you try to connect to the remote server through a web service with SSL you will probably get the following error message:

 
"The underlying connection was closed: Could not establish trust 
relationship for the SSL/TLS secure channel."

inner Exception.Message is:
"The remote certificate is invalid according to the validation procedure." 
 
 
To solve this problem, simply add a line of code which is underlined in red.
Required namespace: 
System.Net;

Code:
ServicePointManager.ServerCertificateValidationCallback = delegate { return true; };


This code simple bypass all the certificate validation check, include invalid and expired certificates.
Sample Code:
 // callback used to validate the certificate in an SSL conversation
private static bool ValidateRemoteCertificate(
object sender,
 X509Certificate certificate,
 X509Chain chain,
 SslPolicyErrors policyErrors
)
{
 if (Convert.ToBoolean(ConfigurationManager.AppSettings["IgnoreSslErrors"]))
 {
  // allow any old dodgy certificate...
  return true;
 }
 else
 {
  return policyErrors == SslPolicyErrors.None;
 }
}

private static string MakeRequest(string uri, string method, WebProxy proxy)
{
 HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(uri);
 webRequest.AllowAutoRedirect = true;
 webRequest.Method = method;

 // allows for validation of SSL conversations
 ServicePointManager.ServerCertificateValidationCallback += new RemoteCertificateValidationCallback(
  ValidateRemoteCertificate
 );

 if (proxy != null)
 {
  webRequest.Proxy = proxy;
 }

 HttpWebResponse response = null;
 try
 {
  response = (HttpWebResponse)webRequest.GetResponse();

  using (Stream s = response.GetResponseStream())
  {
   using (StreamReader sr = new StreamReader(s))
   {
    return sr.ReadToEnd();
   }
  }
 }
 finally
 {
  if (response != null)
   response.Close();
 }
}
Reference:
http://msdn.microsoft.com/en-us/library/system.net.servicepointmanager.servercertificatevalidationcallback.aspx

Saturday, September 18, 2010

How to Remove Broken Theme on a Symbian Device


If you installed your themes on your memory card, then all of them will be stored in the following location:
[MicroSD]:\private\10207114\import
Similarly, if you installed your theme in the cell phone’s memory, you can find the installed themes in the following location:
[CellPhone Memory]:\ private\10207114\import
Location and content of a theme

Now you have to manually seek for the theme that is broke, though it might be painful if you have a lot of themes are installed, because you have to look through all the folders one by one.

In every folder, there is a file with the *.skn extension. Basically, this file contains the information about the theme. If you open it with a hex editor, or any other text editor that can display binary contents, you will find the name of theme in the first few lines. (I used a program called WinHex, which is a very good hexadecimal editor, Google it on the Internet and you will find more information on it.
But there is a way out of pain. The broken themes does not contains files with extensions *.mbm and *.mif in the same folder as *.skn. So if you find only a *.skn file listed in a folder, it is most likely it is the broken theme. If you want to make sure that you are going to delete the right stuff, just open the *.skn file with an advance text editor that is capable of displaying binary content.
File name of the theme in the *.skn file
 
But there is a way out of pain. The broken themes does not contains files with extensions *.mbm and *.mif in the same folder as *.skn. So if you find only a *.skn file listed in a folder, it is most likely it is the broken theme. If you want to make sure that you are going to delete the right stuff, just open the *.skn file with an advance text editor that is capable of displaying binary content.

Tuesday, September 14, 2010

How to Disable the Ctrl + Space Chinese Language Hot Key

If you use Chinese IME input, you may experience a problem where the Ctrl + Space hot key cannot be disabled even you changed the settings in the Regional & Language window. And the hot key may cause some troubles when you playing a game or programming. Unfortunately, there is no fix to disable the hot key. It seems that it is a bug exits since Windows XP era.

To disable the hot key, we need to do some mod in the Windows registry as follows (It’s very simple):

- Open your “regedit.exe” by typing the term into the run dialog.

- Browse the registry editor to the location: HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys\

- Now delete registry entries that with the name: 0000007x (x indicates any number)

Note: Don’t delete 0000001x. You may also leave 000002xx, if the problem can be fixed. Of course, if you want to use the hot key in future again, simply export the registry item HKEY_CURRENT_USER\Control Panel\Input Method\Hot Keys. Import the file when you want to use the feature.



- Log off OR restart your Windows

- Done

This will disable the Ctrl + Space language switching hot key.