-
-
Notifications
You must be signed in to change notification settings - Fork 172
/
startsession.go
executable file
·60 lines (53 loc) · 1.68 KB
/
startsession.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
package ios
import (
"bytes"
plist "howett.net/plist"
)
type startSessionRequest struct {
Label string
ProtocolVersion string
Request string
HostID string
SystemBUID string
}
func newStartSessionRequest(hostID string, systemBuid string) startSessionRequest {
return startSessionRequest{
Label: "go.ios.control",
ProtocolVersion: "2",
Request: "StartSession",
HostID: hostID,
SystemBUID: systemBuid,
}
}
//StartSessionResponse contains the information sent by the device as a response to a StartSessionRequest.
type StartSessionResponse struct {
EnableSessionSSL bool
Request string
SessionID string
}
func startSessionResponsefromBytes(plistBytes []byte) StartSessionResponse {
decoder := plist.NewDecoder(bytes.NewReader(plistBytes))
var data StartSessionResponse
_ = decoder.Decode(&data)
return data
}
//StartSession will send a StartSession Request to Lockdown, wait for the response and enable
//SSL on the underlying connection if necessary. The devices usually always requests to enable
//SSL.
//It returns a StartSessionResponse
func (lockDownConn *LockDownConnection) StartSession(pairRecord PairRecord) (StartSessionResponse, error) {
lockDownConn.Send(newStartSessionRequest(pairRecord.HostID, pairRecord.SystemBUID))
resp, err := lockDownConn.ReadMessage()
if err != nil {
return StartSessionResponse{}, err
}
response := startSessionResponsefromBytes(resp)
lockDownConn.sessionID = response.SessionID
if response.EnableSessionSSL {
err = lockDownConn.deviceConnection.EnableSessionSsl(pairRecord)
if err != nil {
return StartSessionResponse{}, err
}
}
return response, nil
}