Age | Commit message (Collapse) | Author | Files | Lines |
|
* openssl3 support
* check correct attributes for functions
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Make sure we have CKA_SIGN set to sign keys and CKA_DECRYPT set to
decrypt from them.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Explicitly include bn.h and use get1 functions for EC_KEY operations
because get0 requires a const return.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Detect being built with openssl-3 and build with the 1.1 API to prevent
deprecation warnings breaking the build.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Add man page
* use public engine keys
* fix crash on non-existent key
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
This adds a man page which describes how to build your own
configuration file and gives examples of using the PKCS#11 module.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Some engines have corresponding public key load methods, so use those
if the normal load of the public key fails.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Right at the moment the token library segfaults if the public key
isn't found. This is because the serial number gets set to NULL and
the ATTRIB macro tries to do strlen(NULL). Fix this, but also ensure
that any failure to load the public key/cert results in the token
being removed from the exported list.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Fix segfault on no config file
* Fix elliptic curve signature
* Fix C_Initialize and find
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
And update all the tests to reflect this.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Since the result of the bug with find restrictions was for p11tool to
produce "no objects" for every search, check that we can set search
parameters using p11tool and verify the outputs look correct.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
p11tool --list-all isn't showing any keys. That's because it does its
first search of the object with no parameters at all: looking for
every object. However, there's a misplaced condition checking for a
valid find that currently expects to see a type restriction. Fix this
to allow no type restriction as valid.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
C_Initialize is currently returning CKR_CANT_LOCK if the argument is
not null, which is completely bogus. The problem we have is that we
must use OS provided locking primitives because we rely on openssl
which does.
We're given permission to use OS locking primitives in three cases
1) The argument is NULL
2) The arg->flags contain CKF_OS_LOCKING_OK
3) Regardless of arg->flags, all four locking function are NULL
So fix the check to look for these cases.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
This was failing before the EC signature module got fixed, so make
sure it never fails again.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
The size of the signature isn't getting set correctly. Apparently
this doesn't matter for gnutls, but it does for the openssl pkcs11
engine, which otherwise gets the wrong size and thus the wrong format
for the signature. Fix by always setting sig_len regardless of
whether we're signing or not.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
With PKCS11 tokens, if C_Login returns OK that confirms the password
is correct. However, with engine keys, the password may or may not be
checked in ENGINE_load_private_key() so try to perform a signing
operation if that function returns a key.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Now the token should fail to initialize and p11tool should say so
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Make parse_ini_file return a failure if the configuration could not be
extracted and make C_Initialize return and error for this case. This
prevents any correct PKCS11 token user from doing anything else with
the token.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Fix testing problems on older architectures
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Apparently older versions of gnutls don't handle RSA-PSS or ECC keys
very well, even though they seem to understand them. Move those tests
to the p11tools_test_sign.sh test which isn't executed for older
gnutls.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Earlier versions require this otherwise they can't read encrypted keys.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Add certificates
* Fix certificates for mozilla-nss
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Firefox seems to require the token to store the private key and the
certificate, so you can't simply use a token for a private key and an
external certificate. Thus we add the ability to specify a
certificate instead of a public key. In that case, the token will
have three objects: the certificate, the public key (extracted from
the certificate) and the private key.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
At the moment we use a single bit to identify public/private key, so
move this to accessors instead of open coding it in preparation for
adding certificate types as well.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
In order to load dynamic engines, the builtin engines need to be
loaded. Usually this happens automatically, but not when
openssl-pkcs11-export is used by firefox, so do it whenever an engine
is requested.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Fix builds for older gcc and openssl < 1.1.0
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
p11tool before version 3.4.4 didn't have the --test-sign option, which
we use to test signatures. Split out test signing into a separate
module and check that we can run it in configure.ac
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Apparently it gets confused by casting an initializer
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Support for Elliptic Curve Keys (signing only)
* fix bugs that cause problems in mozilla-nss
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
For some unknown reason fedora doesn't have the brainpool curves, so
use secp384r1 for parametrised testing instead.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
It turns out Mozilla nss is keen on C_CreateObject, which is currently
NULL, so identify all the other NULL C_ functions and fill them in
with the unimplemented message.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
mozilla NSS refers to slots by description only. Unfortunately, we
currently use the same default description for every slot, confusing
nss. Fix this by using the section name by default for the slot
description and allowing a per-section override in the conf file.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Apparently this is somewhat hard to do: the pkcs11 engine from libp11
0.4.9 has the C_Sign routines stubbed out, so the only way of checking
is with gnutls p11tool and, apparently, gnutls doesn't understand
parametrised curves. Therefore, signature testing is limited to named
curves until I can find another test programme.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Just sign at the moment. It turns out there's a problem with the
openssl sign routines in that they spit out an incompatible format
from the one pkcs11 expects, so we have to intercept and convert.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
In order to support more key types, first split out all the mechanism
specific key handling into its own separate file.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* fix debian build
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
It turns out to be a huge pain to find in a distro independent fashion
and we only need the definition of ARRAY_SIZE.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Effect rename to openssl-pkcs11-export for Fedora
* Allow multiple sessions and finds per token
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
As of version 3.6.6 gnutls checks to see if we have the CKA_SIGN and
CKA_DECRYPT attributes set for PSS signing and OAEP decryption keys.
These are set in the cache but not processed by our attribute handling
code, so add them.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
p11tool may not NULL terminate the pin (as allowed by pkcs11) but
openssl assumes it is, so copy it into a NULL terminated string to
make sure.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
p11tool provides a number of useful token checks, so add them. This
gives us a dependency on gnutls for testing only.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
In spite of us listing multiple mechanisms it is hard coded only to
accept CKM_RSA_PKCS. Apparently the openssl pkcs11 engine doesn't
check this, but p11tool does, so return the correct information for
all mechanisms.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
It turns out that gnutls p11tool will open multiple sessions to the
token when checking signatures. This looks like a bug in p11tool, but
means we have to implement multiple sessions if we want to get the
tool to check signatures on our keys.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Currently, there can only be one outstanding find at once, which
violates the principles of pkcs11 operation because there may be one
find per session outstanding. Fix this by running find state through
the section cache.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Remove the fixed session limit and now make every session have an
entry in the cache. Keep to one allowable session per slot.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Fix make check on openssl 1.1.1a
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
The value of len must be set before being passed in to the signature
routine because certain versions of openssl won't just blindly set the
length.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* with per session logins, now seems to work in firefox pkcs11
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Having a global login parameter is a failure if we have more than one
key, so make logins local to the session using the presence of the
private key in the cache as an indicator of whether we are logged in
or not.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
The cache assumes that all the memory is fixed, which is usually true
because it's block allocated for the config file. However type
CACHE_PKEY is an exception because they're dynamically allocated, so
add a freeing function callback to make sure they're correctly freed
when no longer in use.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
PKCS#11 requires that all functions in the CK_FUNCTION_LIST have a
value, so add dummy functions for all the missing ones.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Seems that Mozilla uses this one
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
* Now builds on a variety of platforms
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Problems over size_t vs unsigned long mismatches.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Fix builds on older versions of openSUSE
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
openssl 1.0.2 has the following bugs and problems:
- pkeyutls pss signature verification will say the signature verified
OK but then returns a failure code
- have to use BUF_memdup not OPENSSL_memdup
- it will initialize and start any engine. This means the config file
for the token must be in place before any use of openssl. This had
the ancillary problem that pkcs11 doesn't like a module with no
token slots, so set a dummy empty slot for that case.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Since it's a comparatively recent addition to glibc and older OSs
won't have it.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
It looks like we finally have enough functionality to make a release.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
All tokens usually have a serial number so make sure we have one to
show as well. Ideally it is taken from the serial parameter of the
config file, but failing that we'll construct one from the sha256 hash
of the public key.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Add details of the config file as well as use case examples.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
- remove gnutls dependency (p11tool) it's only used for pretty output
- make openssl.cnf find the openssl-pkcs11 module directly
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
p11-kit requires a <thing>.module file which at least points to the
shared pkcs11 library to be installed in its module directory
otherwise it won't include the token in any of its iterations. Install
such a file for openssl-pkcs11.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
The difference between an engine and a PEM key is pretty minor: it's
the password processing, so create a minimal simple engine that reads
keys with a special guard and check that it gets the password right.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Add a suite of tests running through the relevant hashes for PSS and
OAEP to detect that we're passing the parameters correctly.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Even though we never do a hash, we need to know what the hash of the
signature was for the PSS algorithm to work correctly, so set that
information.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Simple key tests for with and without password of rsa
encryption/decryption and sign/verify.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
We already use p11-kit for the module path, so we might as well use it
for the definitions. Add a pkgconf check for the right version and
cope with a missing CKZ symbol (which was eventually added in a later
p11-kit version).
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Somewhat problematic because various versions of openssl have
different levels of support for this, but 1.1.0 supports them fully.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
also redo signatures so we only return the size for a null destination
argument.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
This completes the suite of functions necessary to make RSA private
keys functional with openssl.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
It turns out p11tool forgets to close a session, so allow up to two
concurrent sessions.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
The most of the CKA_XX attributes are shared between public and
private keys, but the booleans aren't because they mostly describe key
properties. For instance CKA_PRIVATE should only be set on private
keys. Fix this by updating the specification system to allow us to
show whether a given attribute belongs to the public or private key
(or both for some attributes).
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Apparently the openssl pkcs11 engine won't recognize us unless we
populate the slot flags with CKF_TOKEN_PRESENT, so do this and add
other slot info (the openssl engine prints out the slot strings not
the token strings when debugging)
With this, both
openssl rsa -text -engine pkcs11 -inform engine -pubin -in <URI>
and
p11tool --export <URI>
Work correctly on the public key URI to export the public key
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Make the library single threaded only, only allow one session and only
loads and finds the public key.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
So we can store quantities like CKA_MODULUS for public keys.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
So git status shows us files we care about rather than all the autoconf
created files
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Still no key functionality.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
Add a simple ini file parser that builds the token information from
the ini formatted config file. Still no key handling, but it does
work with p11-kit and p11tool to list the URIs (will crash if you try
to do any key functions).
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
No need to have an openssl- prefix the current file is simply a pkcs11
provider so call it pkcs11.c
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|
|
This commit represents just enough of pkcs11 to get p11-kit viably
showing urls for the fake token.
Signed-off-by: James Bottomley <James.Bottomley@HansenPartnership.com>
|