Create local certificate and ssl/tls profile using PANOS SDK in python

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Please sign in to see details of an important advisory in our Customer Advisories area.

Create local certificate and ssl/tls profile using PANOS SDK in python

Hi,

 

Has anyone tried creating a local cert and ssl/tls profile using the SDK?

If yes, could you please point me in the right direction.

 

In the configuration tree, I'm unable to find those objects so wondering if this feature hasn't been released in the yet.

https://pan-os-python.readthedocs.io/en/latest/configtree.html

 

Thanks

4 REPLIES 4

L0 Member

Hey I am trying to create the same solution, Did you find something?

L1 Bithead

hi please i need a way to create ssl/tls service profile either with api or sdk
thanks for your time

 

L0 Member

Hello Community i was able to create an SSL Profile using the api 

 

def create_ssl_profile(base_url,api_key):
FW_Name = hostname[hostname.find('fw'):hostname.find('.transit')]
Profile_Name = '{}-mgmt-ssl-tls-service-profile'.format(FW_Name)
#Create a session
session = requests.session()
params = {
'key': api_key,
'type': 'config',
'action': 'set',
'xpath': "/config/shared/ssl-tls-service-profile/entry[@name='profile_name']",
'element': "<certificate>New Wildcard Cert</certificate><protocol-settings><max-version>max</max-version><min-version>tls1-2</min-version></protocol-settings>"
}
old_string = 'profile_name'
new_string = Profile_Name
modified_xpath = params['xpath'].replace(old_string, new_string)
params['xpath'] = modified_xpath
try:
# Send a set request
response = session.post(base_url, params=params, verify=False)
response.raise_for_status()
except requests.exceptions.RequestException as e:
logging("An error occurred: {e}")
print("An error occurred: {e}")
sys.exit()
print('SSL Profile Created:', Profile_Name)
return Profile_Name

def Configure_SSL_Profile(base_url,api_key,Profile_Name):
#Create a session
session = requests.session()
params = {
'key': api_key,
'type': 'config',
'action': 'set',
'xpath': "/config/devices/entry[@name='localhost.localdomain']/deviceconfig/system",
'element': "<ssl-tls-service-profile>profile_name</ssl-tls-service-profile>"
}
old_string = 'profile_name'
new_string = Profile_Name
modified_xpath = params['element'].replace(old_string, new_string)
params['element'] = modified_xpath
try:
# Send a set request
response = session.post(base_url, params=params, verify=False)
response.raise_for_status()
except requests.exceptions.RequestException as e:
logging("An error occurred: {e}")
print("An error occurred: {e}")
sys.exit()
print('SSL Assingned to Interface:', Profile_Name)

def commit(base_url,api_key):
session = requests.session()
params = {
'key': api_key,
'type': 'commit',
'cmd': "<commit></commit>"
}
try:
# Send a commit request
response = session.get(base_url, params=params, verify=False)
response.raise_for_status()
except requests.exceptions.RequestException as e:
logging("An error occurred: {e}")
print("An error occurred: {e}")
sys.exit()
print('Commit Completed')

Thank you so much for your response 🙂

Please tell me how did you create the
xpath:

'xpath'"/config/shared/ssl-tls-service-profile/entry[@name='profile_name']",
and the element 
'element'"<certificate>New Wildcard Cert</certificate><protocol-settings><max-version>max</max-version><min-version>tls1-2</min-version></protocol-settings>"
is there any criteria to create them

 

  • 1945 Views
  • 4 replies
  • 1 Likes
Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

Click Accept as Solution to acknowledge that the answer to your question has been provided.

The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!

These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!