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.

Tuesday, August 31, 2010

How to install themes onto your Symbian device manually

If you own a Symbian cellphone and you like to customize your  cellphone with themes, this is the post for you.

As I mentioned in the previous post, there is a slightly problem with the App. Manager in the Symbian OS.
If you try to install excessive amount of applications (include Java Midlets) and themes, the App. Manager could be exploded and cause many trouble in installing and removing applications and themes (One may not have entries more than 80 or 120, depends on the cellphone that you use). If you want to persevere a lot of theme on your device, this could be a problem, as for every theme that you installed, it creates an entry in the App. Manager.

In this post, you will learn how to install themes manually by copying theme files directly on to your memory card.

1. You need a tool called SisContents. Just google it, you will find it. [Can be used for extracting and signing]
2. Load the theme sis/sisx installation file into this program and click on the package icon. This will unpack/extract the contents from the installation file. See the screen shot below:


3. After you extract the contents from the installation file, you will see the following folders:
> private (contains *.skn)
> resource (contains *.mbm and *.mif files)

The private folder contains the information about your theme and the resource folder contains the actual theme data. If you browse into these two folders, you will find a sub-folder in each of these folders that have the identical name. We need to merge these two folder into 1 folder. After we merged it, we will find 3 files with the file extensions as follows:
- *.skn (the skin information file)
- *.mbm (theme data)
- *.mif (theme element data)

Now we need to copy them into the follow location on your memory card: (Assume that E:\ is your memory card drive)
E:\private\10207114\import\



The folder (private\10207114\import\) contains all the themes that you have installed on your memory card, you can delete anyone of them, only if they do not own an entry in the App. Manager. If this is not the case, rather remove them from the App. Manger on your cellphone.

That's it, after you have done all this, you can check inside of your Theme manager. You will find the theme that you have just installed.

With this method, we can install as much themes as we want to and does not create new entries in the App. Manager.

Clear Notification Area History List

After a long run with your Windows, you might find a list of redundant history listed in the "Customize Notification Icons" window. These also includes the software icon the you have already removed from your computer. To clean up this list you need to modify your registry a bit.

The process is simple, you only need to clean the values stored in 2 binary value strings in the Windows registry:
1. Open your registry editor by typing 'regedit' in the Run dialog. (without the quotation marks)
2. Browse to the following location:
HCR(HKEY_Classes_Root)\Local Settings\Software\Microsoft\Windows\CurrentVersion\TrayNotify\

You will see the following 2 binary value strings:
- IconStreams
- PastIconsStream

All you need to do is to clean up all the value stored in these 2 value strings. (Quickest way is to delete and create these 2 "binary string" with the same name.)

3. Open "Task Manager" (Press "Ctrl + Alt + Esc")
4. Click on the "Process" tab.
5. Find "explorer.exe" and right click on it.
6. Select "End Process"
7. Click on "File"
8. Select "New Task (Run...)"
9. Type 'explorer' and press enter to reopen the explorer process.
10. Done, the notification icon history list is cleared.

How to fix “Memory Full” problem of the App. Manager on any Symbian s60 devices

Everyone who owns a Symbian s60 device will experience a problem after they installed excessive amount of applications on to their mobile device. When you try to open the Application Manager, it either breaks (by not let you from opening it) or moaning about “Memory Full”. And worse, you just cannot uninstall your applications from your device.

Have been reading several articles on the Internet, the problem can be identified as a bug from the Symbian operating system rather than any other memory problem on the device.

How we go about to fix this?

The solution is simple - delete some applications. We can use some 3rd applications like, UninstallKing, BatchUninstaller to remove the applications from the mobile device. (They are very small in size.) Thus, frees the application manager from loading excessive amount of items into its list.

With a 3rd party uninstaller installed on the device, we can actually do more than that. We can do some hacks (not really a hack on the device, no harms), on the Symbian. The way that Application manager works is by searching for all the folders (contains installation data for those applications that you have installed on your memory card) that are stored in the following two locations on your memory card: [Assume that E drive is your memory card storage]
- E:\sys\install\sysregistry
- E:\sys\uninstall

Since the Application Manager only searches for the visible folders in these two directories, we can hide all the folders in Windows; so that the Application Manger cannot find the folders and those entries will not be loaded into the Application Manager.

Now the applications installed on the E drive will not appear on the Application Manager, how we uninstall them then?

Obviously, we can use a 3rd party install manager to accomplish this. I have installed the UninstallKing on my Sony Erricsson U5i Vivaz, and hide all the entries from the Application Manager. It works well. Now I can install even more applications on my cellphone despite the notorious bug of the Symbian Application Manager.

Monday, August 23, 2010

Solve startup problem of MS Office Word

Today I have a case, where an instance of the Microsoft Word program starts up very slow.

The problem was solved by changing the default printer, to a local one
(local means the printer that is connected to your computer directly).

Previously, a network printer is installed on the computer and set as the default printer.
The printer server was not availble at the time, thus, the connection to the printer server was faulty.

It is possible that the word program was waiting for the network printer, which is not available.
Therefore, preventing word from opening.

By going to the Start > Control Panel > Printer Settings > set default printer to any local printer.

Open the word again, it should speed up the opening speed.

The case was investigated on a computer that was running the Windows XP, with the MS Office 2007 installed.

Note: If the problem was caused by an add-in, try use Start > Run > type winword /a (for safe mode).