README.sslcerts 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  1. Lynx SSL support for certificates - README.sslcerts file
  2. BACKGROUND:
  3. The original README.ssl document for lynx stated:
  4. Note that the server... may not have a valid certificate. Lynx will not
  5. complain, as it does not yet support certificates...
  6. Such lack of support is no longer the case. Lynx now features excellent
  7. certificate management through the openssl project. There is almost no
  8. online documentation available regarding how to use openssl's certificate
  9. management with other programs, so this will accompany lynx and hopefully
  10. encourage good practical security for unix clients.
  11. Lynx relies on openssl to not only encrypt connections over https, but also to
  12. determine whether it should even accept a certificate and establish a secure
  13. connection with a remote host. Because of this reliance upon openssl by lynx,
  14. most of this tutorial deals with how to use openssl to "install" both
  15. vendor-provided CA cert bundles as well as self-signed certs from trusted sources
  16. and, most importantly, how to get them recognized by lynx.
  17. While lynx on many systems will transparently accept valid certificates, not
  18. all systems enjoy such functionality. Further, as noted above, older versions
  19. of lynx do not perform any validity checks on a certificate.
  20. There is also the common case of wanting to trust, use and install a
  21. self-signed certificate from a known server source and have it be trusted by
  22. client programs.
  23. Briefly, the procedure will involve confirming the default system location for
  24. certificates, setting values for SSL_CERT_DIR and SSL_CERT_FILE in
  25. the environment, and converting and hashing the certificates using openssl
  26. utilities to enable recognition.
  27. THE CURRENT SITUATION:
  28. Prior to lynx2.8.5dev9, lynx did not check at all for certificate validity.
  29. Since lynx2.8.5.dev9, lynx has reported this openssl error:
  30. SSL error:unable to get local issuer certificate-Continue? (y)
  31. whenever an https connection was initiated and the certificate could not be
  32. found, for whatever reason, by openssl, and therefore lynx.
  33. This checking for a certificate is an enhancement to security, but rather
  34. tediously generates errors at each https browser request.
  35. The ability to turn off reporting of this error to the user was added to
  36. lynx2.8.5dev16 as the FORCE_SSL_PROMPT setting in lynx.cfg as noted in the
  37. CHANGELOG:
  38. This lets the user decide whether to ignore prompting for questionable
  39. aspects of an SSL connection.
  40. While this is a convenient setting to employ when using lynx to script
  41. https -dumps, it by definition ignores the issue of certificate validity
  42. altogether. Those concerned with proper certificate management and
  43. the maintenance of a store of updated CA certificates will be uncomfortable
  44. with this relaxed security setting.
  45. The ability to accept a 'wildcard' certificate, where the first character
  46. is a '*' was added to lynx2.8.6dev18.
  47. PRELIMINARY PROCEDURES:
  48. It is assumed that openssl has been installed correctly, that the default
  49. cert directory is /usr/local/ssl/certs, (it's often /etc/ssl/certs, but we
  50. need a point of departure for the discussion) and that lynx has been compiled
  51. --with-ssl.
  52. The default location for certs on your system may be different, or there may not
  53. be one. You will have to substitute that location for /usr/local/ssl/certs in
  54. the following instructions, and/or set environment variables.
  55. To determine the default location for certs on your system you may run the
  56. following command:
  57. strings libcrypto.a | grep -in cert | less
  58. Look in this output for SSL_CERT_DIR and SSL_CERT_FILE, and the lines just
  59. above them. This is your default location, respectively, for certificates,
  60. and the CA cert bundle, cert.pem. You will need to know where libcrypto.a is
  61. found of course.
  62. Example output:
  63. <snip>
  64. 7490:/etc/ssl/certs
  65. 7491:/etc/ssl/cert.pem
  66. 7492:SSL_CERT_DIR
  67. 7493:SSL_CERT_FILE
  68. <snip>
  69. Other possible example output:
  70. <snip>
  71. 31555:/usr/local/ssl/certs
  72. 31556:/usr/local/ssl/cert.pem
  73. 31557:SSL_CERT_DIR
  74. 31558:SSL_CERT_FILE
  75. <snip>
  76. Note that when OpenSSL is installed, the c_rehash utility is installed in a
  77. bin directory (default /usr/local/ssl/bin). You will need to know where it
  78. is on your system. The command:
  79. whereis c_rehash
  80. will probably give useful results.
  81. Note also that there is no CA cert bundle distributed with OpenSSL. The
  82. OpenSSL team specifically decided NOT to do that. Getting a set of trusted
  83. certificates is left up to the installer.
  84. It is no longer a fairly trivial procedure to pull the bundle of trusted root certs out
  85. of a recent version of Internet Explorer. Multiple certificates are no longer
  86. exportable as a DER formatted file; extraction of a single certificate is the only
  87. export for DER, and DER is what converts to PEM.
  88. Users with access to Apple OS X can export all certificates from Keychain Access System Roots as
  89. a .pem file. Place this in SSL_CERT_DIR and hash it and you're done.
  90. The MirOS BSD project also provides them. The procedure to convert and install them
  91. is detailed later in this document, and if you simply need to have commercially provided
  92. certificates trusted by lynx, you can skip down a few lines to the INSTALLING OR UPDATING
  93. THE CA BUNDLE section.
  94. Extracted Mozilla cert bundles are available for download from the curl project,
  95. http://curl.haxx.se/docs/caextract.html along with a script to extract from Mozilla
  96. source.
  97. INSTALLING A SELF-SIGNED CERTIFICATE:
  98. When you would like to trust a self-signed (non-commercial) certificate you will
  99. need to get hold of the actual file. If it's a cert local to your network you
  100. can ask the sysadmin to make it available for download as a link on a webpage.
  101. If such file is not human-readable it's probably DER formatted and will need to
  102. be converted to PEM format to allow openssl to use it.
  103. To convert DER formatted certificates into something openssl can deal with:
  104. Save the cert as site_name.crt in a directory. In that directory, type:
  105. openssl x509 -inform DER -in site_name.crt -outform PEM -out site_name.pem
  106. You can now copy this individual cert into the directory for that, usually
  107. /usr/local/ssl/certs. The alternative is to concatenate the individual certs
  108. to the cert.pem bundle in /usr/local/ssl. (Please see INSTALLING OR UPDATING
  109. THE CA BUNDLE below).
  110. The cert file will now be in an acceptable format to openssl, PEM encoded.
  111. However, openssl, and by extension lynx, will not know about it until that
  112. cert is symbolically linked to a file named after the hash value of that cert,
  113. in the default directory /usr/local/ssl/certs.
  114. So the next thing to do is to hash the cert using c_rehash.
  115. INSTALLING OR UPDATING THE CA BUNDLE:
  116. Now would be a good time to check to see if you have the bundle of CA certs
  117. /usr/local/ssl/cert.pem, or to update them.
  118. CA bundles are available in various places, such as the MirOS BSD distribution,
  119. for those who want to take that route, or you can extract the current bundle
  120. from a current version of Internet Explorer (export them all from IE and
  121. transfer it onto your system).
  122. From MirOS, a cert bundle is available at
  123. http://caunter.ca/ssl.certs.shar
  124. It includes the cacert.org certificate. Download the latest revision; read the
  125. file to see how to get the certs out.
  126. No hashing is necessary with this set of certs; it is already done; ignore
  127. the c_rehash usage below for this bundle. Simply run `sh ssl.certs.shar`
  128. in SSL_CERT_DIR.
  129. From IE 5.x certs extract as a PKCS7 file and need to be converted with something
  130. like:
  131. openssl pkcs7 -inform DER -in bundle.crt -outform PEM -out cert.pem \
  132. -print_certs -text
  133. The resulting cert.pem file should be copied to the default directory for
  134. bundles (usually /usr/local/ssl) and renamed to "cert.pem", assuming that is
  135. the SSL_CERT_FILE.
  136. Individual certs can also process if added and hashed in /usr/local/ssl/certs.
  137. We now have all of the individual certs we wish to trust in our certs
  138. directory, and the most recent bundle of CA certs as well.
  139. Confirm that you have the script c_rehash (See PRELIMINARY PROCEDURES; if it is
  140. not found, a copy is usually located in the tools directory of the openssl
  141. source tree. If you use this copy, it needs the execute bit set or it will not
  142. run).
  143. Run:
  144. ./c_rehash
  145. The c_rehash utility is a perl script that runs openssl commands which creates
  146. the files named after the hash values of the certs in the default directory
  147. for certs.
  148. Its output looks like this:
  149. Doing /usr/local/ssl/certs
  150. vsignss.pem => f73e89fd.0
  151. vsign3.pem => 7651b327.0
  152. ...more output
  153. <snip>
  154. All pem encoded certs in /usr/local/ssl/certs will now be recognized.
  155. SETTING AND EXPORTING ENVIRONMENT VARIABLES:
  156. If lynx is still not recognizing certs, environment variables need
  157. to be set; if on a sh type shell, the variables also need to be exported.
  158. The environment variables SSL_CERT_DIR and SSL_CERT_FILE need to be set
  159. if a non-default location is used for certificates, or if certs just can't be
  160. found by lynx. They may be set as follows in /etc/profile, or a shell
  161. initialization .profile or .*shrc, if we run a non csh type shell, according
  162. to the results of the search for the default location for certs procedure
  163. (See PRELIMINARY PROCEDURES):
  164. SSL_CERT_DIR="/usr/local/ssl/certs"
  165. SSL_CERT_FILE="/usr/local/ssl/cert.pem"
  166. export SSL_CERT_DIR SSL_CERT_FILE
  167. On csh type shells, you can use:
  168. setenv SSL_CERT_DIR "/usr/local/ssl/certs"
  169. setenv SSL_CERT_FILE "/usr/local/ssl/cert.pem"
  170. Note that the environment variable SSL_CERT_FILE applies to the cert-bundle
  171. if used outside of the default location (/usr/local/ssl/cert.pem) compiled
  172. into OpenSSL. There are issues with SSL_CERT_FILE in 0.9.6x versions of openssl.
  173. The configuration file lynx.cfg allows a system SSL_CERT_FILE variable to be set
  174. which can simplify matters.
  175. SSL_CERT_FILE:/etc/ssl/certs/ca-certificates.crt
  176. Make sure you have FORCE_SSL_PROMPT set to PROMPT in lynx.cfg like so:
  177. FORCE_SSL_PROMPT:PROMPT
  178. You will now connect without error to https servers with trusted certs, but
  179. will still get this error for untrusted certs:
  180. SSL error:self signed certificate-Continue? (y)
  181. A quick check confirms that these procedures have the same effect with ssl
  182. errors in the pine program.
  183. 2003 updated 2009
  184. Stefan Caunter <stefan.caunter@mohawkcollege.ca>
  185. Mohawk College Department of Computer Science
  186. Hamilton Ontario Canada