Saturday, November 14, 2009

Python and RSA


There are many Python toolkits for crypto, so I hope I've done the best choice (at least for now). This is a simple utility class for managing RSA keys, a sort of wrappera to the m2crypto class.

import M2Crypto
class RSA (object):
def __init__ (self, bits=1024, padding=M2Crypto.RSA.pkcs1_padding, exp=65537):
self.bits = bits
self.padding = padding
self.exp = exp
self.rsa = None

def generate (self):
self.rsa = M2Crypto.RSA.gen_key(
self.bits, self.exp, lambda x: None)

def encrypt (self, s):
c = ""
bytes = self.bits/8-11
for i in range(0, len(s), bytes):
c += self.rsa.public_encrypt (s[i:i+bytes], self.padding)
return c

def sign (self, s, algo="sha1"):
dgst = M2Crypto.EVP.MessageDigest (algo)
dgst.update (s)
return self.rsa.sign (dgst.digest (), algo)

def verify (self, s, sign, algo="sha1"):
dgst = M2Crypto.EVP.MessageDigest (algo)
dgst.update (s)
try:
self.rsa.verify (dgst.digest (), sign, algo)
except:
return False
return True

def decrypt (self, c):
s = ""
bytes = self.bits/8
for i in range(0, len(c), bytes):
s += self.rsa.private_decrypt (c[i:i+bytes], self.padding)
return s
Example usage:

rsa = RSA ()
rsa.generate () # generate key pair
s = "a"*2000 # test data
edata = rsa.encrypt (s)
sign = rsa.sign (s)

ddata = rsa.decrypt (edata)
assert rsa.verify (ddata, sign) == True

Friday, October 09, 2009

Debian+Apache+Tomcat+Axis

Hello,
one of the courses I'm following at the university is "Laboratorio di reti
di calcolatori" which uses the technologies (really technologies?????)
listed in the post title. This is a little tutorial for making them works,
with a little script for registering .wsdd files.

- aptitude install apache2 tomcat6
- download the binaries of axis 1.x (latest is 2.x, it's not used in our course) and xerces then unpack them.
- copy *.jar of xerces into the "lib" dir of axis.
- create "/etc/tomcat6/policy.d/99axis.policy" with:
grant codeBase "file:/var/lib/tomcat6/webapps/-" {
permission java.security.AllPermission;
};

- copy the "axis" directory found under webapps of the axis binaries into /var/lib/tomcat6/webapps
- invoke-rc.d apache2 restart
- invoke-rc.d tomcat6 restart

Now go to http://localhost:8080 to make sure that Apache-Axis works.

Finally, this is the script for deploying web services (call it deploy.sh):
export AXIS_HOME="/home/lethal/ingegneria/reti/axis/axis-1_4"
export AXIS_LIB="$AXIS_HOME/lib"
export AXISCLASSPATH="$AXIS_LIB/axis.jar:$AXIS_LIB/commons-discovery-0.2.jar:$AXIS_LIB/commons-logging-1.0.4.jar:$AXIS_LIB/jaxrpc.jar:$AXIS_LIB/saaj.jar:$AXIS_LIB/log4j-1.2.8.jar:$AXIS_LIB/xml-apis.jar:$AXIS_LIB/xercesImpl.jar"
java -cp "$AXISCLASSPATH" org.apache.axis.client.AdminClient -lhttp://localhost:8080/axis/services/AdminService "$1"

In the script, you must tweak the AXIS_HOME variable to point to the unpacked axis binaries: avoid using spaces in this variable or you'll encounter several errors in terms of classpath.
Usage of the script:
sh deploy.sh file.wsdd

We're done!

Wednesday, October 07, 2009

Speeding up zsh completion

Hello,
since I've started using zsh, a great shell with great out of the box completion, one of the most boring issues was having a really slow completion. I can understand it could be slow to get a list of packages, remote files or command line options, but also paths were often slow to be completed. After lots of searches I've ended up in adding this magic line to my ~/.zshrc:
zstyle ':completion:*' accept-exact '*(N)'
This way you tell zsh comp to take the first part of the path to be exact, and to avoid partial globs. Now path completions became nearly immediate.

Another important speed up is using the cache for packages and other stuff:
zstyle ':completion:*' use-cache on
zstyle ':completion:*' cache-path ~/.zsh/cache
If you know how to boost up options/remote files, please share :)

Saturday, August 29, 2009

New GPG key

Hello,
due to some synchronization problems between my desktop and laptop, unfortunately I've lost my GPG secret key. I was planning to renew my key after the SHA issues, but this way I can't neither revoke the old key nor sign the new key. So I please anybody having my pubkey to delete it:
gpg --delete-key C29A9371

I've uploaded my new key as usual so you can get it:
gpg --keyserver pgp.mit.edu --recv-keys D2C27B6B

Sunday, August 09, 2009

Spadi source code

Hello,
after I've written really a few docs, and cleaned up some stuff, I've published the code of both Spadi and Corraza on gitorious here. In the while, I've added support for floors and closeable views.
Help... help is needed.

Stay tuned.

Thursday, August 06, 2009

Constructing a free ArchiCAD alternative

Hello,
together a couple of university mates we talked about a possible free (as in freedom) ArchiCAD alternative. There are several free CAD out there but none is free for architects/engineers. The project is too big and ambitious, but I wanted to give OpenGL a shot with this excuse to learn something new.

I've started two projects:
  • Corraza, the OpenGL framework for editing 3d objects and exporting the scene graph to ray tracing software... think about a very very very minimal blender but as library
  • Spadi, the GTK+ application that runs on top of Corraza

You can find a video here to see what it can do now, after a week of development.
There's no code published at the moment, contact me if you would like to join the development.

Stay tuned.

Tuesday, July 21, 2009

Aruanne, pdf reporting framework

Hello,
a while ago I've been talking about pango cairo and how to generate pdf with a couple of tables.
In the meantime I've worked on it, improving and enhancing new kinds of elements. This has lead to the creation of a small project, a library providing a simple framework for generating mostly PDF reports (I haven't tried to generate SVG or something else yet).

After a couple of release requests, I've found finally the time to publish a sort of working code.

Here's the git repository and here you can download the snapshot tarball.

Any patches welcome.