HOW TO

Import certificates to ArcGIS Server and Portal for ArcGIS using Python

Last Published: May 23, 2023

Summary

A server certificate is a digital file containing information about the identity of the web server and is used to authenticate the server's identity to the client. Instead of importing server certificates through the REST endpoints of the Portal Administrator Directory and the ArcGIS Server Administrator Directory, the Python scripts provided in this article can also be used to import existing certificates to Portal for ArcGIS and ArcGIS Server.

Procedure

Depending on the product, use one of the Python scripts below to import existing server certificates.

Portal for ArcGIS

  1. Import the necessary modules.
import arcgis
  1. Specify the credentials and define the ssl parameter.
gis = arcgis.GIS("https://hostname.domain.com/portal","<username>","<password>")

ssl = gis.admin.security.ssl
  1. Import the certificate and update the necessary properties.
ssl.import_server_certificate("<certificateAlias>", "<privatekey>",
r"<filepath>.pfx")

ssl.update("<certificateAlias>", ssl.properties["<sslProtocols>"], ssl.properties["<cipherSuites>"])

The Python script below is the full sample script to import an existing server certificate to Portal for ArcGIS and update the web server certificate alias.

import arcgis

gis = arcgis.GIS("https://testserver.esri.com/portal","adminuser","adminpassword")

ssl = gis.admin.security.ssl

ssl.import_server_certificate("TestCert", "cer46s5ae1fr98r",
r"C:\Users\USER\Desktop\Cert\Cert.pfx")

ssl.update("TestCert", ssl.properties["TLSv1.2"], ssl.properties["TLS_RSA_WITH_AES_128_CBC_SHA"])

ArcGIS Server

  1. Import the necessary modules.
from arcgis.gis import GIS
from arcgis.gis.server import Server
  1. Specify the credentials and define the hosting server URL.
gis = GIS(url="https://hostname.domain.com/portal", username="<username>", password="<password>")

urlHosting = "https://hostaname.domain.com/server"
hostingServer = Server(url=urlHosting, gis=gis)
  1. Define the path for the certificate.
cert= r"<filepath>.pfx"
  1. Import the certificates.
for machine in hostingServer.machines.list():
    machine.import_existing_server_certificate("<cerificateAlias>","<privatekey>", cert)

The Python script below is the full sample script to import an existing server certificate to ArcGIS Server. Unlike Portal for ArcGIS, there is no documented way to update the ArcGIS Server web server certificate alias using ArcGIS API for Python.

from arcgis.gis import GIS
from arcgis.gis.server import Server

gis = GIS(url="https://testserver.esri.com/portal", username="adminuser", password="adminpassword")

urlHosting = "https://testserver.esri.com/server"

hostingServer = Server(url=urlHosting, gis=gis)

cert= r"C:\Users\USER\Desktop\Cert\Cert.pfx"

for machine in hostingServer.machines.list():
    machine.import_existing_server_certificate("TestCert","cer46s5ae1fr98r", cert)

Article ID: 000029033

Software:
  • Portal for ArcGIS
  • ArcGIS Server
  • ArcGIS Enterprise 10 8 x
  • ArcGIS Enterprise 10 9 x
  • ArcGIS Enterprise 11 0
  • ArcGIS Enterprise 11 1

Receive notifications and find solutions for new or common issues

Get summarized answers and video solutions from our new AI chatbot.

Download the Esri Support App

Related Information

Discover more on this topic

Get help from ArcGIS experts

Contact technical support

Download the Esri Support App

Go to download options