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 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624
|
.TH new_ssl 3 "ssl 3.9" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
ssl \- Interface Functions for Secure Socket Layer
.SH DESCRIPTION
.LP
This module contains interface functions to the Secure Socket Layer\&.
.SH NEW SSL
.LP
This manual page describes functions that are defined in the ssl module and represents the new ssl implementation that coexists with the old one, as the new implementation is not yet compleat enough to replace the old one\&.
.LP
The new implementation can be accessed by providing the option {ssl_imp, new} to the ssl:connect and ssl:listen functions\&.
.LP
The new implementation is Erlang based and all logic is in Erlang and only payload encryption calculations are done in C via the crypto application\&. The main reason for making a new implementation is that the old solution was very crippled as the control of the ssl-socket was deep down in openssl making it hard if not impossible to support all inet options, ipv6 and upgrade of a tcp connection to a ssl connection\&. The alfa version has a few limitations that will be removed before the ssl-4\&.0 release\&. Main differences and limitations in the alfa are listed below\&.
.RS 2
.TP 2
*
New ssl requires the crypto application\&.
.TP 2
*
The option reuseaddr is supported and the default value is false as in gen_tcp\&. Old ssl is patched to accept that the option is set to true to provide a smoother migration between the versions\&. In old ssl the option is hard coded to true\&.
.TP 2
*
ssl:version/0 is replaced by ssl:versions/0
.TP 2
*
ssl:ciphers/0 is replaced by ssl:cipher_suites/0
.TP 2
*
ssl:pid/1 is a meaningless function in new ssl and will be deprecated in ssl-4\&.0 until it is removed it will return a valid but meaningless pid\&.
.TP 2
*
New API functions are ssl:shutdown/2, ssl:cipher_suites/[0,1] and ssl:versions/0
.TP 2
*
Diffie-Hellman keyexchange is not supported\&.
.TP 2
*
Not all inet packet types are supported\&.
.TP 2
*
CRL and policy certificate extensions are not supported\&.
.TP 2
*
In this alfa only sslv3 is enabled, although tlsv1 and tlsv1\&.1 versions are implemented and will be supported in future versions\&.
.TP 2
*
For security reasons sslv2 is not supported\&.
.RE
.SH COMMON DATA TYPES
.LP
The following data types are used in the functions below:
.nf
boolean() = true | false
.fi
.nf
option() = socketoption() | ssloption()
.fi
.nf
socketoption() - [{property(), value()}], property() = atom(),
value() = term(), defaults to
[{mode,list},{packet, 0},{header, 0},{active, true}]\&.
.fi
.LP
For valid options see inet(3) and gen_tcp(3) \&.
.nf
ssloption() = {verify, verify_code()} | {depth, integer()} |
{certfile, path()} | {keyfile, path()} | {password, string()} |
{cacertfile, path()} | {ciphers, ciphers()} | {ssl_imp, ssl_imp()}
| {reuse_sessions, boolean()}
.fi
.nf
path() = string() - representing a file path\&.
.fi
.nf
verify_code() = 0 | 1 | 2
.fi
.nf
host() = hostname() | ipaddress()
.fi
.nf
hostname() = string()
.fi
.nf
ip_address() = {N1,N2,N3,N4} % IPv4
| {K1,K2,K3,K4,K5,K6,K7,K8} % IPv6
.fi
.nf
sslsocket() - opaque to the user\&.
.fi
.nf
protocol() = sslv3 | tlsv1 | \&'tlsv1\&.1\&'
.fi
.nf
ciphers() = [ciphersuite()] | sting() (according to old API)
.fi
.nf
chiphersuite() =
{key_exchange(), chipher(), hash(), exportable()}
.fi
.nf
key_exchange() = rsa | dh_dss | dh_rsa | dh_anon | dhe_dss
| dhe_rsa | krb5 | KeyExchange_export
.fi
.nf
cipher() = rc4_128 | idea_cbc | des_cbc | \&'3des_ede_cbc\&'
des40_cbc | dh_dss | aes_128_cbc | aes_256_cbc |
rc2_cbc_40 | rc4_40
.fi
.nf
hash() = md5 | sha
.fi
.nf
exportable() = export | no_export | ignore
.fi
.nf
ssl_imp() = new | old - default is old\&.
.fi
.SH SSL OPTION DESCRIPTIONS
.RS 2
.TP 4
.B
{verify, verify_code()}:
Specifies type of verification: 0 = do not verify peer; 1 = verify peer, 2 = verify peer, fail if no peer certificate\&. The default value is 0\&.
.TP 4
.B
{depth, integer()}:
Specifies the maximum verification depth, i\&.e\&. how far in a chain of certificates the verification process can proceed before the verification is considered to fail\&. Peer certificate = 0, CA certificate = 1, higher level CA certificate = 2, etc\&. The value 2 thus means that a chain can at most contain peer cert, CA cert, next CA cert, and an additional CA cert\&. The default value is 1\&.
.TP 4
.B
{certfile, path()}:
Path to a file containing the user\&'s certificate\&.
.TP 4
.B
{keyfile, path()}:
Path to file containing user\&'s private PEM encoded key\&.
.TP 4
.B
{password, string()}:
String containing the user\&'s password\&. Only used if the private keyfile is password protected\&.
.TP 4
.B
{cacertfile, path()}:
Path to file containing PEM encoded CA certificates (trusted certificates used for verifying a peer certificate)\&.
.TP 4
.B
{ciphers, ciphers()}:
The function \fIciphers_suites/0\fR can be used to find all availabe ciphers\&.
.TP 4
.B
{ssl_imp, ssl_imp()}:
Specify which ssl implementation you want to use\&.
.TP 4
.B
{reuse_sessions, boolean()}:
Specifies if ssl sessions should be reused when possible\&.
.RE
.SH GENERAL
.LP
When a ssl socket is in active mode (the default), data from the socket is delivered to the owner of the socket in the form of messages:
.RS 2
.TP 2
*
{ssl, Socket, Data}
.TP 2
*
{ssl_closed, Socket}
.TP 2
*
{ssl_error, Socket, Reason}
.RE
.LP
A \fITimeout\fR argument specifies a timeout in milliseconds\&. The default value for a \fITimeout\fR argument is \fIinfinity\fR\&.
.SH EXPORTS
.LP
.B
cipher_suites() ->
.br
.B
cipher_suites(Type) -> ciphers()
.br
.RS
.TP
Types
Type = erlang | openssl
.br
.RE
.RS
.LP
Returns a list of supported cipher suites\&. cipher_suites() is equivalent to cipher_suites(erlang)\&. Type openssl is provided for backwards compatibility with old ssl that used openssl\&.
.RE
.LP
.B
connect(Socket, SslOptions) ->
.br
.B
connect(Socket, SslOptions, Timeout) -> {ok, SslSocket} | {error, Reason}
.br
.RS
.TP
Types
Socket = socket()
.br
SslOptions = [ssloption()]
.br
Timeout = integer() | infinity
.br
SslSocket = sslsocket()
.br
Reason = term()
.br
.RE
.RS
.LP
Upgrades a gen_tcp, or equivalent, connected socket to a ssl socket e\&.i performs the client-side ssl handshake\&.
.RE
.LP
.B
connect(Host, Port, Options) ->
.br
.B
connect(Host, Port, Options, Timeout) -> {ok, SslSocket} | {error, Reason}
.br
.RS
.TP
Types
Host = host()
.br
Port = integer()
.br
Options = [option()]
.br
Timeout = integer() | infinity
.br
SslSocket = sslsocket()
.br
Reason = term()
.br
.RE
.RS
.LP
Opens an ssl connection to Host, Port\&.
.RE
.LP
.B
close(SslSocket) -> ok | {error, Reason}
.br
.RS
.TP
Types
SslSocket = sslsocket()
.br
Reason = term()
.br
.RE
.RS
.LP
Close a ssl connection\&.
.RE
.LP
.B
controlling_process(SslSocket, NewOwner) -> ok | {error, Reason}
.br
.RS
.TP
Types
SslSocket = sslsocket()
.br
NewOwner = pid()
.br
Reason = term()
.br
.RE
.RS
.LP
Assigns a new controlling process to the ssl-socket\&. A controlling process is the owner of a ssl-socket, and receives all messages from the socket\&.
.RE
.LP
.B
connection_info(SslSocket) -> {ok, {ProtocolVersion, CipherSuite}} | {error, Reason}
.br
.RS
.TP
Types
CipherSuite = ciphersuite()
.br
ProtocolVersion = protocol()
.br
.RE
.RS
.LP
Returns the negotiated protocol version and cipher suite\&.
.RE
.LP
.B
getopts(Socket) ->
.br
.B
getopts(Socket, OptionNames) -> {ok, [socketoption()]} | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
OptionNames = [property()]
.br
.RE
.RS
.LP
Get the value of the specified socket options, if no options are specified all options are returned\&.
.RE
.LP
.B
listen(Port, Options) -> {ok, ListenSocket} | {error, Reason}
.br
.RS
.TP
Types
Port = integer()
.br
Options = options()
.br
ListenSocket = sslsocket()
.br
.RE
.RS
.LP
Creates a ssl listen socket\&.
.RE
.LP
.B
peercert(Socket) ->
.br
.B
peercert(Socket, Opts) -> {ok, Cert} | {ok, Subject} | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Opts = [] | [pkix] | [ssl] | [pkix, subject] | [ssl, subject]
.br
Cert = term()
.br
Subject = term()
.br
.RE
.RS
.LP
\fIpeercert(Cert)\fR is equivalent to \fIpeercert(Cert, [])\fR\&.
.LP
The form of the returned certificate depends on the options\&.
.LP
If the options list is empty the certificate is returned as a DER encoded binary\&.
.LP
The options \fIpkix\fR and \fIssl\fR implies that the certificate is returned as a parsed ASN\&.1 structure in the form of an Erlang term\&.
.LP
The \fIssl\fR option gives a more elaborate return structure, with more explicit information\&. In particular object identifiers are replaced by atoms\&.
.LP
The option \fIsubject\fR implies that only the subject\&'s distinguished name part of the peer certificate is returned\&.
.RE
.LP
.B
peername(Socket) -> {ok, {Address, Port}} | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Address = ipaddress()
.br
Port = integer()
.br
.RE
.RS
.LP
Returns the address and port number of the peer\&.
.RE
.LP
.B
recv(Socket, Length) ->
.br
.B
recv(Socket, Length, Timeout) -> {ok, Data} | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Length = integer()
.br
Timeout = integer()
.br
Data = [char()] | binary()
.br
.RE
.RS
.LP
This function receives a packet from a socket in passive mode\&. A closed socket is indicated by a return value \fI{error, closed}\fR\&.
.LP
The \fILength\fR argument is only meaningful when the socket is in \fIraw\fR mode and denotes the number of bytes to read\&. If \fILength\fR = 0, all available bytes are returned\&. If \fILength\fR > 0, exactly \fILength\fR bytes are returned, or an error; possibly discarding less than \fILength\fR bytes of data when the socket gets closed from the other side\&.
.LP
The optional \fITimeout\fR parameter specifies a timeout in milliseconds\&. The default value is \fIinfinity\fR\&.
.RE
.LP
.B
send(Socket, Data) -> ok | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Data = iolist() | binary()
.br
.RE
.RS
.LP
Writes \fIData\fR to \fISocket\fR\&.
.LP
A notable return value is \fI{error, closed}\fR indicating that the socket is closed\&.
.RE
.LP
.B
setopts(Socket, Options) -> ok | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Options = [socketoption]()
.br
.RE
.RS
.LP
Sets options according to \fIOptions\fR for the socket \fISocket\fR\&.
.RE
.LP
.B
shutdown(Socket, How) -> ok | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
How = read | write | read_write
.br
Reason = reason()
.br
.RE
.RS
.LP
Immediately close a socket in one or two directions\&.
.LP
\fIHow == write\fR means closing the socket for writing, reading from it is still possible\&.
.LP
To be able to handle that the peer has done a shutdown on the write side, the \fI{exit_on_close, false}\fR option is useful\&.
.RE
.LP
.B
ssl_accept(ListenSocket) ->
.br
.B
ssl_accept(ListenSocket, Timeout) -> ok | {error, Reason}
.br
.RS
.TP
Types
ListenSocket = sslsocket()
.br
Timeout = integer()
.br
Reason = term()
.br
.RE
.RS
.LP
The \fIssl_accept\fR function establish the SSL connection on the server side\&. It should be called directly after \fItransport_accept\fR, in the spawned server-loop\&.
.RE
.LP
.B
ssl_accept(ListenSocket, SslOptions) ->
.br
.B
ssl_accept(ListenSocket, SslOptions, Timeout) -> {ok, Socket} | {error, Reason}
.br
.RS
.TP
Types
ListenSocket = socket()
.br
SslOptions = ssloptions()
.br
Timeout = integer()
.br
Reason = term()
.br
.RE
.RS
.LP
Upgrades a gen_tcp, or equivalent, socket to a ssl socket e\&.i performs the ssl server-side handshake\&.
.RE
.LP
.B
sockname(Socket) -> {ok, {Address, Port}} | {error, Reason}
.br
.RS
.TP
Types
Socket = sslsocket()
.br
Address = ipaddress()
.br
Port = integer()
.br
.RE
.RS
.LP
Returns the local address and port number of the socket \fISocket\fR\&.
.RE
.LP
.B
start() ->
.br
.B
start(Type) -> ok | {error, Reason}
.br
.RS
.TP
Types
Type = permanent | transient | temporary
.br
.RE
.RS
.LP
Starts the Ssl application\&. Default type is temporary\&. application(3)
.RE
.LP
.B
stop() -> ok
.br
.RS
.LP
Stops the Ssl application\&. application(3)
.RE
.LP
.B
transport_accept(Socket) ->
.br
.B
transport_accept(Socket, Timeout) -> {ok, NewSocket} | {error, Reason}
.br
.RS
.TP
Types
Socket = NewSocket = sslsocket()
.br
Timeout = integer()
.br
Reason = reason()
.br
.RE
.RS
.LP
Accepts an incoming connection request on a listen socket\&. \fIListenSocket\fR must be a socket returned from \fIlisten/2\fR\&. The socket returned should be passed to \fIssl_accept\fR to complete ssl handshaking and establishing the connection\&.
.SS Warning:
.LP
The socket returned can only be used with \fIssl_accept\fR, no traffic can be sent or received before that call\&.
.LP
The accepted socket inherits the options set for \fIListenSocket\fR in \fIlisten/2\fR\&.
.LP
The default value for \fITimeout\fR is \fIinfinity\fR\&. If \fITimeout\fR is specified, and no connection is accepted within the given time, \fI{error, timeout}\fR is returned\&.
.RE
.LP
.B
versions() -> [{SslAppVer, SupportedSslVer, AvailableSslVsn}]
.br
.RS
.TP
Types
SslAppVer = string()
.br
SupportedSslVer = [protocol()]
.br
AvailableSslVsn = [protocol()]
.br
.RE
.RS
.LP
Returns version information relevant for the ssl application\&.
.RE
.SH SEE ALSO
.LP
inet(3) and gen_tcp(3)
|