1# Copyright (c) 2017, The MITRE Corporation. All rights reserved.
2# See LICENSE.txt for complete terms.
3
4from mixbox import entities
5from mixbox import fields
6
7import cybox.bindings.http_session_object as http_session_binding
8from cybox.objects.uri_object import URI
9from cybox.objects.address_object import EmailAddress
10from cybox.objects.port_object import Port
11from cybox.common import ObjectProperties, String, DateTime, PositiveInteger, Integer
12
13
14class HTTPRequestLine(entities.Entity):
15    _binding = http_session_binding
16    _binding_class = http_session_binding.HTTPRequestLineType
17    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
18
19    http_method = fields.TypedField("HTTP_Method", String)
20    value = fields.TypedField("Value", String)
21    version = fields.TypedField("Version", String)
22
23
24class HostField(entities.Entity):
25    _binding = http_session_binding
26    _binding_class = http_session_binding.HostFieldType
27    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
28
29    domain_name = fields.TypedField("Domain_Name", URI)
30    port = fields.TypedField("Port", Port)
31
32
33class HTTPRequestHeaderFields(entities.Entity):
34    _binding = http_session_binding
35    _binding_class = http_session_binding.HTTPRequestHeaderFieldsType
36    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
37
38    accept = fields.TypedField("Accept", String)
39    accept_charset = fields.TypedField("Accept_Charset", String)
40    accept_language = fields.TypedField("Accept_Language", String)
41    accept_datetime = fields.TypedField("Accept_Datetime", String)
42    accept_encoding = fields.TypedField("Accept_Encoding", String)
43    authorization = fields.TypedField("Authorization", String)
44    cache_control = fields.TypedField("Cache_Control", String)
45    connection = fields.TypedField("Connection", String)
46    cookie = fields.TypedField("Cookie", String)
47    content_length = fields.TypedField("Content_Length", Integer)
48    content_md5 = fields.TypedField("Content_MD5", String)
49    content_type = fields.TypedField("Content_Type", String)
50    date = fields.TypedField("Date", DateTime)
51    expect = fields.TypedField("Expect", String)
52    from_ = fields.TypedField("From", EmailAddress)
53    host = fields.TypedField("Host", HostField)
54    if_match = fields.TypedField("If_Match", String)
55    if_modified_since = fields.TypedField("If_Modified_Since", DateTime)
56    if_none_match = fields.TypedField("If_None_Match", String)
57    if_range = fields.TypedField("If_Range", String)
58    if_unmodified_since = fields.TypedField("If_Unmodified_Since", DateTime)
59    max_forwards = fields.TypedField("Max_Forwards", Integer)
60    pragma = fields.TypedField("Pragma", String)
61    proxy_authorization = fields.TypedField("Proxy_Authorization", String)
62    range_ = fields.TypedField("Range", String)
63    referer = fields.TypedField("Referer", URI)
64    te = fields.TypedField("TE", String)
65    user_agent = fields.TypedField("User_Agent", String)
66    via = fields.TypedField("Via", String)
67    warning = fields.TypedField("Warning", String)
68    dnt = fields.TypedField("DNT", String)
69    x_requested_with = fields.TypedField("X_Requested_With", String)
70    x_forwarded_for = fields.TypedField("X_Forwarded_For", String)
71    x_forwarded_proto = fields.TypedField("X_Forwarded_Proto", String)
72    x_att_deviceid = fields.TypedField("X_ATT_DeviceId", String)
73    x_wap_profile = fields.TypedField("X_Wap_Profile", URI)
74
75
76class HTTPRequestHeader(entities.Entity):
77    _binding = http_session_binding
78    _binding_class = http_session_binding.HTTPRequestHeaderType
79    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
80
81    raw_header = fields.TypedField("Raw_Header", String)
82    parsed_header = fields.TypedField("Parsed_Header", HTTPRequestHeaderFields)
83
84
85class HTTPMessage(entities.Entity):
86    _binding = http_session_binding
87    _binding_class = http_session_binding.HTTPMessageType
88    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
89
90    length = fields.TypedField("Length", PositiveInteger)
91    message_body = fields.TypedField("Message_Body", String)
92
93
94class HTTPClientRequest(entities.Entity):
95    _binding = http_session_binding
96    _binding_class = http_session_binding.HTTPClientRequestType
97    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
98
99    http_request_line = fields.TypedField("HTTP_Request_Line", HTTPRequestLine)
100    http_request_header = fields.TypedField("HTTP_Request_Header", HTTPRequestHeader)
101    http_message_body = fields.TypedField("HTTP_Message_Body", HTTPMessage)
102
103
104class HTTPStatusLine(entities.Entity):
105    _binding = http_session_binding
106    _binding_class = http_session_binding.HTTPStatusLineType
107    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
108
109    version = fields.TypedField("Version", String)
110    status_code = fields.TypedField("Status_Code", PositiveInteger)
111    reason_phrase = fields.TypedField("Reason_Phrase", String)
112
113
114class HTTPResponseHeaderFields(entities.Entity):
115    _binding = http_session_binding
116    _binding_class = http_session_binding.HTTPResponseHeaderFieldsType
117    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
118
119    access_control_allow_origin = fields.TypedField("Access_Control_Allow_Origin", String)
120    accept_ranges = fields.TypedField("Accept_Ranges", String)
121    age = fields.TypedField("Age", Integer)
122    cache_control = fields.TypedField("Cache_Control", String)
123    connection = fields.TypedField("Connection", String)
124    content_encoding = fields.TypedField("Content_Encoding", String)
125    content_language = fields.TypedField("Content_Language", String)
126    content_length = fields.TypedField("Content_Length", Integer)
127    content_location = fields.TypedField("Content_Location", String)
128    content_md5 = fields.TypedField("Content_MD5", String)
129    content_disposition = fields.TypedField("Content_Disposition", String)
130    content_range = fields.TypedField("Content_Range", String)
131    content_type = fields.TypedField("Content_Type", String)
132    date = fields.TypedField("Date", DateTime)
133    etag = fields.TypedField("ETag", String)
134    expires = fields.TypedField("Expires", DateTime)
135    last_modified = fields.TypedField("Last_Modified", DateTime)
136    link = fields.TypedField("Link", String)
137    location = fields.TypedField("Location", URI)
138    p3p = fields.TypedField("P3P", String)
139    pragma = fields.TypedField("Pragma", String)
140    proxy_authenticate = fields.TypedField("Proxy_Authenticate", String)
141    refresh = fields.TypedField("Refresh", String)
142    retry_after = fields.TypedField("Retry_After", Integer)
143    server = fields.TypedField("Server", String)
144    set_cookie = fields.TypedField("Set_Cookie", String)
145    strict_transport_security = fields.TypedField("Strict_Transport_Security", String)
146    trailer = fields.TypedField("Trailer", String)
147    transfer_encoding = fields.TypedField("Transfer_Encoding", String)
148    vary = fields.TypedField("Vary", String)
149    via = fields.TypedField("Via", String)
150    warning = fields.TypedField("Warning", String)
151    www_authenticate = fields.TypedField("WWW_Authenticate", String)
152    x_frame_options = fields.TypedField("X_Frame_Options", String)
153    x_xss_protection = fields.TypedField("X_XSS_Protection", String)
154    x_content_type_options = fields.TypedField("X_Content_Type_Options", String)
155    x_powered_by = fields.TypedField("X_Powered_By", String)
156    x_ua_compatible = fields.TypedField("X_UA_Compatible", String)
157
158
159class HTTPResponseHeader(entities.Entity):
160    _binding = http_session_binding
161    _binding_class = http_session_binding.HTTPResponseHeaderType
162    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
163
164    raw_header = fields.TypedField("Raw_Header", String)
165    parsed_header = fields.TypedField("Parsed_Header", HTTPResponseHeaderFields)
166
167
168class HTTPServerResponse(entities.Entity):
169    _binding = http_session_binding
170    _binding_class = http_session_binding.HTTPServerResponseType
171    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
172
173    http_status_line = fields.TypedField("HTTP_Status_Line", HTTPStatusLine)
174    http_response_header = fields.TypedField("HTTP_Response_Header", HTTPResponseHeader)
175    http_message_body = fields.TypedField("HTTP_Message_Body", HTTPMessage)
176
177
178class HTTPRequestResponse(entities.Entity):
179    _binding = http_session_binding
180    _binding_class = http_session_binding.HTTPRequestResponseType
181    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
182
183    ordinal_position = fields.TypedField("ordinal_position")
184    http_client_request = fields.TypedField("HTTP_Client_Request", HTTPClientRequest)
185    http_provisional_server_response = fields.TypedField("HTTP_Provisional_Server_Response", HTTPServerResponse)
186    http_server_response = fields.TypedField("HTTP_Server_Response", HTTPServerResponse)
187
188
189class HTTPSession(ObjectProperties):
190    _binding = http_session_binding
191    _binding_class = http_session_binding.HTTPSessionObjectType
192    _namespace = "http://cybox.mitre.org/objects#HTTPSessionObject-2"
193    _XSI_NS = "HTTPSessionObj"
194    _XSI_TYPE = "HTTPSessionObjectType"
195
196    http_request_response = fields.TypedField("HTTP_Request_Response", HTTPRequestResponse, multiple=True)
197