README.ENGINE 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. ENGINE
  2. ======
  3. With OpenSSL 0.9.6, a new component was added to support alternative
  4. cryptography implementations, most commonly for interfacing with external
  5. crypto devices (eg. accelerator cards). This component is called ENGINE,
  6. and its presence in OpenSSL 0.9.6 (and subsequent bug-fix releases)
  7. caused a little confusion as 0.9.6** releases were rolled in two
  8. versions, a "standard" and an "engine" version. In development for 0.9.7,
  9. the ENGINE code has been merged into the main branch and will be present
  10. in the standard releases from 0.9.7 forwards.
  11. There are currently built-in ENGINE implementations for the following
  12. crypto devices:
  13. o CryptoSwift
  14. o Compaq Atalla
  15. o nCipher CHIL
  16. o Nuron
  17. o Broadcom uBSec
  18. In addition, dynamic binding to external ENGINE implementations is now
  19. provided by a special ENGINE called "dynamic". See the "DYNAMIC ENGINE"
  20. section below for details.
  21. At this stage, a number of things are still needed and are being worked on:
  22. 1 Integration of EVP support.
  23. 2 Configuration support.
  24. 3 Documentation!
  25. 1 With respect to EVP, this relates to support for ciphers and digests in
  26. the ENGINE model so that alternative implementations of existing
  27. algorithms/modes (or previously unimplemented ones) can be provided by
  28. ENGINE implementations.
  29. 2 Configuration support currently exists in the ENGINE API itself, in the
  30. form of "control commands". These allow an application to expose to the
  31. user/admin the set of commands and parameter types a given ENGINE
  32. implementation supports, and for an application to directly feed string
  33. based input to those ENGINEs, in the form of name-value pairs. This is an
  34. extensible way for ENGINEs to define their own "configuration" mechanisms
  35. that are specific to a given ENGINE (eg. for a particular hardware
  36. device) but that should be consistent across *all* OpenSSL-based
  37. applications when they use that ENGINE. Work is in progress (or at least
  38. in planning) for supporting these control commands from the CONF (or
  39. NCONF) code so that applications using OpenSSL's existing configuration
  40. file format can have ENGINE settings specified in much the same way.
  41. Presently however, applications must use the ENGINE API itself to provide
  42. such functionality. To see first hand the types of commands available
  43. with the various compiled-in ENGINEs (see further down for dynamic
  44. ENGINEs), use the "engine" openssl utility with full verbosity, ie;
  45. openssl engine -vvvv
  46. 3 Documentation? Volunteers welcome! The source code is reasonably well
  47. self-documenting, but some summaries and usage instructions are needed -
  48. moreover, they are needed in the same POD format the existing OpenSSL
  49. documentation is provided in. Any complete or incomplete contributions
  50. would help make this happen.
  51. STABILITY & BUG-REPORTS
  52. =======================
  53. What already exists is fairly stable as far as it has been tested, but
  54. the test base has been a bit small most of the time. For the most part,
  55. the vendors of the devices these ENGINEs support have contributed to the
  56. development and/or testing of the implementations, and *usually* (with no
  57. guarantees) have experience in using the ENGINE support to drive their
  58. devices from common OpenSSL-based applications. Bugs and/or inexplicable
  59. behaviour in using a specific ENGINE implementation should be sent to the
  60. author of that implementation (if it is mentioned in the corresponding C
  61. file), and in the case of implementations for commercial hardware
  62. devices, also through whatever vendor support channels are available. If
  63. none of this is possible, or the problem seems to be something about the
  64. ENGINE API itself (ie. not necessarily specific to a particular ENGINE
  65. implementation) then you should mail complete details to the relevant
  66. OpenSSL mailing list. For a definition of "complete details", refer to
  67. the OpenSSL "README" file. As for which list to send it to;
  68. openssl-users: if you are *using* the ENGINE abstraction, either in an
  69. pre-compiled application or in your own application code.
  70. openssl-dev: if you are discussing problems with OpenSSL source code.
  71. USAGE
  72. =====
  73. The default "openssl" ENGINE is always chosen when performing crypto
  74. operations unless you specify otherwise. You must actively tell the
  75. openssl utility commands to use anything else through a new command line
  76. switch called "-engine". Also, if you want to use the ENGINE support in
  77. your own code to do something similar, you must likewise explicitly
  78. select the ENGINE implementation you want.
  79. Depending on the type of hardware, system, and configuration, "settings"
  80. may need to be applied to an ENGINE for it to function as expected/hoped.
  81. The recommended way of doing this is for the application to support
  82. ENGINE "control commands" so that each ENGINE implementation can provide
  83. whatever configuration primitives it might require and the application
  84. can allow the user/admin (and thus the hardware vendor's support desk
  85. also) to provide any such input directly to the ENGINE implementation.
  86. This way, applications do not need to know anything specific to any
  87. device, they only need to provide the means to carry such user/admin
  88. input through to the ENGINE in question. Ie. this connects *you* (and
  89. your helpdesk) to the specific ENGINE implementation (and device), and
  90. allows application authors to not get buried in hassle supporting
  91. arbitrary devices they know (and care) nothing about.
  92. A new "openssl" utility, "openssl engine", has been added in that allows
  93. for testing and examination of ENGINE implementations. Basic usage
  94. instructions are available by specifying the "-?" command line switch.
  95. DYNAMIC ENGINES
  96. ===============
  97. The new "dynamic" ENGINE provides a low-overhead way to support ENGINE
  98. implementations that aren't pre-compiled and linked into OpenSSL-based
  99. applications. This could be because existing compiled-in implementations
  100. have known problems and you wish to use a newer version with an existing
  101. application. It could equally be because the application (or OpenSSL
  102. library) you are using simply doesn't have support for the ENGINE you
  103. wish to use, and the ENGINE provider (eg. hardware vendor) is providing
  104. you with a self-contained implementation in the form of a shared-library.
  105. The other use-case for "dynamic" is with applications that wish to
  106. maintain the smallest foot-print possible and so do not link in various
  107. ENGINE implementations from OpenSSL, but instead leaves you to provide
  108. them, if you want them, in the form of "dynamic"-loadable
  109. shared-libraries. It should be possible for hardware vendors to provide
  110. their own shared-libraries to support arbitrary hardware to work with
  111. applications based on OpenSSL 0.9.7 or later. If you're using an
  112. application based on 0.9.7 (or later) and the support you desire is only
  113. announced for versions later than the one you need, ask the vendor to
  114. backport their ENGINE to the version you need.
  115. How does "dynamic" work?
  116. ------------------------
  117. The dynamic ENGINE has a special flag in its implementation such that
  118. every time application code asks for the 'dynamic' ENGINE, it in fact
  119. gets its own copy of it. As such, multi-threaded code (or code that
  120. multiplexes multiple uses of 'dynamic' in a single application in any
  121. way at all) does not get confused by 'dynamic' being used to do many
  122. independent things. Other ENGINEs typically don't do this so there is
  123. only ever 1 ENGINE structure of its type (and reference counts are used
  124. to keep order). The dynamic ENGINE itself provides absolutely no
  125. cryptographic functionality, and any attempt to "initialise" the ENGINE
  126. automatically fails. All it does provide are a few "control commands"
  127. that can be used to control how it will load an external ENGINE
  128. implementation from a shared-library. To see these control commands,
  129. use the command-line;
  130. openssl engine -vvvv dynamic
  131. The "SO_PATH" control command should be used to identify the
  132. shared-library that contains the ENGINE implementation, and "NO_VCHECK"
  133. might possibly be useful if there is a minor version conflict and you
  134. (or a vendor helpdesk) is convinced you can safely ignore it.
  135. "ID" is probably only needed if a shared-library implements
  136. multiple ENGINEs, but if you know the engine id you expect to be using,
  137. it doesn't hurt to specify it (and this provides a sanity check if
  138. nothing else). "LIST_ADD" is only required if you actually wish the
  139. loaded ENGINE to be discoverable by application code later on using the
  140. ENGINE's "id". For most applications, this isn't necessary - but some
  141. application authors may have nifty reasons for using it. The "LOAD"
  142. command is the only one that takes no parameters and is the command
  143. that uses the settings from any previous commands to actually *load*
  144. the shared-library ENGINE implementation. If this command succeeds, the
  145. (copy of the) 'dynamic' ENGINE will magically morph into the ENGINE
  146. that has been loaded from the shared-library. As such, any control
  147. commands supported by the loaded ENGINE could then be executed as per
  148. normal. Eg. if ENGINE "foo" is implemented in the shared-library
  149. "libfoo.so" and it supports some special control command "CMD_FOO", the
  150. following code would load and use it (NB: obviously this code has no
  151. error checking);
  152. ENGINE *e = ENGINE_by_id("dynamic");
  153. ENGINE_ctrl_cmd_string(e, "SO_PATH", "/lib/libfoo.so", 0);
  154. ENGINE_ctrl_cmd_string(e, "ID", "foo", 0);
  155. ENGINE_ctrl_cmd_string(e, "LOAD", NULL, 0);
  156. ENGINE_ctrl_cmd_string(e, "CMD_FOO", "some input data", 0);
  157. For testing, the "openssl engine" utility can be useful for this sort
  158. of thing. For example the above code excerpt would achieve much the
  159. same result as;
  160. openssl engine dynamic \
  161. -pre SO_PATH:/lib/libfoo.so \
  162. -pre ID:foo \
  163. -pre LOAD \
  164. -pre "CMD_FOO:some input data"
  165. Or to simply see the list of commands supported by the "foo" ENGINE;
  166. openssl engine -vvvv dynamic \
  167. -pre SO_PATH:/lib/libfoo.so \
  168. -pre ID:foo \
  169. -pre LOAD
  170. Applications that support the ENGINE API and more specifically, the
  171. "control commands" mechanism, will provide some way for you to pass
  172. such commands through to ENGINEs. As such, you would select "dynamic"
  173. as the ENGINE to use, and the parameters/commands you pass would
  174. control the *actual* ENGINE used. Each command is actually a name-value
  175. pair and the value can sometimes be omitted (eg. the "LOAD" command).
  176. Whilst the syntax demonstrated in "openssl engine" uses a colon to
  177. separate the command name from the value, applications may provide
  178. their own syntax for making that separation (eg. a win32 registry
  179. key-value pair may be used by some applications). The reason for the
  180. "-pre" syntax in the "openssl engine" utility is that some commands
  181. might be issued to an ENGINE *after* it has been initialised for use.
  182. Eg. if an ENGINE implementation requires a smart-card to be inserted
  183. during initialisation (or a PIN to be typed, or whatever), there may be
  184. a control command you can issue afterwards to "forget" the smart-card
  185. so that additional initialisation is no longer possible. In
  186. applications such as web-servers, where potentially volatile code may
  187. run on the same host system, this may provide some arguable security
  188. value. In such a case, the command would be passed to the ENGINE after
  189. it has been initialised for use, and so the "-post" switch would be
  190. used instead. Applications may provide a different syntax for
  191. supporting this distinction, and some may simply not provide it at all
  192. ("-pre" is almost always what you're after, in reality).
  193. How do I build a "dynamic" ENGINE?
  194. ----------------------------------
  195. This question is trickier - currently OpenSSL bundles various ENGINE
  196. implementations that are statically built in, and any application that
  197. calls the "ENGINE_load_builtin_engines()" function will automatically
  198. have all such ENGINEs available (and occupying memory). Applications
  199. that don't call that function have no ENGINEs available like that and
  200. would have to use "dynamic" to load any such ENGINE - but on the other
  201. hand such applications would only have the memory footprint of any
  202. ENGINEs explicitly loaded using user/admin provided control commands.
  203. The main advantage of not statically linking ENGINEs and only using
  204. "dynamic" for hardware support is that any installation using no
  205. "external" ENGINE suffers no unnecessary memory footprint from unused
  206. ENGINEs. Likewise, installations that do require an ENGINE incur the
  207. overheads from only *that* ENGINE once it has been loaded.
  208. Sounds good? Maybe, but currently building an ENGINE implementation as
  209. a shared-library that can be loaded by "dynamic" isn't automated in
  210. OpenSSL's build process. It can be done manually quite easily however.
  211. Such a shared-library can either be built with any OpenSSL code it
  212. needs statically linked in, or it can link dynamically against OpenSSL
  213. if OpenSSL itself is built as a shared library. The instructions are
  214. the same in each case, but in the former (statically linked any
  215. dependencies on OpenSSL) you must ensure OpenSSL is built with
  216. position-independent code ("PIC"). The default OpenSSL compilation may
  217. already specify the relevant flags to do this, but you should consult
  218. with your compiler documentation if you are in any doubt.
  219. This example will show building the "atalla" ENGINE in the
  220. crypto/engine/ directory as a shared-library for use via the "dynamic"
  221. ENGINE.
  222. 1) "cd" to the crypto/engine/ directory of a pre-compiled OpenSSL
  223. source tree.
  224. 2) Recompile at least one source file so you can see all the compiler
  225. flags (and syntax) being used to build normally. Eg;
  226. touch hw_atalla.c ; make
  227. will rebuild "hw_atalla.o" using all such flags.
  228. 3) Manually enter the same compilation line to compile the
  229. "hw_atalla.c" file but with the following two changes;
  230. (a) add "-DENGINE_DYNAMIC_SUPPORT" to the command line switches,
  231. (b) change the output file from "hw_atalla.o" to something new,
  232. eg. "tmp_atalla.o"
  233. 4) Link "tmp_atalla.o" into a shared-library using the top-level
  234. OpenSSL libraries to resolve any dependencies. The syntax for doing
  235. this depends heavily on your system/compiler and is a nightmare
  236. known well to anyone who has worked with shared-library portability
  237. before. 'gcc' on Linux, for example, would use the following syntax;
  238. gcc -shared -o dyn_atalla.so tmp_atalla.o -L../.. -lcrypto
  239. 5) Test your shared library using "openssl engine" as explained in the
  240. previous section. Eg. from the top-level directory, you might try;
  241. apps/openssl engine -vvvv dynamic \
  242. -pre SO_PATH:./crypto/engine/dyn_atalla.so -pre LOAD
  243. If the shared-library loads successfully, you will see both "-pre"
  244. commands marked as "SUCCESS" and the list of control commands
  245. displayed (because of "-vvvv") will be the control commands for the
  246. *atalla* ENGINE (ie. *not* the 'dynamic' ENGINE). You can also add
  247. the "-t" switch to the utility if you want it to try and initialise
  248. the atalla ENGINE for use to test any possible hardware/driver
  249. issues.
  250. PROBLEMS
  251. ========
  252. It seems like the ENGINE part doesn't work too well with CryptoSwift on Win32.
  253. A quick test done right before the release showed that trying "openssl speed
  254. -engine cswift" generated errors. If the DSO gets enabled, an attempt is made
  255. to write at memory address 0x00000002.