]>
git.proxmox.com Git - swtpm.git/blob - tests/test_setdatafd.py
70b4c394d351aefe26645c87219e23647c45e2ed
10 from array
import array
11 if sys
.version_info
[0] < 3:
12 import twisted
.python
.sendmsg
as sendmsg
16 return ' '.join('{:02x}'.format(x
) for x
in arr
)
19 def test_ReadPCR10(fd
):
20 send_data
= bytearray(b
"\x00\xC1\x00\x00\x00\x0C\x00\x00\x00\x99\x00\x01")
21 exp_data
= bytearray([0x00, 0xC4, 0x00, 0x00, 0x00, 0x0A,
22 0x00, 0x00, 0x00, 0x26])
25 print("Sending data over ....")
26 n
= fd
.send(send_data
)
27 print("Written %d bytes " % n
)
28 except socket
.error
as e
:
36 if bytearray(buf
) == exp_data
:
39 print("Unexpected reply:\n actual: %s\n expected: %s"
40 % (toString(buf
), toString(exp_data
)))
43 print("Null reply from swtpm")
48 fd
, _fd
= socket
.socketpair(socket
.AF_UNIX
, socket
.SOCK_DGRAM
)
49 sock_path
= os
.getenv('SOCK_PATH')
50 cmd_set_data_fd
= bytearray([0x00, 0x00, 0x00, 0x10])
51 expected_res
= bytearray([0x00, 0x00, 0x00, 0x00])
54 fds
.append(_fd
.fileno())
55 ctrlfd
= socket
.socket(socket
.AF_UNIX
, socket
.SOCK_STREAM
)
56 print("Connecting to server at : %s" % sock_path
)
57 ctrlfd
.connect(sock_path
)
58 print("Sending data fd over ctrl fd...")
59 if sys
.version_info
[0] < 3:
60 sendmsg
.send1msg(ctrlfd
.fileno(), str(cmd_set_data_fd
), 0,
63 struct
.pack("i", _fd
.fileno()))])
65 ctrlfd
.sendmsg([cmd_set_data_fd
],
66 [(socket
.SOL_SOCKET
, socket
.SCM_RIGHTS
, fds
)])
67 except socket
.error
as e
:
68 print("SocketError: " + str(e
))
72 print("Received bytes.. : %s" % buf
)
75 if caps
== expected_res
:
76 return test_ReadPCR10(fd
)
78 print("Unexpected reply for CMD_SET_DATA_FD: \n"
79 " actual: %s\n expected: %s"
80 % (toString(caps
), toString(expected_res
)))
83 print("Null reply from swtpm")
86 if __name__
== "__main__":
88 if not test_SetDatafd():
93 print("__Exception: ", sys
.exc_info())