|
Packit Service |
084de1 |
ENGINE
|
|
Packit Service |
084de1 |
======
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
With OpenSSL 0.9.6, a new component was added to support alternative
|
|
Packit Service |
084de1 |
cryptography implementations, most commonly for interfacing with external
|
|
Packit Service |
084de1 |
crypto devices (eg. accelerator cards). This component is called ENGINE,
|
|
Packit Service |
084de1 |
and its presence in OpenSSL 0.9.6 (and subsequent bug-fix releases)
|
|
Packit Service |
084de1 |
caused a little confusion as 0.9.6** releases were rolled in two
|
|
Packit Service |
084de1 |
versions, a "standard" and an "engine" version. In development for 0.9.7,
|
|
Packit Service |
084de1 |
the ENGINE code has been merged into the main branch and will be present
|
|
Packit Service |
084de1 |
in the standard releases from 0.9.7 forwards.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
There are currently built-in ENGINE implementations for the following
|
|
Packit Service |
084de1 |
crypto devices:
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
o Microsoft CryptoAPI
|
|
Packit Service |
084de1 |
o VIA Padlock
|
|
Packit Service |
084de1 |
o nCipher CHIL
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
In addition, dynamic binding to external ENGINE implementations is now
|
|
Packit Service |
084de1 |
provided by a special ENGINE called "dynamic". See the "DYNAMIC ENGINE"
|
|
Packit Service |
084de1 |
section below for details.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
At this stage, a number of things are still needed and are being worked on:
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
1 Integration of EVP support.
|
|
Packit Service |
084de1 |
2 Configuration support.
|
|
Packit Service |
084de1 |
3 Documentation!
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
1 With respect to EVP, this relates to support for ciphers and digests in
|
|
Packit Service |
084de1 |
the ENGINE model so that alternative implementations of existing
|
|
Packit Service |
084de1 |
algorithms/modes (or previously unimplemented ones) can be provided by
|
|
Packit Service |
084de1 |
ENGINE implementations.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
2 Configuration support currently exists in the ENGINE API itself, in the
|
|
Packit Service |
084de1 |
form of "control commands". These allow an application to expose to the
|
|
Packit Service |
084de1 |
user/admin the set of commands and parameter types a given ENGINE
|
|
Packit Service |
084de1 |
implementation supports, and for an application to directly feed string
|
|
Packit Service |
084de1 |
based input to those ENGINEs, in the form of name-value pairs. This is an
|
|
Packit Service |
084de1 |
extensible way for ENGINEs to define their own "configuration" mechanisms
|
|
Packit Service |
084de1 |
that are specific to a given ENGINE (eg. for a particular hardware
|
|
Packit Service |
084de1 |
device) but that should be consistent across *all* OpenSSL-based
|
|
Packit Service |
084de1 |
applications when they use that ENGINE. Work is in progress (or at least
|
|
Packit Service |
084de1 |
in planning) for supporting these control commands from the CONF (or
|
|
Packit Service |
084de1 |
NCONF) code so that applications using OpenSSL's existing configuration
|
|
Packit Service |
084de1 |
file format can have ENGINE settings specified in much the same way.
|
|
Packit Service |
084de1 |
Presently however, applications must use the ENGINE API itself to provide
|
|
Packit Service |
084de1 |
such functionality. To see first hand the types of commands available
|
|
Packit Service |
084de1 |
with the various compiled-in ENGINEs (see further down for dynamic
|
|
Packit Service |
084de1 |
ENGINEs), use the "engine" openssl utility with full verbosity, ie;
|
|
Packit Service |
084de1 |
openssl engine -vvvv
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
3 Documentation? Volunteers welcome! The source code is reasonably well
|
|
Packit Service |
084de1 |
self-documenting, but some summaries and usage instructions are needed -
|
|
Packit Service |
084de1 |
moreover, they are needed in the same POD format the existing OpenSSL
|
|
Packit Service |
084de1 |
documentation is provided in. Any complete or incomplete contributions
|
|
Packit Service |
084de1 |
would help make this happen.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
STABILITY & BUG-REPORTS
|
|
Packit Service |
084de1 |
=======================
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
What already exists is fairly stable as far as it has been tested, but
|
|
Packit Service |
084de1 |
the test base has been a bit small most of the time. For the most part,
|
|
Packit Service |
084de1 |
the vendors of the devices these ENGINEs support have contributed to the
|
|
Packit Service |
084de1 |
development and/or testing of the implementations, and *usually* (with no
|
|
Packit Service |
084de1 |
guarantees) have experience in using the ENGINE support to drive their
|
|
Packit Service |
084de1 |
devices from common OpenSSL-based applications. Bugs and/or inexplicable
|
|
Packit Service |
084de1 |
behaviour in using a specific ENGINE implementation should be sent to the
|
|
Packit Service |
084de1 |
author of that implementation (if it is mentioned in the corresponding C
|
|
Packit Service |
084de1 |
file), and in the case of implementations for commercial hardware
|
|
Packit Service |
084de1 |
devices, also through whatever vendor support channels are available. If
|
|
Packit Service |
084de1 |
none of this is possible, or the problem seems to be something about the
|
|
Packit Service |
084de1 |
ENGINE API itself (ie. not necessarily specific to a particular ENGINE
|
|
Packit Service |
084de1 |
implementation) then you should mail complete details to the relevant
|
|
Packit Service |
084de1 |
OpenSSL mailing list. For a definition of "complete details", refer to
|
|
Packit Service |
084de1 |
the OpenSSL "README" file. As for which list to send it to;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
openssl-users: if you are *using* the ENGINE abstraction, either in an
|
|
Packit Service |
084de1 |
pre-compiled application or in your own application code.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
openssl-dev: if you are discussing problems with OpenSSL source code.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
USAGE
|
|
Packit Service |
084de1 |
=====
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
The default "openssl" ENGINE is always chosen when performing crypto
|
|
Packit Service |
084de1 |
operations unless you specify otherwise. You must actively tell the
|
|
Packit Service |
084de1 |
openssl utility commands to use anything else through a new command line
|
|
Packit Service |
084de1 |
switch called "-engine". Also, if you want to use the ENGINE support in
|
|
Packit Service |
084de1 |
your own code to do something similar, you must likewise explicitly
|
|
Packit Service |
084de1 |
select the ENGINE implementation you want.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
Depending on the type of hardware, system, and configuration, "settings"
|
|
Packit Service |
084de1 |
may need to be applied to an ENGINE for it to function as expected/hoped.
|
|
Packit Service |
084de1 |
The recommended way of doing this is for the application to support
|
|
Packit Service |
084de1 |
ENGINE "control commands" so that each ENGINE implementation can provide
|
|
Packit Service |
084de1 |
whatever configuration primitives it might require and the application
|
|
Packit Service |
084de1 |
can allow the user/admin (and thus the hardware vendor's support desk
|
|
Packit Service |
084de1 |
also) to provide any such input directly to the ENGINE implementation.
|
|
Packit Service |
084de1 |
This way, applications do not need to know anything specific to any
|
|
Packit Service |
084de1 |
device, they only need to provide the means to carry such user/admin
|
|
Packit Service |
084de1 |
input through to the ENGINE in question. Ie. this connects *you* (and
|
|
Packit Service |
084de1 |
your helpdesk) to the specific ENGINE implementation (and device), and
|
|
Packit Service |
084de1 |
allows application authors to not get buried in hassle supporting
|
|
Packit Service |
084de1 |
arbitrary devices they know (and care) nothing about.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
A new "openssl" utility, "openssl engine", has been added in that allows
|
|
Packit Service |
084de1 |
for testing and examination of ENGINE implementations. Basic usage
|
|
Packit Service |
084de1 |
instructions are available by specifying the "-?" command line switch.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
DYNAMIC ENGINES
|
|
Packit Service |
084de1 |
===============
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
The new "dynamic" ENGINE provides a low-overhead way to support ENGINE
|
|
Packit Service |
084de1 |
implementations that aren't pre-compiled and linked into OpenSSL-based
|
|
Packit Service |
084de1 |
applications. This could be because existing compiled-in implementations
|
|
Packit Service |
084de1 |
have known problems and you wish to use a newer version with an existing
|
|
Packit Service |
084de1 |
application. It could equally be because the application (or OpenSSL
|
|
Packit Service |
084de1 |
library) you are using simply doesn't have support for the ENGINE you
|
|
Packit Service |
084de1 |
wish to use, and the ENGINE provider (eg. hardware vendor) is providing
|
|
Packit Service |
084de1 |
you with a self-contained implementation in the form of a shared-library.
|
|
Packit Service |
084de1 |
The other use-case for "dynamic" is with applications that wish to
|
|
Packit Service |
084de1 |
maintain the smallest foot-print possible and so do not link in various
|
|
Packit Service |
084de1 |
ENGINE implementations from OpenSSL, but instead leaves you to provide
|
|
Packit Service |
084de1 |
them, if you want them, in the form of "dynamic"-loadable
|
|
Packit Service |
084de1 |
shared-libraries. It should be possible for hardware vendors to provide
|
|
Packit Service |
084de1 |
their own shared-libraries to support arbitrary hardware to work with
|
|
Packit Service |
084de1 |
applications based on OpenSSL 0.9.7 or later. If you're using an
|
|
Packit Service |
084de1 |
application based on 0.9.7 (or later) and the support you desire is only
|
|
Packit Service |
084de1 |
announced for versions later than the one you need, ask the vendor to
|
|
Packit Service |
084de1 |
backport their ENGINE to the version you need.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
How does "dynamic" work?
|
|
Packit Service |
084de1 |
------------------------
|
|
Packit Service |
084de1 |
The dynamic ENGINE has a special flag in its implementation such that
|
|
Packit Service |
084de1 |
every time application code asks for the 'dynamic' ENGINE, it in fact
|
|
Packit Service |
084de1 |
gets its own copy of it. As such, multi-threaded code (or code that
|
|
Packit Service |
084de1 |
multiplexes multiple uses of 'dynamic' in a single application in any
|
|
Packit Service |
084de1 |
way at all) does not get confused by 'dynamic' being used to do many
|
|
Packit Service |
084de1 |
independent things. Other ENGINEs typically don't do this so there is
|
|
Packit Service |
084de1 |
only ever 1 ENGINE structure of its type (and reference counts are used
|
|
Packit Service |
084de1 |
to keep order). The dynamic ENGINE itself provides absolutely no
|
|
Packit Service |
084de1 |
cryptographic functionality, and any attempt to "initialise" the ENGINE
|
|
Packit Service |
084de1 |
automatically fails. All it does provide are a few "control commands"
|
|
Packit Service |
084de1 |
that can be used to control how it will load an external ENGINE
|
|
Packit Service |
084de1 |
implementation from a shared-library. To see these control commands,
|
|
Packit Service |
084de1 |
use the command-line;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
openssl engine -vvvv dynamic
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
The "SO_PATH" control command should be used to identify the
|
|
Packit Service |
084de1 |
shared-library that contains the ENGINE implementation, and "NO_VCHECK"
|
|
Packit Service |
084de1 |
might possibly be useful if there is a minor version conflict and you
|
|
Packit Service |
084de1 |
(or a vendor helpdesk) is convinced you can safely ignore it.
|
|
Packit Service |
084de1 |
"ID" is probably only needed if a shared-library implements
|
|
Packit Service |
084de1 |
multiple ENGINEs, but if you know the engine id you expect to be using,
|
|
Packit Service |
084de1 |
it doesn't hurt to specify it (and this provides a sanity check if
|
|
Packit Service |
084de1 |
nothing else). "LIST_ADD" is only required if you actually wish the
|
|
Packit Service |
084de1 |
loaded ENGINE to be discoverable by application code later on using the
|
|
Packit Service |
084de1 |
ENGINE's "id". For most applications, this isn't necessary - but some
|
|
Packit Service |
084de1 |
application authors may have nifty reasons for using it. The "LOAD"
|
|
Packit Service |
084de1 |
command is the only one that takes no parameters and is the command
|
|
Packit Service |
084de1 |
that uses the settings from any previous commands to actually *load*
|
|
Packit Service |
084de1 |
the shared-library ENGINE implementation. If this command succeeds, the
|
|
Packit Service |
084de1 |
(copy of the) 'dynamic' ENGINE will magically morph into the ENGINE
|
|
Packit Service |
084de1 |
that has been loaded from the shared-library. As such, any control
|
|
Packit Service |
084de1 |
commands supported by the loaded ENGINE could then be executed as per
|
|
Packit Service |
084de1 |
normal. Eg. if ENGINE "foo" is implemented in the shared-library
|
|
Packit Service |
084de1 |
"libfoo.so" and it supports some special control command "CMD_FOO", the
|
|
Packit Service |
084de1 |
following code would load and use it (NB: obviously this code has no
|
|
Packit Service |
084de1 |
error checking);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
ENGINE *e = ENGINE_by_id("dynamic");
|
|
Packit Service |
084de1 |
ENGINE_ctrl_cmd_string(e, "SO_PATH", "/lib/libfoo.so", 0);
|
|
Packit Service |
084de1 |
ENGINE_ctrl_cmd_string(e, "ID", "foo", 0);
|
|
Packit Service |
084de1 |
ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0);
|
|
Packit Service |
084de1 |
ENGINE_ctrl_cmd_string(e, "CMD_FOO", "some input data", 0);
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
For testing, the "openssl engine" utility can be useful for this sort
|
|
Packit Service |
084de1 |
of thing. For example the above code excerpt would achieve much the
|
|
Packit Service |
084de1 |
same result as;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
openssl engine dynamic \
|
|
Packit Service |
084de1 |
-pre SO_PATH:/lib/libfoo.so \
|
|
Packit Service |
084de1 |
-pre ID:foo \
|
|
Packit Service |
084de1 |
-pre LOAD \
|
|
Packit Service |
084de1 |
-pre "CMD_FOO:some input data"
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
Or to simply see the list of commands supported by the "foo" ENGINE;
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
openssl engine -vvvv dynamic \
|
|
Packit Service |
084de1 |
-pre SO_PATH:/lib/libfoo.so \
|
|
Packit Service |
084de1 |
-pre ID:foo \
|
|
Packit Service |
084de1 |
-pre LOAD
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
Applications that support the ENGINE API and more specifically, the
|
|
Packit Service |
084de1 |
"control commands" mechanism, will provide some way for you to pass
|
|
Packit Service |
084de1 |
such commands through to ENGINEs. As such, you would select "dynamic"
|
|
Packit Service |
084de1 |
as the ENGINE to use, and the parameters/commands you pass would
|
|
Packit Service |
084de1 |
control the *actual* ENGINE used. Each command is actually a name-value
|
|
Packit Service |
084de1 |
pair and the value can sometimes be omitted (eg. the "LOAD" command).
|
|
Packit Service |
084de1 |
Whilst the syntax demonstrated in "openssl engine" uses a colon to
|
|
Packit Service |
084de1 |
separate the command name from the value, applications may provide
|
|
Packit Service |
084de1 |
their own syntax for making that separation (eg. a win32 registry
|
|
Packit Service |
084de1 |
key-value pair may be used by some applications). The reason for the
|
|
Packit Service |
084de1 |
"-pre" syntax in the "openssl engine" utility is that some commands
|
|
Packit Service |
084de1 |
might be issued to an ENGINE *after* it has been initialised for use.
|
|
Packit Service |
084de1 |
Eg. if an ENGINE implementation requires a smart-card to be inserted
|
|
Packit Service |
084de1 |
during initialisation (or a PIN to be typed, or whatever), there may be
|
|
Packit Service |
084de1 |
a control command you can issue afterwards to "forget" the smart-card
|
|
Packit Service |
084de1 |
so that additional initialisation is no longer possible. In
|
|
Packit Service |
084de1 |
applications such as web-servers, where potentially volatile code may
|
|
Packit Service |
084de1 |
run on the same host system, this may provide some arguable security
|
|
Packit Service |
084de1 |
value. In such a case, the command would be passed to the ENGINE after
|
|
Packit Service |
084de1 |
it has been initialised for use, and so the "-post" switch would be
|
|
Packit Service |
084de1 |
used instead. Applications may provide a different syntax for
|
|
Packit Service |
084de1 |
supporting this distinction, and some may simply not provide it at all
|
|
Packit Service |
084de1 |
("-pre" is almost always what you're after, in reality).
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
How do I build a "dynamic" ENGINE?
|
|
Packit Service |
084de1 |
----------------------------------
|
|
Packit Service |
084de1 |
This question is trickier - currently OpenSSL bundles various ENGINE
|
|
Packit Service |
084de1 |
implementations that are statically built in, and any application that
|
|
Packit Service |
084de1 |
calls the "ENGINE_load_builtin_engines()" function will automatically
|
|
Packit Service |
084de1 |
have all such ENGINEs available (and occupying memory). Applications
|
|
Packit Service |
084de1 |
that don't call that function have no ENGINEs available like that and
|
|
Packit Service |
084de1 |
would have to use "dynamic" to load any such ENGINE - but on the other
|
|
Packit Service |
084de1 |
hand such applications would only have the memory footprint of any
|
|
Packit Service |
084de1 |
ENGINEs explicitly loaded using user/admin provided control commands.
|
|
Packit Service |
084de1 |
The main advantage of not statically linking ENGINEs and only using
|
|
Packit Service |
084de1 |
"dynamic" for hardware support is that any installation using no
|
|
Packit Service |
084de1 |
"external" ENGINE suffers no unnecessary memory footprint from unused
|
|
Packit Service |
084de1 |
ENGINEs. Likewise, installations that do require an ENGINE incur the
|
|
Packit Service |
084de1 |
overheads from only *that* ENGINE once it has been loaded.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
Sounds good? Maybe, but currently building an ENGINE implementation as
|
|
Packit Service |
084de1 |
a shared-library that can be loaded by "dynamic" isn't automated in
|
|
Packit Service |
084de1 |
OpenSSL's build process. It can be done manually quite easily however.
|
|
Packit Service |
084de1 |
Such a shared-library can either be built with any OpenSSL code it
|
|
Packit Service |
084de1 |
needs statically linked in, or it can link dynamically against OpenSSL
|
|
Packit Service |
084de1 |
if OpenSSL itself is built as a shared library. The instructions are
|
|
Packit Service |
084de1 |
the same in each case, but in the former (statically linked any
|
|
Packit Service |
084de1 |
dependencies on OpenSSL) you must ensure OpenSSL is built with
|
|
Packit Service |
084de1 |
position-independent code ("PIC"). The default OpenSSL compilation may
|
|
Packit Service |
084de1 |
already specify the relevant flags to do this, but you should consult
|
|
Packit Service |
084de1 |
with your compiler documentation if you are in any doubt.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
This example will show building the "atalla" ENGINE in the
|
|
Packit Service |
084de1 |
crypto/engine/ directory as a shared-library for use via the "dynamic"
|
|
Packit Service |
084de1 |
ENGINE.
|
|
Packit Service |
084de1 |
1) "cd" to the crypto/engine/ directory of a pre-compiled OpenSSL
|
|
Packit Service |
084de1 |
source tree.
|
|
Packit Service |
084de1 |
2) Recompile at least one source file so you can see all the compiler
|
|
Packit Service |
084de1 |
flags (and syntax) being used to build normally. Eg;
|
|
Packit Service |
084de1 |
touch hw_atalla.c ; make
|
|
Packit Service |
084de1 |
will rebuild "hw_atalla.o" using all such flags.
|
|
Packit Service |
084de1 |
3) Manually enter the same compilation line to compile the
|
|
Packit Service |
084de1 |
"hw_atalla.c" file but with the following two changes;
|
|
Packit Service |
084de1 |
(a) add "-DENGINE_DYNAMIC_SUPPORT" to the command line switches,
|
|
Packit Service |
084de1 |
(b) change the output file from "hw_atalla.o" to something new,
|
|
Packit Service |
084de1 |
eg. "tmp_atalla.o"
|
|
Packit Service |
084de1 |
4) Link "tmp_atalla.o" into a shared-library using the top-level
|
|
Packit Service |
084de1 |
OpenSSL libraries to resolve any dependencies. The syntax for doing
|
|
Packit Service |
084de1 |
this depends heavily on your system/compiler and is a nightmare
|
|
Packit Service |
084de1 |
known well to anyone who has worked with shared-library portability
|
|
Packit Service |
084de1 |
before. 'gcc' on Linux, for example, would use the following syntax;
|
|
Packit Service |
084de1 |
gcc -shared -o dyn_atalla.so tmp_atalla.o -L../.. -lcrypto
|
|
Packit Service |
084de1 |
5) Test your shared library using "openssl engine" as explained in the
|
|
Packit Service |
084de1 |
previous section. Eg. from the top-level directory, you might try;
|
|
Packit Service |
084de1 |
apps/openssl engine -vvvv dynamic \
|
|
Packit Service |
084de1 |
-pre SO_PATH:./crypto/engine/dyn_atalla.so -pre LOAD
|
|
Packit Service |
084de1 |
If the shared-library loads successfully, you will see both "-pre"
|
|
Packit Service |
084de1 |
commands marked as "SUCCESS" and the list of control commands
|
|
Packit Service |
084de1 |
displayed (because of "-vvvv") will be the control commands for the
|
|
Packit Service |
084de1 |
*atalla* ENGINE (ie. *not* the 'dynamic' ENGINE). You can also add
|
|
Packit Service |
084de1 |
the "-t" switch to the utility if you want it to try and initialise
|
|
Packit Service |
084de1 |
the atalla ENGINE for use to test any possible hardware/driver
|
|
Packit Service |
084de1 |
issues.
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
PROBLEMS
|
|
Packit Service |
084de1 |
========
|
|
Packit Service |
084de1 |
|
|
Packit Service |
084de1 |
It seems like the ENGINE part doesn't work too well with CryptoSwift on Win32.
|
|
Packit Service |
084de1 |
A quick test done right before the release showed that trying "openssl speed
|
|
Packit Service |
084de1 |
-engine cswift" generated errors. If the DSO gets enabled, an attempt is made
|
|
Packit Service |
084de1 |
to write at memory address 0x00000002.
|
|
Packit Service |
084de1 |
|