Monday, December 28, 2009

Linux: random shutdown and keyboard issues with Ubuntu 9.10 (Karmic Koala)


After upgrading from Ubuntu 9.04 to 9.10 several days ago, my laptop experienced random shutdowns -- or more precisely, sudden power-offs. It turned out to be a known issue of ACPI and i8042 controller conflicts. By adding the parameter of acpi=off to the kernel boot options in grub, the issue of random shutdowns went away.

However, the keyboard would stop working after the laptop ran for some time, or sometimes a key got stuck and repeatedly input the same character after I pressed it. And the touchpad never worked. Command dmesg showed a message of
PNP: PS/2 appears to have AUX port disabled, if this is incorrect please boot with i8042.nopnp
So I followed the instruction and add one more boot parameter of i8042.nopnp. Now it looks like this in my /boot/grub/menu.lst:
kernel          /boot/vmlinuz-2.6.31-16-generic root=UUID=... ro quiet splash acpi=off i8042.nopnp
Saved the file and reboot. The touchpad started to work and the keyboard seemed working properly so far.

However (again), turning off ACPI made the computer sluggish. With the system monitor, I could see the load of the dual CPU's are extremely not balanced. It seemed the system did not perform the multi-threading properly. I tried to change the boot parameter acpi=off to acpi=ht, but no luck.

By reading the change-log of the coming new Linux kernel 2.6.33, I found there are a lot of fixes regarding to ACPI. Hopefully the new release can fix all these issues of ACPI and i8042 controllers. After all, it is already in the test phase so it is worth waiting.

Read an update here.

Wednesday, December 16, 2009

Linux: secure login without entering password (Part 1)


We can use ssh to login to a remote machine with secure encrypted communications. If you are as lazy as me, you would be tired of entering the password on each login. ssh allows you to use a pair of private and public keys to authenticate your logins instead of the password. It is very simple to set it up.

Step 1: generate the keys
Run command:
    ssh-keygen
It would ask you to input a passphrase. The passphrase is used to encrypt your private key. If you use it, you will need to enter it when you use the private key. In other words, you will need to enter the passphrase each time you login to the remote machine unless you use ssh-agent (see Part 2). To make it simple, just press Enter to use no passphrase.

A pair of files are generated in ~/.ssh/. id_rsa contains the private key and id_rsa.pub contains the public key. Don't let anyone else access the file id_rsa because if others steal your private key, they can login to the remote machine as you.

Step 2: copy the public key to the remote machine
Run command
    ssh-copy-id [username@]<remote-machine>
And enter your password on the remote machine.

If your machine doesn't come with the script ssh-copy-id, you can manually add the public key from your id_rsa.pub file to the remote machine. On the remote machine, open file ~/.ssh/authorized_keys and add the public key. Each key should be in one line -- a very long line. Don't add line-breaks to break it into multiple lines.

Step 3: login
Now you can login with command
    ssh [username@]<remote-machine>
It won't prompt you the password request any more.

Part 2 shows how to use a passphrase for private/public keys with ssh-agent.

Saturday, December 12, 2009

Google Chrome Extension: Secure Or Not


When you visit some secure web pages, you sometimes see a warning icon indicating that the webpage contains insecure contents on the address bar:


And you would wonder what information on the page is unencrypted.

This Chrome extension will answer the question. It shows whether the links on a webpage are https links or http, and whether the forms you are going to submit will be transferred securely or not.

Features
After installation, a Secure Or Not icon is added to the toolbar.


When you click on the icon, the http links on the webpage would be bordered by red dashed lines; and the https links on the webpage would be bordered by green dashed lines. Similarly, forms to be submitted insecurely would be bordered by red dashed lines; and forms to be submitted securely would be bordered by green dashed lines.


Isn't that simple?

(Since version 1.1) Images and iframes are also shown whether they are transferred in secure communication or not. Sometimes an image can have a link to another page, it could then be bordered twice. In such a case, there could be a conflict of the color of the borders. For example, if the image is stored in an insecure location but the link points to a secure URL, the image could have both a green and red border.

(Since version 1.2) You can also press the shortcut keys Ctrl-Shift-S to execute the extension. 

Installation
https://chrome.google.com/extensions/detail/hfoeodccbohfpgkldfcdknmlbbgmdcle

Options 

  • Ignore links (since version 1.1) - if it is checked, the secure status of the links on the page are not shown. Because in a secure page, although a link can point to another insecure page, the link itself is transferred in a secure channel. Usually a browser considers the content of the page as secure even there are links pointing to insecure pages. We allow you to select this option so the extension will not show those links as insecure. That would be consistent with the browser's behavior. By default, the option is not checked.
---
If you like it, please share it with your friends.

Friday, December 11, 2009

Google Chrome extensions: example of how to use Options page


If you want to let the user customize the behavior of your extension, you can provide an Options page. In my Boss Key and Button extension (version 1.1), I use an Options page to allow the user control what features they want to enable. Here are the steps to do that.

Add the Options page to file manifest.json
{
  ...
  "options_page": "options.html",
  ...
}

Then in the extensions page (chrome://extensions/), the user can see an Options button beside your extension.

Write an Options page
It is an regular HTML file with the name that you have specified in the manifest.json file. In my example, I use some checkboxes to let the user enable or disable the features (s)he wants.
<html>
<head>
<title>Boss Key & Button Extension Options</title>

<script type="text/javascript">

function saveOptions() {
  localStorage["bossKnB12PrefEnableKey"] =
             document.getElementById("enableKey").checked;
...
}

function restoreOptions() {
  var value = localStorage["bossKnB12PrefEnableKey"];
  if (null != value)
     document.getElementById("enableKey").checked = toBool(value);
...
}
...
</script>
</head> 
 
<body onload="restoreOptions()">

<form>
<input type="checkbox" id="enableKey" checked="checked" /> Enable F12<br />
...
</form>

<button id="saveButton" onclick="saveOptions()">Save</button>
...

</body>
</html> 

When the Options page is loaded, function restoreOptions() is called. It would try to read the old preferences data from the localStorage, and pre-check/uncheck the checkbox on the page accordingly.

After the user has made his own choices, he presses the Save button. Function saveOptions() is then called and it would save the new preferences data to the localStorage.

Please note that in function restoreOptions(), I use a toBool() function to convert the value read from localStorage. That is because localStorage saves boolean value as a string.

Read preferences in Background pages
The localStorage is accessible in the Background pages, so it is very easy to read the preferences.
<script>
...
var value = localStorage["bossKnB12PrefEnableKey"];
if (null != value)
  prefEnableKey = toBool(value);
...
</script>

Read preferences in Content Scripts
The localStorage is not accessible in Content Scripts. To get the preferences in Content Scripts, I use chrome.extension.sendRequest() to send a request to the Background page and get the preferences data in the response.
chrome.extension.sendRequest({name: "getPreferences"},
     function(response)
     {
        myPrefEnableKey = response.prefEnableKey;
        ...
     });

The Background page waits for the request and sends back a response with the preferences data when it receives a request.
chrome.extension.onRequest.addListener(
     function(request, sender, sendResponse)
     {
        switch (request.name)
        {
           ...
           case "getPreferences":
              // request from the content script to get the preferences.
              sendResponse(
                    {
                       prefEnableKey : localStorage["bossKnB12PrefEnableKey"],
                       ...
                    });
              break;
           ...
        }
     }
);

Note: Source code here are simplified to made it more readable.

Thursday, December 3, 2009

Firefox Extensions: Table Of Contents



See the latest updates here.

Autohide Tabbar
This extension auto-hides your Firefox browser's tab bar. It can also relocate the tab bar to the bottom of the browser window.

Boss Key and Buttons
You can press the F12 key or both the mouse buttons to hide all your browser windows.

Invert Input
Invert the input of a text field or a password field.

Packed Menu
A lightweight extension that hides the original main menu bar.

Secure Or Not
It shows whether the links on a webpage are https links or http.

Simple Boss Key
A lightweight extension that lets you use the F12 key to minimize the current browser window.

Take A Break
By reminding you when to take a break during surfing, it tries to help you avoid excessive web browsing and keep healthy.

Support

Firefox extension: Secure Or Not


When you visit some secure web pages, you sometimes see this alert message:
And you would wonder what information on the page is unencrypted.

This Firefox extension will answer the question. It shows whether the links on a webpage are https links or http.

Features
After installation, a "Secure Or Not" item is added to the context menu -- usually you can right-click the webpage or use the menu key on your keyboard to show the context menu.



When you select it on the context menu, the http links on the webpage would be bordered by red dashed lines; and the https links on the webpage would be bordered by green dashed lines. Similarly, forms to be submitted insecurely would be bordered by red dashed lines; and forms to be submitted securely would be bordered by green dashed lines.



Isn't that simple?

(Since version 1.1) Images and iframes are also shown whether they are transferred in secure communication or not. Sometimes an image can have a link to another page, it could then be bordered twice. In such a case, there could be a conflict of the color of the borders. For example, if the image is stored in an insecure location but the link points to a secure URL, the image could have both a green and red border.

(Since version 1.1) You can also press the shortcut keys Ctrl-Shift-S to execute the extension.


Installation
Download and install it here: https://addons.mozilla.org/en-US/firefox/addon/53005

You will need to restart Firefox browser after the installation.


Options 

• Ignore links (since version 1.1): if it is checked, the secure status of the links on the page are not shown. Because in a secure page, although a link can point to another insecure page, the link itself is transferred in a secure channel. Usually a browser considers the content of the page as secure even there are links pointing to insecure pages. We allow you to select this option so the extension will not show those links as insecure. That would be consistent with the browser's behavior. By default, the option is not checked.

Click here to see how to open the "Options" dialog.

---
More Firefox Extensions

---
If you like it, please share it with your friends.

Wednesday, December 2, 2009

Support



Supports are provided here to the software I publish. You can report bugs or give suggestions. To do that, go to the separate webpage of the program and add them as comments. I would provide updates or feedback as soon as possible. When you are reporting bugs, please provide as many details as possible, such as,
  • OS type and version;
  • The version of the browser;
  • The version of the extension;
  • The steps to reproduce the bug.
If possible, please try the latest version of the extension first before you report a bug.

To start, choose the category of the program and then go to its own webpage.

Note: To download or use the program, you must read and agree to the license of the program.
 
Get This <