awnumar / memguard

Secure software enclave for storage of sensitive information in memory.
Apache License 2.0
2.49k stars 124 forks source link

rsa.PrivateKey best practice and judgement call question #134

Closed karlmutch closed 4 years ago

karlmutch commented 4 years ago

Hi,

I need advice on how to handle a *rsa.PrivateKey using memguard. The private key is being used to decrypt smallish messages being sent to the server, once every minute or so.

The naive thing to do is to resort to keeping a PEM and passphrase in Enclaves however this leaves all of the intermediate variables etc exposed each time the private key is needed by code using the key for decryption.

Another thing I could do is to place all of the individual big integers inside the PrivateKey structure into their own Enclaves and reconstruct the private key on every use, seems error prone and not much better than option 1.

Is the only sensible way to protect things like rsa.PrivateKey with tools like memguard to have the enclaves built into the crypto libraries proper ?

Or, is there a philosophy of 'do as much as you can within reason' without resorting to HSM style products?

Thanks, Karl

awnumar commented 4 years ago

Is the only sensible way to protect things like rsa.PrivateKey with tools like memguard to have the enclaves built into the crypto libraries?

Yeah unfortunately that's a common theme. The PrivateKey struct looks like

type PrivateKey struct {
    PublicKey            // public part.
    D         *big.Int   // private exponent
    Primes    []*big.Int // prime factors of N, has >= 2 elements.

    // Precomputed contains precomputed values that speed up private
    // operations, if available.
    Precomputed PrecomputedValues
}

Which isn't in a nice format to just be able to allocate completely within a container. If you can initialise big.Int values within a container then this would be easier as the PrivateKey struct is made up of pointers to these structures.

Or, is there a philosophy of 'do as much as you can within reason' without resorting to HSM style products?

Sure I mean none of what memguard does guarantees the security of information, we just try to make it safer.

karlmutch commented 4 years ago

Thanks for the answer.