简体   繁体   English

使用 HSM 存储“主密钥” - 如何?

[英]Using a HSM to store 'master keys' - how?

I'm using softHSM (FWIW with a go library https://github.com/ThalesIgnite/crypto11 , documentation here https://pkg.go.dev/github.com/ThalesIgnite/crypto11?tab=doc ).我正在使用 softHSM(带有 go 库https://github.com/ThalesIgnite/crypto11 的FWIW,此处的文档https://pkg.go.dev/github.com/ThalesIgnite/crypto11?tab=doc )。

My goal is to store a 'master key' (AES256) for encrypting objects similarly to how AWS S3 does into the HSM device (because it's more secure).我的目标是存储一个“主密钥”(AES256)来加密对象,类似于 AWS S3 进入 HSM 设备的方式(因为它更安全)。 From that key, just derive any other key that I need to encrypt my objects (or decrypt them).从该密钥中,只需派生我需要加密对象(或解密它们)的任何其他密钥。

I'm failing at understanding how a generated secret key in a HSM can later be retrieved by the same software program.我无法理解在 HSM 中生成的密钥以后如何由同一个软件程序检索。 I see that the API mentions of a context ..我看到 API 提到了context ..

rephrased: when I generate a secret key in the HSM like this:改写:当我像这样在 HSM 中生成密钥时:

func TestFindingAllKeys(t *testing.T) {
    withContext(t, func(ctx *Context) {
        for i := 0; i < 10; i++ {
            id := randomBytes()
            key, err := ctx.GenerateSecretKey(id, 128, CipherAES)
            require.NoError(t, err)

            defer func(k *SecretKey) { _ = k.Delete() }(key)
        }

        keys, err := ctx.FindAllKeys()
        require.NoError(t, err)
        require.NotNil(t, keys)

        require.Len(t, keys, 10)
    })
}

how do I 'associate' one of those secret keys with my program data (eg a S3 bucket or customer)?我如何将这些密钥之一与我的程序数据(例如 S3 存储桶或客户)“关联”? How do I retrieve that same secret key again (even if I can't dump it out of the HSM) to decrypt the data at a later time?我如何再次检索相同的密钥(即使我无法将其从 HSM 中转储出来)以稍后解密数据?

I'm missing this apparently stupid, but crucial connection: how does one retrieve a previously generated secret key again at a later time?我错过了这个看似愚蠢但至关重要的联系:如何在以后再次检索以前生成的密钥?

You can use pkcs#11 token labels, or equivalent to tag symmetric keys.您可以使用pkcs#11令牌标签,或等效于标记对称密钥。 You could also use the slot concept, keeping a local database mapping users/customers to keys.您还可以使用插槽概念,保持本地数据库将用户/客户映射到键。

For asymmetric primitives you can export the public key and map this object to a customer/user.对于非对称原语,您可以导出公钥并将此对象映射到客户/用户。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM