securid: Decode a couple of new fields

Store the ctf's version code, as it affects the device ID decode logic.
Use descriptive names for the "app-derived seeds" and "time-derived seeds"
flags.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: Improve handling of device-bound tokens

TokenConverter allows a DeviceSerialNumber that is longer than the
40-byte (smartphone) or 32-byte (feature phone) limit, so we should
accept ctf strings that were generated from an sdtid file containing
such a device ID, and perform the appropriate truncation inside the
library.

TokenConverter also automatically converts the DeviceSerialNumber to
uppercase, even if it was lowercase in the sdtid file.  We will have the
library perform the same conversion.

fixes #3

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Add libxml2 dependency for parsing sdtid files

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: Export AES functions so sdtid.c can use them

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
common: Add new error codes

The sdtid code will use a lot more dynamically allocated memory, so we
might as well have a semi-reliable way to report allocation failures.

Other new error codes involve sdtid files containing multiple tokens,
and better reporting of "file not found" situations.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
common: For --file, read the entire file at once

Parsing line-by-line will not work for sdtid XML files, so just read the
whole file into a buffer and scan each line until we see something
familiar.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
common: Improve error messages for file-related problems

Change "General failure" to "Cannot read file" if a "--file" parameter
cannot be opened or read.  Provide a helpful message if the user tries
to import an sdtid file that has more than one token.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Add skeleton implementation

Call sdtid_decode_sdtid() if we see a file starting with "<?xml ".
Currently doesn't do anything.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Initial commit of parsing/decoding logic

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: Add "paranoid" RNG option

If we're going to be issuing new tokens for production use, make sure
the keys come from a high quality entropy source.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
common: Call fclose() on read error

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Enhance XML utility functions

The lookup_* functions will now perform a recursive lookup in order to
handle the TokenAttributes node.  Fortunately every node in this document
format has a unique name so there are no conflicts.

Add a replace_string() function used to build new sdtid documents.

And add a node_present() function used to determine whether a field is
present in a template document.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
cli: Add infrastructure for new sdtid output commands

New commands are:

stoken issue [ --template=<FILE> ] [ --new-password=<PASSWORD> ]
stoken export --sdtid [ --template=<FILE> ]

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Split generate_keys() out of securid_decrypt_sdtid()

We need to generate keys for both decrypt and encrypt, so make it a
common function.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: Allow parse_sdtid() to work in a "less strict" mode

Template files are allowed to be missing entire sections, so enable strict
mode for a real sdtid but disable it for "stoken issue --template=foo"

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
securid: Switch to the reentrant version of gmtime()

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
sdtid: "stoken issue" and "stoken export --sdtid" are functional

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Move feature test macros into config.h

For now we'll use AC_GNU_SOURCE.  To be revisited later.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Enable AM_SILENT_RULES

This makes it much easier to notice warnings.

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>
autoconf: Use AS_COMPILER_FLAGS to set -W flags

Signed-off-by: Kevin Cernekee <cernekee@gmail.com>