Nginx模块,通过使用Virgil安全基础结构实现噪声套接字协议。
Nginx module that implements Noise Socket Protocol by using Virgil Security infrastructure.
Noise_XX_25519_AESGCM_BLAKE2b
noise protocol pattern is implemented.Noise-C
it is described in Noise-C Documentation.Noise-C
in system:
$ make install
To take stable release of libsodium and to build it:
$ git clone https://github.com/jedisct1/libsodium.git -b stable
$ ./configure
$ make && make check
$ sudo make install
$ autoreconf -i
$ ./configure --with-openssl --with-libsodium
$ make
$ make check
virgil-nginx-noise-socket/config
file (a line 37, ngx_module_libs=”… - lsodium”
$ mkdir ~/workspace
$ tar -xvf path/to/nginx-1.12.1.tar.gz -C ~/workspace
$ git clone https://github.com/VirgilSecurity/virgil-nginx-noise-socket ~/workspace/nginx-1.12.1/virgil-nginx-noise-socket
The example of a script for build of the nginx server with the module is located in virgil-nginx-noise-socket/example/nginx_configure.sh
. You must copy this script to root directory of source code of nginx and run this
$ cp ~/workspace/nginx-1.12.1/virgil-nginx-noise-socket/example/nginx_configure.sh ~/workspace/nginx-1.12.1/
$ sudo ~/workspace/nginx-1.12.1/nginx_configure.sh
The example of a test configuration of the server is located in virgil-nginx-noise-socket/example/nginx.conf
. The configuration realizes a functionality of reverse proxy and a backend server working in one copy of nginx launched by the local machine. The configuration works as follows:
https://localhost/ | -> | internal redirect to noise_socket context | -> | proxy to backend over noise socket | —-> |
—-> | noise_socket context on the backend server | -> | internal redirect to http context | -> | access to the static page index.html “Welcome to nginx!” |
For operation of the Noise Protocol
files of private keys are necessary for noise initiator(client) and noise responder (server). Keys are generated by means of the test utility of echo-keygen
from libraryNoise-C
(noise-c/examples/echo/echo-keygen
). Use of the utility is described in noise-c example echo. Examples of files of the generated keys virgil-nginx-noise-socket/example/server_key_25519
and virgil-nginx-noise-socket/example/client_key_25519
.
It is necessary for start of a test configuration:
virgil-nginx-noise-socket/example/
into /etc/noise directorynginx.conf
from the folder virgil-nginx-noise-socket/example/
into /etc/nginx directory
$ sudo openssl genrsa -out /etc/ssl/nginx-selfsigned.key 2048
$ sudo openssl req -x509 -new -key /etc/ssl/nginx-selfsigned.key -days 10000 -out /etc/ssl/nginx-selfsigned.crt
$ sudo ~/workspace/nginx-1.12.1/objs/nginx
https://localhost
. You shall to see “Welcome to nginx!”
$ sudo ~/workspace/nginx-1.12.1/objs/nginx -s stop
Syntax: noise_socket { ... }
Default: —
Context: main
Provides the configuration file context in which the noise socket server directives are specified.
Syntax: server { ... }
Default: —
Context: noise_socket
Sets the configuration for a server.
Syntax: listen address:port [noise] [udp] [backlog=number] [ipv6only=on|off] [reuseport] [so_keepalive=on|off|[keepidle]:[keepintvl]:[keepcnt]];
Default: —
Context: server
The [noise]
parameter allows specifying that all connections accepted on this port should work in noise socket mode. Defines that this socket is used as noise responder (server). Remaining parameters are similar to the parameters described for the directive of listen of the ngx_stream_core_module module.
Syntax: preread_buffer_size size;
Default: preread_buffer_size 65517;
Context: noise_socket, server
Specifies a size of the preread buffer for server.
Syntax: server_private_key_file file;
Default: —
Context: noise_socket, server
Specifies a file with the secret key in the format of the simple sequence of bytes for the given noise responder (server).
Syntax: client_private_key_file file;
Default: —
Context: noise_socket, server
Specifies a file with the secret key in the format of the simple sequence of bytes for the given noise initiator(client).
Syntax: proxy_noise on | off;
Default: proxy_noise off;
Context: noise_socket, server
Enables the noise socket protocol for connections to a proxied server.
Syntax: block_buffer_size size;
Default: block_buffer_size 65517;
Context: noise_socket, server
Sets the size of the buffer used for reading data from the proxied server. Also sets the size of the buffer used for reading data from the client. Value by default is the maximum size of the payload determined in the specification The Noise Protocol Framework. This parameter determines the buffer size for noise initiator(client) and noise responder (server).
Syntax: noise_handshake_timeout time;
Default: noise_handshake_timeout 60s;
Context: noise_socket, server
Specifies a timeout for the Noise Protocol
handshake to complete.
proxy_pass
, proxy_bind
, proxy_connect_timeout
, proxy_timeout
, proxy_upload_rate
, proxy_download_rate
, proxy_responses
, proxy_next_upstream
, proxy_next_upstream_tries
, proxy_next_upstream_timeout
.
The description of directives same, as for the ngx_stream_proxy_module module only in noise_socket
context.resolver
, resolver_timeout
, preread_timeout
, tcp_nodelay
The description of directives same, as for the ngx_stream_core_module module only in noise_socket
context.
For setup of saving a noise socket session it is possible to use the following directives of nginx for frontend server http:
http {
...
proxy_http_version 1.1;
keepalive_requests 10;
keepalive_timeout 50s;
...
server {
...
location {
...
proxy_set_header Connection keep-alive;
...
}
}
ustream name {
....
keepalive 1;
....
}
}
Directives are designated by comments “###For the noise socket connection keepalive setup…###” in the file of a test configuration virgil-nginx-noise-socket/example/nginx.conf