Encryption/decryption using a PKCS#11 interface of an HSM

637 views
Skip to first unread message

Christian Brunette

unread,
Mar 8, 2018, 4:49:23 AM3/8/18
to keywhiz-users
I start evaluating keywhiz and I need to protect the secrets with a key stored in an hardware security module.
Has anyone already tested this feature ? 
Is keywhiz able to manage PKCS11 interface yet ?

Thanks in advance for your answers.

Best regards,
Christian

Matthew McPherrin

unread,
Mar 8, 2018, 4:56:10 AM3/8/18
to Christian Brunette, keywhiz-users
Keywhiz supports using a java crypto provider which can be hsm backed. Major hsm vendors provide that. We have tested with several vendors.  If you need help for a particular vendor, feel free to ask.

--
You received this message because you are subscribed to the Google Groups "keywhiz-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keywhiz-users+unsubscribe@googlegroups.com.
To post to this group, send email to keywhi...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/keywhiz-users/991b7436-e16a-497a-8cf5-30fc972d883b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Christian Brunette

unread,
Mar 8, 2018, 5:29:24 AM3/8/18
to keywhiz-users
Thanks for your answer.
I am using Bull Trustway Proteccio which provides only a PKCS11 interface for Linux environment (in the qualified version).

I am interested by all documentations or examples (keywhiz configuration file) for an HSM integration you can provide, even for another type of HSM.


Le jeudi 8 mars 2018 10:56:10 UTC+1, Matthew McPherrin a écrit :
Keywhiz supports using a java crypto provider which can be hsm backed. Major hsm vendors provide that. We have tested with several vendors.  If you need help for a particular vendor, feel free to ask.
On Mar 8, 2018 1:49 AM, "Christian Brunette" <cbru...@gmail.com> wrote:
I start evaluating keywhiz and I need to protect the secrets with a key stored in an hardware security module.
Has anyone already tested this feature ? 
Is keywhiz able to manage PKCS11 interface yet ?

Thanks in advance for your answers.

Best regards,
Christian

--
You received this message because you are subscribed to the Google Groups "keywhiz-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to keywhiz-user...@googlegroups.com.

Matthew McPherrin

unread,
Mar 8, 2018, 9:07:07 PM3/8/18
to Christian Brunette, keywhiz-users
I suspect PKCS11 module would be pretty easy to work, but I'm not sure if it would work out of the box.  I don't have a lot of experience with PKCS11 and Java.  It'll require some config at least.

The relevant Keywhiz config looks like this for an nCipher module. 

derivationProviderClass: com.ncipher.provider.km.nCipherKM

contentKeyStore:
  path: /.../derivation.sworld
  type: ncipher.sworld
  password: external:/.../derivation.password
  alias: basekey

Those options configure the "Derivation Provider", ie the Java crypto provider which does the key derivation per-item.  That's the bit you want in your HSM.

There's a sun.security.pkcs11.SunPKCS11 which looks like it's probably usable here.

The only thing is it seems to need a configuration file passed to it, which isn't supported right now in Keywhiz.
It's not entirely clear to me but you might be able to configure the PKCS11 module entirely using JVM options or the 

If not, we'd need some changes, at least to pass in the argument in 
And we'd need to add it to the configuration in

To unsubscribe from this group and stop receiving emails from it, send an email to keywhiz-users+unsubscribe@googlegroups.com.

To post to this group, send email to keywhi...@googlegroups.com.

Alok Menghrajani

unread,
Mar 8, 2018, 10:23:27 PM3/8/18
to Christian Brunette, keywhiz-users
Hey,

HSM vendors will typically support many interfaces in addition to pkcs11 e.g. something for Windows, JCE for Java, TDE for databases, etc.

You can totally use pkcs11 with Java (we did that in the past with another app and it should work with Keywhiz). Our experience is that the JCE providers are much nicer+easier to work with than pkcs11.

You should talk to your vendor about JCE, you might get lucky?

Alok

Alok Menghrajani

unread,
Mar 9, 2018, 5:29:49 PM3/9/18
to Matthew McPherrin, Christian Brunette, keywhiz-users
For PKCS11, it should look something like:

derivationProviderClass: sun.security.pkcs11.SunPKCS11
contentKeyStore:
path: <pkcs11.cfg see
https://docs.oracle.com/javase/7/docs/technotes/guides/security/p11guide.html>
type: PKCS11
password: external:/.../derivation.password
alias: basekey

Let us know if this works or if you still need additional help?

Alok

Matthew McPherrin

unread,
Mar 9, 2018, 5:34:05 PM3/9/18
to Alok Menghrajani, Christian Brunette, keywhiz-users
Does putting the config in the path work like that?  the p11guide said to use keytool like this:

keytool -keystore NONE -storetype PKCS11 \
        -providerClass sun.security.pkcs11.SunPKCS11 \
        -providerArg /foo/bar/token.config \
        -list
which implies to me "path" should be "NONE" and the config file should be passed as a constructor argument -- we currently invoke the zero-arg constructor.

Alok Menghrajani

unread,
Mar 9, 2018, 5:41:09 PM3/9/18
to Matthew McPherrin, Christian Brunette, keywhiz-users
You are right.

The contents of the pkcs11 config file needs to be the first argument
to the provider.
https://github.com/square/keywhiz/blob/90d7493d42e3df5072135bb619c531724f54a98b/server/src/main/java/keywhiz/service/crypto/CryptoModule.java#L92
would need to be changed to work with pkcs11 (unless there's some
other way to provide the config?).

Alok

Matthew McPherrin

unread,
Mar 9, 2018, 5:45:51 PM3/9/18
to Alok Menghrajani, Christian Brunette, keywhiz-users
There's some reference to configuring providers in the java.security file online, but I haven't investigated.
Reply all
Reply to author
Forward
0 new messages