Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Interfacing with a Hardware Security Module on Linux

I have to work with an HSM device for security requirements in my project. I am confused about how HSM is interfaced with C on a Linux machine.

How does a user access HSM internal memory for performing different operations with it?

like image 201
Deepak Sharma Avatar asked May 29 '12 09:05

Deepak Sharma


2 Answers

Every HSM vendor supports at least one cryptographic API. PKCS#11 is a particularly common choice, but there are many other options. OpenSSL, for example, supports HSMs through an engine interface.

Often the vendor will expose a proprietary API in addition to the "standard" APIs it implements. The proprietary API typically offers a greater degree of control over key security properties and key usage than is possible to express in the standard APIs.

When using an HSM, one typically issues a command to load a key from a secure store and retrieve a handle to the key object. This handle is the layer of abstraction that allows the HSM to perform the key operations securely without exposing the key material.

With regards to your project, it is important that you don't simply "shove" the HSM somewhere in your solution to make it appear secure. Instead, think long and hard about the security properties of your system and how cryptography may help you defend against attacks. Once you've identified your attack vectors (and your associated cryptographic defences), then consider which cryptographic API can support your use cases. Only then should you select the best vendor from those who support that API.

In my experience, the standard APIs only suffice for simple security systems. For complex projects, it's almost always necessary to work with the proprietary API of a particular vendor. In such cases, lean heavily on the vendor for support and proof-of-concepts before settling on a product that truly meets your needs.

like image 104
Duncan Jones Avatar answered Sep 29 '22 15:09

Duncan Jones


I know this is a year old, but in case someone else runs across it, there is a more detailed discussion at this link:

Digital Signing using certificate and key from USB token

Including some long-form working code that I added. You are also welcome to get my code directly at this link: https://github.com/tkil/openssl-pkcs11-samples

Good luck!

like image 31
AnthonyFoiani Avatar answered Sep 29 '22 17:09

AnthonyFoiani