-
-
Notifications
You must be signed in to change notification settings - Fork 161
/
readpairrecord.go
executable file
·98 lines (88 loc) · 2.8 KB
/
readpairrecord.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package ios
import (
"bytes"
log "github.com/sirupsen/logrus"
plist "howett.net/plist"
)
//ReadPair contains all the Infos necessary
//to request a PairRecord from usbmuxd.
//use newReadPair(udid string) to create one.
type ReadPair struct {
BundleID string
ClientVersionString string
MessageType string
ProgName string
LibUSBMuxVersion uint32 `plist:"kLibUSBMuxVersion"`
PairRecordID string
}
func newReadPair(udid string) ReadPair {
data := ReadPair{
BundleID: "go.ios.control",
ClientVersionString: "go-usbmux-0.0.1",
MessageType: "ReadPairRecord",
ProgName: "go-usbmux",
LibUSBMuxVersion: 3,
PairRecordID: udid,
}
return data
}
//PairRecordData only holds a []byte containing the PairRecord data as
//a serialized Plist.
type PairRecordData struct {
PairRecordData []byte
}
//PairRecord contains the HostID string,
//the SystemBUID string, the HostCertificate []byte
//and the HostPrivateKey []byte.
//It is needed for enabling SSL Connections over Lockdown
type PairRecord struct {
HostID string
SystemBUID string
HostCertificate []byte
HostPrivateKey []byte
DeviceCertificate []byte
EscrowBag []byte
WiFiMACAddress string
RootCertificate []byte
RootPrivateKey []byte
}
func pairRecordDatafromBytes(plistBytes []byte) PairRecordData {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data PairRecordData
err := decoder.Decode(&data)
if err != nil {
log.Fatalf("Failed decoding pair record plist %x", plistBytes)
}
if data.PairRecordData == nil {
resp := MuxResponsefromBytes(plistBytes)
log.Fatalf("ReadPair failed with errorcode '%d', is the device paired?", resp.Number)
}
return data
}
//PairRecordfromBytes parsed a plist into a PairRecord
func PairRecordfromBytes(plistBytes []byte) PairRecord {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data PairRecord
err := decoder.Decode(&data)
if err != nil {
log.Fatalf("Failed decoding pair record plist %x", plistBytes)
}
return data
}
//ReadPair reads the PairRecord from the usbmux socket for the given udid.
//It returns the deserialized PairRecord.
func (muxConn *UsbMuxConnection) ReadPair(udid string) PairRecord {
muxConn.Send(newReadPair(udid))
resp, err := muxConn.ReadMessage()
if err != nil {
log.Fatal("Error reading PairRecord", err)
}
pairRecordData := pairRecordDatafromBytes(resp.Payload)
return PairRecordfromBytes(pairRecordData.PairRecordData)
}
//ReadPairRecord creates a new USBMuxConnection just to read the pair record and closes it right after than.
func ReadPairRecord(udid string) PairRecord {
muxConnection := NewUsbMuxConnection(NewDeviceConnection(DefaultUsbmuxdSocket))
defer muxConnection.ReleaseDeviceConnection()
return muxConnection.ReadPair(udid)
}