ipapython: port p11helper C code to Python

This replaces the binary _ipap11helper module with cffi-based Python code.

https://fedorahosted.org/freeipa/ticket/5596

Reviewed-By: Martin Basti <mbasti@redhat.com>
This commit is contained in:
Jan Cholasta
2016-01-06 13:10:11 +01:00
committed by Martin Basti
parent f5f5c8c603
commit 500ee7e2b1
16 changed files with 1873 additions and 2492 deletions

View File

@@ -1,8 +1,6 @@
PYTHON ?= /usr/bin/python2
PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib())")
SUBDIRS = ipap11helper
all:
@for subdir in $(SUBDIRS); do \
(cd $$subdir && $(MAKE) $@) || exit 1; \

View File

@@ -2,7 +2,7 @@
# Copyright (C) 2014 FreeIPA Contributors see COPYING for license
#
import _ipap11helper
from ipapython import p11helper as _ipap11helper
attrs_id2name = {
#_ipap11helper.CKA_ALLOWED_MECHANISMS: 'ipk11allowedmechanisms',

View File

@@ -18,7 +18,7 @@ from ipapython.dnssec.abshsm import (
AbstractHSM,
bool_attr_names,
populate_pkcs11_metadata)
import _ipap11helper
from ipapython import p11helper as _ipap11helper
import uuid
def uri_escape(val):

View File

@@ -13,7 +13,7 @@ from pprint import pprint
from ipaplatform.paths import paths
import _ipap11helper
from ipapython import p11helper as _ipap11helper
from ipapython.dnssec.abshsm import (attrs_name2id, attrs_id2name, AbstractHSM,
keytype_id2name, keytype_name2id,
ldap2p11helper_api_params)
@@ -65,7 +65,7 @@ class Key(collections.MutableMapping):
return self.p11.set_attribute(self.handle, attrs_name2id[key], value)
def __delitem__(self, key):
raise _ipap11helper.Exception('__delitem__ is not supported')
raise _ipap11helper.P11HelperException('__delitem__ is not supported')
def __iter__(self):
"""generates list of ipa names of all attributes present in the object"""

View File

@@ -1,19 +0,0 @@
PYTHON ?= /usr/bin/python2
PYTHONLIBDIR ?= $(shell $(PYTHON) -c "from distutils.sysconfig import *; print(get_python_lib())")
all:
$(PYTHON) setup.py build
install:
if [ "$(DESTDIR)" = "" ]; then \
$(PYTHON) setup.py install; \
else \
$(PYTHON) setup.py install --root $(DESTDIR); \
fi
clean:
rm -rf build
distclean: clean
maintainer-clean: distclean

View File

@@ -1,87 +0,0 @@
/*
* Copyright (C) 2014 FreeIPA Contributors see COPYING for license
*
* This code is based on PKCS#11 code from SoftHSM project:
* https://github.com/opendnssec/SoftHSMv2/
* Original license follows:
*/
/*
* Copyright (c) 2010 .SE (The Internet Infrastructure Foundation)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*****************************************************************************
library.c
Support function for handling PKCS#11 libraries
*****************************************************************************/
#include "library.h"
#include <stdio.h>
#include <stdlib.h>
#include <dlfcn.h>
// Load the PKCS#11 library
CK_C_GetFunctionList loadLibrary(const char* module, void** moduleHandle)
{
CK_C_GetFunctionList pGetFunctionList = NULL;
void* pDynLib = NULL;
// Load PKCS #11 library
if (module)
{
pDynLib = dlopen(module, RTLD_NOW | RTLD_LOCAL);
} else {
return NULL;
}
if (pDynLib == NULL)
{
// Failed to load the PKCS #11 library
return NULL;
}
// Retrieve the entry point for C_GetFunctionList
pGetFunctionList = (CK_C_GetFunctionList) dlsym(pDynLib, "C_GetFunctionList");
if (pGetFunctionList == NULL)
{
dlclose(pDynLib);
return NULL;
}
// Store the handle so we can dlclose it later
*moduleHandle = pDynLib;
return pGetFunctionList;
}
void unloadLibrary(void* moduleHandle)
{
if (moduleHandle)
{
dlclose(moduleHandle);
}
}

View File

@@ -1,48 +0,0 @@
/*
* Copyright (C) 2014 FreeIPA Contributors see COPYING for license
*
* This code is based on PKCS#11 code from SoftHSM project:
* https://github.com/opendnssec/SoftHSMv2/
* Original license follows:
*/
/*
* Copyright (c) 2010 .SE (The Internet Infrastructure Foundation)
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
* IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*****************************************************************************
library.h
Support function for handling PKCS#11 libraries
*****************************************************************************/
#ifndef _SOFTHSM_V2_BIN_LIBRARY_H
#define _SOFTHSM_V2_BIN_LIBRARY_H
#include <p11-kit/pkcs11.h>
CK_C_GetFunctionList loadLibrary(const char* module, void** moduleHandle);
void unloadLibrary(void* moduleHandle);
#endif // !_SOFTHSM_V2_BIN_LIBRARY_H

File diff suppressed because it is too large Load Diff

View File

@@ -1,43 +0,0 @@
#!/usr/bin/python2
#
# Copyright (C) 2014 FreeIPA Contributors see COPYING for license
#
from distutils.core import setup, Extension
from distutils.sysconfig import get_python_inc
import sys
import os
python_header = os.path.join(get_python_inc(plat_specific=0), 'Python.h')
if not os.path.exists(python_header):
sys.exit("Cannot find Python development packages that provide Python.h")
module = Extension('_ipap11helper',
define_macros = [],
include_dirs = [],
libraries = ['dl', 'crypto', 'p11-kit'],
library_dirs = [],
extra_compile_args = [
'-std=c99',
'-I/usr/include/p11-kit-1',
'-ggdb3',
'-O2',
'-W',
'-Wall',
'-Wno-unused-parameter',
'-Wbad-function-cast',
'-Wextra',
],
sources = ['p11helper.c', 'library.c'])
setup(name='_ipap11helper',
version='0.1',
description='FreeIPA pkcs11 helper',
author='Martin Basti, Petr Spacek',
author_email='mbasti@redhat.com, pspacek@redhat.com',
license='GPLv2+',
url='http://www.freeipa.org',
long_description="""
FreeIPA pkcs11 key manipulation utils.
""",
ext_modules = [module])

File diff suppressed because it is too large Load Diff