1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<!-- This document was generated using DocBuilder 3.3.2 -->
<HTML>
<HEAD>
<TITLE>Using SSL for Erlang Distribution</TITLE>
<SCRIPT type="text/javascript" src="../../../../doc/erlresolvelinks.js">
</SCRIPT>
</HEAD>
<BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#FF00FF"
ALINK="#FF0000">
<CENTER>
<A HREF="http://www.erlang.se"><IMG BORDER=0 ALT="[Ericsson AB]" SRC="min_head.gif"></A>
</CENTER>
<A NAME="5"><!-- Empty --></A>
<H2>5 Using SSL for Erlang Distribution</H2>
<P>This chapter describes how the Erlang distribution can use
SSL to get additional verification and security.<A NAME="5.1"><!-- Empty --></A>
<H3>5.1 Introduction</H3>
<P> The Erlang distribution can in theory use almost any connection
based protocol as bearer. A module that implements the protocol
specific parts of connection setup is however needed. The
default distribution module is <CODE>inet_tcp_dist</CODE> which is
included in the Kernel application. When starting an
Erlang node distributed, <CODE>net_kernel</CODE> uses this module to
setup listen ports and connections.
<P> In the SSL application there is an additional distribution
module, <CODE>inet_ssl_dist</CODE> which can be used as an
alternative. All distribution connections will be using SSL and
all participating Erlang nodes in a distributed system must use
this distribution module.
<P> The security depends on how the connections are set up, one can
use key files or certificates to just get a crypted
connection. One can also make the SSL package verify the
certificates of other nodes to get additional security.
Cookies are however always used as they can be used to
differentiate between two different Erlang networks.
<P> Setting up Erlang distribution over SSL involves some simple but
necessary steps:
<P>
<UL>
<LI>
Building boot scripts including the SSL application
</LI>
<LI>
Specifying the distribution module for net_kernel
</LI>
<LI>
Specifying security options and other SSL options
</LI>
</UL>
<P> The rest of this chapter describes the above mentioned steps in
more detail.
<A NAME="5.2"><!-- Empty --></A>
<H3>5.2 Building boot scripts including the SSL application</H3>
<P> Boot scripts are built using the <CODE>systools</CODE> utility in the
SASL application. Refer to the SASL documentations
for more information on systools. This is only an example of
what can be done.
<P> The simplest boot script possible includes only the Kernel
and STDLIB applications. Such a script is located in the
Erlang distributions bin directory. The source for the script
can be found under the Erlang installation top directory under
<CODE>releases/<OTP version>start_clean.rel</CODE>. Copy that
script to another location (and preferably another name)
and add the SSL application with its current version number
after the STDLIB application.
<P>An example .rel file with SSL added may look like this:
<PRE>
{release, {"OTP APN 181 01","P7A"}, {erts, "5.0"},
[{kernel,"2.5"},
{stdlib,"1.8.1"},
{ssl,"2.2.1"}]}.
</PRE>
<P> Note that the version numbers surely will differ in your system.
Whenever one of the applications included in the script is
upgraded, the script has to be changed.
<P> Assuming the above .rel file is stored in a file
<CODE>start_ssl.rel</CODE> in the current directory, a boot script
can be built like this:
<PRE>
1> systools:make_script("start_ssl",[]).
</PRE>
<P> There will now be a file <CODE>start_ssl.boot</CODE> in the current
directory. To test the boot script, start Erlang with the
<CODE>-boot</CODE> command line parameter specifying this boot script
(with its full path but without the <CODE>.boot</CODE> suffix), in
Unix it could look like this:
<P>
<PRE>
$ erl -boot /home/me/ssl/start_ssl
Erlang (BEAM) emulator version 5.0
Eshell V5.0 (abort with ^G)
1> whereis(ssl_server).
<0.32.0>
</PRE>
<P> The <CODE>whereis</CODE> function call verifies that the SSL
application is really started.
<P> As an alternative to building a bootscript, one can explicitly
add the path to the ssl <CODE>ebin</CODE> directory on the command
line. This is done with the command line option <CODE>-pa</CODE>. This
works as the ssl application really need not be started for the
distribution to come up, a primitive version of the ssl server
is started by the distribution module itself, so as long as the
primitive code server can reach the code, the distribution will
start. The <CODE>-pa</CODE> method is only recommended for testing
purpouses.
<A NAME="5.3"><!-- Empty --></A>
<H3>5.3 Specifying distribution module for net_kernel
</H3>
<P> The distribution module for SSL is named <CODE>inet_ssl_dist</CODE>
and is specified on the command line whit the <CODE>-proto_dist</CODE>
option. The argument to <CODE>-proto_dist</CODE> should be the module
name without the <CODE>_dist</CODE> suffix, so this distribution
module is specified with <CODE>-proto_dist inet_ssl</CODE> on the
command line.
<P>
<P> Extending the command line from above gives us the following:
<PRE>
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_ssl
</PRE>
<P> For the distribution to actually be started, we need to give
the emulator a name as well:
<PRE>
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_ssl -sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0 (abort with ^G)
(ssl_test@myhost)1>
</PRE>
<P> Note however that a node started in this way will refuse to talk
to other nodes, as no certificates or key files are supplied
(see below).
<P> When the SSL distribution starts, the OTP system is in its
early boot stage, why neither <CODE>application</CODE> nor <CODE>code</CODE>
are usable. As SSL needs to start a port program in this early
stage, it tries to determine the path to that program from the
primitive code loaders code path. If this fails, one need to
specify the directory where the port program resides. This can
be done either with an environment variable
<CODE>ERL_SSL_PORTPROGRAM_DIR</CODE> or with the command line option
<CODE>-ssl_portprogram_dir</CODE>. The value should be the directory
where the <CODE>ssl_esock</CODE> port program is located. Note that
this option is never needed in a normal Erlang installation.
<A NAME="5.4"><!-- Empty --></A>
<H3>5.4 Specifying security options and other SSL options</H3>
<P> For SSL to work, you either need certificate files or a
key file. Certificate files can be specified both when working as
client and as server (connecting or accepting).
<P>
<P> On the <CODE>erl</CODE> command line one can specify options that the
ssl distribution will add when creation a socket. It is
mandatory to specify at least a key file or client and server
certificates. One can specify any <STRONG>SSL option</STRONG> on the
command line, but must not specify any socket options (like
packet size and such). The SSL options are listed in the
Reference Manual. The only difference between the
options in the reference manual and the ones that can be
specified to the distribution on the command line is that
<CODE>certfile</CODE> can (and usually needs to) be specified as
<CODE>client_certfile</CODE> and <CODE>server_certfile</CODE>. The
<CODE>client_certfile</CODE> is used when the distribution initiates a
connection to another node and the <CODE>server_cerfile</CODE> is used
when accepting a connection from a remote node.
<P> The command line argument for specifying the SSL options is named
<CODE>-ssl_dist_opt</CODE> and should be followed by an even number of
SSL options/option values. The <CODE>-ssl_dist_opt</CODE> argument can
be repeated any number of times.
<P> An example command line would now look something like this
(line breaks in the command are for readability,
they should not be there when typed):
<PRE>
$ erl -boot /home/me/ssl/start_ssl -proto_dist inet_ssl
-ssl_dist_opt client_certfile "/home/me/ssl/erlclient.pem"
-ssl_dist_opt server_certfile "/home/me/ssl/erlserver.pem"
-ssl_dist_opt verify 1 depth 1
-sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0 (abort with ^G)
(ssl_test@myhost)1>
</PRE>
<P> A node started in this way will be fully functional, using SSL
as the distribution protocol.
<A NAME="5.5"><!-- Empty --></A>
<H3>5.5 Setting up environment to always use SSL</H3>
<P> A convenient way to specify arguments to Erlang is to use the
<CODE>ERL_FLAGS</CODE> environment variable. All the flags needed to
use SSL distribution can be specified in that variable and will
then be interpreted as command line arguments for all
subsequent invocations of Erlang.
<P>
<P> In a Unix (Bourne) shell it could look like this (line breaks for
readability):
<PRE>
$ ERL_FLAGS="-boot \"/home/me/ssl/start_ssl\" -proto_dist inet_ssl
-ssl_dist_opt client_certfile \"/home/me/ssl/erlclient.pem\"
-ssl_dist_opt server_certfile \"/home/me/ssl/erlserver.pem\"
-ssl_dist_opt verify 1 -ssl_dist_opt depth 1"
$ export ERL_FLAGS
$ erl -sname ssl_test
Erlang (BEAM) emulator version 5.0 [source]
Eshell V5.0 (abort with ^G)
(ssl_test@myhost)1> init:get_arguments().
[{root,["/usr/local/erlang"]},
{progname,["erl "]},
{sname,["ssl_test"]},
{boot,["/home/me/ssl/start_ssl"]},
{proto_dist,["inet_ssl"]},
{ssl_dist_opt,["client_certfile","/home/me/ssl/erlclient.pem"]},
{ssl_dist_opt,["server_certfile","/home/me/ssl/erlserver.pem"]},
{ssl_dist_opt,["verify","1"]},
{ssl_dist_opt,["depth","1"]},
{home,["/home/me"]}]
</PRE>
<P> The <CODE>init:get_arguments()</CODE> call verifies that the correct
arguments are supplied to the emulator.
<CENTER>
<HR>
<SMALL>
Copyright © 1991-2004
<A HREF="http://www.erlang.se">Ericsson AB</A><BR>
</SMALL>
</CENTER>
</BODY>
</HTML>
|