@@ -27,9 +27,49 @@ type DcapQuote struct {
2727	M_SigLen   uint32 
2828}
2929
30+ func  VerifyCertDCAP (blob  []byte , pos0  uintptr , pos1  uintptr ) ([]byte , error ) {
31+ 	var  quote  DcapQuote 
32+ 
33+ 	buf  :=  bytes .NewReader (blob [pos0 :pos1 ])
34+ 	err  :=  binary .Read (buf , binary .LittleEndian , & quote )
35+ 	if  err  !=  nil  {
36+ 		return  nil , err 
37+ 	}
38+ 
39+ 	fmt .Println ("DCAP quote Extracted pk: " , hex .EncodeToString (quote .M_PubKey [:]))
40+ 	return  quote .M_PubKey [:], nil 
41+ }
42+ 
3043func  VerifyCombinedCert (blob  []byte ) ([]byte , error ) {
3144	var  hdr  CombinedHdr 
3245
46+ 	if  (len (blob ) >  0 ) &&  (blob [0 ] !=  0 ) {
47+ 		// try the newer format 
48+ 		pos  :=  0 
49+ 
50+ 		for  pos + 5  <  len (blob ) {
51+ 
52+ 			block_tag  :=  blob [pos ]
53+ 			pos  +=  1 
54+ 
55+ 			block_size  :=  binary .LittleEndian .Uint32 (blob [pos  : pos + 4 ])
56+ 			pos  +=  4 
57+ 
58+ 			if  block_size  >  uint32 (len (blob )- pos ) {
59+ 				break 
60+ 			}
61+ 
62+ 			pos1  :=  pos  +  int (block_size )
63+ 
64+ 			if  (block_tag  ==  2 ) &&  (block_size  >  0 ) {
65+ 				return  VerifyCertDCAP (blob , uintptr (pos ), uintptr (pos1 ))
66+ 			}
67+ 
68+ 			pos  =  pos1 
69+ 		}
70+ 
71+ 	}
72+ 
3373	if  uintptr (len (blob )) <  unsafe .Sizeof (hdr ) {
3474		return  nil , errors .New ("Combined hdr too small" )
3575	}
@@ -60,16 +100,7 @@ func VerifyCombinedCert(blob []byte) ([]byte, error) {
60100	}
61101
62102	if  idx2  >  idx1  {
63- 		var  quote  DcapQuote 
64- 
65- 		buf  :=  bytes .NewReader (blob [idx1 :idx2 ])
66- 		err  :=  binary .Read (buf , binary .LittleEndian , & quote )
67- 		if  err  !=  nil  {
68- 			return  nil , err 
69- 		}
70- 
71- 		fmt .Println ("DCAP quote Extracted pk: " , hex .EncodeToString (quote .M_PubKey [:]))
72- 		return  quote .M_PubKey [:], nil 
103+ 		return  VerifyCertDCAP (blob , idx1 , idx2 )
73104	}
74105
75106	return  nil , errors .New ("No valid attestatoin found" )
0 commit comments