Presentation of cryptographic processes¶
Date |
Sep 20, 2024 |
Written by |
Hubert TOUVET, Vincent Cardon |
Applicable for WAPT |
>= 2.3.0.13180 |
Version of the Document |
2.3.0.0-0 |
Git hash |
812c0b1290d9eb243be0f07e7478b288b476aa39 |
Cryptographic processes are used in the following activities:
Signature and verification of the files contained in a package.
Signature and verification of the attributes of a package.
Signature and verification of instantaneous actions on the WAPT Agents.
Signature of inventories and status of WAPT Agents.
Authentication of the WAPT Agents Websocket connections on the WAPT Server.
HTTPS communication between the WAPT Agents and the WAPT Server.
HTTPS communication between the WAPT Console and the WAPT Server.
HTTPS communication between the WAPT Agents and the WAPT repositories.
Folders and files referenced in this document¶
<WAPT>
: WAPT installation folder. By default%ProgramFiles(x86)%\WAPT
.<WAPT>\wapt-get.ini
: WAPT Agent configuration file (wapt-get and waptservice).<WAPT>\ssl
: default directory of trusted certificates for signed packages and actions.<WAPT>\ssl\server
: default directory for storing the WAPT HTTPS Server certificates (pinning).<WAPT>\private
: default host key and certificate directory for signing the inventory and the Websocket connections.%LOCALAPPDATA%\waptconsole\waptconsole.ini
: configuration file for the WAPT Console and package development actions for the wapt-get tool.%APPDATA%\waptconsole\ssl
: default trusted certificate directory for importing packages from an external repository (i.e. package templates).
Definitions of Actors¶
Organization
An Organization is the realm of responsibility within which WAPT is used.
Certificate Authority
A Certificate Authority is the entity that keeps the keys that have been used to sign certificates for the Package Developers, the Package Deployers and the WAPT HTTPS Servers.
Administrators
Administrators have a personal RSA key and a certificate that has been signed by the Certificate Authority of the Organization; they also have a login and a password for accessing the WAPT Console.
WAPT Agents
WAPT clients are the realm of devices that the Organization has allowed the Administrators to manage with WAPT. The clients may or may not be a member of the Organization’s Active Directory domain.
WAPT Server
The WAPT Server is the Linux / Nginx/ PostgreSQL that the Organization uses to keep the inventory of WAPT equipped devices.
By default, the WAPT Server also plays the role of an internal WAPT Repository. The WAPT Server has a host account in the Organization’s Active Directory.
Internal WAPT repositories
Internal WAPT repositories are one or several Linux/ Nginx servers that deliver signed WAPT packages to WAPT clients using the HTTPS protocol.
External WAPT repositories
External WAPT repositories are a public WAPT repository that the Package Developers may use to import packages designed by other Organizations, under the condition that they check the adequacy of the WAPT package in regards the internal policies on security and safety;
Active Directory Server
The Active Directory Server manages the Organization’s AD domain;
Summary of crypto modules present in WAPT¶
The WAPT Agent, the WAPT Server and the WAPT Console make use of both Python interpreter code and Lazarus / FPC compiled code.
The Lazarus / FPC code make use of the mORMot framework (>= 2.0.4383) for the https protocol handling, client kerberos handling, X509 certificates operations, and cryptographic operations (Hash, RSA).
The mORMot framework is itself configured and linked to make use of OpenSSL 1.1.1s 1 Nov 2022 library for TLS sockets, asymetric RSA operations (key generation, encrypt, decrypt, sign, verify), and X509 certificates operations.
Python code (WAPT Agent, WAPT Server, WAPT Packages) is linked against the very same OpenSSL 1.1.1s 1 Nov 2022 libraries and makes use of following modules:
WAPT Agent Side:
cryptography==3.3.2 and pyOpenSSL==20.0.1 python modules linked on openssl 1.1.1s: used for all RSA crypto operations, X509 certificate generations and signature verifications in the python WAPT Agent.
winkerberos==0.8.0 (Windows agent) / kerberos==1.3.1 (Linux agent) and requests-kerberos==0.12.0: used for authenticating the WAPT client on its first registrationg on the WAPT Server.
certifi==2021.5.30: used as base for the Root Authorities certificates.
WAPT Server Side:
Python 3.8.18 ssl module linked on openssl 1.1.1s.
cryptography==3.3.2 and pyOpenSSL==20.0.1 linked on openssl 1.1.1s: used for all RSA crypto operations such as key generations, X509 certificate generations and signature verifications.
On the WAPT Server, the nginx/1.18.0 service is configured to serve WAPT Packages over https, it handles https API requests to the WAPT Server, client Kerberos authentications, and client certificate check. The nginx server is configured for TLS1.2, cipher ‘EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH’.
Types of PKI / CA infrastructures in a standard WAPT Setup¶
There are three types of PKI / CA in a standard WAPT setup
Type |
Usage |
Origin and registration |
Renewal |
Revocation |
---|---|---|---|---|
HTTPS transport certificate |
The purpose of this certificate is to secure the communications between the WAPT Agent and the WAPT Server and to authenticate the WAPT Server. |
The certificate is issued by a Certificate Authority trusted by the client computer (the Certificate Authority must be integrated into the local Certificate Store), and the private https key must be stored on the nginx http server. |
The certificate must be renewed as any https certificates handled by the Organization. |
The certificate must be revoked as any https certiticates handled by the Organization. |
The Administrator / Packager certificate |
The purpose of this certificate is to sign Packages and Messages |
This certificate is issued by the Certificate Authority of the Organization, and must be stored in the |
The certificate must be renewed using the standard process of the Certificate Authority of the Organization. |
CRL must be published through http and reachable by the WAPT Server, and the CRL distribution point attribute must be set in the certificate. The WAPT Server redistributes the CRL to the WAPT Agent. |
The WAPT Agent client certificate |
The purpose of this certificate is to authenticate the WAPT Agent with the WAPT server, to sign data and finally potentialy encrypt data that the WAPT Agent sends to the WAPT Server.
This certificate is purely technical to identify a WAPT client and is created through a CSR process initiated by the client during registration of the WAPT Agent with the WAPT Server.
The private key is stored on the client in |
The Certificate Authority is handled internaly by the WAPT Server and is used only for the authentication of clients on the WAPT Server. |
The renewal is done during intial registration or when the client certification fails. |
The revocation is handled internally by the WAPT Server which configures a CRL for the Nginx service. |
Key and certificate management for the Administrators¶
Packages and actions done by an Administrator are signed so that only Trusted Administrators are authorized to manage the devices.
The WAPT Administrator holds:
A private 2048 bit RSA key that has been encrypted by the aes-256-cbc algorithm.
A X509 certificate signed by an Certificate Authority trusted by the Organization.
Note
The process for creating the keys and signing, distributing and revocating the certificates are of the responsibility of the Organization using WAPT; that process is beyond the functional perimeter of WAPT.
However, to make the testing of WAPT easy, WAPT offers a function to generate a RSA key and its corresponding X509 certificate:
The generated RSA key is 2048bit long, encrypted with aes-256-cbc, encoded in PEM format and saved with a .pem extension.
The certificate is either self-signed, or signed by a Trusted Authority from whom we have received a key and a PEM formated certificate.
If the certificate is self-signed, then its
KeyUsage
attribute contains thekeyCertSign
flag.If the Administrator is authorized by the Organization to sign packages that contain python code (the presence of a
setup.py
file is detected in the package), theextendedKeyUsage
attribute of the certificate contains theCodeSigning
flag.The X509 certificate is encoded and handed over to the Administrator in PEM format with a .crt extension.
Validity of the Administrator’s certificate¶
The WAPT Agent trusts all unexpired X509 certificates located in the <wapt>ssl WAPT Agent directory.
If a PEM encoded .crt file in <wapt>ssl WAPT Agent directory contains more than one certificates, only the first one is trusted.
the WAPT Agent only checks the dates of validity (notValidBefore
/ notValidAfter
attributes).
The certificate is valid if (Now
>= notValidBefore
and Now
<= notValidAfter
).
Managing the WAPT Agent’s key and certificate¶
The WAPT Agent (waptservice) uses RSA keys and X509 certificates to authenticate itself with the WAPT Server.
The WAPT client certificate is used in the following situations:
To control access to hosts packages and other packages repositories when client certificate authentication is enabled in NGINX server configuration.
When updating the WAPT client status on the WAPT Server (update_server_status) signing informations.
When the WAPT Agent establishes a Websocket with the WAPT Server (waptservice) signing the WAPT client UUID.
First emission and later update of the WAPT Agent’s certificate¶
On finishing the installation process of the WAPT Agent on the device, the WAPT Agent automatically registers itself on the WAPT Server by sending a kerberos authenticated HTTPS request that uses the TGT of the host account.
The WAPT Agent uses Windows kerberos APIs implemented with kerberos-sspi and requests-kerberos python modules.
Note
This process works if and only if the device is joined to the Windows domain for which the WAPT Server is configured.
If the key and the certificates have not yet been generated, or if they do not match the current FQDN of the device, the WAPT Agent generates a self-signed RSA key and X509 certificate with the following parameters:
The key is 2048 bit RSA encoded in PEM format and stored in the file
<WAPT>\private\<device UID>.pem
.The generated certificate has the following attributes:
Subject.COMMON_NAME
=<device UID>
.Subject.ORGANIZATIONAL_UNIT_NAME
=name of the Organization registered in the WAPT client's Windows registry
.SubjectAlternativeName.DNSName
=<device UID>
.BasicConstraint.CA
=True
.Validity
=10 years
.Serialnumber
=random
.
The temporary self signed client certificate is saved in the
<WAPT>\private\<device UID>.crt
.Note
Only host accounts and Local Administrators have access to the
<WAPT>\private
directory because specific ACLs have been applied upon first installation of the WAPT Agent on the device.The inventory and the WAPT Agent status updates are sent to the WAPT Server over POST HTTPS requests.
The POST HTTPS requests are authenticated by adding two specific headers:
X-Signature:
JSON encoded BLOB of inventory or status informations.
Signature of the .json file with the private key of the WAPT Client: sha256 hashing and PKCS#1 v1.5 padding.
Base64 encoding of the signature.
X-Signer: Subject.COMMON_NAME of the WAPT Client.
After having initially authenticated the WAPT client with kerberos, the WAPT Server receives the certificate signing request sent by the Client, sign a proper client certificate and stores it in the table hosts of its inventory in PEM format (column host_certificate).
The newly signed client certificate is sent to the client.
The client then saves its certificate in the
<WAPT>\private\<device UID>.crt
.
Note
If the device is renamed, the key / certificate pair is regenerated.
When the WAPT Agent will update its status with the WAPT Server, the POST request will be refused because the remote device is registered in the database with another certificate.
The device will then retry to register with the WAPT Server using kerberos; then the new client certificate that has been signed by the WAPT Server will be saved in the database.
HTTPS communication between the WAPT clients and the WAPT repositories¶
Websocket communications between the WAPT clients and the WAPT Server¶
To allow immediate actions on the WAPT clients, the WAPT service deployed on the clients establishes and maintains a permanent Websocket with the WAPT Server.
This connection is TLS encrypted and uses on the client side the same bundle of certificates as the HTTPS connexion from the WAPT client to the WAPT Server.
Communications between the WAPT Console and the WAPT Server¶
Deploying certificates of Authorities of Certification¶
The verify_cert
parameter in section [global]
in file %LOCALAPPDATA%\waptconsole\waptconsole.ini
can have different values:
verify_cert
=True
or1
This method will only work well if the WAPT HTTPS Server is configured to send its certificate and the intermediary certificates upon initialization of the TLS connexion.
verify_cert
= <path to .pem>This method checks the HTTPS certificate using the indicated bundle of certificates. All the certificates of the intermediary Certificate Authorities MUST be bundled in a .pem formated file.
verify_cert
=False
or0
This method does not verify the HTTPS certificate of the WAPT Server.
Conventionally, the approved bundle of certificates from the Certificate Authority is stored in the <WAPT>\ssl\server
directory.
The WAPT Console includes a function that facilitates the initial recovery of the WAPT Server certificate chain and that stores it in .pem format in the <WAPT>\ssl\server\<server FQDN>
.
The Administrator is responsible for insuring that the recovered certificate chain is authentic.
It is also possible to recover the WAPT Server certificate chain and fill out the verify_cert
parameter with the command line wapt-get enable-check-certificate.
Process for signing a WAPT package¶
The process for signing a WAPT package is launched with the following actions:
Action wapt-get.exe build-upload <directory>.
Action wapt-get.exe sign-package <path-to-package-file.wapt>.
Saving a host package in the WAPT Console.
Editing or saving any package in the WAPT Console.
Importing a package from an external repository.
Creating a package with the setup wizard.
Initial parameters¶
ZIP file of the WAPT package.
.pem formated RSA private key of the certificate holder (encrypted with OpenSSL’s aes-256-cbc algorithm if the key has been created in the WAPT Console).
X509 certificate of the certificate holder matching the private key.
If the package to be signed contains a
setup.py
file, then the X509 certificate MUST have the advanced Key Usage extension codeSigning (1.3.6.1.5.5.7.3.3);
Signing the attributes in the control file¶
The control
file defines the metadata of a WAPT package and in particular its name, its version, its dependencies and its conflicts.
It is the identity card of the WAPT package.
These metadata are primarily used by the WAPT Agent to determine whether a package must be upgraded, and what packages must be first installed or removed.
The package attributes are therefore signed to insure the integrity and the authenticity of the WAPT package.
Process steps:
The attributes
signed_attributes
,signer
,signature_date
,signer_fingerprint
are added to the structure of thecontrol
file:signed_attributes
: comma separated list of the names of the attributes taken in account in the signature;signer
: CommonName of the certificate holder for information;signature_date
: current date and time (UTC) in ‘%Y-%m-%dT%H:%M:%S format;signer_fingerprint
: hexadecimal encoded sha256 fingerprint of the signer’s certificate obtained with the fingerprint function included in the cryptography.x509.Certificate class.
The signed attributes of the control structure are JSON encoded without space and line feed, and sorted in alphabetical order.
The resulting JSON BLOB is signed with sha256 hashing and PKCS#1 v1.5 padding.
The signature is base64 encoded and stored as a
signature
attribute in thecontrol
file.
Signing the files of the package¶
The
control
file attributes are signed and serialized in JSON format. The result is stored in the<WAPT>\control
file of the WAPT package.The PEM serialized X509 certificate of the certificate holder is stored in the
<WAPT>\certificate.crt
file of the WAPT package.The sha256 fingerprints of the all files contained in the WAPT package are hexadecimal encoded and stored as a JSON list [(filename,hash),] in the
<WAPT>\manifest.sha256
file in the WAPT package.The content of the file
<WAPT>\manifest.sha256
is signed with the private key of the Administrator (2048 bit RAS key), sha256 hashed and PKCS#1 v1.5 padded:The signature process relies on the signing function of the cryptography.rsa.RSAPrivateKey.signer class.
cryptography.rsa.RSAPrivateKey.signer relies on the OpenSSL functions of EVP_DigestSignInit.
The signature is base64 serialized and stored in the file
<WAPT>\signature.sha256
of the WAPT package.
Verifying the signature of a package attributes¶
The verification takes place:
When the
index
file of available packages on the WAPT client is updated from thePackages
index file on the repository.When a package signature is verified (installation, download) when not in development mode, i.e. if the installation takes place from a ZIP file and not from a development directory.
The verification consists of:
Reading the control attributes from the WAPT package’s
control
file.Recovering the X509 certificate from the certificate holder from the WAPT package’s
certificate.crt
file.Decoding the base64 formated signature attribute.
Constructing a JSON structure with the attributes to be signed (such as defined in the PackageEntry class).
Verifying if the public key of the holder’s certificate can verify the hash of the JSON structured list of attributes and the signature of the
control
file, using sha256 hashing and PKCS#1 v1.5 padding.Verifying whether the certificate is trusted (either it is present in the list of trusted certificates, or signed by a Trusted Certificate Authority).
In case we must verify the attributes without having the WAPT package on hand, we recover the list of certificates of potential certificate holders from the Packages
index file on the WAPT repository.
The certificates are named ssl/<hexadecimal formated certificate fingerprint>.crt
.
An attribute in the WAPT package’s control
file specifies the fingerprint of the control
file’s certificate holder.
Verifying the signature of a WAPT package¶
The verification takes place:
When installing a WAPT package on a WAPT client.
When editing an existing WAPT package.
When importing a WAPT package from an external repository (if the checkbox is checked in the WAPT Console).
The verification consists of:
Recovering the X509 certificate of the certificate holder from the WAPT package’s .crt file.
Verifying that the certificate has been signed by a Trusted Authority whose certificate is present in the folder
ssl
on the WAPT client.Verifying the signature of the file
manifest.sha256
with the public key.
Signing immediate actions¶
From the WAPT Console, the Administrators may launch actions directly on the WAPT clients connected with the WAPT Server using Websockets.
The WAPT Console signs these actions with the key and certificate of the Administrator before sending them to the WAPT Server using an HTTPS POST request; the request is then forwarded to the targeted WAPT clients.
Possible immediate actions are:
trigger_host_update.
trigger_host_upgrade.
trigger_install_packages.
trigger_remove_packages.
trigger_forget_packages.
trigger_cancel_all_tasks.
trigger_host_register.
start_waptexit.
show_message.
trigger_host_update_server_status.
trigger_change_description.
trigger_waptservicerestart.
unregister_computer.
trigger_gpupdate.
trigger_waptwua_scan.
trigger_waptwua_download.
trigger_waptwua_install.
trigger_waptwua_uninstall.
trigger_host_audit.
trigger_audit_packages.
trigger_cleanmgr.
trigger_host_reboot.
trigger_host_shutdown.
trigger_session_setup.
run_wol.
get_tasks_status.
Signing process for immediate actions¶
The action is defined by its name and the actions attributes. The attributes are uuid, action, force, notify_server, and packages (for actions implicating a list of packages).
The attributes
signed_attributes
,signer
,signature_date
,signer_certificate
are added to the structure of the action:signed_attributes
list of the attributes that are signed.signer
Subject.COMMON_NAME of certificate holder.signature_date
: current date and time (UTC) in ‘%Y-%m-%dT%H:%M:%S’ format.signer_certificate
certificate holder’s base64 encoded X509 certificate.
The structure is JSON encoded.
The signature of the JSON file is calculated from the RSA private key of the
signer
using a sha256 hash algorithm and a PKCS1 v1.5 padding.The signature is base64 encoded and stored on the
signature
attribute inside the JSON file.
Verifying the signature of an immediate action¶
From the WAPT Console, the Administrators may launch actions directly on the WAPT clients connected with the WAPT Server using Websockets.
The actions are JSON encoded, signed with the key and certificate of the Administrator, and relayed to the targeted WAPT clients by the WAPT Server.
The action get_tasks_status does not require SSL authentication.
Upon receiving an event on the Websocket connexion of the WAPT client:
The X509 certificate of the certificate holder is extracted from the JSON file (format PEM).
The WAPT client tests whether the certificate is to be trusted, i.e. that it is present in
<WAPT>\ssl
or that it has been signed by a Trusted Authority (certificate of the Authority present in<WAPT>\ssl
).The WAPT client checks whether the certificate can verify the signature that is present in the JSON structure of the action, which consists of:
Extracting the base64 encoded signature from the
signature
attribute in the JSON file.Extracting the signature date formated in ‘%Y-%m-%dT%H:%M:%S’ from the
signature_date
attribute.Checking that the signature date is neither too old in the past, nor too late into the future by over 10 minutes.
Reconstructing a JSON representation of the attributes of the action.
Checking that the certificate’s public key can verify the JSON file with the signature by using a sha256 hash algorithm and a PKCS1 v1.5 padding.
Verifying the complete download of a WAPT package¶
For each WAPT package, a md5 sum of the file is calculated and stored in the Packages
index file on the repository.
When installing a WAPT package, the WAPT client checks whether a local version of the WAPT package is already available in the cache directory <WAPT>\cache
.
If the package file is cached, its md5 sum is calculated and compared with the md5 sum in the index file. If they are different, the cached WAPT package is deleted.
Important
This md5 sum is only used to insure that a WAPT package has been fully downloaded.
The checking of the signature of the WAPT package will be used instead of the md5 sum to fully insure the integrity and the authenticity of the WAPT package.