1 Star 0 Fork 0

mysnapcore/mygo-tpm2

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
credential.go 1.50 KB
一键复制 编辑 原始数据 按行查看 历史
// Copyright 2021 Canonical Ltd.
// Licensed under the LGPLv3 with static-linking exception.
// See LICENCE file for details.
package util
import (
"errors"
"gitee.com/mysnapcore/mygo-tpm2"
"gitee.com/mysnapcore/mygo-tpm2/mu"
)
// MakeCredential performs the duties of a certificate authority in order to
// create an activation credential. It produces a seed and encrypts this with
// the supplied public key. The seed and supplied object name is then used to
// apply an outer wrapper to the credential.
//
// The encrypted credential blob and encrypted seed are returned, and these can
// be passed to the TPM2_ActivateCredential on the TPM on which both the private
// part of key and the object associated with objectName are loaded.
func MakeCredential(key *tpm2.Public, credential tpm2.Digest, objectName tpm2.Name) (credentialBlob tpm2.IDObjectRaw, secret tpm2.EncryptedSecret, err error) {
if !key.IsStorageParent() || !key.IsAsymmetric() {
return nil, nil, errors.New("key must be an asymmetric storage parent")
}
if !key.NameAlg.Available() {
return nil, nil, errors.New("name algorithm for key is not available")
}
secret, seed, err := tpm2.CryptSecretEncrypt(key, []byte(tpm2.IdentityKey))
if err != nil {
return nil, nil, err
}
credentialBlob = mu.MustMarshalToBytes(credential)
credentialBlob, err = ProduceOuterWrap(key.NameAlg, &key.Params.AsymDetail(key.Type).Symmetric, objectName, seed, false, credentialBlob)
if err != nil {
return nil, nil, err
}
return credentialBlob, secret, nil
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/mysnapcore/mygo-tpm2.git
git@gitee.com:mysnapcore/mygo-tpm2.git
mysnapcore
mygo-tpm2
mygo-tpm2
v0.0.6

搜索帮助