When producing the hex representation of values >= 2^52 make sure that
the value is in big endian format, so that the hex representation is
correct.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Add a check to ensure that structures are a multiple of the TTLV block
length. If thats not the case return an error early, and do not only
rely on parsing the structure elements to fail.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
if field 'tls_ca' is NULL in the connection config structure, the system's
default CA certificates are supposed to be loaded and used. This is
currently not done, leaving it with an empty certificate store and
any peer or hostname verification will fail.
Call SSL_CTX_set_default_verify_paths() to load the system's default CA
certificates.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Just resetting the OpenSSL BIO via BIO_reset() leaves the BIO in a state
where the next attempt to use it will reconnect to the server and perform
a TLS handshake freshly. However, this reconnect omits the checks done
by kmip_connection_tls_verify_server().
In case of any I/O failure tear down the connection completely to
avoid any reconnects.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
When a corrupted KMIP response contains KMIP nodes that are expected to
be of type TEXT-STRING, but they are of a different type, then function
kmip_node_get_text_string() returns NULL. Fix all callers to check
for such NULL returns and return -EBADMSG if so.
Not checking for NULL might cause NULL pointer dereferences in the
callers, or the callers further down the stack.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Although the fiends in 'sinfo[slot_no]' in question are usually NUL-terminated
(do_str() pads the string with NUL values), there is one case where it is not
NUL-terminated: when the string length matches the target field length.
Use the 'str' variable, which is always NUL-terminated for the checks.
Variable 'str' and the struct field are identical in value, using 'str'
is semantically equivalent, but eliminates the unterminated string usage.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
When writing the initial NVTOK.dat file fails before the file name is
set, the attempt to unlink the file uses an uninitialized variable name.
Initialize fname with zeros, and attempt the unlink only if the file name
was set before.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
For better scripting capabilities, the SO PIN and the RACF password can
optionally be supplied via options -R and -S. If not specified you are
prompted for them.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
If -slot is specified then create the new ICSF token at the given slot number.
Otherwise the next free slot is used.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
If relative file names are specified for the SASL key and certificates,
store the absolute path of them into the ICSF token config file.
This makes it location independent.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Use 'pkcsicsf -p <token-name>' to change the RACF password of an existing
ICSF token.
The pkcsicsf tool updates the RACF file under the XProcLock, so the ICSF
token must read the RACF file under the XProcLock. This prevents concurrent
reads on a RACF file that is currently modified.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Similar to the FIPS-compliant token data store format of the other tokens,
define a new token data store format for the ICSF token.
The new data format is used when the ICSF token has 'tokversion = 3.28'
in the slot definition in opencryptoki.conf. Existing ICSF tokens continue
to work unchanged. New ICSF tokens added via the pkcsicsf tool will always
have 'tokversion = 3.28' and thus use the new data format.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
The use of liblber has been eliminated for most of the cases already.
The only leftover cases are in RSA, DSA, and DH public key encoding
functions for encoding BIT STRINGs.
Update these leftover places and use the already existing
ber_encode_BIT_STRING() function instead.
With this, '-lber' can be removed from the make files for most of
the tokens and tools. The ICSF token still requires liblber for its
LDAP communication.
Also adjust the configure script and example RPM spec accordingly.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
In kmip_get_attribute_v1(), KMIP_TAG_ATTRIBUTE_NAME is retrieved by tag,
and the function stores the result of kmip_node_get_text_string(nam)
without rejecting a non-text node. kmip_node_get_text_string() returns
NULL on a type mismatch, so a malformed v1.x 'Attribute Name' can leave
name == NULL while kmip_get_attribute_v1() still returns success.
kmip_v2_attr_from_v1_attr() then dereferences name through strncmp().
Reported by: Aisle Research
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Include file mechtable-gen.h is generated, and thus needs statements
in the make file.
Fixes: 7174f72dc6
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Allow that the adapter and domain values can be specified in decimal
(as before), but also in hex, like the man page states already.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Wrap key attributes can only come from the config file. Verify they were
set regardless of whether a config file was found.
Also remove the unused define P11KMIP_CONFIG_KEYWORD_PORT. The port
number can be specified as part of the host setting.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Using pkcsicsf with '-a all' adds all available ICSF tokens. Mention this in
the man page.
For each added token, pkcsicsf prompts for the SO pin to set. Mention the
token name for which the SO pin is prompted.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Besides the token directory, also the corresponding lock directory must
be created. If this is not done, then the pkcsslotd might do so during
startup, but only if it is stared as root.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Currently the ICSF token is added using 'pkcsicsf -a' and the default
SO pin (87654321) must be used with it. Only then a subsequent setting
of the SO pin via 'pkcsconf -P' works (where the old pin is also the
default SO pin).
The reason for this is that 'pkcsicsf -a' does not create a NVTOK.dat,
and thus, when the token comes up the very first time, the NVTOK.dat
is created, but with the SO default pin. This happens for example
during 'pkcsconf -P', before the new PIN is set.
Update pkcsicsf tool to also create an initial NVTOK.dat file which
contains the hash of the user supplied SO pin. Thus, any SO pin can
be used with 'pkcsicsf -a', and this already sets the SO pin.
The initial NVTOK.dat is a too short version, and will be written in
its full length on the very first use of the token.
With this change no subsequent 'pkcsconf -P' is required (but possible),
the desired SO pin is already set and the token is already initialized.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Refactor the code to use file descriptor operations relative to the directory
(e.g. openat(), unlinkat(), fstatat(), renameat()) instead of path based
operations. This is safer against TOCTOU issues and symlink-following
attacks where the files or directories are replaced after the check, but
before the path based operation on it.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Refactor the code to use file descriptor operations relative to the directory
(e.g. openat(), unlinkat(), fstatat(), renameat()) instead of path based
operations. This is safer against TOCTOU issues and symlink-following
attacks where the files or directories are replaced after the check, but
before the path based operation on it.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Function p11kmip_unwrap_local_secret_key() may leak memory when an
unsupported wrapping method is used.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Retrieving an RSA public key with KMIP_KEY_FORMAT_TYPE_TRANSPARENT_RSA_PUBLIC_KEY
can never have worked. Implement it correctly.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
For import, the private seed is obtained via p11tool_get_octet_string_param_from_pkey()
but is not freed at the end of the import functions.
For export the private seed is allocated but never freed.
Fixes: 5e27911d0a
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
If p11tool_get_attribute() allocated a value buffer, but it then fails
to obtain the attribute value, free the allocated buffer and set
pValue = NULL and ulValueLen = 0.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Limit the p11tool_bio_readall() to read only up to 64 MB. That is far
more than any realistic wrapped key or opaque blob.
While at it, fix the use of OPENSSL_free() instead of free().
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>
Use fstat() on the already opened file to avoid a TOCTOU issue.
While at it also cleanse the clear key data on error path.
Signed-off-by: Ingo Franzki <ifranzki@linux.ibm.com>