1
<?xml version="1.0" encoding="latin1" ?>
2
<!DOCTYPE erlref SYSTEM "erlref.dtd">
7
<year>1999</year><year>2010</year>
8
<holder>Ericsson AB. All Rights Reserved.</holder>
11
The contents of this file are subject to the Erlang Public License,
12
Version 1.1, (the "License"); you may not use this file except in
13
compliance with the License. You should have received a copy of the
14
Erlang Public License along with this software. If not, it can be
15
retrieved online at http://www.erlang.org/.
17
Software distributed under the License is distributed on an "AS IS"
18
basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
19
the License for the specific language governing rights and limitations
25
<prepared>Peter Högfeldt</prepared>
26
<responsible>Peter Högfeldt</responsible>
28
<approved>Peter Högfeldt</approved>
30
<date>2003-03-25</date>
32
<file>old_ssl.xml</file>
34
<module>old_ssl</module>
35
<modulesummary>Interface Functions for Secure Socket Layer</modulesummary>
37
<p>This module contains interface functions to the Secure Socket Layer.</p>
41
<title>General</title>
43
<p>This manual page describes functions that are defined
44
in the ssl module and represents the old ssl implementation
45
that coexists with the new one until it has been
46
totally phased out. </p>
48
<p>The old implementation can be
49
accessed by providing the option {ssl_imp, old} to the
50
ssl:connect and ssl:listen functions.</p>
52
<p>The reader is advised to also read the <c>ssl(6)</c> manual page
53
describing the SSL application.
56
<p>It is strongly advised to seed the random generator after
57
the ssl application has been started (see <c>seed/1</c>
58
below), and before any connections are established. Although
59
the port program interfacing to the ssl libraries does a
60
"random" seeding of its own in order to make everything work
61
properly, that seeding is by no means random for the world
62
since it has a constant value which is known to everyone
63
reading the source code of the port program.</p>
68
<title>Common data types</title>
69
<p>The following datatypes are used in the functions below:
71
<list type="bulleted">
73
<p><c>options() = [option()]</c></p>
76
<p><c>option() = socketoption() | ssloption()</c></p>
79
<p><c>socketoption() = {mode, list} | {mode, binary} | binary | {packet, packettype()} | {header, integer()} | {nodelay, boolean()} | {active, activetype()} | {backlog, integer()} | {ip, ipaddress()} | {port, integer()}</c></p>
82
<p><c>ssloption() = {verify, code()} | {depth, depth()} | {certfile, path()} | {keyfile, path()} | {password, string()} | {cacertfile, path()} | {ciphers, string()}</c></p>
85
<p><c>packettype()</c> (see inet(3))</p>
88
<p><c>activetype()</c> (see inet(3))</p>
91
<p><c>reason() = atom() | {atom(), string()}</c></p>
94
<p><c>bytes() = [byte()]</c></p>
97
<p><c>string() = [byte()]</c></p>
100
<p><c>byte() = 0 | 1 | 2 | ... | 255</c></p>
103
<p><c>code() = 0 | 1 | 2</c></p>
106
<p><c>depth() = byte()</c></p>
109
<p><c>address() = hostname() | ipstring() | ipaddress()</c></p>
112
<p><c>ipaddress() = ipstring() | iptuple()</c></p>
115
<p><c>hostname() = string()</c></p>
118
<p><c>ipstring() = string()</c></p>
121
<p><c>iptuple() = {byte(), byte(), byte(), byte()}</c></p>
124
<p><c>sslsocket()</c></p>
127
<p><c>protocol() = sslv2 | sslv3 | tlsv1</c></p>
133
<p>The socket option <c>{backlog, integer()}</c> is for
134
<c>listen/2</c> only, and the option <c>{port, integer()}</c>
135
is for <c>connect/3/4</c> only.
137
<p>The following socket options are set by default: <c>{mode, list}</c>, <c>{packet, 0}</c>, <c>{header, 0}</c>, <c>{nodelay, false}</c>, <c>{active, true}</c>, <c>{backlog, 5}</c>,
138
<c>{ip, {0,0,0,0}}</c>, and <c>{port, 0}</c>.
140
<p>Note that the options <c>{mode, binary}</c> and <c>binary</c>
141
are equivalent. Similarly <c>{mode, list}</c> and the absence of
142
option <c>binary</c> are equivalent.
144
<p>The ssl options are for setting specific SSL parameters as follows:
146
<list type="bulleted">
148
<p><c>{verify, code()}</c> Specifies type of verification:
149
0 = do not verify peer; 1 = verify peer, 2 = verify peer,
150
fail if no peer certificate. The default value is 0.
154
<p><c>{depth, depth()}</c> Specifies the maximum
155
verification depth, i.e. how far in a chain of certificates
156
the verification process can proceed before the verification
157
is considered to fail.
159
<p>Peer certificate = 0, CA certificate = 1, higher level CA
160
certificate = 2, etc. The value 2 thus means that a chain
161
can at most contain peer cert, CA cert, next CA cert, and an
164
<p>The default value is 1.
168
<p><c>{certfile, path()}</c> Path to a file containing the
170
chain of PEM encoded certificates.</p>
173
<p><c>{keyfile, path()}</c> Path to file containing user's
174
private PEM encoded key.</p>
177
<p><c>{password, string()}</c> String containing the user's
178
password. Only used if the private keyfile is password protected.</p>
181
<p><c>{cacertfile, path()}</c> Path to file containing PEM encoded
182
CA certificates (trusted certificates used for verifying a peer
186
<p><c>{ciphers, string()}</c> String of ciphers as a colon
187
separated list of ciphers. The function <c>ciphers/0</c> can
188
be used to find all available ciphers.</p>
191
<p>The type <c>sslsocket()</c> is opaque to the user.
193
<p>The owner of a socket is the one that created it by a call to
194
<c>transport_accept/[1,2]</c>, <c>connect/[3,4]</c>,
197
<p>When a socket is in active mode (the default), data from the
198
socket is delivered to the owner of the socket in the form of
201
<list type="bulleted">
203
<p><c>{ssl, Socket, Data}</c></p>
206
<p><c>{ssl_closed, Socket}</c></p>
209
<p><c>{ssl_error, Socket, Reason}</c></p>
212
<p>A <c>Timeout</c> argument specifies a timeout in milliseconds. The
213
default value for a <c>Timeout</c> argument is <c>infinity</c>.
215
<p>Functions listed below may return the value <c>{error, closed}</c>, which only indicates that the SSL socket is
216
considered closed for the operation in question. It is for
217
instance possible to have <c>{error, closed}</c> returned from
218
an call to <c>send/2</c>, and a subsequent call to <c>recv/3</c>
219
returning <c>{ok, Data}</c>.
221
<p>Hence a return value of <c>{error, closed}</c> must not be
222
interpreted as if the socket was completely closed. On the
223
contrary, in order to free all resources occupied by an SSL
224
socket, <c>close/1</c> must be called, or else the process owning
225
the socket has to terminate.
227
<p>For each SSL socket there is an Erlang process representing the
228
socket. When a socket is opened, that process links to the
229
calling client process. Implementations that want to detect
230
abnormal exits from the socket process by receiving <c>{'EXIT', Pid, Reason}</c> messages, should use the function <c>pid/1</c>
231
to retrieve the process identifier from the socket, in order to
232
be able to match exit messages properly.</p>
236
<name>ciphers() -> {ok, string()} | {error, enotstarted}</name>
237
<fsummary>Get supported ciphers.</fsummary>
239
<p>Returns a string consisting of colon separated cipher
240
designations that are supported by the current SSL library
243
<p>The SSL application has to be started to return the string
248
<name>close(Socket) -> ok | {error, Reason}</name>
249
<fsummary>Close a socket returned by <c>transport_accept/[1,2]</c>, <c>connect/3/4</c>, or <c>listen/2</c>.</fsummary>
251
<v>Socket = sslsocket()</v>
254
<p>Closes a socket returned by <c>transport_accept/[1,2]</c>,
255
<c>connect/[3,4]</c>, or <c>listen/2</c></p>
259
<name>connect(Address, Port, Options) -> {ok, Socket} | {error, Reason}</name>
260
<name>connect(Address, Port, Options, Timeout) -> {ok, Socket} | {error, Reason}</name>
261
<fsummary>Connect to <c>Port</c>at <c>Address</c>.</fsummary>
263
<v>Address = address()</v>
264
<v>Port = integer()</v>
265
<v>Options = [connect_option()]</v>
266
<v>connect_option() = {mode, list} | {mode, binary} | binary | {packet, packettype()} | {header, integer()} | {nodelay, boolean()} | {active, activetype()} | {ip, ipaddress()} | {port, integer()} | {verify, code()} | {depth, depth()} | {certfile, path()} | {keyfile, path()} | {password, string()} | {cacertfile, path()} | {ciphers, string()}</v>
267
<v>Timeout = integer()</v>
268
<v>Socket = sslsocket()</v>
271
<p>Connects to <c>Port</c> at <c>Address</c>. If the optional
272
<c>Timeout</c> argument is specified, and a connection could not
273
be established within the given time, <c>{error, timeout}</c> is
274
returned. The default value for <c>Timeout</c> is <c>infinity</c>.
276
<p>The <c>ip</c> and <c>port</c> options are for binding to a
277
particular <em>local</em> address and port, respectively.</p>
281
<name>connection_info(Socket) -> {ok, {Protocol, Cipher}} | {error, Reason}</name>
282
<fsummary>Get current protocol version and cipher.</fsummary>
284
<v>Socket = sslsocket()</v>
285
<v>Protocol = protocol()</v>
286
<v>Cipher = string()</v>
289
<p>Gets the chosen protocol version and cipher for an established
290
connection (accepted och connected). </p>
294
<name>controlling_process(Socket, NewOwner) -> ok | {error, Reason}</name>
295
<fsummary>Assign a new controlling process to the socket.</fsummary>
297
<v>Socket = sslsocket()</v>
298
<v>NewOwner = pid()</v>
301
<p>Assigns a new controlling process to <c>Socket</c>. A controlling
302
process is the owner of a socket, and receives all messages from
307
<name>format_error(ErrorCode) -> string()</name>
308
<fsummary>Return an error string.</fsummary>
310
<v>ErrorCode = term()</v>
313
<p>Returns a diagnostic string describing an error.</p>
317
<name>getopts(Socket, OptionsTags) -> {ok, Options} | {error, Reason}</name>
318
<fsummary>Get options set for socket</fsummary>
320
<v>Socket = sslsocket()</v>
321
<v>OptionTags = [optiontag()]()</v>
324
<p>Returns the options the tags of which are <c>OptionTags</c> for
325
for the socket <c>Socket</c>. </p>
329
<name>listen(Port, Options) -> {ok, ListenSocket} | {error, Reason}</name>
330
<fsummary>Set up a socket to listen on a port on the local host.</fsummary>
332
<v>Port = integer()</v>
333
<v>Options = [listen_option()]</v>
334
<v>listen_option() = {mode, list} | {mode, binary} | binary | {packet, packettype()} | {header, integer()} | {active, activetype()} | {backlog, integer()} | {ip, ipaddress()} | {verify, code()} | {depth, depth()} | {certfile, path()} | {keyfile, path()} | {password, string()} | {cacertfile, path()} | {ciphers, string()}</v>
335
<v>ListenSocket = sslsocket()</v>
338
<p>Sets up a socket to listen on port <c>Port</c> at the local host.
339
If <c>Port</c> is zero, <c>listen/2</c> picks an available port
340
number (use <c>port/1</c> to retrieve it).
342
<p>The listen queue size defaults to 5. If a different value is
343
wanted, the option <c>{backlog, Size}</c> should be added to the
346
<p>An empty <c>Options</c> list is considered an error, and
347
<c>{error, enooptions}</c> is returned.
349
<p>The returned <c>ListenSocket</c> can only be used in calls to
350
<c>transport_accept/[1,2]</c>.</p>
354
<name>peercert(Socket) -> {ok, Cert} | {error, Reason}</name>
355
<fsummary>Return the peer certificate.</fsummary>
357
<v>Socket = sslsocket()</v>
358
<v>Cert = binary()()</v>
359
<v>Subject = term()()</v>
362
<p>Returns the DER encoded peer certificate, the certificate can be decoded with
363
<c>public_key:pkix_decode_cert/2</c>.
368
<name>peername(Socket) -> {ok, {Address, Port}} | {error, Reason}</name>
369
<fsummary>Return peer address and port.</fsummary>
371
<v>Socket = sslsocket()</v>
372
<v>Address = ipaddress()</v>
373
<v>Port = integer()</v>
376
<p>Returns the address and port number of the peer.</p>
380
<name>pid(Socket) -> pid()</name>
381
<fsummary>Return the pid of the socket process.</fsummary>
383
<v>Socket = sslsocket()</v>
386
<p>Returns the pid of the socket process. The returned pid should
387
only be used for receiving exit messages.</p>
391
<name>recv(Socket, Length) -> {ok, Data} | {error, Reason}</name>
392
<name>recv(Socket, Length, Timeout) -> {ok, Data} | {error, Reason}</name>
393
<fsummary>Receive data on socket.</fsummary>
395
<v>Socket = sslsocket()</v>
396
<v>Length = integer() >= 0</v>
397
<v>Timeout = integer()</v>
398
<v>Data = bytes() | binary()</v>
401
<p>Receives data on socket <c>Socket</c> when the socket is in
402
passive mode, i.e. when the option <c>{active, false}</c>
405
<p>A notable return value is <c>{error, closed}</c> which
406
indicates that the socket is closed.
408
<p>A positive value of the <c>Length</c> argument is only
409
valid when the socket is in raw mode (option <c>{packet, 0}</c> is set, and the option <c>binary</c> is <em>not</em>
410
set); otherwise it should be set to 0, whence all available
413
<p>If the optional <c>Timeout</c> parameter is specified, and
414
no data was available within the given time, <c>{error, timeout}</c> is returned. The default value for
415
<c>Timeout</c> is <c>infinity</c>.</p>
419
<name>seed(Data) -> ok | {error, Reason}</name>
420
<fsummary>Seed the ssl random generator.</fsummary>
422
<v>Data = iolist() | binary()</v>
425
<p>Seeds the ssl random generator.
427
<p>It is strongly advised to seed the random generator after
428
the ssl application has been started, and before any
429
connections are established. Although the port program
430
interfacing to the OpenSSL libraries does a "random" seeding
431
of its own in order to make everything work properly, that
432
seeding is by no means random for the world since it has a
433
constant value which is known to everyone reading the source
436
<p>A notable return value is <c>{error, edata}}</c> indicating that
437
<c>Data</c> was not a binary nor an iolist.</p>
441
<name>send(Socket, Data) -> ok | {error, Reason}</name>
442
<fsummary>Write data to a socket.</fsummary>
444
<v>Socket = sslsocket()</v>
445
<v>Data = iolist() | binary()</v>
448
<p>Writes <c>Data</c> to <c>Socket</c>. </p>
449
<p>A notable return value is <c>{error, closed}</c> indicating that
450
the socket is closed.</p>
454
<name>setopts(Socket, Options) -> ok | {error, Reason}</name>
455
<fsummary>Set socket options.</fsummary>
457
<v>Socket = sslsocket()</v>
458
<v>Options = [socketoption]()</v>
461
<p>Sets options according to <c>Options</c> for the socket
466
<name>ssl_accept(Socket) -> ok | {error, Reason}</name>
467
<name>ssl_accept(Socket, Timeout) -> ok | {error, Reason}</name>
468
<fsummary>Perform server-side SSL handshake and key exchange</fsummary>
470
<v>Socket = sslsocket()</v>
471
<v>Timeout = integer()</v>
472
<v>Reason = atom()</v>
475
<p>The <c>ssl_accept</c> function establish the SSL connection
476
on the server side. It should be called directly after
477
<c>transport_accept</c>, in the spawned server-loop.</p>
478
<p>Note that the ssl connection is not complete until <c>ssl_accept</c>
479
has returned <c>true</c>, and if an error is returned, the socket
480
is unavailable and for instance <c>close/1</c> will crash.</p>
484
<name>sockname(Socket) -> {ok, {Address, Port}} | {error, Reason}</name>
485
<fsummary>Return the local address and port.</fsummary>
487
<v>Socket = sslsocket()</v>
488
<v>Address = ipaddress()</v>
489
<v>Port = integer()</v>
492
<p>Returns the local address and port number of the socket
497
<name>transport_accept(Socket) -> {ok, NewSocket} | {error, Reason}</name>
498
<name>transport_accept(Socket, Timeout) -> {ok, NewSocket} | {error, Reason}</name>
499
<fsummary>Accept an incoming connection and prepare for <c>ssl_accept</c></fsummary>
501
<v>Socket = NewSocket = sslsocket()</v>
502
<v>Timeout = integer()</v>
503
<v>Reason = atom()</v>
506
<p>Accepts an incoming connection request on a listen socket.
507
<c>ListenSocket</c> must be a socket returned from <c>listen/2</c>.
508
The socket returned should be passed to <c>ssl_accept</c> to
509
complete ssl handshaking and establishing the connection.</p>
511
<p>The socket returned can only be used with <c>ssl_accept</c>,
512
no traffic can be sent or received before that call.</p>
514
<p>The accepted socket inherits the options set for <c>ListenSocket</c>
515
in <c>listen/2</c>.</p>
516
<p>The default value for <c>Timeout</c> is <c>infinity</c>. If
517
<c>Timeout</c> is specified, and no connection is accepted within
518
the given time, <c>{error, timeout}</c> is returned.</p>
522
<name>version() -> {ok, {SSLVsn, CompVsn, LibVsn}}</name>
523
<fsummary>Return the version of SSL.</fsummary>
525
<v>SSLVsn = CompVsn = LibVsn = string()()</v>
528
<p>Returns the SSL application version (<c>SSLVsn</c>), the library
529
version used when compiling the SSL application port program
530
(<c>CompVsn</c>), and the actual library version used when
531
dynamically linking in runtime (<c>LibVsn</c>).
533
<p>If the SSL application has not been started, <c>CompVsn</c> and
534
<c>LibVsn</c> are empty strings.
541
<title>ERRORS</title>
542
<p>The possible error reasons and the corresponding diagnostic strings
543
returned by <c>format_error/1</c> are either the same as those defined
544
in the <c>inet(3)</c> reference manual, or as follows:
547
<tag><c>closed</c></tag>
549
<p>Connection closed for the operation in question.
552
<tag><c>ebadsocket</c></tag>
554
<p>Connection not found (internal error).
557
<tag><c>ebadstate</c></tag>
559
<p>Connection not in connect state (internal error).
562
<tag><c>ebrokertype</c></tag>
564
<p>Wrong broker type (internal error).
567
<tag><c>ecacertfile</c></tag>
569
<p>Own CA certificate file is invalid.
572
<tag><c>ecertfile</c></tag>
574
<p>Own certificate file is invalid.
577
<tag><c>echaintoolong</c></tag>
579
<p>The chain of certificates provided by peer is too long.
582
<tag><c>ecipher</c></tag>
584
<p>Own list of specified ciphers is invalid.
587
<tag><c>ekeyfile</c></tag>
589
<p>Own private key file is invalid.
592
<tag><c>ekeymismatch</c></tag>
594
<p>Own private key does not match own certificate.
597
<tag><c>enoissuercert</c></tag>
599
<p>Cannot find certificate of issuer of certificate provided
603
<tag><c>enoservercert</c></tag>
605
<p>Attempt to do accept without having set own certificate.
608
<tag><c>enotlistener</c></tag>
610
<p>Attempt to accept on a non-listening socket.
613
<tag><c>enoproxysocket</c></tag>
615
<p>No proxy socket found (internal error).
618
<tag><c>enooptions</c></tag>
620
<p>The list of options is empty.
623
<tag><c>enotstarted</c></tag>
625
<p>The SSL application has not been started.
628
<tag><c>eoptions</c></tag>
630
<p>Invalid list of options.
633
<tag><c>epeercert</c></tag>
635
<p>Certificate provided by peer is in error.
638
<tag><c>epeercertexpired</c></tag>
640
<p>Certificate provided by peer has expired.
643
<tag><c>epeercertinvalid</c></tag>
645
<p>Certificate provided by peer is invalid.
648
<tag><c>eselfsignedcert</c></tag>
650
<p>Certificate provided by peer is self signed.
653
<tag><c>esslaccept</c></tag>
655
<p>Server SSL handshake procedure between client and server failed.
658
<tag><c>esslconnect</c></tag>
660
<p>Client SSL handshake procedure between client and server failed.
663
<tag><c>esslerrssl</c></tag>
665
<p>SSL protocol failure. Typically because of a fatal alert
669
<tag><c>ewantconnect</c></tag>
671
<p>Protocol wants to connect, which is not supported in
672
this version of the SSL application.
675
<tag><c>ex509lookup</c></tag>
677
<p>Protocol wants X.509 lookup, which is not supported in
678
this version of the SSL application.
681
<tag><c>{badcall, Call}</c></tag>
683
<p>Call not recognized for current mode (active or passive) and
687
<tag><c>{badcast, Cast}</c></tag>
689
<p>Call not recognized for current mode (active or passive) and
693
<tag><c>{badinfo, Info}</c></tag>
695
<p>Call not recognized for current mode (active or passive) and
703
<title>SEE ALSO</title>
704
<p>gen_tcp(3), inet(3) public_key(3) </p>