README.TLS 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414
  1. [NOTE: this file is obsolete, use README instead]
  2. free-TLS core module
  3. Created By: Peter Griffiths
  4. Mantainer: Cesc Santasusana
  5. Edited by
  6. Cesc Santasusana
  7. Copyright © 2005 Cesc Santasusana
  8. _________________________________________________________
  9. TABLE OF CONTENTS
  10. 1. CHAPTER 1. USER'S GUIDE 2
  11. 1.1. OVERVIEW 2
  12. 1.2. DEPENDENCIES 2
  13. 1.2.1. SER Core and patches 2
  14. 1.2.2. SER Modules 2
  15. 1.2.3. External Libraries or Applications 2
  16. 1.3. HOW TO INSTALL 3
  17. 1.3.1. File Structure
  18. 1.3.2. Patches
  19. 1.3.3. Test Configuration in tls/etc
  20. 1.3.4. Tools to create certificates in tls/tools
  21. 1.4. HOW TO COMPILE 3
  22. 1.5. CONFIG FILE PARAMETERS 3
  23. 1.5.1. disable_tls 4
  24. 1.5.2. listen 4
  25. 1.5.3. tls_certificate 4
  26. 1.5.4. tls_private_key 4
  27. 1.5.5. tls_ca_list 4
  28. 1.5.6. tls_ciphers_list 4
  29. 1.5.7. tls_method 4
  30. 1.5.8. tls_verify and tls_require_certificate 4
  31. 1.5.9. tls_handshake_timeout and tls_send_timeout 5
  32. 1.5.10. tls_domain[IP_2:port2] 5
  33. 1.6. SSL/TLS AUTHENTICATION: CLIENT AND SERVER 5
  34. 1.7. EXPORTED FUNCTIONS 6
  35. 2. CHAPTER 2. DEVELOPER'S GUIDE 6
  36. 2.1. TLS_CONFIG 6
  37. 2.2. TLS_INIT 6
  38. 2.2.1. default ssl context 6
  39. 2.2.2. init_tls(void) 6
  40. 2.2.3. destroy_tls(void) 6
  41. 2.2.4. tls_init(struct socket_info *) 7
  42. 2.2.5. ser_malloc, ser_realloc, ser_free 7
  43. 2.3. TLS_SERVER 7
  44. 2.3.1. SSL data per connection 7
  45. 2.3.2. tls_print_errstack(void) 7
  46. 2.3.3. tls_tcpconn_init( struct tcp_connection *, int) 7
  47. 2.3.4. tls_tcpconn_clean( struct tcp_connection *) 7
  48. 2.3.5. tls_close( struct tcp_connection *, int ) 7
  49. 2.3.6. tls_blocking_write( struct tcp_connection, int, const char, size_t ) 7
  50. 2.3.7. tls_read( struct tcp_connection *) 8
  51. 2.3.8. tls_fix_read_conn( struct tcp_connection ) 8
  52. 2.4. TLS_DOMAIN 8
  53. 2.4.1. tls_domains 8
  54. 2.4.2. tls_find_domain( struct ip_addr *, unsigned short) 8
  55. 2.4.3. tls_new_domain( struct ip_addr *, unsigned *) 8
  56. 2.4.4. tls_free_domains(void) 8
  57. 3. CHAPTER 3. FREQUENTLY ASKED QUESTIONS 8
  58. 3.1. WHERE CAN I FIND MORE ABOUT SER? 8
  59. 3.2. WHERE CAN I POST A QUESTION ABOUT THIS MODULE? 8
  60. 3.3. HOW CAN I REPORT A BUG? 9
  61. 3.4. WHAT IS THE DIFFERENCE WITH OpenSER-TLS?
  62. 3.5. I AM NOT HAPPY WITH THIS README ... NOW WHAT?
  63. _________________________________________________________
  64. 1. CHAPTER 1. USER'S GUIDE
  65. 1.1. OVERVIEW
  66. TLS is an optional part of the core, not a module.
  67. TLS, as defined in SIP RFC, is a mandatory feature for proxies and can be used to secure the SIP signalling
  68. on a hop-by-hop basis (not end-to-end). TLS works on top of TCP (DTLS, or TLS over UDP is already
  69. defined by IETF and may become available in the future).
  70. _________________________________________________________
  71. 1.2. DEPENDENCIES
  72. 1.2.1. SER Core and patches
  73. Core must be compiled with TCP support and the patched cfg.y and cfg.lex, and some
  74. modification in Makefile.defs.
  75. The Makefile.defs file is where the library and include paths are set (where to locate Openssl)
  76. Read more on this below on the "external libraries" dependencies.
  77. The cfg.XXX patch provide configuration features from the ser.cfg file, usefull and necessary.
  78. This core module has been compiled successfully with ser branch rel_0_9_0 (updated
  79. as of June 2005, ser-0.9.3). It should compile in HEAD too without problem.
  80. It has been tested for functionality (successfully) with rel_0_9_0 (ser-0.9.0).
  81. Report on success/failure stories to the mantainer. Tks!
  82. _________________________________________________________
  83. 1.2.2. SER Modules
  84. No dependencies on SER modules
  85. _________________________________________________________
  86. 1.2.3. External Libraries or Applications
  87. The following libraries or applications must be installed before running SER with this module loaded:
  88. * OpenSSL v0.9.7 or higher (OpenSSL v0.9.6 also compiles, though not recommended).
  89. Out of OpenSSL, you need:
  90. * libssl
  91. * libcrypto
  92. * openssl/*.h
  93. Locate this, usually in:
  94. /usr/local/lib (for libraries)
  95. /usr/local/ssl/include/openssl (for header files)
  96. Depending on your distro, these paths may vary. In this case, you need to modify Makefile.defs file in
  97. $SERROOT. At the bottom of the file, look for
  98. ifneq ($(TLS),)
  99. LIBS+= -L$SOMEPATH/lib -lssl -lcrypto
  100. DEFS+= -I$SOMEPATH/ssl/include
  101. endif
  102. Change the LIBS entry to include the folder where the libssl and libcrypto files are.
  103. Change the DEFS entry to include the folder where the openssl/ folder is.
  104. NOTE: RedHat ships by default with a very strange setup of the paths, as well as not usual compilation of
  105. the libraries, which resumes in ... trouble. Look for solutions in Google, or locally compile OpenSSL
  106. sources on your system.
  107. ________________________________________________________
  108. 1.3. HOW TO INSTALL
  109. 1.3.1. File Structure
  110. This is the file structure that needs to be created:
  111. $SER_ROOT/tls/tls_config.h and .c
  112. $SER_ROOT/tls/tls_init.h and .c
  113. $SER_ROOT/tls/tls_server.h and .c
  114. $SER_ROOT/tls/tls_domain.h and .c
  115. The files that (may) need to be patched or modified
  116. $SER_ROOT/Makefile.defs
  117. $SER_ROOT/cfg.y
  118. $SER_ROOT/cfg.lex
  119. NOTE: patches can be found in the tls/patches. See above for Makefile.defs tweaking to locate OpenSSL.
  120. 1.3.2. Patches
  121. In the experimental/tls/patches folder, there are the following files:
  122. - cfg.lex.patch and cfg.y.patch, to be used to patch the corresponding
  123. files in $SERROOT.
  124. > cp cfg.XXX.patch $SERROOT/
  125. > cd $SERROOT
  126. > patch -p0 < cfg.XXX.patch
  127. - cfg.y and cfg.lex: these are the full files, taken from the cvs rel_0_9_0 and patched
  128. with the above patches (for lazy people :D ).
  129. Use the patches if you have modified your cfg.y or cfg.lex files or if it is a different
  130. branch. Use the full files if you don't want to patch the files, or have the standard
  131. cvs rel_0_9_0 branch files.
  132. 1.3.3. Test configuration
  133. In the folder tls/etc you can find a sample config file, along with test certificates ready to use.
  134. Note that in the tls/etc/tls.ser.cfg, the path to certificates and private keys are set to
  135. /usr/local/etc/ser/certs and /usr/local/etc/ser/private
  136. (change according to your local configuration)
  137. 1.3.4. Tools to create certificates
  138. In the folder tls/tools there are script and configuration files to be used with openssl application
  139. to create certificate (root CA and user certs).
  140. Read the README.tls.tools file there for more info.
  141. ________________________________________________________
  142. 1.4. HOW TO COMPILE
  143. Easy ;) Add the TLS=1 flag when compiling, for example:
  144. > make TLS=1 install
  145. If you have problems compiling the TLS code, such as header files not found, or linking problems related
  146. to SSL_* functions, check the paths in Makefile.defs (at the bottom, the DEFS+= and LIB+=, and check if
  147. the openssl/ folder is there, and if the libssl.so and libcrypto.so files are in the specified folders).
  148. ________________________________________________________
  149. 1.5. CONFIG FILE PARAMETERS
  150. All these parameters can be used from the ser.cfg file, to configure the behavior of SER-tls.
  151. ________________________________________________________
  152. 1.5.1. disable_tls
  153. Disables TLS (no server is created on the listen addresses, no outgoing connections can be set up).
  154. It only exhists if TLS=1 is used at compile time.
  155. Default_value: disable_tls=0
  156. ________________________________________________________
  157. 1.5.2. listen
  158. Not specific to TLS. Allows to specify the protocol (udp, tcp, tls), the IP address and the port
  159. where the listening server will be.
  160. listen=tls:IP:port
  161. ________________________________________________________
  162. 1.5.3. tls_certificate
  163. NOTE: To be able to use most of this configuration parameters, you need to have patched cfg.y and cfg.lex
  164. (and recompile :D )
  165. Public certificate file for SER. It will be used as server-side certificate for incoming TLS
  166. connections, and as a client-side certificate for outgoing TLS connections.
  167. default: "CFG_DIR/cert.pem"
  168. example: tls_certificate="/mycerts/certs/ser_server_cert.pem"
  169. ________________________________________________________
  170. 1.5.4. tls_private_key
  171. Private key of the above certificate ... keep it in a safe place with tight permissions!
  172. default: CFG_DIR/cert.pem
  173. example: tls_private_key="/mycerts/private/prik.pem"
  174. ________________________________________________________
  175. 1.5.5. tls_ca_list
  176. List of trusted CAs. The file contains the certificates accepted, one after the other ( cat x >>
  177. ca.list). It MUST be a file, not a folder (for now).
  178. default: "" (no ca_list)
  179. example: tls_ca_list="/mycerts/certs/ca_list.pem"
  180. ________________________________________________________
  181. 1.5.6. tls_ciphers_list
  182. We can specify the list of algorithms for authentication and encryption that we allow.
  183. To obtain a list of ciphers and then choose, use the openssl application:
  184. > openssl ciphers 'ALL:eNULL:!LOW:!EXPORT'
  185. Do not use the NULL algorithms ... only for testing!!!
  186. Default: no change, use the default ciphers choosen by OpenSSL.
  187. Example: tls_ciphers_list="NULL-SHA:NULL-MD5:AES256-SHA:AES128-SHA"
  188. ________________________________________________________
  189. 1.5.7. tls_method
  190. Protocol version to use. Best is to use sslv23, for extended compatibility. Using any of the other
  191. will restrict the version to just that one version. In fact, sslv2 is disabled in the source code... to use it, you
  192. need to edit tls_init.c
  193. Default: sslv23
  194. tls_method= [sslv2 | sslv23 | sslv3 | tlsv1]
  195. ________________________________________________________
  196. 1.5.8. tls_verify and tls_require_certificate
  197. This two variables highly effect the final security of your deployment. READ carefully!
  198. Technically, tls_verify activates SSL_VERIFY_PEER in the ssl_context.
  199. tls_require_certificate does the same with SSL_VERIFY_FAIL_IF_NO_PEER_CERT, which is
  200. only possible if SSL_VERIFY_PEER is also turned on.
  201. See the "how does verification work" for more info
  202. default is 0 for both.
  203. Example: tls_verify = 1
  204. tls_require_certificate = 1
  205. (this example turns on the strictest and strongest authentication possible)
  206. ________________________________________________________
  207. 1.5.9. tls_handshake_timeout and tls_send_timeout
  208. Timeouts ... advanced users only.
  209. default is 120 seconds for both.
  210. Example: tls_handshake_timeout=119 [number of seconds]
  211. Example: tls_send_timeout=121 [number of seconds]
  212. ________________________________________________________
  213. 1.5.10. tls_domain[IP_2:port2]
  214. Note: domains are only possible if cfg.y and cfg.lex are patched.
  215. If you only run one domain, the main one is enough. If you are running several tls servers (that is,
  216. you have more than one listen:tls:ip:port entry in the config file), you can specify some parameters for each
  217. of them separately (not all the above).
  218. tls_domain[IP_2:port2] {
  219. #specify parameters for a domain in particular, otherwise,
  220. #it will use the default. These are the possible parameters to
  221. #change for each domain
  222. tls_certificate="new_cert"
  223. tls_private_key="new_cert_key"
  224. tls_ca_list="other ca"
  225. tls_method="tlsv1"
  226. }
  227. tls_domain[IP_3:port3] {
  228. ...
  229. }
  230. NOTE: For now, tls_ciphers_list cannot be specified on a per domain basis. When I have the time
  231. to thoroughly test tls_domains, I will add this.
  232. _________________________________________________________
  233. 1.6. SSL/TLS AUTHENTICATION: CLIENT AND SERVER
  234. TLS provides for strong authentication mechanism, as well as encryption following authentication. Of
  235. course, null encryption can be used, as well as weak authentication mechanisms (for example, anonymous,
  236. that is, no authentication).
  237. How does verification work?
  238. Verification is the process by which the authentication data provided by the peers is checked. This data
  239. consists usually of a peer certificate, plus a chain of trusted certification authorities. If for whatever reason,
  240. either of the peers thinks that the handshake is not valid, the ssl connection is not established.
  241. The reasons could be many: untrusted server certficate, too-weak algorithm, invalid client cert, no client
  242. authentication, ...
  243. The "tls_verify" and "tls_require_certificate" are SER-names for the
  244. OpenSSL defined flags:
  245. - SSL_VERIFY_PEER is tls_verify) and
  246. - SSL_VERIFY_FAIL_IF_NO_PEER_CERT is tls_require_certificate (tls_require_certificate is only used
  247. if tls_verify=1)
  248. If we are acting as a server, we always send our server-side certificate to the client.
  249. - If tls_verify=0, we do not request the client a client-certificate. This means that the client is not
  250. authenticated.
  251. - If tls_verify=1, we (the server) send a client-certificate request to the client. But the client is free
  252. to not provide any. In this case, tls_require_certificate comes into play:
  253. _ if tls_require_cert=0, the verification process will succedd if
  254. the client does not provide a certificate, or if it provides
  255. one, it verifies correctly against the server's list of
  256. trusted certification authorities.
  257. _ if tls_require_cert=1, the verification process will only succeed
  258. if the client provides a certificate and this verifies correctly
  259. against the server's list of trusted CAs.
  260. _________________________________________________________
  261. 1.7. EXPORTED FUNCTIONS
  262. Functions are accessible by including the appropriate tls/tls_xxx.h file.
  263. _________________________________________________________
  264. 2. CHAPTER 2. DEVELOPER'S GUIDE
  265. ________________________________________________________
  266. 2.1. TLS_CONFIG
  267. It contains configuration variables for ser's tls (timeouts, file paths, etc).
  268. ________________________________________________________
  269. 2.2. TLS_INIT
  270. Initialization related functions and parameters.
  271. ________________________________________________________
  272. 2.2.1. default ssl context
  273. extern SSL_CTX *default_ctx;
  274. It is the common context for all tls sockets. If domains are used, each has its own.
  275. ________________________________________________________
  276. 2.2.2. init_tls(void)
  277. Called once to initialize the tls subsystem, from the main().
  278. int init_tls(void);
  279. ________________________________________________________
  280. 2.2.3. destroy_tls(void)
  281. Called once, just before cleanup.
  282. void destroy_tls(void);
  283. ________________________________________________________
  284. 2.2.4. tls_init(struct socket_info *)
  285. Called once for each tls socket created.
  286. int tls_init(struct socket_info *si);
  287. ________________________________________________________
  288. 2.2.5. ser_malloc, ser_realloc, ser_free
  289. Wrapper functions around the shm_* functions. OpenSSL uses non-shared memory to create its objects,
  290. thus it would not work in SER. By creating these wrappers and configuring OpenSSL to use them instead
  291. of its default memory functions, we have all OpenSSL objects in shared memory, ready to use.
  292. ________________________________________________________
  293. 2.3. TLS_SERVER
  294. ________________________________________________________
  295. 2.3.1. SSL data per connection
  296. Each TLS connection, incoming or outgoing, creates an SSL * object, where configuration inherited from
  297. the SSL_CTX * and particular info on that socket are stored. This SSL * structure is kept in SER as long as
  298. the connection is alive, as part of the struct tcp_connection * object:
  299. struct tcp_connection *c;
  300. SSL *ssl;
  301. //create somehow SSL object
  302. c->extra_data = (void *) ssl;
  303. ssl = (SSL *) c->extra_data;
  304. ________________________________________________________
  305. 2.3.2. tls_print_errstack(void)
  306. /*
  307. * dump ssl error stack
  308. */
  309. void tls_print_errstack(void);
  310. ________________________________________________________
  311. 2.3.3. tls_tcpconn_init( struct tcp_connection *, int)
  312. /*
  313. * Called when new tcp connection is accepted
  314. */
  315. int tls_tcpconn_init(struct tcp_connection *c, int sock);
  316. ________________________________________________________
  317. 2.3.4. tls_tcpconn_clean( struct tcp_connection *)
  318. /*
  319. * clean the extra data upon connection shut down
  320. */
  321. void tls_tcpconn_clean(struct tcp_connection *c);
  322. ________________________________________________________
  323. 2.3.5. tls_close( struct tcp_connection *, int )
  324. /*
  325. * shut down the TLS connection
  326. */
  327. void tls_close(struct tcp_connection *c, int fd);
  328. ________________________________________________________
  329. 2.3.6. tls_blocking_write( struct tcp_connection, int, const char, size_t )
  330. size_t tls_blocking_write(struct tcp_connection *c, int fd,
  331. const char *buf, size_t len);
  332. ________________________________________________________
  333. 2.3.7. tls_read( struct tcp_connection *)
  334. size_t tls_read(struct tcp_connection *c);
  335. ________________________________________________________
  336. 2.3.8. tls_fix_read_conn( struct tcp_connection )
  337. int tls_fix_read_conn(struct tcp_connection *c);
  338. ________________________________________________________
  339. 2.4. TLS_DOMAIN
  340. ________________________________________________________
  341. 2.4.1. tls_domains
  342. extern struct tls_domain *tls_domains;
  343. ________________________________________________________
  344. 2.4.2. tls_find_domain( struct ip_addr *, unsigned short)
  345. /*
  346. * find domain with given ip and port
  347. */
  348. struct tls_domain *tls_find_domain(struct ip_addr *ip,
  349. unsigned short port);
  350. ________________________________________________________
  351. 2.4.3. tls_new_domain( struct ip_addr *, unsigned *)
  352. /*
  353. * create a new domain
  354. */
  355. int tls_new_domain(struct ip_addr *ip, unsigned short port);
  356. ________________________________________________________
  357. 2.4.4. tls_free_domains(void)
  358. /*
  359. * clean up
  360. */
  361. void tls_free_domains(void);
  362. ________________________________________________________
  363. CHAPTER 3. FREQUENTLY ASKED QUESTIONS
  364. ________________________________________________________
  365. 3.1. WHERE CAN I FIND MORE ABOUT SER?
  366. Take a look at http://iptel.org/ser and http://www.openser.org
  367. ________________________________________________________
  368. 3.2. WHERE CAN I POST A QUESTION ABOUT THIS MODULE?
  369. In the webpages above there is access to mailing list. Use the users list for normal user support, use the dev
  370. list for development questions (bugs, fixes, etc).
  371. ________________________________________________________
  372. 3.3. HOW CAN I REPORT A BUG?
  373. At the dev lists on the above webpages, and also at:
  374. http://bugs.sip-router.org
  375. ________________________________________________________
  376. 3.4. WHAT IS THE DIFFERENCE WITH OpenSER-TLS?
  377. None. At least for now. The initial commit in both repositories
  378. (experimental tree for SER, HEAD for OpenSER) come from the same source:
  379. an extended version of that released sometime late in 2004 by Peter Griffiths
  380. and modified by Cesc Santasusana.
  381. ________________________________________________________
  382. 3.5. I AM NOT HAPPY WITH THIS README ... NOW WHAT?
  383. Three things:
  384. 1 - Complain to the maintainer.
  385. 2 - Contribute yourself with your acquired knowledge. It is welcome.
  386. 3 - Take a look at OpenSER tutorials for TLS: http://openser.org/docs/tls.html