A local copy of OpenSSL from GitHub
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

317 lines
15 KiB

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