Thursday, March 29, 2007

Linux Printing with CUPS - sucked into dependency hell

After two days of struggling, I finally got my Epson C67 printer to work again. All in the name of upgrading GIMP-Print to Gutenprint which should provide better support for the printer, especially for photo printing.

The initial build process for Gutenprint was smooth - no error what so ever. But when I tried to print - nothing happen. After much reading and Google around, I found the problem was due to dependency issues. This simply means I had to re-build my Gimp and Ghostscript to newer versions (and also I took the opportunity to re-build CUPS). Only after all those re-built I managed to print again. I just wish there is an easier way to resolve dependency in the future.

Monday, March 26, 2007

A Simple Step-By-Step Guide of SSL Key Management With OpenSSL

This is a simplified step by step guide to manage SSL key using OpenSSL. For further information do man openssl.

1. Become a root certificate authority(CA)

  • $openssl req -new -x509 -keyout ca.key -out ca.crt -days 3650
  • This will request for (-)new self-signed(-x509) root certificate with private key(-keyout) named "ca.key") and certificate file(-out) named "ca.crt" which is certified for 10 years(-days 3650).

2. View the contents of the certificate
  • $openssl x509 -in ca.crt -noout -text
  • $openssl x509 -in ca.crt -noout -dates
  • $openssl x509 -in ca.crt -noout -purpose

3. Create the certificate signing request
  • This request is actually generated by those who want their certificate to be signed by root CA
  • $openssl req -new -nodes -keyout my.key -out my.csr -days 365
  • If paranoid, remove -nodes option to make the private key encrypted and password protected.

4. Signing a certificate
  • $openssl ca -out my.crt -in my.csr
  • Optionally, remove the human-readable portions of the certificate :
    • $openssl x509 -in my.crt -out my-nohuman-readable.crt

5. Deployment of certificates
  • The following certificates my.key, my.crt and ca.crt are needed by application using SSL.
  • Some applications require both the key and certificate in one file, which can be achived by running:
    • $cat server.key server.crt > key-cert.pem
  • For applications using SSL/TLS, the Diffie Hellman parameters may be required on the server side. Create the DH (using 2048 bits) by issuing:
    • $openssl dhparam -out dh2048.pem 2048

6. Certification Revocation List (CRL)
  • $openssl ca -gencrl -crldays 30 -out rootca.crl

7. Renewing and revoking certificates
  • Both root certificate and other signed certificates are subjected to expiry.
  • If root certificate expires, a new root CA certificate must be created and distributed. All other certificate that it signed must also be re-created and signed.
  • For other certificates, those certificates can be renewed by first revoking the old certificate, then re-signed the original request or do another round of request and sign procedure. To revoke a certificate, issue the following command:
    • $openssl ca -revoke expire.crt
  • Regenerate CRL again if necessary.

Tuesday, March 20, 2007

Wow! del.icio.us

Just open an account at del.icio.us :) It's a rather late entry into social bookmarking. I already formed an initial impression of social bookmarking - it's pretty cool.

You can view my bookmarks at http://del.icio.us/efaisal

Wednesday, March 14, 2007

Posting source code

I not really satisfied the way source code is being displayed. Currently I'm just putting the <pre> tag around the code. No fancy formatting, just plain <pre>. So, is there a better way to format source code? May be use <pre> tag with some cool CSS hacks?

Scheduleable Event Loop for asyncore/asynchat

Been a while since I write a blog. Below is the Python code which is quite usable to replace the default asyncore loop. It's based on Sam Rushing code which can be found at http://squirl.nightmare.com/medusa/async_sockets.html

import sys, time, asyncore

map = asyncore.socket_map

class EventLoop:
def __init__(self):
self.events = {}
self.poll = asyncore.poll3
self.__quit = None

def loop(self, timeout=30.0):
while map:
if self.__quit is True: break
now = int(time.time())
for k, v in self.events.iteritems():
if now >= k:
for o in v:
try:
o[0](*o[1][0], **o[1][1])
except:
type, value, tb = sys.exc_info()
parm = str(o[1])
logstr = "Error in Evenloop processing " + \
"scheduled task."
logstr = "Error details: %s: %s" % (type, value)
logstr = "Error details(parm): %s" % parm
logstr = "Error details(tb): %s" % \
tb.tb_frame.f_code
del self.events[k]
self.poll(timeout)

def schedule(self, delta, callback, *args, **kargs):
now = int(time.time())
if self.events.has_key(now + delta) is False:
self.events[now + delta] = []
self.events[now + delta].append((callback, (args, kargs)))

def unschedule(self, callback):
for k, v in self.events.iteritems():
for o in v:
if o[0] is callback:
del self.events[k][v][self.events[k][v].index(o)]
if len(v) == 0:
del self.events[k]

def quit(self):
self.__quit = True