Skip to content

Commit

Permalink
add calulated cdhash to codesign
Browse files Browse the repository at this point in the history
  • Loading branch information
blacktop committed Jul 22, 2020
1 parent 41cdc68 commit a3b265c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 5 deletions.
3 changes: 2 additions & 1 deletion cmds.go
Original file line number Diff line number Diff line change
Expand Up @@ -628,8 +628,9 @@ type CodeSignature struct {
Size uint32
ID string
TeamID string
CDHash string
CodeDirectory ctypes.CodeDirectory
Requirements []ctypes.Requirement
Requirements ctypes.Requirement
CMSSignature []byte
Entitlements string
}
Expand Down
2 changes: 2 additions & 0 deletions file.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,8 @@ func NewFile(r io.ReaderAt, loads ...types.LoadCmd) (*File, error) {
return nil, err
}
l.ID = cs.ID
l.TeamID = cs.TeamID
l.CDHash = cs.CDHash
l.CodeDirectory = cs.CodeDirectory
l.Requirements = cs.Requirements
l.CMSSignature = cs.CMSSignature
Expand Down
15 changes: 12 additions & 3 deletions pkg/codesign/codesign.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package codesign
import (
"bufio"
"bytes"
"crypto/sha256"
"encoding/binary"
"fmt"
"io"
Expand Down Expand Up @@ -39,7 +40,16 @@ func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {
if err := binary.Read(r, binary.BigEndian, &cs.CodeDirectory); err != nil {
return nil, err
}
// TODO parse all the cdhashs
// Calculate the cdhashs
r.Seek(int64(index.Offset), io.SeekStart)
cdData := make([]byte, cs.CodeDirectory.Length)
if err := binary.Read(r, binary.LittleEndian, &cdData); err != nil {
return nil, err
}
h := sha256.New()
h.Write(cdData)
cs.CDHash = fmt.Sprintf("%x", h.Sum(nil))
// Parse version
switch cs.CodeDirectory.Version {
case types.SUPPORTS_SCATTER:
if cs.CodeDirectory.ScatterOffset > 0 {
Expand Down Expand Up @@ -97,7 +107,6 @@ func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {
}
}
case types.CSSLOT_REQUIREMENTS:
// TODO find out if there can be more than one requirement(s)
req := types.Requirement{}
if err := binary.Read(r, binary.BigEndian, &req.RequirementsBlob); err != nil {
return nil, err
Expand All @@ -120,7 +129,7 @@ func ParseCodeSignature(cmddat []byte) (*types.CodeSignature, error) {
} else {
req.Detail = "empty requirement set"
}
cs.Requirements = append(cs.Requirements, req)
cs.Requirements = req
case types.CSSLOT_ENTITLEMENTS:
entBlob := types.Blob{}
if err := binary.Read(r, binary.BigEndian, &entBlob); err != nil {
Expand Down
3 changes: 2 additions & 1 deletion pkg/codesign/types/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ type magic uint32
type CodeSignature struct {
ID string
TeamID string
CDHash string
CodeDirectory CodeDirectory
Requirements []Requirement
Requirements Requirement
CMSSignature []byte
Entitlements string
}
Expand Down

0 comments on commit a3b265c

Please sign in to comment.