Version: 1.1.107
libtaxii.clients
Module¶
Classes¶
-
class
libtaxii.clients.
HttpClient
(auth_type=0, auth_credentials=None, use_https=False)[source]¶ -
call_taxii_service2
(host, path, message_binding, post_data, port=None, get_params_dict=None, content_type=None, headers=None)[source]¶ Call a TAXII service.
Note: this uses urllib2 instead of httplib, and therefore returns a different kind of object than
call_taxii_service()
.Returns: urllib2.Response
-
set_auth_credentials
(auth_credentials_dict)[source]¶ Set the authentication credentials used later when making a request.
Note that it is possible to pass in one dict containing credentials for different authentication types and swap between them later.
Parameters: dict (auth_credentials_dict) – The dictionary containing authentication credentials. e.g.: - {‘key_file’: ‘/path/to/key.key’, ‘cert_file’: ‘/path/to/cert.crt’} - {‘username’: ‘abc’, ‘password’: ‘xyz’} - Or both, if both username/password and certificate based auth are used
-
set_auth_type
(auth_type)[source]¶ Set the authentication type for this client.
Parameters: auth_type (string) – Must be one of AUTH_NONE
,AUTH_BASIC
, orAUTH_CERT
-
set_proxy
(proxy_string=None)[source]¶ Set the proxy settings to use when making a connection.
Parameters: proxy_string (string) – Proxy address formatted like http://proxy.example.com:80. Set to SYSTEM_PROXY
to use the system proxy; set toNO_PROXY
to use no proxy.
-
Examples¶
TAXII clients have three types of authentication credentials: None, HTTP Basic, and TLS Certificate. This section demonstrates usage of all three auth types.
All examples assume the following imports:
import libtaxii as t import libtaxii.messages_11 as tm11 import libtaxii.clients as tc from libtaxii.common import generate_message_id from libtaxii.constants import * from dateutil.tz import tzutc
Using No Credentials¶
client = tc.HttpClient()
client.set_auth_type(tc.AUTH_NONE)
client.set_use_https(False)
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)
Using Basic HTTP Auth¶
client = tc.HttpClient()
client.set_use_https(True)
client.set_auth_type(tc.HttpClient.AUTH_BASIC)
client.set_auth_credentials({'username': 'MyUsername', 'password': 'MyPassword'})
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)
Using TLS Certificate Auth¶
client = tc.HttpClient()
client.set_use_https(True)
client.set_auth_type(tc.HttpClient.AUTH_CERT)
client.set_auth_credentials({'key_file': '../PATH_TO_KEY_FILE.key', 'cert_file': '../PATH_TO_CERT_FILE.crt'})
discovery_request = tm11.DiscoveryRequest(generate_message_id())
discovery_xml = discovery_request.to_xml(pretty_print=True)
http_resp = client.call_taxii_service2('taxiitest.mitre.org', '/services/discovery/', VID_TAXII_XML_11, discovery_xml)
taxii_message = t.get_message_from_http_response(http_resp, discovery_request.message_id)
print taxii_message.to_xml(pretty_print=True)