提交 1adab6cf 编写于 作者: jia zhang's avatar jia zhang

runectl: Implement new command gen-qe-target-info

Support to retrieve quoting enclave's target information.
Signed-off-by: jia zhang's avatarJia Zhang <zhang.jia@linux.alibaba.com>
上级 48db17d4
package main // import "github.com/inclavare-containers/runectl"
import (
"github.com/opencontainers/runc/libenclave/intelsgx"
"github.com/sirupsen/logrus"
"github.com/urfave/cli"
"io/ioutil"
)
var generateQeTargetInfoCommand = cli.Command{
Name: "gen-qe-target-info",
Usage: "retrieve the target information about Quoting Enclave from aesmd",
ArgsUsage: `[command options]
EXAMPLE:
For example, save the target information file about Quoting Enclave retrieved from aesmd:
# runectl gen-qe-target-info --targetinfo foo`,
Flags: []cli.Flag{
cli.StringFlag{
Name: "targetinfo",
Usage: "path to the output target information file containing TARGETINFO",
},
},
Action: func(context *cli.Context) error {
if context.GlobalBool("verbose") {
logrus.SetLevel(logrus.DebugLevel)
}
ti, err := intelsgx.GetQeTargetInfo()
if err != nil {
logrus.Print(err)
return err
}
tiPath := context.String("targetinfo")
if tiPath == "" {
tiPath = "qe_targetinfo.bin"
}
if err := ioutil.WriteFile(tiPath, ti, 0664); err != nil {
return err
}
logrus.Infof("quoting enclave's target info file %s saved", tiPath)
return nil
},
SkipArgReorder: true,
}
......@@ -43,6 +43,7 @@ func main() {
app.Commands = []cli.Command{
generateTokenCommand,
generateQeTargetInfoCommand,
}
//app.Before = func(context *cli.Context) error {
......
......@@ -189,3 +189,59 @@ func GetLaunchToken(sig []byte) ([]byte, error) {
return resp.GetLaunchToken.GetToken(), nil
}
func GetQeTargetInfo() ([]byte, error) {
conn, err := dialAesmd()
if err != nil {
return nil, err
}
defer conn.Close()
req := pb.AesmServiceRequest{}
req.GetQeTargetInfo = &pb.AesmServiceRequest_GetQeTargetInfo{
Timeout: 10000,
}
rdata, err := transmitAesmd(conn, &req)
if err != nil {
return nil, err
}
resp := pb.AesmServiceResponse{}
resp.GetQeTargetInfo = &pb.AesmServiceResponse_GetQeTargetInfo{}
if err := proto.Unmarshal(rdata, &resp); err != nil {
return nil, err
}
if resp.GetQeTargetInfo.GetError() != 0 {
return nil, fmt.Errorf("failed to get TARGETINFO (error code = %d)",
resp.GetQeTargetInfo.GetError())
}
targetInfo := resp.GetQeTargetInfo.GetTargetinfo()
if len(targetInfo) != TargetinfoLength {
return nil, fmt.Errorf("invalid length of TARGETINFO: (returned %d, expected %d)",
len(targetInfo), TargetinfoLength)
}
ti := &Targetinfo{}
if err := restruct.Unpack(targetInfo, binary.LittleEndian, &ti); err != nil {
return nil, err
}
logrus.Debugf("Quoting Enclave's TARGETINFO:\n")
logrus.Debugf(" Enclave Hash: 0x%v\n",
hex.EncodeToString(ti.Measurement[:]))
logrus.Debugf(" Enclave Attributes: 0x%v\n",
hex.EncodeToString(ti.Attributes[:]))
logrus.Debugf(" CET Attributes: %#02x\n",
ti.CetAttributes)
logrus.Debugf(" Config SVN: %#04x\n",
ti.ConfigSvn)
logrus.Debugf(" Misc Select: %#08x\n",
ti.MiscSelect)
logrus.Debugf(" Config ID: 0x%v\n",
hex.EncodeToString(ti.ConfigId[:]))
return resp.GetQeTargetInfo.GetTargetinfo(), nil
}
......@@ -26,6 +26,7 @@ const (
const (
SigStructLength = 1808
EinittokenLength = 304
TargetinfoLength = 512
ReportLength = ReportBodyLength + 48
ReportBodyLength = 384
QuoteLength = QuoteBodyLength + ReportBodyLength + 4
......@@ -79,6 +80,18 @@ type Einittoken struct {
Mac [16]byte `struct:"[16]byte"`
}
type Targetinfo struct {
Measurement [32]byte `struct:"[32]byte"`
Attributes [16]byte `struct:"[16]byte"`
CetAttributes uint8 `struct:"uint8"`
_ uint8 `struct:"uint8"`
ConfigSvn uint16 `struct:"uint16"`
MiscSelect uint32 `struct:"uint32"`
_ [8]byte `struct:"[8]byte"`
ConfigId [64]byte `struct:"[64]byte"`
_ [384]byte `struct:"[384]byte"`
}
type Report struct {
ReportBody
Keyid [32]byte `struct:"[32]byte"`
......
......@@ -21,10 +21,11 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type AesmServiceRequest struct {
GetLaunchToken *AesmServiceRequest_GetLaunchToken `protobuf:"bytes,3,opt,name=getLaunchToken,proto3" json:"getLaunchToken,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
GetQeTargetInfo *AesmServiceRequest_GetQeTargetInfo `protobuf:"bytes,1,opt,name=getQeTargetInfo,proto3" json:"getQeTargetInfo,omitempty"`
GetLaunchToken *AesmServiceRequest_GetLaunchToken `protobuf:"bytes,3,opt,name=getLaunchToken,proto3" json:"getLaunchToken,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *AesmServiceRequest) Reset() { *m = AesmServiceRequest{} }
......@@ -52,6 +53,13 @@ func (m *AesmServiceRequest) XXX_DiscardUnknown() {
var xxx_messageInfo_AesmServiceRequest proto.InternalMessageInfo
func (m *AesmServiceRequest) GetGetQeTargetInfo() *AesmServiceRequest_GetQeTargetInfo {
if m != nil {
return m.GetQeTargetInfo
}
return nil
}
func (m *AesmServiceRequest) GetGetLaunchToken() *AesmServiceRequest_GetLaunchToken {
if m != nil {
return m.GetLaunchToken
......@@ -59,6 +67,45 @@ func (m *AesmServiceRequest) GetGetLaunchToken() *AesmServiceRequest_GetLaunchTo
return nil
}
type AesmServiceRequest_GetQeTargetInfo struct {
Timeout uint32 `protobuf:"varint,9,opt,name=timeout,proto3" json:"timeout,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *AesmServiceRequest_GetQeTargetInfo) Reset() { *m = AesmServiceRequest_GetQeTargetInfo{} }
func (m *AesmServiceRequest_GetQeTargetInfo) String() string { return proto.CompactTextString(m) }
func (*AesmServiceRequest_GetQeTargetInfo) ProtoMessage() {}
func (*AesmServiceRequest_GetQeTargetInfo) Descriptor() ([]byte, []int) {
return fileDescriptor_85fe23d8fdbcfe93, []int{0, 0}
}
func (m *AesmServiceRequest_GetQeTargetInfo) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo.Unmarshal(m, b)
}
func (m *AesmServiceRequest_GetQeTargetInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo.Marshal(b, m, deterministic)
}
func (m *AesmServiceRequest_GetQeTargetInfo) XXX_Merge(src proto.Message) {
xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo.Merge(m, src)
}
func (m *AesmServiceRequest_GetQeTargetInfo) XXX_Size() int {
return xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo.Size(m)
}
func (m *AesmServiceRequest_GetQeTargetInfo) XXX_DiscardUnknown() {
xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo.DiscardUnknown(m)
}
var xxx_messageInfo_AesmServiceRequest_GetQeTargetInfo proto.InternalMessageInfo
func (m *AesmServiceRequest_GetQeTargetInfo) GetTimeout() uint32 {
if m != nil {
return m.Timeout
}
return 0
}
type AesmServiceRequest_GetLaunchToken struct {
Enclavehash []byte `protobuf:"bytes,1,opt,name=enclavehash,proto3" json:"enclavehash,omitempty"`
Modulus []byte `protobuf:"bytes,2,opt,name=modulus,proto3" json:"modulus,omitempty"`
......@@ -73,7 +120,7 @@ func (m *AesmServiceRequest_GetLaunchToken) Reset() { *m = AesmServiceRe
func (m *AesmServiceRequest_GetLaunchToken) String() string { return proto.CompactTextString(m) }
func (*AesmServiceRequest_GetLaunchToken) ProtoMessage() {}
func (*AesmServiceRequest_GetLaunchToken) Descriptor() ([]byte, []int) {
return fileDescriptor_85fe23d8fdbcfe93, []int{0, 0}
return fileDescriptor_85fe23d8fdbcfe93, []int{0, 1}
}
func (m *AesmServiceRequest_GetLaunchToken) XXX_Unmarshal(b []byte) error {
......@@ -123,10 +170,11 @@ func (m *AesmServiceRequest_GetLaunchToken) GetTimeout() uint32 {
}
type AesmServiceResponse struct {
GetLaunchToken *AesmServiceResponse_GetLaunchToken `protobuf:"bytes,3,opt,name=getLaunchToken,proto3" json:"getLaunchToken,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
GetQeTargetInfo *AesmServiceResponse_GetQeTargetInfo `protobuf:"bytes,1,opt,name=getQeTargetInfo,proto3" json:"getQeTargetInfo,omitempty"`
GetLaunchToken *AesmServiceResponse_GetLaunchToken `protobuf:"bytes,3,opt,name=getLaunchToken,proto3" json:"getLaunchToken,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *AesmServiceResponse) Reset() { *m = AesmServiceResponse{} }
......@@ -154,6 +202,13 @@ func (m *AesmServiceResponse) XXX_DiscardUnknown() {
var xxx_messageInfo_AesmServiceResponse proto.InternalMessageInfo
func (m *AesmServiceResponse) GetGetQeTargetInfo() *AesmServiceResponse_GetQeTargetInfo {
if m != nil {
return m.GetQeTargetInfo
}
return nil
}
func (m *AesmServiceResponse) GetGetLaunchToken() *AesmServiceResponse_GetLaunchToken {
if m != nil {
return m.GetLaunchToken
......@@ -161,6 +216,61 @@ func (m *AesmServiceResponse) GetGetLaunchToken() *AesmServiceResponse_GetLaunch
return nil
}
type AesmServiceResponse_GetQeTargetInfo struct {
Error uint32 `protobuf:"varint,1,opt,name=error,proto3" json:"error,omitempty"`
Targetinfo []byte `protobuf:"bytes,2,opt,name=targetinfo,proto3" json:"targetinfo,omitempty"`
Gid []byte `protobuf:"bytes,3,opt,name=gid,proto3" json:"gid,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"`
XXX_unrecognized []byte `json:"-"`
XXX_sizecache int32 `json:"-"`
}
func (m *AesmServiceResponse_GetQeTargetInfo) Reset() { *m = AesmServiceResponse_GetQeTargetInfo{} }
func (m *AesmServiceResponse_GetQeTargetInfo) String() string { return proto.CompactTextString(m) }
func (*AesmServiceResponse_GetQeTargetInfo) ProtoMessage() {}
func (*AesmServiceResponse_GetQeTargetInfo) Descriptor() ([]byte, []int) {
return fileDescriptor_85fe23d8fdbcfe93, []int{1, 0}
}
func (m *AesmServiceResponse_GetQeTargetInfo) XXX_Unmarshal(b []byte) error {
return xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo.Unmarshal(m, b)
}
func (m *AesmServiceResponse_GetQeTargetInfo) XXX_Marshal(b []byte, deterministic bool) ([]byte, error) {
return xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo.Marshal(b, m, deterministic)
}
func (m *AesmServiceResponse_GetQeTargetInfo) XXX_Merge(src proto.Message) {
xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo.Merge(m, src)
}
func (m *AesmServiceResponse_GetQeTargetInfo) XXX_Size() int {
return xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo.Size(m)
}
func (m *AesmServiceResponse_GetQeTargetInfo) XXX_DiscardUnknown() {
xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo.DiscardUnknown(m)
}
var xxx_messageInfo_AesmServiceResponse_GetQeTargetInfo proto.InternalMessageInfo
func (m *AesmServiceResponse_GetQeTargetInfo) GetError() uint32 {
if m != nil {
return m.Error
}
return 0
}
func (m *AesmServiceResponse_GetQeTargetInfo) GetTargetinfo() []byte {
if m != nil {
return m.Targetinfo
}
return nil
}
func (m *AesmServiceResponse_GetQeTargetInfo) GetGid() []byte {
if m != nil {
return m.Gid
}
return nil
}
type AesmServiceResponse_GetLaunchToken struct {
Error uint32 `protobuf:"varint,1,opt,name=error,proto3" json:"error,omitempty"`
Token []byte `protobuf:"bytes,2,opt,name=token,proto3" json:"token,omitempty"`
......@@ -173,7 +283,7 @@ func (m *AesmServiceResponse_GetLaunchToken) Reset() { *m = AesmServiceR
func (m *AesmServiceResponse_GetLaunchToken) String() string { return proto.CompactTextString(m) }
func (*AesmServiceResponse_GetLaunchToken) ProtoMessage() {}
func (*AesmServiceResponse_GetLaunchToken) Descriptor() ([]byte, []int) {
return fileDescriptor_85fe23d8fdbcfe93, []int{1, 0}
return fileDescriptor_85fe23d8fdbcfe93, []int{1, 1}
}
func (m *AesmServiceResponse_GetLaunchToken) XXX_Unmarshal(b []byte) error {
......@@ -210,8 +320,10 @@ func (m *AesmServiceResponse_GetLaunchToken) GetToken() []byte {
func init() {
proto.RegisterType((*AesmServiceRequest)(nil), "aesm_service.AesmServiceRequest")
proto.RegisterType((*AesmServiceRequest_GetQeTargetInfo)(nil), "aesm_service.AesmServiceRequest.GetQeTargetInfo")
proto.RegisterType((*AesmServiceRequest_GetLaunchToken)(nil), "aesm_service.AesmServiceRequest.GetLaunchToken")
proto.RegisterType((*AesmServiceResponse)(nil), "aesm_service.AesmServiceResponse")
proto.RegisterType((*AesmServiceResponse_GetQeTargetInfo)(nil), "aesm_service.AesmServiceResponse.GetQeTargetInfo")
proto.RegisterType((*AesmServiceResponse_GetLaunchToken)(nil), "aesm_service.AesmServiceResponse.GetLaunchToken")
}
......@@ -220,21 +332,26 @@ func init() {
}
var fileDescriptor_85fe23d8fdbcfe93 = []byte{
// 250 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x84, 0x91, 0xb1, 0x4e, 0xc3, 0x30,
0x10, 0x86, 0x65, 0x10, 0x20, 0xae, 0x69, 0x07, 0xc3, 0x60, 0x31, 0xa0, 0xa8, 0x53, 0x16, 0x02,
0x82, 0x95, 0x85, 0x89, 0x85, 0xc9, 0x20, 0xc1, 0x86, 0xdc, 0x70, 0x22, 0x11, 0x8d, 0x5d, 0x7c,
0xe7, 0x3e, 0x02, 0x6f, 0xc3, 0xeb, 0x31, 0xa3, 0xd8, 0x54, 0x4a, 0x88, 0xa0, 0xe3, 0xff, 0xdb,
0x9f, 0x7d, 0x9f, 0x0e, 0x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 0xc9, 0x63, 0x3d, 0xa8, 0x63, 0x32, 0x99, 0x8b, 0x25,
0xce, 0x84, 0x9e, 0xd9, 0xc0, 0x0d, 0x9e, 0x95, 0x52, 0x5c, 0x2c, 0xa7, 0x66, 0x6e, 0xb4, 0x5f,
0xb1, 0x6f, 0xd7, 0x23, 0x3b, 0x06, 0x10, 0x44, 0x2a, 0x1a, 0x1b, 0x42, 0x6d, 0x03, 0x35, 0x78,
0x46, 0x29, 0x3f, 0x48, 0xff, 0xbb, 0x02, 0x47, 0x1b, 0x59, 0xf5, 0x42, 0x26, 0x1a, 0xd9, 0x6b,
0x59, 0x05, 0xe7, 0x5b, 0xf6, 0xe4, 0xbc, 0xff, 0x77, 0xf0, 0x54, 0xd2, 0xc1, 0x70, 0x27, 0xf6,
0xb6, 0x12, 0x9e, 0x8b, 0x25, 0x74, 0xa0, 0x86, 0x4a, 0x49, 0x65, 0xcf, 0xdf, 0xe4, 0x6e, 0x48,
0x37, 0x46, 0xf6, 0x9b, 0x28, 0x8d, 0xe6, 0xd6, 0x99, 0x51, 0xd8, 0x21, 0x54, 0xc3, 0x68, 0xba,
0x5a, 0x65, 0xfa, 0xd8, 0xbd, 0x2a, 0x34, 0xf6, 0x37, 0xb9, 0x03, 0x35, 0xb2, 0x99, 0x1c, 0xd4,
0x0d, 0xe3, 0x3d, 0x7b, 0xfd, 0x2f, 0x7f, 0x03, 0x00, 0x00, 0xff, 0xff, 0xef, 0x36, 0xfc, 0x14,
0x14, 0x03, 0x00, 0x00,
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册