From 47e2f6175f527cbf86c2f2ce474f935dd2e5caed Mon Sep 17 00:00:00 2001 From: Christian Hohnstaedt Date: Mon, 16 Nov 2009 08:12:05 +0100 Subject: [PATCH] hack libp11 to work with Aloaha PKCS#11 library --- INSTALL.w32 | 2 ++ misc/lip11_aloaha_hack.diff | 47 +++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+) create mode 100644 misc/lip11_aloaha_hack.diff diff --git a/INSTALL.w32 b/INSTALL.w32 index a706f571..e0e8987c 100644 --- a/INSTALL.w32 +++ b/INSTALL.w32 @@ -35,6 +35,8 @@ $ ./configure --host i586-mingw32msvc --prefix ${INSTALL_DIR} $ make && make install unpack libp11-0.2.7 an cd into libp11-0.2.7 +Apply hack for Aloaha PKCS#11 libraray if intend to use it: +$ patch -p1 < ../xca/misc/lip11_aloaha_hack.diff $ CFLAGS=-I${INSTALL_DIR}/include LDFLAGS="-L${INSTALL_DIR}/lib" LTLIB_LIBS="-lltdl" OPENSSL_LIBS="-leay32" ./configure --host i586-mingw32msvc --prefix ${INSTALL_DIR} $ make && make install diff --git a/misc/lip11_aloaha_hack.diff b/misc/lip11_aloaha_hack.diff new file mode 100644 index 00000000..d41633d3 --- /dev/null +++ b/misc/lip11_aloaha_hack.diff @@ -0,0 +1,47 @@ +diff -ur libp11-0.2.7.orig/src/libp11-int.h libp11-0.2.7/src/libp11-int.h +--- libp11-0.2.7.orig/src/libp11-int.h 2008-08-28 22:12:43.000000000 +0200 ++++ libp11-0.2.7/src/libp11-int.h 2009-11-16 07:51:12.000000000 +0100 +@@ -140,8 +140,20 @@ + #define key_getattr(key, t, p, s) \ + pkcs11_getattr(KEY2TOKEN((key)), PRIVKEY((key))->object, (t), (p), (s)) + +-#define key_getattr_bn(key, t, bn) \ +- pkcs11_getattr_bn(KEY2TOKEN((key)), PRIVKEY((key))->object, (t), (bn)) ++static inline int ++key_getattr_bn(const PKCS11_KEY *key, CK_ATTRIBUTE_TYPE type, BIGNUM **bn) ++{ ++ PKCS11_KEY_private *pkey = PRIVKEY(key); ++ CK_OBJECT_HANDLE object = pkey->object; ++ if (type == CKA_MODULUS || type == CKA_PUBLIC_EXPONENT) { ++ /* 08002003 ->pub ++ * 08003003 ->priv */ ++ // printf("ALOAHA HACK: '%s'\n", pkey->parent->manufacturer); ++ if (!strcmp(pkey->parent->manufacturer, "Aloaha PKCS#11")) ++ object &= ~0x1000UL; ++ } ++ return pkcs11_getattr_bn(pkey->parent, object, type, bn); ++} + + typedef int (*pkcs11_i2d_fn) (void *, unsigned char **); + extern void pkcs11_addattr(CK_ATTRIBUTE_PTR, int, const void *, size_t); +diff -ur libp11-0.2.7.orig/src/p11_key.c libp11-0.2.7/src/p11_key.c +--- libp11-0.2.7.orig/src/p11_key.c 2008-08-28 22:12:43.000000000 +0200 ++++ libp11-0.2.7/src/p11_key.c 2009-11-16 07:53:02.000000000 +0100 +@@ -444,15 +444,13 @@ + } + int PKCS11_get_key_modulus(PKCS11_KEY * key, BIGNUM **bn) + { +- +- if (pkcs11_getattr_bn(KEY2TOKEN(key), PRIVKEY(key)->object, CKA_MODULUS, bn)) ++ if (key_getattr_bn(key, CKA_MODULUS, bn)) + return 0; + return 1; + } + int PKCS11_get_key_exponent(PKCS11_KEY * key, BIGNUM **bn) + { +- +- if (pkcs11_getattr_bn(KEY2TOKEN(key), PRIVKEY(key)->object, CKA_PUBLIC_EXPONENT, bn)) ++ if (key_getattr_bn(key, CKA_PUBLIC_EXPONENT, bn)) + return 0; + return 1; + }