/usr/lib/swi-prolog/library/ssl.pl is in swi-prolog-nox 6.6.4-2ubuntu1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 | /* $Id$
Part of SWI-Prolog
Author: Jan Wielemaker
E-mail: J.Wielemaker@vu.nl
WWW: http://www.swi-prolog.org
Copyright (C): 2004-2011, SWI-Prolog Foundation
VU University Amsterdam
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:- module(ssl,
[ load_certificate/2, % +Stream, -Certificate
load_private_key/3, % +Stream, +Password, -Key
load_public_key/2, % +Stream, -Key
load_crl/2, % +Stream, -Crl
rsa_private_decrypt/3, % +Key, +Ciphertext, -Plaintext
rsa_private_encrypt/3, % +Key, +Plaintext, -Ciphertext
rsa_public_decrypt/3, % +Key, +Ciphertext, -Plaintext
rsa_public_encrypt/3, % +Key, +Plaintext, -Ciphertext
ssl_context/3, % +Role, -Config, +Options
ssl_init/3, % -Config, +Role, +Options
ssl_accept/3, % +Config, -Socket, -Peer
ssl_open/3, % +Config, -Read, -Write
ssl_open/4, % +Config, +Socket, -Read, -Write
ssl_negotiate/5, % +Config, +PlainRead, +PlainWrite, -SSLRead, -SSLWrite
ssl_exit/1, % +Config
ssl_session/2 % +Stream, -Session
]).
:- use_module(library(socket)).
:- use_module(library(error)).
:- use_module(library(option)).
:- use_foreign_library(foreign(ssl4pl)).
:- meta_predicate
ssl_init(-, +, :),
ssl_context(+, -, :).
:- predicate_options(ssl_context/3, 3,
[ host(atom),
port(integer),
certificate_file(atom),
key_file(atom),
password(any),
pem_password_hook(callable),
cacert_file(atom),
cert_verify_hook(callable),
cert(boolean),
peer_cert(boolean),
close_parent(boolean)
]).
:- predicate_options(ssl_init/3, 3, [pass_to(ssl_context/3, 3)]).
/** <module> Secure Socket Layer library
*/
ssl_context(Role, SSL, Options) :- % Prolog to exploit meta-predicate
'_ssl_context'(Role, SSL, Options).
/*
These predicates are here to support backward compatability with the previous
incarnation of the SSL library. No changes should be required for legacy code.
*/
ssl_init(SSL, Role, Options) :-
must_be(oneof([client,server]), Role),
ssl_init2(Role, SSL, Options).
ssl_init2(server, SSL, Options) :-
Options = _:Options1,
option(port(Port), Options1),
tcp_socket(Socket),
tcp_setopt(Socket, reuseaddr),
tcp_bind(Socket, Port),
tcp_listen(Socket, 5),
catch(ssl_context(server, SSL, Options),
Exception,
( tcp_close_socket(Socket),
throw(Exception))),
Socket = '$socket'(S),
ssl_put_socket(SSL, S).
ssl_init2(client, SSL, Options) :-
Options = _:Options1,
option(port(Port), Options1),
option(host(Host), Options1),
tcp_socket(Socket),
tcp_setopt(Socket, reuseaddr),
tcp_connect(Socket, Host:Port),
catch(ssl_context(client, SSL, Options),
Exception,
( tcp_close_socket(Socket),
throw(Exception))),
Socket = '$socket'(S),
ssl_put_socket(SSL, S).
ssl_accept(SSL, Socket, Peer):-
ssl_get_socket(SSL, S),
tcp_accept('$socket'(S), Socket, Peer).
ssl_open(SSL, Socket, In, Out):-
tcp_open_socket(Socket, Read, Write),
ssl_negotiate(SSL, Read, Write, In, Out).
ssl_open(SSL, In, Out):-
ssl_get_socket(SSL, S),
tcp_open_socket('$socket'(S), Read, Write),
ssl_negotiate(SSL, Read, Write, In, Out).
|