aboutsummaryrefslogtreecommitdiff
path: root/pow/POW-0.7/pkix-m2crypto-driver.py
diff options
context:
space:
mode:
authorRob Austein <sra@hactrn.net>2007-10-05 15:17:50 +0000
committerRob Austein <sra@hactrn.net>2007-10-05 15:17:50 +0000
commit91e72bf2592a0c71cb4f9099df1c9a0420bc11cc (patch)
tree5a35ace37b0ed2268b45477c6887ac6fe40fc04c /pow/POW-0.7/pkix-m2crypto-driver.py
parent258b05bae4a6265b4e7835bb132aafd2c7c6a972 (diff)
Refile m2crypto driver
svn path=/pow/POW-0.7/pkix-m2crypto-driver.py; revision=1097
Diffstat (limited to 'pow/POW-0.7/pkix-m2crypto-driver.py')
-rw-r--r--pow/POW-0.7/pkix-m2crypto-driver.py42
1 files changed, 42 insertions, 0 deletions
diff --git a/pow/POW-0.7/pkix-m2crypto-driver.py b/pow/POW-0.7/pkix-m2crypto-driver.py
new file mode 100644
index 00000000..61dabac7
--- /dev/null
+++ b/pow/POW-0.7/pkix-m2crypto-driver.py
@@ -0,0 +1,42 @@
+# $Id$
+
+"""Crypto driver for POW.pkix using M2Crypto.
+
+This driver is part of an attempt to salvage the (really nice)
+POW.pkix code from the POW package. I like POW well enough, but it's
+old and missing some pieces and the Python world seems to have moved
+to M2Crypto. But M2Crypto has nothing like POW.pkix, so I whacked
+together an interface to let POW.pkix run over other crypto packages.
+
+This module is a driver for M2Crypto.
+"""
+
+# NB: Module names may change eventually
+
+import POW.pkix
+
+class M2CryptoCryptoDriver(POW.pkix.CryptoDriver):
+ """Dispatcher for crypto calls using M2Crypto package."""
+
+ def __init__(self):
+ import M2Crypto
+ self.driver2OID = {
+ "md5" : (1, 2, 840, 113549, 1, 1, 4), # md5WithRSAEncryption
+ "sha1" : (1, 2, 840, 113549, 1, 1, 5), # sha1withRSAEncryption
+ "ripemd160" : (1, 2, 840, 113549, 1, 1, 6), # ripemd160WithRSAEncryption
+ "sha256" : (1, 2, 840, 113549, 1, 1, 11), # sha256WithRSAEncryption
+ }
+ self.OID2driver = dict((v,k) for k,v in self.driver2OID.iteritems())
+
+ def sign(self, key, oid, plaintext):
+ digest = M2Crypto.EVP.MessageDigest(self.OID2driver[oid])
+ digest.update(plaintext)
+ return key.sign(digest.final(), self.OID2driver[oid])
+
+ def verify(self, key, oid, plaintext, signature):
+ return key.verify(plaintext, signature, self.OID2driver[oid])
+
+ def keyDER(self, key):
+ bio = M2Crypto.BIO.MemoryBuffer()
+ key.save_key_der_bio(bio)
+ return bio.read()