<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Is it possible to use TLS client certs to connect to Splunk REST API? in Splunk Dev</title>
    <link>https://community.splunk.com/t5/Splunk-Dev/Is-it-possible-to-use-TLS-client-certs-to-connect-to-Splunk-REST/m-p/446302#M8091</link>
    <description>&lt;P&gt;I need to use TLS client certs to connect to Splunk REST API.&lt;/P&gt;
&lt;P&gt;It seems this is not possible out of the box with client.connet() as per the docs here: &lt;CODE&gt;docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/client.html#splunklib.client.connect&lt;/CODE&gt; - there is no cert/key param.&lt;/P&gt;
&lt;P&gt;Is it somehow possible to use TLS client certs with the Splunk Python SDK ?&lt;/P&gt;</description>
    <pubDate>Wed, 17 Jun 2020 22:40:16 GMT</pubDate>
    <dc:creator>vinzentalves</dc:creator>
    <dc:date>2020-06-17T22:40:16Z</dc:date>
    <item>
      <title>Is it possible to use TLS client certs to connect to Splunk REST API?</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-it-possible-to-use-TLS-client-certs-to-connect-to-Splunk-REST/m-p/446302#M8091</link>
      <description>&lt;P&gt;I need to use TLS client certs to connect to Splunk REST API.&lt;/P&gt;
&lt;P&gt;It seems this is not possible out of the box with client.connet() as per the docs here: &lt;CODE&gt;docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/client.html#splunklib.client.connect&lt;/CODE&gt; - there is no cert/key param.&lt;/P&gt;
&lt;P&gt;Is it somehow possible to use TLS client certs with the Splunk Python SDK ?&lt;/P&gt;</description>
      <pubDate>Wed, 17 Jun 2020 22:40:16 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-it-possible-to-use-TLS-client-certs-to-connect-to-Splunk-REST/m-p/446302#M8091</guid>
      <dc:creator>vinzentalves</dc:creator>
      <dc:date>2020-06-17T22:40:16Z</dc:date>
    </item>
    <item>
      <title>Re: TLS client certs and the Splunk Python SDK</title>
      <link>https://community.splunk.com/t5/Splunk-Dev/Is-it-possible-to-use-TLS-client-certs-to-connect-to-Splunk-REST/m-p/446303#M8092</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;

&lt;P&gt;You can achieve this using &lt;CODE&gt;splunklib.six&lt;/CODE&gt; module. Below is sample script which connects to splunk server and retrieve &lt;CODE&gt;sessionKey&lt;/CODE&gt;  and then you can use that &lt;CODE&gt;session_key&lt;/CODE&gt; to do other work in same script.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;import sys
sys.path.append('splunk-sdk-python-1.6.5')
import splunklib.six as six
import urllib
from xml.etree import ElementTree
import getpass

HOST = raw_input("Enter splunk server hostname/ip: ")
PORT = 8089

splunkUser = raw_input("Enter Splunk Username: ")
splunkPassword = getpass.getpass("Enter Password: ")

connection = six.moves.http_client.HTTPSConnection(HOST, PORT)
body = urllib.urlencode({'username': splunkUser, 'password': splunkPassword})
headers = {'Content-Type': "application/x-www-form-urlencoded",
           'Host': HOST
          }

connection.request("POST", "/services/auth/login", body, headers)
response = connection.getresponse()
content = response.read()
connection.close()

session_key = ElementTree.XML(content).findtext("./sessionKey")
&lt;/CODE&gt;&lt;/PRE&gt;

&lt;P&gt;As per my knowledge (I am not at advanced level of python) in above script &lt;CODE&gt;six.moves.http_client.HTTPSConnection&lt;/CODE&gt; is using &lt;CODE&gt;httplib&lt;/CODE&gt; module which has &lt;CODE&gt;key_file&lt;/CODE&gt; and &lt;CODE&gt;cert_file&lt;/CODE&gt; parameter so you can use those parameter for TLS connections.&lt;/P&gt;

&lt;PRE&gt;&lt;CODE&gt;Help on class HTTPSConnection in splunklib.six.moves.http_client:

splunklib.six.moves.http_client.HTTPSConnection = class HTTPSConnection(HTTPConnection)
 |  This class allows communication via SSL.
 |
 |  Methods defined here:
 |
 |  __init__(self, host, port=None, key_file=None, cert_file=None, strict=None, timeout=&amp;lt;object object&amp;gt;, source_address=None, context=None, check_hostname=None)
 |
 |  connect(self)
 |      Connect to a host on a given (SSL) port.
 |
&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Aug 2019 14:02:53 GMT</pubDate>
      <guid>https://community.splunk.com/t5/Splunk-Dev/Is-it-possible-to-use-TLS-client-certs-to-connect-to-Splunk-REST/m-p/446303#M8092</guid>
      <dc:creator>harsmarvania57</dc:creator>
      <dc:date>2019-08-16T14:02:53Z</dc:date>
    </item>
  </channel>
</rss>

