[Python-modules-commits] [pykcs11] 04/07: New upstream version 1.4.1

Ludovic Rousseau rousseau at moszumanska.debian.org
Sat Feb 11 13:43:09 UTC 2017


This is an automated email from the git hooks/post-receive script.

rousseau pushed a commit to branch master
in repository pykcs11.

commit c187aa1434b3909c37ffe8b84ce5bd6d26dcd8a7
Author: Ludovic Rousseau <rousseau at debian.org>
Date:   Sat Feb 11 14:31:42 2017 +0100

    New upstream version 1.4.1
---
 Makefile                          |  2 +-
 PKG-INFO                          |  2 +-
 PyKCS11/LowLevel.py               |  1 +
 PyKCS11/__init__.py               |  2 ++
 readme.txt                        |  4 ++++
 samples/encrypt.py                | 10 ++++++----
 samples/generate.py               |  2 +-
 samples/genkeypair_import_cert.py |  2 +-
 samples/modulus.py                |  6 ++++--
 samples/signature.py              |  8 +++++---
 setup.py                          |  2 +-
 src/pykcs11.i                     | 11 +++++++----
 src/pykcs11_wrap.cpp              |  8 +++++---
 13 files changed, 39 insertions(+), 21 deletions(-)

diff --git a/Makefile b/Makefile
index 79ce98a..21bc943 100644
--- a/Makefile
+++ b/Makefile
@@ -4,7 +4,7 @@ DESTDIR ?= /
 ifeq (, $(PYTHON))
 PYTHON=python
 endif
-IS_PYTHON_3 = $(shell python -c 'import sys; print(sys.version_info[0] >= 3)')
+IS_PYTHON_3 = $(shell $(PYTHON) -c 'import sys; print(sys.version_info[0] >= 3)')
 ifeq ($(IS_PYTHON_3), True)
 SWIG_OPTS := -py3
 endif
diff --git a/PKG-INFO b/PKG-INFO
index 25f5145..2e9f8e3 100644
--- a/PKG-INFO
+++ b/PKG-INFO
@@ -1,6 +1,6 @@
 Metadata-Version: 1.1
 Name: PyKCS11
-Version: 1.4.0
+Version: 1.4.1
 Summary: A Full PKCS#11 wrapper for Python
 Home-page: https://bitbucket.org/PyKCS11/pykcs11
 Author: Ludovic Rousseau
diff --git a/PyKCS11/LowLevel.py b/PyKCS11/LowLevel.py
index ddeadea..8002506 100644
--- a/PyKCS11/LowLevel.py
+++ b/PyKCS11/LowLevel.py
@@ -997,6 +997,7 @@ class CK_RSA_PKCS_OAEP_PARAMS(_object):
 CK_RSA_PKCS_OAEP_PARAMS_swigregister = _LowLevel.CK_RSA_PKCS_OAEP_PARAMS_swigregister
 CK_RSA_PKCS_OAEP_PARAMS_swigregister(CK_RSA_PKCS_OAEP_PARAMS)
 
+CK_RSA_PKCS_OAEP_PARAMS_LENGTH = _LowLevel.CK_RSA_PKCS_OAEP_PARAMS_LENGTH
 class CK_MECHANISM_INFO(_object):
     __swig_setmethods__ = {}
     __setattr__ = lambda self, name, value: _swig_setattr(self, CK_MECHANISM_INFO, name, value)
diff --git a/PyKCS11/__init__.py b/PyKCS11/__init__.py
index a2b506d..b685c77 100644
--- a/PyKCS11/__init__.py
+++ b/PyKCS11/__init__.py
@@ -721,6 +721,7 @@ class RSAOAEPMechanism(object):
         self._mech = PyKCS11.LowLevel.CK_MECHANISM()
         self._mech.mechanism = CKM_RSA_PKCS_OAEP
         self._mech.pParameter = self._param
+        self._mech.ulParameterLen = PyKCS11.LowLevel.CK_RSA_PKCS_OAEP_PARAMS_LENGTH
 
     def to_native(self):
         return self._mech
@@ -1018,6 +1019,7 @@ class Session(object):
         m = mecha.to_native()
         data1 = ckbytelist()
         data1.reserve(len(data))
+
         if isinstance(data, bytes):
             for x in data:
                 data1.append(byte_to_int(x))
diff --git a/readme.txt b/readme.txt
index 8764625..40927bb 100644
--- a/readme.txt
+++ b/readme.txt
@@ -84,6 +84,10 @@ that doesn't come with the standard distribution.
 History
 """""""
 
+1.4.1 - February 2017, Ludovic Rousseau
+    - fix compilation under Python 3
+    - add rsa encryption sample program
+
 1.4.0 - February 2017, Ludovic Rousseau
     - fix closeAllSessions() and move it Session to PKCS11Lib
     - add RSAOAEPMechanism to support RSA Encryption
diff --git a/samples/encrypt.py b/samples/encrypt.py
index eb7edeb..ad56a82 100755
--- a/samples/encrypt.py
+++ b/samples/encrypt.py
@@ -16,11 +16,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
+from __future__ import print_function
+
 from PyKCS11 import *
 import binascii
 
 pkcs11 = PyKCS11Lib()
-pkcs11.load("p11.framework/p11")
+pkcs11.load()  # define environment variable PYKCS11LIB=YourPKCS11Lib
 
 # get 2nd slot
 slot = pkcs11.getSlotList()[1]
@@ -37,9 +39,9 @@ privKey = session.findObjects([(CKA_CLASS, CKO_PRIVATE_KEY)])[0]
 enc = session.encrypt(pubKey, binascii.unhexlify(message))
 dec = session.decrypt(privKey, enc)
 
-print "\nmessage: " + message
-print "\nencrypted: " + binascii.hexlify(bytearray(enc))
-print "\ndecrypted: " + bytearray(dec)
+print("\nmessage: " + message)
+print("\nencrypted: " + binascii.hexlify(bytearray(enc)))
+print("\ndecrypted: " + bytearray(dec))
 
 # logout
 session.logout()
diff --git a/samples/generate.py b/samples/generate.py
index 9fef15f..867e0fc 100755
--- a/samples/generate.py
+++ b/samples/generate.py
@@ -19,7 +19,7 @@
 from PyKCS11 import *
 
 pkcs11 = PyKCS11Lib()
-pkcs11.load("p11.framework/p11")
+pkcs11.load()  # define environment variable PYKCS11LIB=YourPKCS11Lib
 
 # get 2nd slot
 slot = pkcs11.getSlotList()[1]
diff --git a/samples/genkeypair_import_cert.py b/samples/genkeypair_import_cert.py
index 1afb68f..eaf00ba 100755
--- a/samples/genkeypair_import_cert.py
+++ b/samples/genkeypair_import_cert.py
@@ -19,7 +19,7 @@
 from PyKCS11 import *
 
 pkcs11 = PyKCS11Lib()
-pkcs11.load('libacospkcs11.so')  # tested with ACS ACOS5-64 smart card and token
+pkcs11.load()  # define environment variable PYKCS11LIB=YourPKCS11Lib
 
 slot = 0  # adjust this if you have more readers
 session = pkcs11.openSession(slot, PyKCS11.CKF_RW_SESSION)
diff --git a/samples/modulus.py b/samples/modulus.py
index 40f9f2d..18701ce 100755
--- a/samples/modulus.py
+++ b/samples/modulus.py
@@ -16,11 +16,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
+from __future__ import print_function
+
 from PyKCS11 import *
 import binascii
 
 pkcs11 = PyKCS11Lib()
-pkcs11.load("p11.framework/p11")
+pkcs11.load()  # define environment variable PYKCS11LIB=YourPKCS11Lib
 
 # get 2nd slot
 slot = pkcs11.getSlotList()[1]
@@ -34,7 +36,7 @@ keyID = (0x11,)
 # find public key and print modulus
 pubKey = session.findObjects([(CKA_CLASS, CKO_PUBLIC_KEY), (CKA_ID, keyID)])[0]
 modulus = session.getAttributeValue(pubKey, [CKA_MODULUS])[0]
-print "\nmodulus: " + binascii.hexlify(bytearray(modulus))
+print("\nmodulus: " + binascii.hexlify(bytearray(modulus)))
 
 # logout
 session.logout()
diff --git a/samples/signature.py b/samples/signature.py
index 15bb602..6aa830a 100755
--- a/samples/signature.py
+++ b/samples/signature.py
@@ -16,11 +16,13 @@
 # along with this program; if not, write to the Free Software
 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA.
 
+from __future__ import print_function
+
 from PyKCS11 import *
 import binascii
 
 pkcs11 = PyKCS11Lib()
-pkcs11.load("p11.framework/p11")
+pkcs11.load()  # define environment variable PYKCS11LIB=YourPKCS11Lib
 
 # get 3rd slot
 slot = pkcs11.getSlotList()[2]
@@ -37,12 +39,12 @@ toSign = "48656c6c6f20776f726c640d0a"
 # find private key and compute signature
 privKey = session.findObjects([(CKA_CLASS, CKO_PRIVATE_KEY), (CKA_ID, keyID)])[0]
 signature = session.sign(privKey, binascii.unhexlify(toSign), Mechanism(CKM_SHA1_RSA_PKCS, None))
-print "\nsignature: " + binascii.hexlify(bytearray(signature))
+print("\nsignature: " + binascii.hexlify(bytearray(signature)))
 
 # find public key and verify signature
 pubKey = session.findObjects([(CKA_CLASS, CKO_PUBLIC_KEY), (CKA_ID, keyID)])[0]
 result = session.verify(pubKey, binascii.unhexlify(toSign), signature, Mechanism(CKM_SHA1_RSA_PKCS, None))
-print "\nVerified:", result
+print("\nVerified:", result)
 
 # logout
 session.logout()
diff --git a/setup.py b/setup.py
index c7cabf5..52b31b1 100755
--- a/setup.py
+++ b/setup.py
@@ -55,7 +55,7 @@ else:
     libraries_val = []
 
 setup(name="PyKCS11",
-    version="1.4.0",
+    version="1.4.1",
     description="A Full PKCS#11 wrapper for Python",
     keywords="crypto,pki,pkcs11,c++",
     classifiers=classifiers,
diff --git a/src/pykcs11.i b/src/pykcs11.i
index a327426..f7ff4d6 100644
--- a/src/pykcs11.i
+++ b/src/pykcs11.i
@@ -42,7 +42,7 @@ using namespace std;
 
 %include cdata.i
 %include cpointer.i
-    %include typemaps.i
+%include typemaps.i
 %include std_vector.i
 
 %template(ckintlist) vector<long>;
@@ -229,10 +229,11 @@ typedef struct CK_DATE{
 
 %typemap(in) void* {
     char *buf;
-    Py_ssize_t sz;
+    size_t sz;
+    int alloc2 = 0;
     // If the value being set is of string type:
     if (PyString_Check($input) && 
-        PyString_AsStringAndSize($input, &buf, &sz) == 0) {
+        SWIG_IsOK(SWIG_AsCharPtrAndSize($input, &buf, &sz, &alloc2))) {
       arg2 = buf;
     } else {
       // If the value being set is of CK_RSA_PKCS_OAEP_PARAMS type:
@@ -280,10 +281,12 @@ typedef struct CK_RSA_PKCS_OAEP_PARAMS {
 		p->src = 0;
 		p->source_data = NULL;
 		p->source_data_len = 0;
-        return p;
+    return p;
 	}
 };
 
+%constant int CK_RSA_PKCS_OAEP_PARAMS_LENGTH = sizeof(CK_RSA_PKCS_OAEP_PARAMS);
+
 typedef struct CK_MECHANISM_INFO {
 %immutable;
     unsigned long    ulMinKeySize;
diff --git a/src/pykcs11_wrap.cpp b/src/pykcs11_wrap.cpp
index de71a40..3b415d5 100644
--- a/src/pykcs11_wrap.cpp
+++ b/src/pykcs11_wrap.cpp
@@ -5601,7 +5601,7 @@ SWIGINTERN CK_RSA_PKCS_OAEP_PARAMS *new_CK_RSA_PKCS_OAEP_PARAMS(){
 		p->src = 0;
 		p->source_data = NULL;
 		p->source_data_len = 0;
-        return p;
+    return p;
 	}
 
 SWIGINTERNINLINE PyObject*
@@ -15835,10 +15835,11 @@ SWIGINTERN PyObject *_wrap_CK_MECHANISM_pParameter_set(PyObject *SWIGUNUSEDPARM(
   arg1 = reinterpret_cast< CK_MECHANISM * >(argp1);
   {
     char *buf;
-    Py_ssize_t sz;
+    size_t sz;
+    int alloc2 = 0;
     // If the value being set is of string type:
     if (PyString_Check(obj1) && 
-      PyString_AsStringAndSize(obj1, &buf, &sz) == 0) {
+      SWIG_IsOK(SWIG_AsCharPtrAndSize(obj1, &buf, &sz, &alloc2))) {
       arg2 = buf;
     } else {
       // If the value being set is of CK_RSA_PKCS_OAEP_PARAMS type:
@@ -21216,6 +21217,7 @@ SWIG_init(void) {
   
   SWIG_InstallConstants(d,swig_const_table);
   
+  SWIG_Python_SetConstant(d, "CK_RSA_PKCS_OAEP_PARAMS_LENGTH",SWIG_From_int(static_cast< int >(sizeof(CK_RSA_PKCS_OAEP_PARAMS))));
   SWIG_Python_SetConstant(d, "FALSE",SWIG_From_int(static_cast< int >(0)));
   SWIG_Python_SetConstant(d, "TRUE",SWIG_From_int(static_cast< int >(!(0))));
   SWIG_Python_SetConstant(d, "CK_TRUE",SWIG_From_int(static_cast< int >(1)));

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/pykcs11.git



More information about the Python-modules-commits mailing list