Daiki Ueno [Fri, 9 Jun 2017 12:44:04 +0000 (14:44 +0200)]
build: Allow use of _GNU_SOURCE
This reverts commit 6b457ffc, which forbids the use of GNU extension
for the incompatibility of strerror_r. However, now that strerror_l
is used instead on glibc systems, it has no point to do that.
Daiki Ueno [Thu, 11 May 2017 13:26:36 +0000 (15:26 +0200)]
rpc: Convert attribute value for portability
When using the RPC across multiple architectures, where data models
are different, say LP64 vs ILP32, there can be unwanted truncation of
attribute values.
This patch converts the values into portable format for the known
attributes.
Daiki Ueno [Thu, 18 May 2017 09:11:45 +0000 (11:11 +0200)]
trust: Check magic comment in persist file for modifiablity
A persistent file written by the trust module starts with the line "#
This file has been auto-generated and written by p11-kit". This can
be used as a magic word to determine whether the objects read from a
.p11-kit file are read-only.
Daiki Ueno [Tue, 28 Feb 2017 15:06:50 +0000 (16:06 +0100)]
build: Remove systemd unit files for now
Given that the remote proxy service shall be only used by NetworkManager
and not generally useful, revert commit a4fb2bb587fb1a0146cf97f039b671d3258488f9 for now.
Once the necessary command that runs the proxy module is implemented in
p11-kit, maybe NetworkManager itself could install those files.
In common/unix-peer.c, we are checking if HAVE_GETPEEREID is defined,
however, we never actually check if getpeereid() is available, so
fix that by checking this function using AC_CHECK_FUNCS().
Daiki Ueno [Fri, 17 Feb 2017 15:18:21 +0000 (16:18 +0100)]
trust: Honor "modifiable" setting in persist file
Previously, all objects read from p11-kit persist files are marked as
modifiable when parsing, regardless of the explicit "modifiable: false"
setting in the file.
Reported by Kai Engert in:
https://bugs.freedesktop.org/show_bug.cgi?id=99797
Daiki Ueno [Wed, 11 Jan 2017 08:32:19 +0000 (09:32 +0100)]
rpc: Add PKCS#11 module that connects to socket
This patch adds a PKCS#11 module that connects to the p11-kit server
exposed on the filesystem. The filename of the socket is determined in
the following order:
- $P11_KIT_SERVER_ADDRESS, if the envvar is available
- $XDG_RUNTIME_DIR/p11-kit/pkcs11, if the envvar is available
- /run/$(id -u)/p11-kit/pkcs11, if /run/$(id -u) exists
- /var/run/$(id -u)/p11-kit/pkcs11, if /var/run/$(id -u) exists
- ~/.cache/p11-kit/pkcs11.
Note that the program loading this module may have called setuid() and
secure_getenv() which we use for fetching envvars could return NULL.
Daiki Ueno [Wed, 15 Feb 2017 11:07:31 +0000 (12:07 +0100)]
rpc: Port exec transport to Windows
On Windows, use _spawnv() to create a subprocess and two unidirectional
pipe created with _pipe() to communicate with it. If we can assume
WinSock, it might be simpler to use a socketpair() replacement from:
https://github.com/ncm/selectable-socketpair.
Kai Engert [Thu, 2 Feb 2017 15:01:01 +0000 (16:01 +0100)]
Support loading new NSS attribute CKA_NSS_MOZILLA_CA_POLICY from .p11-kit files.
See also NSS bug https://bugzilla.mozilla.org/show_bug.cgi?id=1334976
and p11-kit bug https://bugs.freedesktop.org/show_bug.cgi?id=99453
Daiki Ueno [Tue, 14 Feb 2017 15:36:23 +0000 (16:36 +0100)]
virtual: Move mutex into p11_library_init()
We used to provide p11_virtual_fixed_{,un}init() to only initialize a
mutex used in virtual.c. That required all the tests calling virtual
functions to call p11_virtual_fixed_{,un}init() in main().
For simplicity, move the mutex variable initialization into
p11_library_init().
Daiki Ueno [Mon, 13 Feb 2017 15:32:01 +0000 (16:32 +0100)]
trust: Revert to the original 'extract' behavior
Since commit f4384a40, due to a missing ex->flags setting, the 'trust
extract' command didn't retrieve correlation between related objects and
that was causing assertion failure when writing PEM files.
Daiki Ueno [Sat, 17 Dec 2016 06:11:36 +0000 (07:11 +0100)]
iter: Enable iteration over slots/tokens/modules
While PKCS#11 URI can identify slots/tokens/modules, P11KitIter is only
capable of iterating over objects.
This patch adds new behaviors to P11KitIter to support iterations over
slots/tokens/modules, using the C coroutine trick as described in:
http://www.chiark.greenend.org.uk/~sgtatham/coroutines.html
Daiki Ueno [Mon, 23 Jan 2017 09:02:56 +0000 (10:02 +0100)]
uri: Relax pin-* parsing for compatibility
While 'pin-source' and 'pin-value' are defined as query atttribute, they
were defined as path attribute in earlier drafts, and some
implementations still stick to it.
For backward compatibility, accept those in path attributes when
parsing (but not when formatting).
Reported by Andreas Metzler in:
https://lists.freedesktop.org/archives/p11-glue/2017-January/000637.html
Stef Walter [Sun, 29 Jan 2017 14:10:37 +0000 (15:10 +0100)]
trust: Implement a 'trust dump' command
This dumps all the PKCS#11 objects in the internal .p11-kit
persistence format.
This is part of the trust command and tooling, even though
at some point it could go in the p11-kit command. The reason
for this is that the code related to the internal .p11-kit
objects is in the trust code, and consumed solely by the
trust related modules.
Daiki Ueno [Fri, 26 Aug 2016 15:20:06 +0000 (17:20 +0200)]
build: Make libffi closure optional
libffi's closure support is not available on all platforms and may fail
at run time if running under a stricter SELinux policy. Fallback to
pre-compiled closures if it is not usable.
* common/compat.c: Fix "implicit declaration of function 'issetugid'"
warning. On FreeBSD, it's required to define __BSD_VISIBLE to make
issetugid(2) visible
* common/test-message.c: Fix "implicit declaration of function
'asprintf'" by including <stdio.h>
* p11-kit/test-iter.c: Fix "format '%lu' expects argument of
type 'long unsigned int', but argument 3 has type 'int'" by
changing format string to "%d"
Lubomir Rintel [Thu, 8 Dec 2016 17:20:37 +0000 (18:20 +0100)]
systemd: add per-user remoting socket
This allows daemons outside user's session to use per-user PKCS#11
modules. Useful for letting VPN daemons or wpa_supplicant use
certificates stored in user's GNOME keyring, etc.
Lubomir Rintel [Tue, 3 Nov 2015 07:11:39 +0000 (08:11 +0100)]
common: use recursive pthread mutex for library lock
This allows us to do nested locking within one thread avoiding a lockup
when remoting the p11-kit-proxy.so module:
#0 0x00007f190f35838d in __lll_lock_wait () from /lib64/libpthread.so.0
#1 0x00007f190f351e4d in pthread_mutex_lock () from /lib64/libpthread.so.0
#2 0x00007f190f98657f in C_GetFunctionList (list=0x7ffe7ec3f798) at p11-kit/proxy.c:2355
#3 0x00007f190f993cc9 in dlopen_and_get_function_list (funcs=0x7ffe7ec3f798, path=0x7ffe7ec40926 "/usr/local/lib/p11-kit-proxy.so", mod=0x249e3d0) at p11-kit/modules.c:337
#4 load_module_from_file_inlock (name=name@entry=0x0, path=path@entry=0x7ffe7ec40926 "/usr/local/lib/p11-kit-proxy.so", result=result@entry=0x7ffe7ec3f7e8) at p11-kit/modules.c:382
#5 0x00007f190f99587f in p11_kit_module_load (module_path=module_path@entry=0x7ffe7ec40926 "/usr/local/lib/p11-kit-proxy.so", flags=flags@entry=0) at p11-kit/modules.c:2427
#6 0x0000000000401c4b in serve_module_from_file (file=0x7ffe7ec40926 "/usr/local/lib/p11-kit-proxy.so") at p11-kit/remote.c:105
#7 main (argc=1, argv=<optimized out>) at p11-kit/remote.c:169
The Windows NT mutex is aready recursive by default.
Daiki Ueno [Mon, 16 Jan 2017 13:06:30 +0000 (14:06 +0100)]
uri: Avoid typecasting confusion on s390x
Like memcpy(), the 'void *' argument of p11_buffer_add() points to the
memory area ordered in host's endianness. Add typecast of int->char to
avoid the confusion.
Reported by Andreas Metzler in:
https://lists.freedesktop.org/archives/p11-glue/2017-January/000633.html
Lubomir Rintel [Wed, 28 Dec 2016 15:11:21 +0000 (16:11 +0100)]
uri: fix the query attribute parsing
The pin-* attributes belong to the query part. We should not parse them
until we see a '?' and they're separated with a '&'.
This might be an important thing -- some of the query attributes may
have security implications reaching outside scope of the token itself, to the
host system itself. E.g. a pin-source may cause the consumer to access a file
or module-path (unimplemented) execute code. The user may want to just chop the
attribute part off if they want the consumer access the token and not take the
security considerations into account.
- Current command for creation of the p11-kit-proxy symlink
uses shell brace expansion that isn't supported by all
the shells (e.g. FreeBSD's /bin/sh does not support that).
Replace it with the old-fashioned 'for' loop
- Match extension of the source and the target, i.e. so links
to so, dylib links to dylib (previously dylib linked to so)
- Add an uninstall-local target to clean up the symlink