[Freeipa-devel] DNSSEC key wrapping: cryptographer needed

Tomas Mraz tmraz at redhat.com
Tue Jun 24 13:45:56 UTC 2014


On Po, 2014-06-23 at 14:57 +0200, Petr Spacek wrote:
> Hello list,
> 
> I'm working on key wrapping mechanism described in thread "LDAP schema for 
> DNSSEC keys" [0] and I'm really puzzled from the maze of crypto here. I would 
> really appreciate any suggestions or comments on this.

I am not sure I am able to respond to all of your questions and problems
you're trying to solve but let's try at least some.

> - I have difficulties to pick and use proper wrapping mechanisms and their 
> configuration/usage patterns.
> 
> - Rick van Rein from OpenDNSSEC-user list noted that we are defeating purpose 
> of PKCS#11 by exporting raw keys from HSM. I can see his point and we should 
> be able to do all crypto operations inside SoftHSM.
> 
> I have asked him to describe his doubts on freeipa-devel list - stay tuned.

It is really questionable what are you trying to achieve here. I would
definitely stay away from trying to replicate any back-up mechanisms
that eventual HSM (software or hardware one) should have. This is all
fairly non-trivial functionality and if any HSM implementation is
serious enough it should have backup facility of its own (which should
also allow duplicating such HSM if needed). Note that simply allowing to
export wrapped key with a key you provide to HSM during a normal
operation (not as a special privileged operation) is defeating the
purpose of HSM anyway as you can unwrap the protected key as you wish.

So the only wrapping key that can be used in normal operation should be
a key that is preset or pre-generated in the HSM by the HSM admin.

> 
> We need to wrap
> ===============
> - asymmetric key (zone key)   with symmetric key  (master key)
> - symmetric key  (master key) with asymmetric key (replica key)

Can you please provide more info what purpose these keys have? I
understand that the zone key is the DNSSEC asymmetric key for the zone.
But what about the master key and replica key? Why the master key is
symmetric and the replica asymmetric?

> LDAP schema prescribes some storage formats but my question is about crypto 
> algorithms (and padding!) used for key wrapping.
> 
> 
> Asymmetric keys
> ===============
> According to schema [1] wrapped asymmetric (i.e. private) key must be stored 
> in 'ipaPrivateKey' attribute as DER-encoded EncryptedPrivateKeyInfo structure 
> according to RFC 5958 [2].
> 
> It seem that SoftHSM's C_WrapKey PKCS#11 call will give us encryptedData part 
> of EncryptedPrivateKeyInfo structure so we only have to add algorithm 
> identifier, DER-encode the whole thing, and we could be done.
> 
> I'm not sure where should I stick IV or what happens if default (fixed) IV 
> value is left in place...?

In general using fixed IV when encrypting multiple data (keys) with the
same key breaks the security of the wrapped data. So no, fixed IV must
not be used.

> 
> Technically SoftHSM's C_WrapKey call produces PKCS#8 structure encrypted with 
> AES according to RFC 3394 (no padding) or RFC 5649 (with padding).
> 
> RFC 3394 works only on blocks of 64 bits, which is not our case because 
> EncryptedPrivateKeyInfo has no padding. So we should use RFC 5649 to get 
> proper padding etc.
> 
> And here is the problem: SoftHSM can use RFC 5649 using OpenSSL functions but 
> OpenSSL doesn't support RFC 5649! The patch with this functionality was 
> submitted back in 2010 to OpenSSL bug tracker [3] but the ticket is in state 
> "new" and there was no reply to the e-mail in the original thread [4].

I am sorry, but this does not make much sense to me. Iff the SoftHSM's
C_WrapKey is really safe wrapping method for backing up and/or
replicating HSM's it must provide wrapped key in such format that the IV
is pregenerated as part of the Wrap operation and stored in the final
blob of wrapped key. Unfortunately I do not know much of SoftHSM.

> What do we do?
> - Convince OpenSSL to review and accept the patch?

I would say the patch is not too useful as is - there are multiple
problems with it such as it is not using proper high level interfaces
for the AES encryption, etc.

> - Hack it around #0: Use something else as key wrapping method? Other wrapping 
> methods would require SoftHSM modification because SoftHSM supports only AES 
> mechanisms now.
> - Hack it around #1: Implement the RFC 5649 wrapping algorithm in a downstream 
> patch in SoftHSM? Do we have enough expertise to implement it correctly?
> - Hack it around #2: Implement raw key extraction from SoftHSM and do key 
> wrapping somehow somewhere? (Please nooooooo.)
> 
> 
> Symmetric keys
> ==============
> should be stored in 'ipaSecretKey' attribute but detailed storage format 
> definition is missing from schema [1] right now.
> 
> Unfortunately, SoftHSM doesn't support C_WrapKey PKCS#11 function with 
> asymmetric key as *wrapping* key so we need to add this functionality.
> 
> The first question is:
> What algorithm and padding scheme should we use?
> 
> Something like OpenSSL's RSA_PKCS1_OAEP_PADDING [6]? That would be relatively 
> easy to implement to SoftHSM because it is already there, just not handled in 
> C_WrapKey (so we need to add appropriate 'glue' there).
> 
> Another question is storage format of the wrapped key.
> PKCS#11 2.40d2 [7] contains this comment about "PKCS #1 RSA OAEP" algorithm:
> "For wrapping, the “input” to the encryption operation is the value of the 
> CKA_VALUE attribute of the key that is wrapped; similarly for unwrapping. The 
> mechanism does not wrap the key type or any other information about the key, 
> except the key length; the application must convey these separately."
> 
> AFAIK it means that it wraps raw secret key and nothing else. If I'm not wrong 
> we should be able to take resulting blob and stick it into OneSymmetricKey 
> structure from RFC 6031 [5]. Honza, is it correct assumption/idea?
> 
> 
> I would really appreciate any suggestions or comments on this.
> 
> Thank you for your time.
> 
> [0] https://www.redhat.com/archives/freeipa-devel/2014-April/msg00565.html
> [1] http://www.freeipa.org/page/V4/PKCS11_in_LDAP/Schema#Encoded_key_data_2
> [2] http://tools.ietf.org/html/rfc5958#section-3
> [3] http://rt.openssl.org/Ticket/Display.html?id=2204
> [4] http://marc.info/?l=openssl-dev&m=126953517430167&w=2
> [5] https://tools.ietf.org/html/rfc6031#section-2
> [6] https://www.openssl.org/docs/crypto/RSA_public_encrypt.html
> [7] 
> http://docs.oasis-open.org/pkcs11/pkcs11-curr/v2.40/csprd02/pkcs11-curr-v2.40-csprd02.html#_Toc387327841
> 

-- 
Tomas Mraz
No matter how far down the wrong road you've gone, turn back.
                                              Turkish proverb
(You'll never know whether the road is wrong though.)





More information about the Freeipa-devel mailing list