Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #28541
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <cornelius.koelbel@lsexperts.de> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.001 |
| X-Spam-Evidence | '*H*': 1.00; '*S*': 0.00; 'else:': 0.03; '%s"': 0.07; 'null,': 0.07; 'python': 0.09; 'label,': 0.09; 'subject:ctypes': 0.09; 'def': 0.10; 'template': 0.11; 'library': 0.15; '"created': 0.16; '(%s):': 0.16; 'ctypes.': 0.16; 'filename:fname piece:signature': 0.16; 'from:charset:iso-8859-15': 0.16; 'guru': 0.16; 'hint': 0.16; 'low.': 0.16; 'library,': 0.17; 'mechanism': 0.17; 'preferred': 0.20; 'skip:" 30': 0.20; 'trying': 0.21; 'raise': 0.24; 'header:User-Agent:1': 0.26; 'charset:iso-8859-15': 0.26; 'skip:" 20': 0.26; 'appreciated.': 0.26; 'guess': 0.27; 'language.': 0.27; 'label': 0.27; 'initialized': 0.29; 'print': 0.32; 'to:addr:python-list': 0.33; '(with': 0.33; 'that,': 0.34; 'be.': 0.36; 'should': 0.36; 'data': 0.37; 'received:10': 0.38; 'there,': 0.38; 'to:addr:python.org': 0.39; 'skip:" 10': 0.40; 'header:Received:5': 0.40; 'end': 0.40; 'address': 0.60; 'skip:u 10': 0.60; 'subject:, ': 0.61; 'kind': 0.61; 'belt': 0.91 |
| Date | Wed, 05 Sep 2012 22:41:05 +0200 |
| From | Cornelius Kölbel <cornelius.koelbel@lsexperts.de> |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20120827 Thunderbird/15.0 |
| MIME-Version | 1.0 |
| To | python-list@python.org |
| Subject | ctypes, strange structures of PKCS11 |
| X-Enigmail-Version | 1.4.4 |
| OpenPGP | id=3F337C71 |
| Content-Type | multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="------------enig36B91ABAEB0DE9305FABF167" |
| X-Virus-Scanned | by amavisd-new at pawisda.de |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.269.1346877675.27098.python-list@python.org> (permalink) |
| Lines | 101 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1346877675 news.xs4all.nl 6894 [2001:888:2000:d::a6]:36664 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:28541 |
Show key headers only | View raw
[Multipart message — attachments visible in raw view] - view raw
Hi there,
I am trying to use a pkcs11 library (with python 2.7) and address this
library with ctypes.
Alas, I am neither the python black belt guru and C is not my preferred
language.
Till now, I do not want to use pykcs11, since I want to keep my
dependencies low.
I initialized the library, logged in to the token and got a session
(self.hSession).
Now I try to create an AES key using C_CreateKey.
--snip--
def createAES(self, ks=32):
rv=0
mechanism = CK_MECHANISM(CKM_AES_KEY_GEN, NULL, 0)
print "Mech:",mechanism.mechanism
print "Mech:",mechanism.pParameter
print "Mech:",mechanism.usParameterLen
keysize = c_ulong(ks)
klass = CKO_SECRET_KEY
keytype = CKK_AES
label = "testAES"
ck_true = c_ubyte(1)
ck_false = c_ubyte(0)
objHandle = CK_OBJECT_HANDLE()
size=7
CK_TEMPLATE = CK_ATTRIBUTE * 6
template = CK_TEMPLATE(
CK_ATTRIBUTE(CKA_KEY_TYPE, c_void_p(keytype),0),
CK_ATTRIBUTE(CKA_LABEL, cast( label, c_void_p),
len( label )),
CK_ATTRIBUTE(CKA_VALUE_LEN,
cast(byref(keysize),c_void_p), sizeof(keysize) ),
CK_ATTRIBUTE(CKA_PRIVATE,
cast(byref(ck_false),c_void_p), sizeof(ck_false)),
CK_ATTRIBUTE(CKA_TOKEN,
cast(byref(ck_true),c_void_p), sizeof(ck_true)),
CK_ATTRIBUTE(CKA_SENSITIVE,
cast(byref(ck_true),c_void_p), sizeof(ck_true))
)
template_len = c_ulong(size)
print "Template: ", template
print "Template: ", len(template)
print "Handle:", objHandle
print "Handle:", type(addressof(objHandle))
rv = self.etpkcs11.C_GenerateKey(self.hSession,
addressof(mechanism),
addressof(template),
template_len,
objHandle)
print "rv=",rv
print "handle=",objHandle
if rv:
if self.debug: print "Failed to create key: " , rv
raise Exception("createAES - Failed to C_GenerateKey (%s):
%s" % (rv, pkcs11error(rv)) )
else:
if self.debug: print "created key successfully: %s" %
str(handle)
--snap--
Unfortunately I end up with a return value of 32, which means invalid
data -- I guess my template is not that, what is should be.
Any hint on this is highly appreciated.
Kind regards
Cornelius
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
ctypes, strange structures of PKCS11 Cornelius Kölbel <cornelius.koelbel@lsexperts.de> - 2012-09-05 22:41 +0200
csiph-web