Secure Mode for NetGear API¶
Overview¶
Secure Mode provides easy access to powerful, smart & secure ZeroMQ's Security Layers in NetGear API that enables strong encryption on data, and unbreakable authentication between the Server and the Client with the help of custom Certificates/keys and brings cheap, standardized privacy and authentication for distributed systems over the network.
Secure Mode uses a new wire protocol, ZMTP 3.0 that adds a security handshake to all ZeroMQ connections and a new security protocol, CurveZMQ, that implements "perfect forward security" between two ZeroMQ peers over a TCP connection.
Secure Mode can be easily activated in NetGear API through secure_mode attribute of its options dictionary parameter, during initialization. Furthermore, for managing this mode, NetGear API provides additional custom_cert_location, overwrite_cert & allowed_ips like attribute too.
In NetGear, the receiver (Client) binds and acts as the CURVE server (and runs the ZAP authenticator), whereas the sender (Server) connects and acts as the CURVE client. Therefore in this page, 'server' in ZeroMQ's security terms refers to NetGear's Client end.
Â
Supported ZMQ Security Layers¶
Secure mode supports the two most powerful ZMQ security layers:
-
Stonehouse: which switches to the CURVE security protocol that provides strong encryption on data, and almost unbreakable authentication. Stonehouse is the minimum you would use over public networks and assures the senders (NetGear Servers) that they are speaking to an authentic receiver (NetGear Client) while allowing any sender to connect. This security layer is less secure but at the same time faster than IronHouse security mechanism.
-
Ironhouse: which further extends Stonehouse layer with sender (NetGear Server) public key authentication. This is the strongest security model present in ZeroMQ, protecting against every attack we know about except end-point attacks. This security layer enhanced security comes at a price of additional latency.
Â
Important Information regarding Secure Mode
-
Secure Mode MUST be enabled at both ends (as the Server needs it to use the CURVE keys), but only the Client's
secure_modevalue decides the security layer (i.e. StoneHouse or IronHouse), since the Client is the CURVE server. -
In Secure Mode, The Client's end MUST run before the Server's end to establish a secure connection.
-
The Public+Secret Keypairs generated at the Server end MUST be made available at the Client's end too for successful authentication. If mismatched, connection failure will occur.
-
By Default, the Public+Secret Keypairs will be generated/stored at the
$HOME/.vidgear/keysdirectory of your machine (e.g./home/foo/.vidgear/keyson Linux). But you can also usecustom_cert_locationattribute to set your own Custom-Path for a directory to generate/store these Keypairs. -
DO NOT share generated public+secret Keypairs with anyone else on the network to avoid any potential security breach. At the Server End, You can easily use the
'overwrite_cert'attribute for regenerating New-Keypairs on initialization. But make sure those newly generated Keypairs at the Server-End MUST be made available at Client's End for successful authentication. -
IronHouse is the strongest Security Layer available, but it involves certain security checks that lead to ADDITIONAL LATENCY.
-
Secure Mode requires
libzmqlibrary version>= 4.2built with CURVE support. Otherwise, NetGear raisesRuntimeError. -
On Windows, Secure Mode also requires
tornado>= 6.1, which pyzmq's authenticator needs to run its event loop. It is already included in VidGear'scoreandasyncioextras (i.e.pip install vidgear[core]), otherwise install it viapip install tornado. -
Secret key files are created with
0600permissions inside a0700directory (on non-Windows systems). -
In IronHouse, all Servers share the one auto-generated client Keypair, so the Client can't tell them apart or revoke one of them. If you need that, use per-Server Keypairs instead.
Â
Features¶
-
Supports the two most powerful ZMQ security layers: StoneHouse & IronHouse.
-
Auto-generates, auto-validates & auto-stores the required Public+Secret Keypairs safely.
-
Compatible with all messaging pattern, primary and exclusive modes, and works across machines.
-
Survives auto-reconnection (Lazy Pirate pattern) without losing CURVE security.
-
Strong data encryption & Unbreakable authentication.
-
Able to protect against many man-in-the-middle (MITM) attacks.
-
Minimum hassle and very easy to enable and integrate.
Â
Exclusive Attributes¶
For implementing Secure Mode, NetGear API currently provide following exclusive attribute for its options dictionary parameter:
-
secure_mode(integer) : This attribute activates and sets the ZMQ security Mechanism. Its possible values are:1(StoneHouse) &2(IronHouse), and its default value is0(Grassland(no security)). Its usage is as follows: -
custom_cert_location(string): This attribute sets a custom location/path to directory to generate/store Public+Secret Keypair/Certificates for enabling encryption. This attribute will force NetGear to create.vidgearfolder (only if not available) at the assigned custom path (instead of home directory), and then use that directory for storing new Keypairs/Certificates. It can be used as follows:The assigned directory MUST already exist and be writable, otherwise NetGear raises
AssertionError. -
overwrite_cert(bool): [For Server-end only] This attribute sets whether to overwrite existing Public+Secret Keypair/Certificates and re-generate new ones, to protect against any potential security breach. If set toTruea new Keypair/Certificates will be generated during NetGear initialization in place of old ones. Its usage is as follows:overwrite_certparameter is disabled for Client's end! -
allowed_ips(list of strings): [For Client-end only] This optional attribute sets a ZAP whitelist of IP addresses of the Servers (senders) allowed to connect. By default, there's no IP whitelist, and any peer with valid CURVE credentials is accepted. Its usage is as follows:
Â
Usage Examples¶
Bare-Minimum Usage¶
Following is the bare-minimum code you need to get started with Secure Mode in NetGear API:
In Secure Mode, Client's end MUST run before the Server's end to establish a secure connection!
Client's End¶
Open your favorite terminal and execute the following python code:
You can terminate client anytime by pressing Ctrl+C on your keyboard!
Server's End¶
Then open another terminal on the same system and execute the following python code to send the frames to our client:
You can terminate both sides anytime by pressing Ctrl+C on your keyboard!
Â
Â
Using Secure Mode with Variable Parameters¶
Client's End¶
Open a terminal on Client System (where you want to display the input frames received from the Server) and execute the following python code:
In Secure Mode, Client's end MUST run before the Server's end to establish a secure connection!
Note down the local IP-address of this system(required at Server's end) and also replace it in the following code. You can follow this FAQ for this purpose.
You need to paste the Public+Secret Keypairs (generated at the Server End) at the $HOME/.vidgear/keys directory of your Client machine for a successful authentication!
You can terminate client anytime by pressing Ctrl+C on your keyboard!
Â
Server's End¶
Now, Open the terminal on another Server System (with a webcam connected to it at index 0), and execute the following python code:
Replace the IP address in the following code with Client's IP address you noted earlier.
You also need to copy the Public+Secret Keypairs (generated on running this example code) present in the $HOME/.vidgear/keys directory, and make available at Client's end for a successful authentication.
You can terminate stream on both side anytime by pressing Ctrl+C on your keyboard!
Â
Using per-Server Keypairs with IronHouse¶
In IronHouse, every Server uses the same auto-generated client.key_secret Keypair by default. If you need to tell Servers apart or revoke one of them, give each Server its own Keypair as follows:
-
On each Server machine, generate a new client Keypair (e.g. with pyzmq's
zmq.auth.create_certificates): -
Replace
client.keyandclient.key_secretin that Server's$HOME/.vidgear/keys/public_keysand$HOME/.vidgear/keys/private_keysdirectories respectively with the newly generated files. -
Copy that Server's new public
client.keyfile into the Client's$HOME/.vidgear/keys/public_keysdirectory under a unique name (e.g.server-1.key). The Client accepts any public key present in this directory. -
To revoke a Server, delete its public key file from the Client's
public_keysdirectory and restart the Client.
DO NOT use overwrite_cert at these Servers, as it will regenerate and overwrite these Keypairs.
Â