Blame README.ENGINE

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