Thursday, July 15, 2010

SSL using website -- Setting up the server

First of all you need to realize that SSL doesn't work for name based virtual hosts so it needs to be an ip. Technically 1 SSL using host does work it does but the SSL cert is shared for all sites and this is a serious issue from a business/search engine/customer point of view.

  1. Check that you have completed the basic ssl module set up
    sudo a2enmod ssl
    

    And check that the server is listening on 443. either netstat antp for it or grep for the Listen line in the apache2 config files.
    Listen 443
    

  2. Choose a new ip address for the ssl version of the server. Lets say we pick the IP: 192.168.1.200. Once you have gotten the crt back from the provider move it into place and remember to chown and chmod it for root only

    Lets assume we placed it at; /etc/apache2/ss/www.mysite.com.crt


  3. Now to multi-home the server (ie give it the new ip address to play with). You do this by editing and appending the following to /etc/network/interfaces
    #this is mysite's ip for its ssl
    auto eth0:1
      iface eth0:1 inet static
      address 192.168.1.200
      netmask 255.255.255.0
      network 192.168.1.0
      broadcast 192.168.1.255

    Remember to update your DNS server if needed

  4. Then add a new virtual host for the SSL version of the site.

    <VirtualHost 192.168.1.200:443>
      ... COPY OF NON-SSL VERSIONS SETTINGS ...
    
      SSLEngine On
      SSLCertificateKeyFile   /etc/apache2/ssl/www.mysite.com.key
      SSLCertificateFile      /etc/apache2/ssl/www.mysite.com.crt
    </VirtualHost>
    
I may have missed a few things since my servers have been serving SSL for a long time now. Refer:
https://help.ubuntu.com/8.04/serverguide/C/httpd.html https://help.ubuntu.com/8.04/serverguide/C/certificates-and-security.html

SSL using website - Generating an SSL cert for apache2

  1. Generate a the ssl key pair
    openssl genrsa -out www.mysite.com.key 2048
    
    • using a pass-phrase is problematic since the apache2 server cant boot with the having the pass-phrase input.
    • if you need to use a passphrase then add on -des3 param
  2. Generate a code signing request (without a pass-phrase)
    openssl req -new -key www.mysite.com.key -out www.mysite.com.csr
    
    • do not enter an email address, challenge password or an optional company name when generating the CSR.
    • Enter the info which MATCHES THE WHOIS for the domain or your request is likely to get rejected.
      • Country Name:
      • State or Province: (the capitalized two letter code)
      • Locality or City: (without abbreviations)
      • Company: (without &, @, or any other symbol)
      • Organizational Unit: (optional; to skip hit enter)
      • Common Name: the host name ie "www.mysite.com" (make certain it matches the main one used by end customers, to avoid ssl mismatch warnings.)

  3. Send the code code signing request to the certificate authority and wait for them to send the signed certificate back (the crt file).
  4. The files should be stored at the following location with the following permissions/owner. Remember to do it or the key can be viewed and copied.
    /etc/apache2/ssl$ ls -al
    drwxr-xr-x 2 root root 4096 2010-01-08 16:38 .
    drwxr-xr-x 9 root root 4096 2010-01-08 09:42 ..
    -r-------- 1 root root 1354 2010-01-08 09:17 www.mysite.com.crt
    -r-------- 1 root root 1354 2010-01-08 09:17 www.mysite.com.csr
    -r-------- 1 root root 1675 2010-01-08 16:38 www.mysite.com.key
    
Refer https://knowledge.verisign.com/support/ssl-certificates-support/index?page=content&actp=CROSSLINK&id=AR198

rails - Forcing a certain encoding type for the page

response.headers["Content-Type"] = "text/html; charset=shift_jis"

tcpdump to debug the an encoding problem

This is kind of over kill but the HTTP headers plugin for firefox wasn't telling me the truth. I dev web apps using a locale apache2 server. And in this case I needed to deal out an sjis page, of course rails is utf-8 inside and somewhere/somehow the encoding is getting forced to utf8. So to get the truth tcpdump it.

sudo tcpdump -i lo  -Xx -s1500

After this I refreshed the page in question and read the log. Its was clear that rails is always writing utf-8 into the HTTP header which overrode the weaker meta tag setting I was trying to us.

fixing "svn: Malformed file" and other broken svn file problems...

This happens when you get to smart for yourself and alter the contents of the .svn dir accidentally...


To fix it;
Basically move the whole working dir over and recheck out and then restore the new/edited/deleted files. Sounds hard but it is quite easy(especially if you have had to do it a few times).... Run the following commands on the console. And note the commands with "| sh" allow you to first confirm the exact action before executing it so use it to double check before you make a total mess


#move broken trunk out of the way
mv trunk broken
mkdir trunk 
cd trunk
svn checkout https://server.svn/repos/project/trunk
cd ../broken

# make the new dirs -- confirm first...
find ./ -type d | grep -v svn | egrep "^./(app|test|lib|db)" | sed "s|\(.*\)|mkdir -p ../trunk/\1|"
find ./ -type d | grep -v svn | egrep "^./(app|test|lib|db)" | sed "s|\(.*\)|mkdir -p ../trunk/\1|" | sh

# move all the normal non-svn files that are relevant back in (im my case its a rails app) -- confirm first... find ./ -type f | grep -v svn | egrep "^./(app|test|lib|db)" | sed "s|\(.*\)|cp \1 ../trunk/\1|" find ./ -type f | grep -v svn | egrep "^./(app|test|lib|db)" | sed "s|\(.*\)|cp \1 ../trunk/\1|" | sh

# remove all deleted files. -- confirm first... svn status | grep "^D" | sed "s|^D *|svn del ../trunk/|" svn status | grep "^D" | sed "s|^D *|svn del ../trunk/|" | sh

rails - using truncate from a the lib dir ie a module

Here is how to get the helpers into the libs area, Sometimes the helpers use/set data on the controller etc so this doesn't work.

module MyModule
  include ActionView::Helpers::TextHelper
  module_function :truncate
end


Here is how to get it on the console
helper.truncate(string, :length => length)

Monday, July 12, 2010

A quick javascript console web page.

If you have problematic javascript on a website then its often a pain to locate the exact cause of the problem in the particular browser (excluding firefox due to firebug). This site gives you a nice in browser console to work out your issues on.

http://www.jconsole.com/

Hopefully some hack doesn't find it and use it for blackhat purposes that results in it getting taken down.