go-tpm-tools icon indicating copy to clipboard operation
go-tpm-tools copied to clipboard

Support loading cached key

Open daniel-weisse opened this issue 1 year ago • 0 comments

Is it possible to simply load a cached key without having to know extra parameters, e.g. a template matching the key?

Basically, I want a TPM client function like the following:

// LoadKey loads a key from the provided handle.
func LoadKey(rw io.ReadWriter, handle tpmutil.Handle) (*Key, error) {
        cachedPub, _, _, err := tpm2.ReadPublic(rw, handle)
        if err != nil {
                return nil, err
        }
        k := &Key{
                rw: rw,
                handle: handle,
                pubArea: cachedPub,
        }
        return k, k.finish()
}

The only function that does a similar thing is NewCachedKey, but comes with the risk of overwriting a key at the given handle if the provided template does not match the existing key.

daniel-weisse avatar Aug 11 '22 11:08 daniel-weisse