<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kirill+Krinkin</id>
	<title>OpenVZ Virtuozzo Containers Wiki - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.openvz.org/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Kirill+Krinkin"/>
	<link rel="alternate" type="text/html" href="https://wiki.openvz.org/Special:Contributions/Kirill_Krinkin"/>
	<updated>2026-06-10T02:46:02Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.31.1</generator>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15258</id>
		<title>Virtual HSM</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15258"/>
		<updated>2014-04-27T18:24:11Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual HSM (VHSM)''' is a software suite for storing and manipulating secret data outside the virtualized application environment. While [http://en.wikipedia.org/wiki/Hardware_security_module HSM] is a physical device connected to the computer, this software provides HSM functionality through the [http://www.emc.com/emc-plus/rsa-labs/standards-initiatives/pkcs-11-cryptographic-token-interface-standard.htm PKCS#11] API in virtual environment based on OpenVZ container technology. &lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
[[File:Vhsm_overview.png|thumb|right|400px|Fig. 1 — VHSM overview]]&lt;br /&gt;
The architecture of the Virtual HSM is shown in the [[Media:Vhsm_overview.png|Fig. 1]]. The project consists of the following key components:&lt;br /&gt;
;VHSM virtual environment&lt;br /&gt;
:VHSM VE is the isolated environment that contains the VHSM server and secure storage. The server performs operations on secret data and storage keeps encrypted user data&lt;br /&gt;
;Transport layer&lt;br /&gt;
:transport exchanges data between client and server virtual environments; based on [http://en.wikipedia.org/wiki/Netlink Netlink]&lt;br /&gt;
;Client virtual environment&lt;br /&gt;
:client API and accompanying utilities for accessing the VHSM server from a client environment&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
=== VHSM virtual environment ===&lt;br /&gt;
[[File:VHSM_data_encryption.png|thumb|right|400px|Fig. 2 — Data encryption in the VHSM]]&lt;br /&gt;
The VHSM VE contains the secure storage which is the database that stores the sensitive data in the encrypted form while other data (refer the table below) are stored unencrypted. The encryption key (master key) is derived from the user password using [http://en.wikipedia.org/wiki/PBKDF2 PBKDF2] and not stored in database. Utilizing PBKDF2 reduces the brute-force attack rate significantly if the database is compromised. The following table lists data that stored in the VHSM:&lt;br /&gt;
{|class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Data&lt;br /&gt;
 !Type&lt;br /&gt;
 !Encrypted&lt;br /&gt;
 !Comments&lt;br /&gt;
 |-&lt;br /&gt;
 |Key ID&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |keys in the VHSM can be accessed by their string-ID&lt;br /&gt;
 |-&lt;br /&gt;
 |Key data&lt;br /&gt;
 |blob&lt;br /&gt;
 |yes&lt;br /&gt;
 |encrypted key data (see the [[Media:VHSM_data_encryption.png|Fig. 2]])&lt;br /&gt;
 |-&lt;br /&gt;
 |Key attributes&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |data structure that holds PKCS#11 key attributes&lt;br /&gt;
 |-&lt;br /&gt;
 |Import date&lt;br /&gt;
 |date-time&lt;br /&gt;
 |no&lt;br /&gt;
 |key creation date&lt;br /&gt;
 |-&lt;br /&gt;
 |User name&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |VHSM user login&lt;br /&gt;
 |-&lt;br /&gt;
 |User auth key&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |binary data for the user password check&lt;br /&gt;
 |-&lt;br /&gt;
 |User type&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |&amp;lt;tt&amp;gt;CKU_USER&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; from the PKCS#11 standard&lt;br /&gt;
 |-&lt;br /&gt;
 |User flags&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |Flags determine access rights (read, write, delete) for the user&lt;br /&gt;
 |-&lt;br /&gt;
 |Password derivation params&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |PBKDF2 params used for master key derivation (refer the Fig. 3)&lt;br /&gt;
 |-&lt;br /&gt;
 |User VEIDs&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |List of VEIDs where the user can get access to the VHSM&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
[[File:Vshm_user_registration.png|thumb|right|400px|Fig. 3 — User registration]]&lt;br /&gt;
[[File:Vhsm_user_auth.png|thumb|right|400px|Fig. 4 — User authentication]]&lt;br /&gt;
The VHSM server is responsible for user authentication, interaction with the secure storage, and performing cryptographic operations.&lt;br /&gt;
A client must be registered in the system to work with VHSM. VHSM admins (users with &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user type) can register new clients. These users can be both a real person or program. Anyway communication with the VHSM performed through the API. When the client is registered in the system a 256-bit authentication key is generated and encrypted in [http://en.wikipedia.org/wiki/Galois/Counter_Mode GCM mode] using the master key. &lt;br /&gt;
The GCM mode guarantees integrity and confidentiality of the user data and therefore makes it possible to authenticate the encryption key derived from the user password. The VHSM uses this feature for user authentication. Registration process is shown in the [[Media:Vshm_user_registration.png|Fig. 3]].&lt;br /&gt;
&lt;br /&gt;
A user is authenticated ([[Media:Vhsm_user_auth.png|Fig. 4]]) using the login/password pair and the container ID (VEID) where authentication request is received from. When a user is registered it's bound to the set of containers authorised to access VHSM API. If the user attempts to access to the VHSM from a non-authorized container the request is refused.&lt;br /&gt;
&lt;br /&gt;
=== Transport ===&lt;br /&gt;
The data exchanging protocol between clients and the VHSM is written in the [https://code.google.com/p/protobuf/ Protocol Buffers] language. Inter-container communication is based on Netlink, so the OS kernel contains the module that passes messages between virtual environments while VEs contain the transport API library which interacts with this module via Netlink sockets.&lt;br /&gt;
The kernel module identifies containers by their VEIDs that are provided by OpenVZ. The VHSM environment ID is passed as a parameter to the module. Messages from other containers are routed to that VEID. The passed message contains serialized protobuf data and the header with the message type, container VEID and process PID (actually it's the unique socket ID generated by the kernel). Meaning of these parameters depends on the transfer direction. If the message comes from a client container then the module checks its VEID and forwards the message to the VHSM VE if the container is allowed to send requests to the VHSM. When the kernel module forwards the message it sets the VEID in the message header to the sender VEID and the PID to the sender process PID derived from the Netlink message header. So the VHSM can address the response to the client. If the message is transferred from the VHSM then the VEID and PID in the message header are set by the VHSM itself. It's possible because the VHSM sends responses to the client requests only and never initiates communication with a client.&lt;br /&gt;
&lt;br /&gt;
=== Client virtual environment ===&lt;br /&gt;
[[File:Vhsm_pkcs11_mapping.png|thumb|right|400px|Fig. 5 — PKCS#11 slots and VHSM users]]&lt;br /&gt;
The client part of the VHSM consists from the API-library and some auxiliary tools.&lt;br /&gt;
The VHSM API library partially implements [ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/pkcs-11v2-20.pdf PKCS#11 v2.20 standard] and provides some additional functions for the user management.&lt;br /&gt;
Here the list of VHSM-specific features:&lt;br /&gt;
* '''Supported object classes'''&lt;br /&gt;
*: Currently only &amp;lt;tt&amp;gt;CKO_SECRET_KEY&amp;lt;/tt&amp;gt; with key types &amp;lt;tt&amp;gt;CKK_GENERIC_SECRET, CKK_AES&amp;lt;/tt&amp;gt; is supported&lt;br /&gt;
* '''Supported mechanisms'''&lt;br /&gt;
** encryption: &amp;lt;code&amp;gt;CKM_AES_CTR&amp;lt;/code&amp;gt; (actually it's AES-GCM)&lt;br /&gt;
** digest: &amp;lt;code&amp;gt;CKM_SHA_1&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;CKM_SHA_1_HMAC&amp;lt;/code&amp;gt;&lt;br /&gt;
** key generation: &amp;lt;code&amp;gt;CKM_GENERIC_SECRET_KEY_GEN&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Unsupported functions'''&lt;br /&gt;
** slot management: &amp;lt;code&amp;gt;C_InitToken, C_InitPin, C_SetPin, C_WaitForSlotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** session management: &amp;lt;code&amp;gt;C_GetOperationState, C_SetOperationState &amp;lt;/code&amp;gt;&lt;br /&gt;
** object management: &amp;lt;code&amp;gt;C_CopyObject&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;C_SignRecoverInit, C_SignRecover, C_VerifyRecoverInit, C_VerifyRecover&amp;lt;/code&amp;gt;&lt;br /&gt;
** key management: &amp;lt;code&amp;gt;C_GenerateKeyPair, C_WrapKey, C_UnwrapKey, C_DeriveKey&amp;lt;/code&amp;gt;&lt;br /&gt;
** all dual functions&lt;br /&gt;
* '''Additional VHSM-specific functions'''&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetUserSlot&amp;lt;/code&amp;gt; returns slotID for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ImportSecretKey&amp;lt;/code&amp;gt; imports secret key with the default template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetObjectById&amp;lt;/code&amp;gt; returns object handle without use of &amp;lt;code&amp;gt;C_FindObjects&amp;lt;/code&amp;gt;&lt;br /&gt;
*: Following functions can be called only by &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user:&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_CreateUser&amp;lt;/code&amp;gt; creates a new VHSM user using the given template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ModifyUser&amp;lt;/code&amp;gt; allows to set user flags and VEIDs for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_DeleteUser&amp;lt;/code&amp;gt; removes user and all associated data by user name&lt;br /&gt;
* '''User flags'''&lt;br /&gt;
*: VHSM users have associated flags that determine which functions can be called by the user&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_READ&amp;lt;/tt&amp;gt; — read-only functions (like encryption, signing, etc)&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE&amp;lt;/tt&amp;gt; — user can create objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_MODIFY&amp;lt;/tt&amp;gt; — user can change objects attributes&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_DELETE&amp;lt;/tt&amp;gt; — user can destroy objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE_EXTENDED&amp;lt;/tt&amp;gt; — user can create &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; users. Only &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt; user (created during VHSM installation) can has this flag&lt;br /&gt;
* '''PKCS#11 slot / token selection'''&lt;br /&gt;
*: In the VHSM slots and tokens are abstract because users are authenticated by login/password pair. In fact, &amp;lt;code&amp;gt;C_GetSlotList&amp;lt;/code&amp;gt; called from VE returns the list of usernames that can be used from this VE. Opening session with one of these slots means that in this session user wants to use username associated with this slot. [[Media:Vhsm_pkcs11_mapping.png|Fig. 5]] shows how it works.&lt;br /&gt;
* '''Multithreading'''&lt;br /&gt;
*:Each thread must call &amp;lt;code&amp;gt;C_Initialize&amp;lt;/code&amp;gt; to work with VHSM, as in PKCS#11, but if some thread logs into VHSM  then other threads with open VHSM sessions do '''not''' automatically log into VHSM as it should be according to the standard;&lt;br /&gt;
&lt;br /&gt;
OpenSSL can act as a layer between a client application and the VHSM API library – it's achieved by OpenSSL [http://www.openssl.org/docs/crypto/engine.html engines] – and makes it possible to use a cryptographic device (or VHSM) without modifying the code of the client program. You may try pkcs#11 OpenSSL engines like [https://github.com/OpenSC/engine_pkcs11 engine_pkcs11], [http://sourceforge.net/projects/opencryptoki/files/PKCS%2311%20OpenSSL%20Engine/openssl-ibmpkcs11/ ibmpkcs11] with VHSM.&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
Install the following packages to build the project on your system. On CentOS use [http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F EPEL repositories]. In addition, VHSM uses some [http://gcc.gnu.org/ gcc]-specific features, so gcc 4+ is required.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Package&lt;br /&gt;
 !Debian&lt;br /&gt;
 !CentOS&lt;br /&gt;
 |-&lt;br /&gt;
 |CMake 2.8&lt;br /&gt;
 |cmake&lt;br /&gt;
 |cmake28&lt;br /&gt;
 |-&lt;br /&gt;
 |OpenVZ kernel headers&lt;br /&gt;
 |linux-headers-2.6.32-5-openvz&lt;br /&gt;
 |vzkernel-headers&lt;br /&gt;
 |-&lt;br /&gt;
 |Google protobuf compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |-&lt;br /&gt;
 |libprotobuf&lt;br /&gt;
 |libprotobuf-dev&lt;br /&gt;
 |protobuf-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |crypto++ 5.6.2&lt;br /&gt;
 |libcrypto++-dev&lt;br /&gt;
 |cryptopp-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |SQLite 3&lt;br /&gt;
 |libsqlite3-dev&lt;br /&gt;
 |sqlite-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |cppunit ''(optional)''&lt;br /&gt;
 |libcppunit-dev&lt;br /&gt;
 |cppunit-devel&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
To build the project just run &amp;lt;code&amp;gt;cmake&amp;lt;/code&amp;gt; and then &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;. You may build binary packages with the command &amp;lt;code&amp;gt;make pkg&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
You may use binary packages or install manually:&lt;br /&gt;
* VHSM VE: &amp;lt;tt&amp;gt;vhsm&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Client VE: &amp;lt;tt&amp;gt;libvhsmapi.a, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Host: &amp;lt;tt&amp;gt;vhsm_transport.ko, vhsm_admin, vhsm_config&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
To run VHSM perform the following steps:&lt;br /&gt;
# Insert transport module: &amp;lt;code&amp;gt;insmod vhsm_transport.ko vhsm_veid=[veid]&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;[veid]&amp;lt;/code&amp;gt; is VEID of the VHSM container. '''OR''' Use &amp;lt;tt&amp;gt;vhsm_config&amp;lt;/tt&amp;gt; to configure VHSM&lt;br /&gt;
# Start VHSM in the VHSM container: &amp;lt;code&amp;gt;vhsm /path/to/storage&amp;lt;/code&amp;gt;. You can init secure storage and create &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt;-user on the first run&lt;br /&gt;
# Add VHSM users from host: &amp;lt;code&amp;gt;vhsm_admin user create &amp;lt;admin login&amp;gt; &amp;lt;admin password&amp;gt; [options...]&amp;lt;/code&amp;gt;. Run &amp;lt;code&amp;gt;vhsm_admin help&amp;lt;/code&amp;gt; for details.&lt;br /&gt;
# Now you can use VHSM from client VEs&lt;br /&gt;
&lt;br /&gt;
== Links ==&lt;br /&gt;
&lt;br /&gt;
* [http://git.openvz.org/?p=vhsm VHSM repository]&lt;br /&gt;
* [https://dl.dropboxusercontent.com/u/65580332/vhsm-pkg_0.1_x86_64-0.1-Linux.rpm Prebuilt RPM package (x64)] (temporary)&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vshm_user_registration.png&amp;diff=15257</id>
		<title>File:Vshm user registration.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vshm_user_registration.png&amp;diff=15257"/>
		<updated>2014-04-27T14:07:05Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: Kirill Krinkin uploaded a new version of &amp;amp;quot;File:Vshm user registration.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15256</id>
		<title>Virtual HSM</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15256"/>
		<updated>2014-04-27T13:45:09Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual HSM (VHSM)''' is a software suite for storing and manipulating secret data outside the virtualized application environment. While [http://en.wikipedia.org/wiki/Hardware_security_module HSM] is a physical device connected to the computer, this software provides HSM functionality through the [http://www.emc.com/emc-plus/rsa-labs/standards-initiatives/pkcs-11-cryptographic-token-interface-standard.htm PKCS#11] API in virtual environment based on OpenVZ container technology. &lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
[[File:Vhsm_overview.png|thumb|right|400px|Fig. 1 — VHSM overview]]&lt;br /&gt;
The architecture of the Virtual HSM is shown in the [[Media:Vhsm_overview.png|Fig. 1]]. The project consists of the following key components:&lt;br /&gt;
;VHSM virtual environment&lt;br /&gt;
:VHSM VE is the isolated environment that contains the VHSM server and secure storage. The server performs operations on secret data and storage keeps encrypted user data&lt;br /&gt;
;Transport layer&lt;br /&gt;
:transport exchanges data between client and server virtual environments; based on [http://en.wikipedia.org/wiki/Netlink Netlink]&lt;br /&gt;
;Client virtual environment&lt;br /&gt;
:client API and accompanying utilities for accessing the VHSM server from a client environment&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
=== VHSM virtual environment ===&lt;br /&gt;
[[File:VHSM_data_encryption.png|thumb|right|400px|Fig. 2 — Data encryption in the VHSM]]&lt;br /&gt;
The VHSM VE contains the secure storage which is the database that stores the sensitive data in the encrypted form while other data (refer the table below) are stored unencrypted. The encryption key (master key) is derived from the user password using [http://en.wikipedia.org/wiki/PBKDF2 PBKDF2] and not stored in database. Utilizing PBKDF2 reduces the brute-force attack rate significantly if the database is compromised. The following table lists data that stored in the VHSM:&lt;br /&gt;
{|class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Data&lt;br /&gt;
 !Type&lt;br /&gt;
 !Encrypted&lt;br /&gt;
 !Comments&lt;br /&gt;
 |-&lt;br /&gt;
 |Key ID&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |keys in the VHSM can be accessed by their string-ID&lt;br /&gt;
 |-&lt;br /&gt;
 |Key data&lt;br /&gt;
 |blob&lt;br /&gt;
 |yes&lt;br /&gt;
 |encrypted key data (see the [[Media:VHSM_data_encryption.png|Fig. 2]])&lt;br /&gt;
 |-&lt;br /&gt;
 |Key attributes&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |data structure that holds PKCS#11 key attributes&lt;br /&gt;
 |-&lt;br /&gt;
 |Import date&lt;br /&gt;
 |date-time&lt;br /&gt;
 |no&lt;br /&gt;
 |key creation date&lt;br /&gt;
 |-&lt;br /&gt;
 |User name&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |VHSM user login&lt;br /&gt;
 |-&lt;br /&gt;
 |User auth key&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |binary data for the user password check&lt;br /&gt;
 |-&lt;br /&gt;
 |User type&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |&amp;lt;tt&amp;gt;CKU_USER&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; from the PKCS#11 standard&lt;br /&gt;
 |-&lt;br /&gt;
 |User flags&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |Flags determine access rights (read, write, delete) for the user&lt;br /&gt;
 |-&lt;br /&gt;
 |Password derivation params&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |PBKDF2 params used for master key derivation (refer the Fig. 3)&lt;br /&gt;
 |-&lt;br /&gt;
 |User VEIDs&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |List of VEIDs where the user can get access to the VHSM&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
[[File:Vshm_user_registration.png|thumb|right|400px|Fig. 3 — User registration]]&lt;br /&gt;
[[File:Vhsm_user_auth.png|thumb|right|400px|Fig. 4 — User authentication]]&lt;br /&gt;
The VHSM server is responsible for user authentication, interaction with the secure storage, and performing cryptographic operations.&lt;br /&gt;
A client must be registered in the system to work with VHSM. VHSM admins (users with &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user type) can register new clients. These users can be both a real person or program. Anyway communication with the VHSM performed through the API. When the client is registered in the system a 256-bit authentication key is generated and encrypted in [http://en.wikipedia.org/wiki/Galois/Counter_Mode GCM mode] using the master key. &lt;br /&gt;
The GCM mode guarantees integrity and confidentiality of the user data and therefore makes it possible to authenticate the encryption key derived from the user password. The VHSM uses this feature for user authentication. Registration process is shown in the [[Media:Vshm_user_registration.png|Fig. 3]].&lt;br /&gt;
&lt;br /&gt;
A user is authenticated ([[Media:Vhsm_user_auth.png|Fig. 4]]) using the login/password pair and the container ID (VEID) where authentication request is received from. When a user is registered it's bound to the set of containers authorised to access VHSM API. If the user attempts to access to the VHSM from a non-authorized container the request is refused.&lt;br /&gt;
&lt;br /&gt;
=== Transport ===&lt;br /&gt;
The data exchanging protocol between clients and the VHSM is written in the [https://code.google.com/p/protobuf/ Protocol Buffers] language. Inter-container communication is based on Netlink, so the OS kernel contains the module that passes messages between virtual environments while VEs contain the transport API library which interacts with this module via Netlink sockets.&lt;br /&gt;
The kernel module identifies containers by their VEIDs that are provided by OpenVZ. The VHSM environment ID is passed as a parameter to the module. Messages from other containers are routed to that VEID. The passed message contains serialized protobuf data and the header with the message type, container VEID and process PID (actually it's the unique socket ID generated by the kernel). Meaning of these parameters depends on the transfer direction. If the message comes from a client container then the module checks its VEID and forwards the message to the VHSM VE if the container is allowed to send requests to the VHSM. When the kernel module forwards the message it sets the VEID in the message header to the sender VEID and the PID to the sender process PID derived from the Netlink message header. So the VHSM can address the response to the client. If the message is transferred from the VHSM then the VEID and PID in the message header are set by the VHSM itself. It's possible because the VHSM sends responses to the client requests only and never initiates communication with a client.&lt;br /&gt;
&lt;br /&gt;
=== Client virtual environment ===&lt;br /&gt;
[[File:Vhsm_pkcs11_mapping.png|thumb|right|400px|Fig. 5 — PKCS#11 slots and VHSM users]]&lt;br /&gt;
The client part of the VHSM consists from the API-library and some auxiliary tools.&lt;br /&gt;
The VHSM API library partially implements [ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/pkcs-11v2-20.pdf PKCS#11 v2.20 standard] and provides some additional functions for the user management.&lt;br /&gt;
Here the list of VHSM-specific features:&lt;br /&gt;
* '''Supported object classes'''&lt;br /&gt;
*: Currently only &amp;lt;tt&amp;gt;CKO_SECRET_KEY&amp;lt;/tt&amp;gt; with key types &amp;lt;tt&amp;gt;CKK_GENERIC_SECRET, CKK_AES&amp;lt;/tt&amp;gt; is supported&lt;br /&gt;
* '''Supported mechanisms'''&lt;br /&gt;
** encryption: &amp;lt;code&amp;gt;CKM_AES_CTR&amp;lt;/code&amp;gt; (actually it's AES-GCM)&lt;br /&gt;
** digest: &amp;lt;code&amp;gt;CKM_SHA_1&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;CKM_SHA_1_HMAC&amp;lt;/code&amp;gt;&lt;br /&gt;
** key generation: &amp;lt;code&amp;gt;CKM_GENERIC_SECRET_KEY_GEN&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Unsupported functions'''&lt;br /&gt;
** slot management: &amp;lt;code&amp;gt;C_InitToken, C_InitPin, C_SetPin, C_WaitForSlotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** session management: &amp;lt;code&amp;gt;C_GetOperationState, C_SetOperationState &amp;lt;/code&amp;gt;&lt;br /&gt;
** object management: &amp;lt;code&amp;gt;C_CopyObject&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;C_SignRecoverInit, C_SignRecover, C_VerifyRecoverInit, C_VerifyRecover&amp;lt;/code&amp;gt;&lt;br /&gt;
** key management: &amp;lt;code&amp;gt;C_GenerateKeyPair, C_WrapKey, C_UnwrapKey, C_DeriveKey&amp;lt;/code&amp;gt;&lt;br /&gt;
** all dual functions&lt;br /&gt;
* '''Additional VHSM-specific functions'''&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetUserSlot&amp;lt;/code&amp;gt; returns slotID for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ImportSecretKey&amp;lt;/code&amp;gt; imports secret key with the default template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetObjectById&amp;lt;/code&amp;gt; returns object handle without use of &amp;lt;code&amp;gt;C_FindObjects&amp;lt;/code&amp;gt;&lt;br /&gt;
*: Following functions can be called only by &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user:&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_CreateUser&amp;lt;/code&amp;gt; creates a new VHSM user using the given template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ModifyUser&amp;lt;/code&amp;gt; allows to set user flags and VEIDs for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_DeleteUser&amp;lt;/code&amp;gt; removes user and all associated data by user name&lt;br /&gt;
* '''User flags'''&lt;br /&gt;
*: VHSM users have associated flags that determine which functions can be called by the user&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_READ&amp;lt;/tt&amp;gt; — read-only functions (like encryption, signing, etc)&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE&amp;lt;/tt&amp;gt; — user can create objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_MODIFY&amp;lt;/tt&amp;gt; — user can change objects attributes&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_DELETE&amp;lt;/tt&amp;gt; — user can destroy objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE_EXTENDED&amp;lt;/tt&amp;gt; — user can create &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; users. Only &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt; user (created during VHSM installation) can has this flag&lt;br /&gt;
* '''PKCS#11 slot / token selection'''&lt;br /&gt;
*: In the VHSM slots and tokens are abstract because users are authenticated by login/password pair. In fact, &amp;lt;code&amp;gt;C_GetSlotList&amp;lt;/code&amp;gt; called from VE returns the list of usernames that can be used from this VE. Opening session with one of these slots means that in this session user wants to use username associated with this slot. [[Media:Vhsm_pkcs11_mapping.png|Fig. 5]] shows how it works.&lt;br /&gt;
* '''Multithreading'''&lt;br /&gt;
*:Each thread must call &amp;lt;code&amp;gt;C_Initialize&amp;lt;/code&amp;gt; to work with VHSM, as in PKCS#11, but if some thread logs into VHSM  then other threads with open VHSM sessions do '''not''' automatically log into VHSM as it should be according to the standard;&lt;br /&gt;
&lt;br /&gt;
OpenSSL can act as a layer between a client application and the VHSM API library – it's achieved by OpenSSL [http://www.openssl.org/docs/crypto/engine.html engines] – and makes it possible to use a cryptographic device (or VHSM) without modifying the code of the client program. You may try pkcs#11 OpenSSL engines like [https://github.com/OpenSC/engine_pkcs11 engine_pkcs11], [http://sourceforge.net/projects/opencryptoki/files/PKCS%2311%20OpenSSL%20Engine/openssl-ibmpkcs11/ ibmpkcs11] with VHSM.&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
Install the following packages to build the project on your system. On CentOS use [http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F EPEL repositories]. In addition, VHSM uses some [http://gcc.gnu.org/ gcc]-specific features, so gcc 4+ is required.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Package&lt;br /&gt;
 !Debian&lt;br /&gt;
 !CentOS&lt;br /&gt;
 |-&lt;br /&gt;
 |CMake 2.8&lt;br /&gt;
 |cmake&lt;br /&gt;
 |cmake28&lt;br /&gt;
 |-&lt;br /&gt;
 |OpenVZ kernel headers&lt;br /&gt;
 |linux-headers-2.6.32-5-openvz&lt;br /&gt;
 |vzkernel-headers&lt;br /&gt;
 |-&lt;br /&gt;
 |Google protobuf compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |-&lt;br /&gt;
 |libprotobuf&lt;br /&gt;
 |libprotobuf-dev&lt;br /&gt;
 |protobuf-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |crypto++ 5.6.2&lt;br /&gt;
 |libcrypto++-dev&lt;br /&gt;
 |cryptopp-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |SQLite 3&lt;br /&gt;
 |libsqlite3-dev&lt;br /&gt;
 |sqlite-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |cppunit ''(optional)''&lt;br /&gt;
 |libcppunit-dev&lt;br /&gt;
 |cppunit-devel&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
To build the project just run &amp;lt;code&amp;gt;cmake&amp;lt;/code&amp;gt; and then &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;. You may build binary packages with the command &amp;lt;code&amp;gt;make pkg&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
You may use binary packages or install manually:&lt;br /&gt;
* VHSM VE: &amp;lt;tt&amp;gt;vhsm&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Client VE: &amp;lt;tt&amp;gt;libvhsmapi.a, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Host: &amp;lt;tt&amp;gt;vhsm_transport.ko, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
To run VHSM perform the following steps:&lt;br /&gt;
# Insert transport module: &amp;lt;code&amp;gt;insmod vhsm_transport.ko vhsm_veid=[veid]&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;[veid]&amp;lt;/code&amp;gt; is VEID of the VHSM container&lt;br /&gt;
# Start VHSM in the VHSM container: &amp;lt;code&amp;gt;vhsm /path/to/storage&amp;lt;/code&amp;gt;. You can init secure storage and create &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt;-user on the first run&lt;br /&gt;
# Add VHSM users from host: &amp;lt;code&amp;gt;vhsm_admin user create &amp;lt;admin login&amp;gt; &amp;lt;admin password&amp;gt; [options...]&amp;lt;/code&amp;gt;. Run &amp;lt;code&amp;gt;vhsm_admin help&amp;lt;/code&amp;gt; for details.&lt;br /&gt;
# Now you can use VHSM from client VEs&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vhsm_overview.png&amp;diff=15255</id>
		<title>File:Vhsm overview.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vhsm_overview.png&amp;diff=15255"/>
		<updated>2014-04-27T13:34:40Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: Kirill Krinkin uploaded a new version of &amp;amp;quot;File:Vhsm overview.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15231</id>
		<title>Virtual HSM</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15231"/>
		<updated>2014-04-05T19:41:14Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual HSM (VHSM)''' is a software suite for storing and manipulating secret data outside the virtualized application environment. While [http://en.wikipedia.org/wiki/Hardware_security_module HSM] is a physical device connected to the computer, this software provides HSM functionality through the [http://www.emc.com/emc-plus/rsa-labs/standards-initiatives/pkcs-11-cryptographic-token-interface-standard.htm PKCS#11] API in virtual environment based on OpenVZ container technology. &lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
[[File:Vhsm_overview.png|thumb|right|400px|Fig. 1 — VHSM overview]]&lt;br /&gt;
The architecture of the Virtual HSM is shown in the [[Media:Vhsm_overview.png|Fig. 1]]. The project consists of the following key components:&lt;br /&gt;
;VHSM virtual environment&lt;br /&gt;
:VHSM VE is the isolated environment that contains the VHSM server and secure storage. The server performs operations on secret data and storage keeps encrypted user data&lt;br /&gt;
;Transport layer&lt;br /&gt;
:transport exchanges data between client and server virtual environments; based on [http://en.wikipedia.org/wiki/Netlink Netlink]&lt;br /&gt;
;Client virtual environment&lt;br /&gt;
:client API and accompanying utilities for accessing the VHSM server from a client environment&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
=== VHSM virtual environment ===&lt;br /&gt;
[[File:VHSM_data_encryption.png|thumb|right|400px|Fig. 2 — Data encryption in the VHSM]]&lt;br /&gt;
The VHSM VE contains the secure storage which is the database that stores the sensitive data in the encrypted form while other data (refer the table below) are stored unencrypted. The encryption key (master key) is generated from the user password using [http://en.wikipedia.org/wiki/PBKDF2 PBKDF2] and not stored in database. Utilizing PBKDF2 reduces the brute-force attack rate significantly if the database is compromised. The following table lists data that stored in the VHSM:&lt;br /&gt;
{|class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Data&lt;br /&gt;
 !Type&lt;br /&gt;
 !Encrypted&lt;br /&gt;
 !Comments&lt;br /&gt;
 |-&lt;br /&gt;
 |Key ID&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |keys in the VHSM can be accessed by their string-ID&lt;br /&gt;
 |-&lt;br /&gt;
 |Key data&lt;br /&gt;
 |blob&lt;br /&gt;
 |yes&lt;br /&gt;
 |encrypted key data (see the [[Media:VHSM_data_encryption.png|Fig. 2]])&lt;br /&gt;
 |-&lt;br /&gt;
 |Key attributes&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |data structure that holds PKCS#11 key attributes&lt;br /&gt;
 |-&lt;br /&gt;
 |Import date&lt;br /&gt;
 |date-time&lt;br /&gt;
 |no&lt;br /&gt;
 |key creation date&lt;br /&gt;
 |-&lt;br /&gt;
 |User name&lt;br /&gt;
 |string&lt;br /&gt;
 |no&lt;br /&gt;
 |VHSM user login&lt;br /&gt;
 |-&lt;br /&gt;
 |User auth key&lt;br /&gt;
 |blob&lt;br /&gt;
 |no&lt;br /&gt;
 |binary data for the user password check&lt;br /&gt;
 |-&lt;br /&gt;
 |User type&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |&amp;lt;tt&amp;gt;CKU_USER&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; from the PKCS#11 standard&lt;br /&gt;
 |-&lt;br /&gt;
 |User flags&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |Flags determine access rights (read, write, delete) for the user&lt;br /&gt;
 |-&lt;br /&gt;
 |Password derivation params&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |PBKDF2 params used for master key derivation (refer the Fig. 3)&lt;br /&gt;
 |-&lt;br /&gt;
 |User VEIDs&lt;br /&gt;
 |integer&lt;br /&gt;
 |no&lt;br /&gt;
 |List of VEIDs where the user can get access to the VHSM&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
[[File:Vshm_user_registration.png|thumb|right|400px|Fig. 3 — User registration]]&lt;br /&gt;
[[File:Vhsm_user_auth.png|thumb|right|400px|Fig. 4 — User authentication]]&lt;br /&gt;
The VHSM server is responsible for user authentication, interaction with the secure storage, and performing cryptographic operations.&lt;br /&gt;
A client must be registered in the system to work with VHSM. VHSM admins (users with &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user type) can register new clients. These users can be both a real person or program. Anyway communication with the VHSM performed through the API. When the client is registered in the system a 256-bit authentication key is generated and encrypted in [http://en.wikipedia.org/wiki/Galois/Counter_Mode GCM mode] using the master key. &lt;br /&gt;
The GCM mode guarantees integrity and confidentiality of the user data and therefore makes it possible to authenticate the encryption key derived from the user password. The VHSM uses this feature for user authentication. Registration process is shown in the [[Media:Vshm_user_registration.png|Fig. 3]].&lt;br /&gt;
&lt;br /&gt;
A user is authenticated ([[Media:Vhsm_user_auth.png|Fig. 4]]) using the login/password pair and the container ID (VEID) where authentication request is received from. When a user is registered it's bound to the set of containers where one can get access to the VHSM from. If the user attempts to access to the VHSM from a non-authorized container the request is refused.&lt;br /&gt;
&lt;br /&gt;
=== Transport ===&lt;br /&gt;
The data exchanging protocol between clients and the VHSM is written in the [https://code.google.com/p/protobuf/ Protocol Buffers] language. Inter-container communication is based on Netlink, so the OS kernel contains the module that passes messages between virtual environments while VEs contain the transport API library which interacts with this module via Netlink sockets.&lt;br /&gt;
The kernel module identifies containers by their VEIDs that are provided by OpenVZ. The VHSM environment ID is passed as a parameter to the module. Messages from other containers are routed to that VEID. The passed message contains serialized protobuf data and the header with the message type, container VEID and process PID (actually it's the unique socket ID generated by the kernel). Meaning of these parameters depends on the transfer direction. If the message comes from a client container then the module checks its VEID and forwards the message to the VHSM VE if the container is allowed to send requests to the VHSM. When the kernel module forwards the message it sets the VEID in the message header to the sender VEID and the PID to the sender process PID derived from the Netlink message header. So the VHSM can address the response to the client. If the message is transferred from the VHSM then the VEID and PID in the message header are set by the VHSM itself. It's possible because the VHSM sends responses to the client requests only and never initiates communication with a client.&lt;br /&gt;
&lt;br /&gt;
=== Client virtual environment ===&lt;br /&gt;
[[File:Vhsm_pkcs11_mapping.png|thumb|right|400px|Fig. 5 — PKCS#11 slots and VHSM users]]&lt;br /&gt;
The client part of the VHSM consists from the API-library and some auxiliary tools.&lt;br /&gt;
The VHSM API library partially implements [ftp://ftp.rsasecurity.com/pub/pkcs/pkcs-11/v2-20/pkcs-11v2-20.pdf PKCS#11 v2.20 standard] and provides some additional functions for the user management.&lt;br /&gt;
Here the list of VHSM-specific features:&lt;br /&gt;
* '''Supported object classes'''&lt;br /&gt;
*: Currently only &amp;lt;tt&amp;gt;CKO_SECRET_KEY&amp;lt;/tt&amp;gt; with key types &amp;lt;tt&amp;gt;CKK_GENERIC_SECRET, CKK_AES&amp;lt;/tt&amp;gt; is supported&lt;br /&gt;
* '''Supported mechanisms'''&lt;br /&gt;
** encryption: &amp;lt;code&amp;gt;CKM_AES_CTR&amp;lt;/code&amp;gt; (actually it's AES-GCM)&lt;br /&gt;
** digest: &amp;lt;code&amp;gt;CKM_SHA_1&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;CKM_SHA_1_HMAC&amp;lt;/code&amp;gt;&lt;br /&gt;
** key generation: &amp;lt;code&amp;gt;CKM_GENERIC_SECRET_KEY_GEN&amp;lt;/code&amp;gt;&lt;br /&gt;
* '''Unsupported functions'''&lt;br /&gt;
** slot management: &amp;lt;code&amp;gt;C_InitToken, C_InitPin, C_SetPin, C_WaitForSlotEvent&amp;lt;/code&amp;gt;&lt;br /&gt;
** session management: &amp;lt;code&amp;gt;C_GetOperationState, C_SetOperationState &amp;lt;/code&amp;gt;&lt;br /&gt;
** object management: &amp;lt;code&amp;gt;C_CopyObject&amp;lt;/code&amp;gt;&lt;br /&gt;
** signing: &amp;lt;code&amp;gt;C_SignRecoverInit, C_SignRecover, C_VerifyRecoverInit, C_VerifyRecover&amp;lt;/code&amp;gt;&lt;br /&gt;
** key management: &amp;lt;code&amp;gt;C_GenerateKeyPair, C_WrapKey, C_UnwrapKey, C_DeriveKey&amp;lt;/code&amp;gt;&lt;br /&gt;
** all dual functions&lt;br /&gt;
* '''Additional VHSM-specific functions'''&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetUserSlot&amp;lt;/code&amp;gt; returns slotID for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ImportSecretKey&amp;lt;/code&amp;gt; imports secret key with the default template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_GetObjectById&amp;lt;/code&amp;gt; returns object handle without use of &amp;lt;code&amp;gt;C_FindObjects&amp;lt;/code&amp;gt;&lt;br /&gt;
*: Following functions can be called only by &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; user:&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_CreateUser&amp;lt;/code&amp;gt; creates a new VHSM user using the given template&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_ModifyUser&amp;lt;/code&amp;gt; allows to set user flags and VEIDs for the specified user&lt;br /&gt;
** &amp;lt;code&amp;gt;VHSM_DeleteUser&amp;lt;/code&amp;gt; removes user and all associated data by user name&lt;br /&gt;
* '''User flags'''&lt;br /&gt;
*: VHSM users have associated flags that determine which functions can be called by the user&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_READ&amp;lt;/tt&amp;gt; — read-only functions (like encryption, signing, etc)&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE&amp;lt;/tt&amp;gt; — user can create objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_MODIFY&amp;lt;/tt&amp;gt; — user can change objects attributes&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_DELETE&amp;lt;/tt&amp;gt; — user can destroy objects&lt;br /&gt;
** &amp;lt;tt&amp;gt;VF_CREATE_EXTENDED&amp;lt;/tt&amp;gt; — user can create &amp;lt;tt&amp;gt;CKU_SO&amp;lt;/tt&amp;gt; users. Only &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt; user (created during VHSM installation) can has this flag&lt;br /&gt;
* '''PKCS#11 slot / token selection'''&lt;br /&gt;
*: In the VHSM slots and tokens are abstract because users are authenticated by login/password pair. In fact, &amp;lt;code&amp;gt;C_GetSlotList&amp;lt;/code&amp;gt; called from VE returns the list of usernames that can be used from this VE. Opening session with one of these slots means that in this session user wants to use username associated with this slot. [[Media:Vhsm_pkcs11_mapping.png|Fig. 5]] shows how it works.&lt;br /&gt;
* '''Multithreading'''&lt;br /&gt;
*:Each thread must call &amp;lt;code&amp;gt;C_Initialize&amp;lt;/code&amp;gt; to work with VHSM, as in PKCS#11, but if some thread logs into VHSM  then other threads with open VHSM sessions do '''not''' automatically log into VHSM as it should be according to the standard;&lt;br /&gt;
&lt;br /&gt;
OpenSSL can act as a layer between a client application and the VHSM API library – it's achieved by OpenSSL [http://www.openssl.org/docs/crypto/engine.html engines] – and makes it possible to use a cryptographic device (or VHSM) without modifying the code of the client program. You may try pkcs#11 OpenSSL engines like [https://github.com/OpenSC/engine_pkcs11 engine_pkcs11], [http://sourceforge.net/projects/opencryptoki/files/PKCS%2311%20OpenSSL%20Engine/openssl-ibmpkcs11/ ibmpkcs11] with VHSM.&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
Install the following packages to build the project on your system. On CentOS use [http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F EPEL repositories]. In addition, VHSM uses some [http://gcc.gnu.org/ gcc]-specific features, so gcc 4+ is required.&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Package&lt;br /&gt;
 !Debian&lt;br /&gt;
 !CentOS&lt;br /&gt;
 |-&lt;br /&gt;
 |CMake 2.8&lt;br /&gt;
 |cmake&lt;br /&gt;
 |cmake28&lt;br /&gt;
 |-&lt;br /&gt;
 |OpenVZ kernel headers&lt;br /&gt;
 |linux-headers-2.6.32-5-openvz&lt;br /&gt;
 |vzkernel-headers&lt;br /&gt;
 |-&lt;br /&gt;
 |Google protobuf compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |-&lt;br /&gt;
 |libprotobuf&lt;br /&gt;
 |libprotobuf-dev&lt;br /&gt;
 |protobuf-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |crypto++ 5.6.2&lt;br /&gt;
 |libcrypto++-dev&lt;br /&gt;
 |cryptopp-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |SQLite 3&lt;br /&gt;
 |libsqlite3-dev&lt;br /&gt;
 |sqlite-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |cppunit ''(optional)''&lt;br /&gt;
 |libcppunit-dev&lt;br /&gt;
 |cppunit-devel&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
To build the project just run &amp;lt;code&amp;gt;cmake&amp;lt;/code&amp;gt; and then &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;. You may build binary packages with the command &amp;lt;code&amp;gt;make pkg&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
You may use binary packages or install manually:&lt;br /&gt;
* VHSM VE: &amp;lt;tt&amp;gt;vhsm&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Client VE: &amp;lt;tt&amp;gt;libvhsmapi.a, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Host: &amp;lt;tt&amp;gt;vhsm_transport.ko, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
To run VHSM perform the following steps:&lt;br /&gt;
# Insert transport module: &amp;lt;code&amp;gt;insmod vhsm_transport.ko vhsm_veid=[veid]&amp;lt;/code&amp;gt; where &amp;lt;code&amp;gt;[veid]&amp;lt;/code&amp;gt; is VEID of the VHSM container&lt;br /&gt;
# Start VHSM in the VHSM container: &amp;lt;code&amp;gt;vhsm /path/to/storage&amp;lt;/code&amp;gt;. You can init secure storage and create &amp;lt;tt&amp;gt;root&amp;lt;/tt&amp;gt;-user on the first run&lt;br /&gt;
# Add VHSM users from host: &amp;lt;code&amp;gt;vhsm_admin user create &amp;lt;admin login&amp;gt; &amp;lt;admin password&amp;gt; [options...]&amp;lt;/code&amp;gt;. Run &amp;lt;code&amp;gt;vhsm_admin help&amp;lt;/code&amp;gt; for details.&lt;br /&gt;
# Now you can use VHSM from client VEs&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vhsm_pkcs11_mapping.png&amp;diff=15230</id>
		<title>File:Vhsm pkcs11 mapping.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vhsm_pkcs11_mapping.png&amp;diff=15230"/>
		<updated>2014-04-05T17:15:36Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: Kirill Krinkin uploaded a new version of &amp;amp;quot;File:Vhsm pkcs11 mapping.png&amp;amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vhsm_pkcs11_mapping.png&amp;diff=15229</id>
		<title>File:Vhsm pkcs11 mapping.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vhsm_pkcs11_mapping.png&amp;diff=15229"/>
		<updated>2014-04-05T17:02:31Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vhsm_user_auth.png&amp;diff=15228</id>
		<title>File:Vhsm user auth.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vhsm_user_auth.png&amp;diff=15228"/>
		<updated>2014-04-05T14:13:31Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vshm_user_registration.png&amp;diff=15227</id>
		<title>File:Vshm user registration.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vshm_user_registration.png&amp;diff=15227"/>
		<updated>2014-04-05T13:54:29Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:VHSM_data_encryption.png&amp;diff=15226</id>
		<title>File:VHSM data encryption.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:VHSM_data_encryption.png&amp;diff=15226"/>
		<updated>2014-04-05T13:30:53Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=File:Vhsm_overview.png&amp;diff=15225</id>
		<title>File:Vhsm overview.png</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=File:Vhsm_overview.png&amp;diff=15225"/>
		<updated>2014-04-05T12:53:02Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15104</id>
		<title>Virtual HSM</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15104"/>
		<updated>2014-03-03T01:20:03Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: &lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;'''Virtual HSM (VHSM)''' is a software suite for storing and manipulating secret data outside the virtualized application environment. While [http://en.wikipedia.org/wiki/Hardware_security_module HSM] is a physical device connected to the computer, this software provides HSM functionality in virtual environment based on OpenVZ container technology. &lt;br /&gt;
&lt;br /&gt;
== Structure ==&lt;br /&gt;
The project consists of the following key components:&lt;br /&gt;
;VHSM virtual environment&lt;br /&gt;
:VHSM VE is the isolated environment that contains the VHSM server and secure storage. The server performs operations on secret data and storage keeps encrypted user data&lt;br /&gt;
;Transport layer&lt;br /&gt;
:transport exchanges data between client and server virtual environments; based on [http://en.wikipedia.org/wiki/Netlink Netlink]&lt;br /&gt;
;Client virtual environment&lt;br /&gt;
:client API and accompanying utilities for accessing the VHSM server from a client environment&lt;br /&gt;
&lt;br /&gt;
== Details ==&lt;br /&gt;
=== VHSM virtual environment ===&lt;br /&gt;
The VHSM VE contains the secure storage which is the database that stores the sensitive data in the encrypted form while other data (import date, purpose, etc) are stored unencrypted. The encryption key (master key) is generated from the user password using [http://en.wikipedia.org/wiki/PBKDF2 PBKDF2], and the salt that is used in the function is stored unencrypted in database. Thereby the VHSM doesn't keep the encryption key and utilizing PBKDF2 reduces the brute-force attack rate significantly if the database is compromised.&lt;br /&gt;
The VHSM server is responsible for user authentication, interaction with the secure storage, and performing cryptographic operations.&lt;br /&gt;
A client must be registered in the system to work with VHSM, so it reports its credentials to the VHSM admin. When the client is registered in the system a 256-bit authentication key is generated and encrypted in [http://en.wikipedia.org/wiki/Galois/Counter_Mode GCM mode] using the master key. The GCM mode guarantees integrity and confidentiality of the user data and therefore makes it possible to authenticate the encryption key derived from the user password. The VHSM uses this feature for user authentication.&lt;br /&gt;
A user is authenticated using the login/password pair and the container ID (VEID) where authentication request is received from. When a user is registered it's bound to the set of containers where one can get access to the VHSM from. If the user attempts to access to the VHSM from a non-authorized container the request is refused.&lt;br /&gt;
&lt;br /&gt;
=== Transport ===&lt;br /&gt;
The data exchanging protocol between clients and the VHSM is written in the [https://code.google.com/p/protobuf/ Protocol Buffers] language. On the one hand, it allows to easily extend the protocol, on the other it's more space efficient compared to XML. In general, a protocol message contains parameters of the API function being called and some service information as well.&lt;br /&gt;
As mentioned above, inter-container communication is based on Netlink, so the OS kernel contains the module that passes messages between virtual environments while VEs contain the transport API library which interacts with this module via Netlink sockets.&lt;br /&gt;
The kernel module identifies containers by their VEIDs that are provided by OpenVZ. The VHSM environment ID is passed as a parameter to the module. Messages from other containers are routed to that VEID. The passed message contains serialized protobuf data and the header with the message type, container VEID and process PID. Meaning of these parameters depends on the transfer direction. If the message comes from a client container then the module checks its VEID and forwards the message to the VHSM VE if the container is allowed to send requests to the VHSM. When the kernel module forwards the message it sets the VEID in the message header to the sender VEID and the PID to the sender process PID derived from the Netlink message header. So the VHSM can address the response to the client. If the message is transferred from the VHSM then the VEID and PID in the message header are set by the VHSM itself. It's possible because the VHSM sends responses to the client requests only and never initiates communication with a client.&lt;br /&gt;
&lt;br /&gt;
=== Client virtual environment ===&lt;br /&gt;
The client part of the VHSM consists from the API-library and some auxiliary tools (such as [http://www.openssl.org/docs/crypto/engine.html OpenSSL engines]).&lt;br /&gt;
The VHSM API library provides PKCS#11-like functions for managing sessions and user keys and for digital signing.&lt;br /&gt;
Client applications may directly call library functions or may use OpenSSL extensions. The VHSM API allows the user to import or generate some secret data (keys). These data is encrypted by AES-GCM algorithm using the user master key and then stored in the database. Then the user gets the data id which allows to use these data in the future. &lt;br /&gt;
If the user wants to perform a cryptographic operation then one tells key id for this operation to the VHSM. The VHSM extracts the key from the storage, decrypts it and performs computations in its isolated virtual environment while the user gets the result of the operation only.&lt;br /&gt;
OpenSSL can act as a layer between a client application and the VHSM API library. To achieve that OpenSSL engines can be used. Engines extend the functionality of the OpenSSL and allow to override implementation of some cryptographic algorithms. For example, OpenSSL engines make it possible to use a physical cryptographic device without modifying the code of the client program.&lt;br /&gt;
&lt;br /&gt;
== Building ==&lt;br /&gt;
&lt;br /&gt;
Install the following packages to build the project on your system. On CentOS use [http://fedoraproject.org/wiki/EPEL/FAQ#How_can_I_install_the_packages_from_the_EPEL_software_repository.3F EPEL repositories]&lt;br /&gt;
&lt;br /&gt;
{| class=&amp;quot;standard&amp;quot; border=&amp;quot;1&amp;quot;&lt;br /&gt;
 !Package&lt;br /&gt;
 !Debian&lt;br /&gt;
 !CentOS&lt;br /&gt;
 |-&lt;br /&gt;
 |CMake 2.8&lt;br /&gt;
 |cmake&lt;br /&gt;
 |cmake28&lt;br /&gt;
 |-&lt;br /&gt;
 |OpenVZ kernel headers&lt;br /&gt;
 |linux-headers-2.6.32-5-openvz&lt;br /&gt;
 |vzkernel-headers&lt;br /&gt;
 |-&lt;br /&gt;
 |Google protobuf compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |protobuf-compiler&lt;br /&gt;
 |-&lt;br /&gt;
 |libprotobuf&lt;br /&gt;
 |libprotobuf-dev&lt;br /&gt;
 |protobuf-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |crypto++ 5.6.2&lt;br /&gt;
 |libcrypto++-dev&lt;br /&gt;
 |cryptopp-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |SQLite 3&lt;br /&gt;
 |libsqlite3-dev&lt;br /&gt;
 |sqlite-devel&lt;br /&gt;
 |-&lt;br /&gt;
 |cppunit ''(optional)''&lt;br /&gt;
 |libcppunit-dev&lt;br /&gt;
 |cppunit-devel&lt;br /&gt;
 |}&lt;br /&gt;
&lt;br /&gt;
To build the project just run &amp;lt;code&amp;gt;cmake&amp;lt;/code&amp;gt; and then &amp;lt;code&amp;gt;make&amp;lt;/code&amp;gt;. You may build binary packages with the command &amp;lt;code&amp;gt;make pkg&amp;lt;/code&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
== Installation ==&lt;br /&gt;
&lt;br /&gt;
You may use binary packages or install manually:&lt;br /&gt;
* VHSM VE: &amp;lt;tt&amp;gt;vhsm, vhsm_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Client VE: &amp;lt;tt&amp;gt;libvhsmapi.so, vhsm_user_admin&amp;lt;/tt&amp;gt;&lt;br /&gt;
* Host: &amp;lt;tt&amp;gt;vhsm_transport.ko&amp;lt;/tt&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Usage ==&lt;br /&gt;
&lt;br /&gt;
To run VHSM perform the following steps:&lt;br /&gt;
# insert transport module: &amp;lt;code&amp;gt;insmod vhsm_transport.ko vhsm_veid=%veid%&amp;lt;/code&amp;gt; where %veid% is VEID of the VHSM container&lt;br /&gt;
# create secure storage in the VHSM VE: &amp;lt;code&amp;gt;vhsm_admin i /path/to/storage&amp;lt;/code&amp;gt;&lt;br /&gt;
# add VHSM user: &amp;lt;code&amp;gt;vhsm_admin c /path/to/storage login password&amp;lt;/code&amp;gt;&lt;br /&gt;
# start VHSM in the VHSM container. You can specify the path to the secure storage in program arguments&lt;br /&gt;
# run &amp;lt;code&amp;gt;vhsm_user_admin&amp;lt;/code&amp;gt; from client VE&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15103</id>
		<title>Virtual HSM</title>
		<link rel="alternate" type="text/html" href="https://wiki.openvz.org/index.php?title=Virtual_HSM&amp;diff=15103"/>
		<updated>2014-03-02T17:07:56Z</updated>

		<summary type="html">&lt;p&gt;Kirill Krinkin: Created page with &amp;quot;TBD&amp;quot;&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;TBD&lt;/div&gt;</summary>
		<author><name>Kirill Krinkin</name></author>
		
	</entry>
</feed>