Discussion:
[Opendnssec-user] SoftHSMv2: key extraction
Petr Spacek
2014-06-20 22:20:51 UTC
Permalink
Hello list,

I'm investigating feasibility of migration from SoftHSM v1 to v2 in Fedora and
I have noticed that v2 doesn't support key extraction.

Unfortunately, it is absolutely crucial feature and we can't migrate to v2
until we find a way how to do key exports.

I understand that it is not desirable to enable this by default, it is
perfectly fine to provide key export in separate binary (i.e. not built-in
into softhsm2-util).

Could you point me to the right part of the code in SoftHSM so I can take a
look if it is feasible to do key extraction, please?

Thank you for your time!
--
Petr Spacek @ Red Hat
Rick van Rein
2014-06-20 22:27:27 UTC
Permalink
Hello Petr,
Unfortunately, it is absolutely crucial feature and we can't migrate to v2 until we find a way how to do key exports.
Are you talking about wrapped export, or plaintext export of private keys?
I understand that it is not desirable to enable this by default, it is perfectly fine to provide key export in separate binary (i.e. not built-in into softhsm2-util).
What you want is a bypass for private key protection? which is exactly what PKCS #11 is designed to avoid.

This sounds to me like you should not be looking for problem resolution in SoftHSM, but in the surrounding process. It might transpire that your application is unsuitable for use with PKCS #11, or requires more advanced cryptography that can deal with encapsulated private keys.

Confused,
-Rick
Petr Spacek
2014-06-20 22:49:04 UTC
Permalink
Post by Rick van Rein
Unfortunately, it is absolutely crucial feature and we can't migrate to v2 until we find a way how to do key exports.
Are you talking about wrapped export, or plaintext export of private keys?
Well, the intent is to take keys from (local) SoftHSM, wrap them with
symmetric key and distribute resulting blobs to all nodes in a distributed
cluster.

So if we speak about wrapped export, the requirement is to be able to use raw
symmetric key as wrapping key (without password->key derivation).

Of course, it would be better to use PKCS#11 as interface on top of the
distribution mechanism itself and omit "key export-import phase", but it will
take a long time to develop it. (However, it is the long-term plan.)

Maybe I should add that this key export-import will happen in memory of single
machine so there is not a huge risk.
Post by Rick van Rein
I understand that it is not desirable to enable this by default, it is perfectly fine to provide key export in separate binary (i.e. not built-in into softhsm2-util).
What you want is a bypass for private key protection? which is exactly what PKCS #11 is designed to avoid.
Please correct me if I'm wrong but my impression is that SoftHSM doesn't
provide *real* protection. The library and keys are loaded to process memory
(process = the PKCS#11 caller) ... Isn't it correct?

Some level of protection could be provided by process separation, i.e. one
process maintains key database and provides PKCS#11 interface and other
processes connect to the first process ('key keeper').
Post by Rick van Rein
This sounds to me like you should not be looking for problem resolution in SoftHSM, but in the surrounding process. It might transpire that your application is unsuitable for use with PKCS #11, or requires more advanced cryptography that can deal with encapsulated private keys.
As I said, I'm trying to solve key distribution problem in clustered environment.

For now I would like to get key extraction working in SoftHSM (either to get
plain text key or key wrapped with raw symmetric key).

I hope this explains the intent.
--
Petr^2 Spacek
Paul Wouters
2014-06-21 05:34:58 UTC
Permalink
Post by Rick van Rein
What you want is a bypass for private key protection? which is exactly what PKCS #11 is designed to avoid.
But the key extraction could be via non-PKCS#11 method. It could also
insist on some additional permissions (unix, selinux or otherwise).
Post by Rick van Rein
This sounds to me like you should not be looking for problem resolution in SoftHSM, but in the surrounding process. It might transpire that your application is unsuitable for use with PKCS #11, or requires more advanced cryptography that can deal with encapsulated private keys.
hardware HSMs often also allow some kind of export, to allow running the
same private keys amonst shared devices. Usually, after sharing they
can be put into a no-more-export mode. With softhsm, the library could
still not allow any exports while some softhsm util could allow this.

Paul
(note that I don't know the details of Petr's requirements)
Rick van Rein
2014-06-21 08:09:30 UTC
Permalink
Hi Petr,

I have to be bold I fear?
https://www.redhat.com/archives/freeipa-devel/2014-April/msg00565.html
You are proposing to drag around the private keys between pieces of software, in a format encrypted to an externally generated, symmetric master key that is known to multiple pieces of infrastructure. That ranks as? functional thinking, but rather poor security practice.
(Discussion continues in next months, I'm sorry for mailman inability to create direct links across months.)
Quickly browsing through the responses, there has only been discussion about directory formatting issues, but there are no security-minded responses.
Any comments on it are more than welcome!
To be honest, I am shocked ? this is a *very* weak design from a security perspective. What you are doing undermines the concept of PKCS #11 completely, and it is *much* weaker than a SoftHSM-based implementation.

The thing is, even with SoftHSM you have good control over where your private key material is copied to; think non-swappable memory, think avoidance of static bits burning into DRAM cells through ion displacement; I don?t know how far SoftHSMv2 goes, but at least it is in a position to care. The PKCS #11 API is the way to access private keys through using them, and anything that comes out of a signing operation is safe to publish. An HSM strongly limits the places where the (wrapped) private key is stored temporarily or for a long time, while you are proposing to drag the private key material through all sorts of functional / technical / networking tools, a lot of which has not been vetted for security like an HSM is. SoftHSMv2, is designed by knowledgeable cryptographers and should be considered a superb manner of key management relative to your own coding, unless you and all coders in the wrapped-private-key path also happen to be such knowledgeable cryptographers.

The use of a master key, which I presume is used to decode the private key, is an even clearer misuse of PKCS #11; not only are you not using its private key encapsulation, you are even decrypting it outside of any HSM (?professional key management?) engine. You are effectively reducing PKCS #11 to a software library, indeed pretty much like an OpenSSL library that loads private keys into the rich / complex / dangerous functionality of an application, decrypts them for use in what may or may not be rock-solid signing code. You are basically saying that you don?t want or need PKCS #11 and that you would rather not have to deal with it at all, because it is obstructing you and its security model is not of interest to you.This means that your users wil not be able to upgrade from SoftHSMv2 to the higher level of security from a ?real? HSM because you are bypassing it anyway.

This is indeed the type of problem in your architecture that I suspected from your question.

So, please don?t do it this way.

A much better way would be:

1. Distribute public key material through LDAP
2. Keep private keys behind PKCS #11
3. Access PKCS #11, possibly remotely, to create any signatures
4. Exercise strict access control over the HSM, and be very mindful about the PIN used to access it
5. If you must, encapsulate replication algorithms between HSM nodes into a small and very, very secure and very, very limited-task bit of code (PKCS #11 wrapper or SoftHSMv2 storage engine) and don?t treat it is a trivial bit of coding but as a security hazard

I apologise if I?ve been bold in the above; that must then have been my desire for clarity. I hope that similar mistakes haven?t been made in other parts of FreeIPA?


Hopefully useful,

Cheers,

Rick van Rein
OpenFortress Digital signatures
Andreas Schwier
2014-06-23 22:14:23 UTC
Permalink
Hi Petr and Rick,

actually PKCS#11 provides for a mechanism to wrap / unwrap keys for
export and import from and into key devices. You can wrap asymmetric
keys with symmetric keys and symmetric keys with asymmetric ones. Even
the formats and mechanism are well defined.

However, with SoftHSM you still deal with key material in software, aka
process memory of the CPU. The symmetric wrapping keys has no more
protection than the private key to the wrapped.

The weakness of the design is already to store keys in memory, even if
you use some kind of obfuscation or even employ a very skilled
cryptographer. Easiest attack is to copy the database with key material
and you're done - Keys copied and not even detected.

So security here comes from the assumption that the machine running
SoftHSM is well protected - an assumption that often might not hold true
(see the heartbleed bug).

We've implemented a similar key backup / restore mechanism in the
SmartCard-HSM, which is a hardware token storing private keys. In that
design the symmetric wrapping key is introduced into the SmartCard-HSM
as part of an organizational key management procedure using key shares
in an n-of-m threshold scheme [1]. Once that procedure is completed, the
SmartCard-HSM can be integrated into a cluster and keys can be shared
amongst them. Neither private signing keys nor the wrapping key are ever
exposed, you just have the ability to use the private key, export it in
wrapped form or import a wrapped key from some other SmartCard-HSM in
the cluster.

That way you can implement a scalable and redundant key management
scheme with minimal hardware cost. Unless you need more that 10 signing
operations per second, you should be fine with that setup.

Andreas

[1]
https://github.com/OpenSC/OpenSC/wiki/SmartCardHSM#using-key-backup-and-restore
Post by Rick van Rein
Hi Petr,
I have to be bold I fear?
https://www.redhat.com/archives/freeipa-devel/2014-April/msg00565.html
You are proposing to drag around the private keys between pieces of software, in a format encrypted to an externally generated, symmetric master key that is known to multiple pieces of infrastructure. That ranks as? functional thinking, but rather poor security practice.
(Discussion continues in next months, I'm sorry for mailman inability to create direct links across months.)
Quickly browsing through the responses, there has only been discussion about directory formatting issues, but there are no security-minded responses.
Any comments on it are more than welcome!
To be honest, I am shocked ? this is a *very* weak design from a security perspective. What you are doing undermines the concept of PKCS #11 completely, and it is *much* weaker than a SoftHSM-based implementation.
The thing is, even with SoftHSM you have good control over where your private key material is copied to; think non-swappable memory, think avoidance of static bits burning into DRAM cells through ion displacement; I don?t know how far SoftHSMv2 goes, but at least it is in a position to care. The PKCS #11 API is the way to access private keys through using them, and anything that comes out of a signing operation is safe to publish. An HSM strongly limits the places where the (wrapped) private key is stored temporarily or for a long time, while you are proposing to drag the private key material through all sorts of functional / technical / networking tools, a lot of which has not been vetted for security like an HSM is. SoftHSMv2, is designed by knowledgeable cryptographers and should be considered a superb manner of key management relative to your own coding, unless you and all coders in the wrapped-private-key path also happen to be such knowledgeable cryptographers.
The use of a master key, which I presume is used to decode the private key, is an even clearer misuse of PKCS #11; not only are you not using its private key encapsulation, you are even decrypting it outside of any HSM (?professional key management?) engine. You are effectively reducing PKCS #11 to a software library, indeed pretty much like an OpenSSL library that loads private keys into the rich / complex / dangerous functionality of an application, decrypts them for use in what may or may not be rock-solid signing code. You are basically saying that you don?t want or need PKCS #11 and that you would rather not have to deal with it at all, because it is obstructing you and its security model is not of interest to you.This means that your users wil not be able to upgrade from SoftHSMv2 to the higher level of security from a ?real? HSM because you are bypassing it anyway.
This is indeed the type of problem in your architecture that I suspected from your question.
So, please don?t do it this way.
1. Distribute public key material through LDAP
2. Keep private keys behind PKCS #11
3. Access PKCS #11, possibly remotely, to create any signatures
4. Exercise strict access control over the HSM, and be very mindful about the PIN used to access it
5. If you must, encapsulate replication algorithms between HSM nodes into a small and very, very secure and very, very limited-task bit of code (PKCS #11 wrapper or SoftHSMv2 storage engine) and don?t treat it is a trivial bit of coding but as a security hazard
I apologise if I?ve been bold in the above; that must then have been my desire for clarity. I hope that similar mistakes haven?t been made in other parts of FreeIPA?
Hopefully useful,
Cheers,
Rick van Rein
OpenFortress Digital signatures
_______________________________________________
Opendnssec-user mailing list
https://lists.opendnssec.org/mailman/listinfo/opendnssec-user
--
--------- CardContact Software & System Consulting
|.##> <##.| Andreas Schwier
|# #| Sch?lerweg 38
|# #| 32429 Minden, Germany
|'##> <##'| Phone +49 571 56149
--------- http://www.cardcontact.de
http://www.tscons.de
http://www.openscdp.org
Rick van Rein
2014-06-23 22:22:45 UTC
Permalink
Yeah,
Post by Andreas Schwier
However, with SoftHSM you still deal with key material in software, aka
process memory of the CPU. The symmetric wrapping keys has no more
protection than the private key to the wrapped.
True. But as long as it sits behind the generic PKCS #11 API that is a
choice made at deployment time by the operator; any other HSM can
replace it if so desired. Bypassing PKCS #11 to do all private key
processing in the PKCS #11 client software renders that option invalid.

-Rick
Rickard Bellgrim
2014-06-24 14:40:21 UTC
Permalink
Post by Petr Spacek
Unfortunately, it is absolutely crucial feature and we can't migrate to v2
until we find a way how to do key exports.
I understand that it is not desirable to enable this by default, it is
perfectly fine to provide key export in separate binary (i.e. not built-in
into softhsm2-util).
Could you point me to the right part of the code in SoftHSM so I can take
a look if it is feasible to do key extraction, please?
Are you looking for the functions C_WrapKey() and C_UnwrapKey()?

https://github.com/opendnssec/SoftHSMv2/blob/develop/src/lib/SoftHSM.cpp#L4792
https://github.com/opendnssec/SoftHSMv2/blob/develop/src/lib/SoftHSM.cpp#L5066

// Rickard
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.opendnssec.org/pipermail/opendnssec-user/attachments/20140624/63adb803/attachment.html
Loading...