2

My C# .NET4 program has been storing data in encrypted files on the regular Windows file system and one of our customers has requested that we integrate the program with a PKCS#11 token (henceforth known as the 'token'). After a bit of researching, I discovered NCryptoki and I believe that will provide the necessary interface between my program and a compliant token.

I've got a couple of questions that I can't seem to find answers for that I hope the experienced people here can help me with. I'm still new with PKCS#11 and cryptography principles in general so some of these questions may seem a little juvenile.

  1. My theory is that the token will be able to be inserted into a computer and, using methods in my program that implemented the NCryptoki library, the encrypted files will be able to be saved directly onto it. The files would only be able to be accessed through a wizard in my program. I should be able to continue saving files on the drive as long as the token has space. Is all of this correct?
  2. I will need at least 64K memory on the token and the token must be a minimum of FIPS 140-2 Level 2, preferably level 3. I've looked and have only come across the SafeNet iKey 4000. I KNOW there must be more PKCS#11 compliant tokens that have at least 64K storage. I've spent hours going through the FIPS 140-1/2 Validated Crypto Modules looking for USB Storage PKCS#11 tokens but haven't had much luck. Does anyone know of any other companies that sell what I'm looking for? This could be a USB device or even a Smart Card. We want to be able to provide multiple options for the customer.
  3. Has anyone had any experience with this sort of implementation before that could provide me with some "lessons learned" or things to be aware of?

Also, if this isn't the correct place to put this, please let me know where to repost. I appreciate all of the help!

Brett Wertz
  • 412
  • 4
  • 19
  • This question appears to be off-topic because it is not about programming. See [What topics can I ask about here](https://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Information Security Stack Exchange](http://security.stackexchange.com/) would be a better place to ask. – jww Jul 09 '14 at 04:56

2 Answers2

2

While PKCS#11 supports storing of application data on the devices, the devices themselves (I am talking about USB cryptotokens and smartcards now) are designed for a different purpose. In particular, they are designed to hold small pieces of secret or sensitive data. They are not a data storage. Some vendors provide hybrid tokens, where a USB cryptotoken is combined with a flash disk. But even in this situation these would be two devices in one case.

It is possible that your scenario can be modified in the following way so that you:

  1. generate a session key (possibly right on the device)
  2. use this key to encrypt your sensitive data.
  3. store the encrypted data elsewhere (on a USB disk part of the hybrid device, for example) and use the USB cryptotoken to encrypt/decrypt the data.

On a side note: almost all cryptotoken devices require their drivers to be installed to the system. Unlike USB disks and flash cards there's no universal driver in the OS that would let you plug the USB cryptotoken and use it immediately without installing the driver. This is a hassle from user's perspective, so take this into account as well.

Eugene Mayevski 'Callback
  • 45,135
  • 8
  • 71
  • 121
  • technically, the unencrypted files contain a proprietary XML structure format containing AES and DES Keys as well as other miscellaneous information. The encrypted file size is typically around 4KB-7KB. I do know what you're saying though. Our product had previously used smart cards to store this information but when we started encrypting the data, we decided to allow them to save it to a file. However, one customer still wants a secure device that will prevent unauthorized copying in the case of a malicious person. I would have thought that the 64K of storage on the device could be used. – Brett Wertz May 23 '14 at 15:45
  • @BrettWertz PKCS#11 devices besides the amount of memory have the "maximum block size" parameter which defines how large objects you can keep there. And this parameter is surprisingly small - sometimes it's not enough to hold a certificate with a 4096-bit key! – Eugene Mayevski 'Callback May 23 '14 at 15:59
0

While NCryptoki is good and you will probably have no issues using it, I would recommend you to look at PKCS11Interop. It is fully unit tested and even the unit test are documented and serve as examples. It is a joy using it :) (Disclaimer: I am not the author of this library. I just happen to know the author and have been using this library a lot.)

  1. It could be possible. As a reference how to save data objects on smartcard please look at this keypass plugin.
  2. I have worked with Gemalto cards and Siemens cards but I don't know if they had FIPS 140-2 certification. When I searched for that keypas plugin I found Cryptostick. Doesn't say if it has Fips, but it has Common criteria 5 certification so it might be worth looking at.
  3. Look at the keypass plugin I mentioned. It is implemented using PKCS11Interop I mentioned earlier.
pepo
  • 8,644
  • 2
  • 27
  • 42
  • this library seems to provide another interface similar to [NCryptoki](http://www.ncryptoki.com/Default.aspx). I know the lack of FIPS 140-2 in the [Cryptostick](https://www.crypto-stick.com/en/introduction) is a deal breaker. If you recommend using [PKCS11Interop](http://pkcs11interop.net/), what benefits would it provide to me over using [NCryptoki](http://www.ncryptoki.com/Default.aspx)? – Brett Wertz May 27 '14 at 18:12
  • 1
    As for me, the benefits are: 1. fully documented code, 2. tests for every imaginable scenario and also documented, 3. sources are available. – pepo May 28 '14 at 07:09