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 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 the authentication type for this client.
Parameters: | auth_type (string) – Must be one of AUTH_NONE, AUTH_BASIC, or AUTH_CERT |
---|
Set the proxy settings to use when making a connection.
Parameters: |
|
---|
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
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)
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)
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)