Skip to main content

スクリプトタイプ

DigiCert​​®​​ Trust Lifecycle Manager は、サーバーでのエージェントベースの証明書ライフサイクル管理をカスタマイズするために、以下のスクリプトタイプをサポートしています。各スクリプトタイプの詳細については、それぞれのリンクを選択してください。

スクリプトタイプ

説明

SNI 情報

DigiCert エージェントが使用する SNI ドメインの情報を動的に取得し、証明書を検出および管理する

インストール前

自動化イベント中、Web サーバーアプリケーション用の証明書のインストールに、追加作業を実行する

インストール後

自動化イベント中、Web サーバーアプリケーション用の証明書のインストールに、追加作業を実行する

配信後の管理者要求

証明書をサーバーシステムに配信した後、Admin web request 登録方法を使用して追加作業を実行する

Custom automation

カスタムサーバーアプリケーション用の証明書を管理する

重要

カスタムエージェントスクリプトでは、ホストオペレーティングシステムに基づき、以下のいずれかの言語を使用します。

  • Windows: bat、cmd、または PowerShell スクリプト

  • Linux: シェルスクリプト(任意)

作業を実行するために別の言語/形式を使用する場合は、上記のいずれかのスクリプト言語をラッパーとして使用して互換性を確保します。

Trust Lifecycle Manager では、SNI(サーバー名表示)を使用して Web サイト上の証明書を検出および自動化するために、管理者がアクティブなドメインのリストを提供する必要があります。SNI 情報スクリプトを使用して、サーバー上の SNI FQDN(完全修飾ドメイン名)の情報を動的に取得できるため、SNI FQDN を手動で設定する必要はありません。

たとえば、DigiCert エージェントが常に最新情報を得られるようにするために、Web サーバー構成から直接 SNI FQDN を読み取る方法があります。

To simplify management, Trust Lifecycle Manager allows you to assign the scripts across multiple agents in bulk.

スクリプト出力形式

SNI FQDN 情報を JSON として次の形式で出力する SNI スクリプトをセットアップします。

1. SNI 情報スクリプトの JSON 出力形式
[
   {
        "IP": "10.1.2.3",
        "Port": "8443",
        "Domain": "www.example.com"
    },
    {
        "IP": "10.1.2.3",
        "Port": "8443",
        "Domain": "app2.example.com"
    }
]

スクリプトの例(PowerShell)

次の SNI 情報スクリプトの例は、Microsoft PowerShell スクリプト言語を使用して、ローカル IIS Web サーバーから最新の SNI 情報を読み取ります。このスクリプトは、ローカルの DigiCert エージェントを動的に構成するために使用される情報を JSON 形式で出力します。

2. IIS Web サーバーアプリケーション用の SNI 情報スクリプト(PowerShell)
$bindingInfo = get-website | select -ExpandProperty Bindings | Select -ExpandProperty Collection | where sslFlags -eq 1 | select bindingInformation

$res = @{}

foreach($ele in $bindingInfo) {
        $list = $ele.bindingInformation.split(":")
        $res[$list[2]] = @{IP=$list[0]; Port=$list[1]; Domain=$list[2]}
}

$thumbs = Get-ChildItem IIS:SSLBindings | Foreach-Object {
        [PSCustomObject]@{
                Host       = $_.Host
                Thumbprint = $_.Thumbprint
        }
}

echo($res.values | ConvertTo-Json)

インストール前/後スクリプトは、自動化イベントの前(インストール前)、または自動化イベントでローカルの DigiCert エージェントが証明書をインストールした後で(インストール後)、追加作業を実行するために使用します。

このタイプのスクリプトでは、サーバーで PKI オペレーションを容易にするために必要な、レディネステスト、準備、クリーンアップなど、あらゆるタイプの作業を実行できます。Web サーバーアプリケーションごとに、さまざまなインストール前/後スクリプトを使用できます。

管理を簡素化するために、Trust Lifecycle Manager では、スクリプトを複数のエージェントに一括で割り当てることができます。

戻りコード

インストール前スクリプトが成功した場合は 0 を返し、失敗した場合は 0 以外の値を返します。戻りコード 1127、または 4294770688 の使用は避けてください。これらは他の目的のためにエージェントによって事前定義されています。

インストール前スクリプトを使用すると、DigiCert エージェントは、スクリプトから成功コード 0 が返されなければ、自動化イベントをキャンセルします。これは、証明書が外部入力に基づいて自動化されるタイミングを制御するのに役立ちます。

Use this script type to perform extra work after delivering a certificate from Trust Lifecycle Manager to an external server system using the admin web request enrollment method.

When you assign the post-delivery script to an agent-based certificate automation event, you can enter up to five parameters to pass to the target host to control how the script gets executed there.

注記

Custom post-delivery scripts for agents enable you to deploy certificates for custom applications. DigiCert provides the following GitHub repository with production-ready reference scripts for integrating different vendors and platforms:

https://github.com/digicert/product-solutions

Script execution data

During a certificate delivery event, the local DigiCert agent adds script-related data to the DC1_POST_SCRIPT_DATA environment variable in Base64-encoded JSON format. Target and decode this variable in your post-delivery scripts to get the list of parameters passed from Trust Lifecycle Manager and other relevant details to help process the delivered certificate, as in the following examples:

  • Example of decoded DC1_POST_SCRIPT_DATA environment variable value after delivering a PKCS#12 certificate (.pfx file extension) on a Windows system:

    {"args":["abc", "def"],"certfolder":"C:\Program Files\DigiCert\TLM Agent\.secrets","files":["my-cert-1.pfx"], "password":"P@ssw0rd"}
  • Example of decoded DC1_POST_SCRIPT_DATA environment variable value after delivering an X.509 certificate (.crt file extension) on a Linux system:

    {"args":["abc","def","ghi"],"certfolder":"/opt/tlm_agent/.secrets","files":["my-cert-1.crt","my-cert-1.key"]}

JSON fields in the output depend on the type of certificate delivered and may include:

JSON field

Description

Certificate types

args

List of up to five extra parameters passed to the script from Trust Lifecycle Manager.

All

certfolder

Directory path where the certificate was delivered.

All

files

Names of the certificate files delivered to the above directory.

All

password

The password used to encrypt the certificate file.

PKCS#12 (PFX), PEM, P7B

keystorepassword

Password for the keystore where the certificate was delivered.

JKS

truststorepassword

Password for the truststore where the certificate was delivered.

JKS

Example script (PowerShell)

The following example post-delivery script uses the Microsoft PowerShell scripting language to import a delivered PKCS#12 (PFX) certificate to the LocalMachine\My certificate store on a Windows system. The script decodes and parses the JSON in the DC1_POST_SCRIPT_DATA environment variable to determine the certificate filename, password, and directory where it was delivered by the local DigiCert agent.

# Function to decode base64 encoded string
function Decode-Base64 {
    param (
        [string]$base64String
    )
    $bytes = [System.Convert]::FromBase64String($base64String)
    $decodedString = [System.Text.Encoding]::UTF8.GetString($bytes)
    return $decodedString
}

# Base64 encoded JSON input
$base64Json = [System.Environment]::GetEnvironmentVariable("DC1_POST_SCRIPT_DATA")

# Decode the base64 encoded JSON
$jsonString = Decode-Base64 -base64String $base64Json

# Convert JSON string to PowerShell object
$jsonObject = $jsonString | ConvertFrom-Json

Write-Host "Arguments : "$jsonObject.args

# Extract values from JSON object
$certFolder = $jsonObject.certfolder
$pfxFile = Join-Path -Path $certFolder -ChildPath $jsonObject.files[0]
$password = $jsonObject.password

# Validate inputs
if (-not (Test-Path -Path $pfxFile)) {
    Write-Error "ERROR: The PFX file does not exist."
    exit 1
}

# Import the PFX file into the LocalMachine\My store
try {
    $cert = Import-PfxCertificate -FilePath $pfxFile -CertStoreLocation Cert:\LocalMachine\My -Password (ConvertTo-SecureString -String $password -Force -AsPlainText)
    if ($null -eq $cert) {
        throw "Failed to import the certificate."
    }
    Write-Output "Certificate imported successfully."
} catch {
    Write-Error "ERROR: Failed to import the certificate. $_"
    exit 1
}

Example script (Bash shell)

The following example post-delivery script uses the Bash shell scripting language to import a delivered X.509 (CRT) certificate to the /etc/pki/ca-trust/source/anchors trusted CA directory on a Red Hat-based Linux system that has the ca-certificates package installed. The script decodes and parses the JSON in the DC1_POST_SCRIPT_DATA environment variable to determine the certificate filename and directory where it was delivered by the local DigiCert agent.

#!/bin/bash

# Step 1: Read the Base64-encoded JSON string from the environment variable
CERT_INFO=${DC1_POST_SCRIPT_DATA}

if [[ -z "$CERT_INFO" ]]; then
    echo "Error: Environment variable 'DC1_POST_SCRIPT_DATA' is not set or is empty."
    exit 1
fi

# Step 2: Decode the Base64 string into JSON
JSON_STRING=$(echo "$CERT_INFO" | base64 -d)

# Step 3: Parse JSON manually to extract 'certfolder' and '.crt' file
CERT_FOLDER=$(echo "$JSON_STRING" | grep -oP '"certfolder":"\K[^"]+')
CRT_FILE=$(echo "$JSON_STRING" | grep -oP '"files":\["\K[^"]+\.crt')

if [[ -z "$CERT_FOLDER" || -z "$CRT_FILE" ]]; then
    echo "Error: Invalid JSON data. Could not find 'certfolder' or '.crt' file."
    exit 1
fi

# Step 4: Construct full path to the certificate file
CRT_FILE_PATH="${CERT_FOLDER}/${CRT_FILE}"

if [[ ! -f "$CRT_FILE_PATH" ]]; then
    echo "Error: Certificate file not found at path '$CRT_FILE_PATH'."
    exit 1
fi

# Step 5: Copy the certificate to the system's trusted CA directory
TRUSTED_CA_DIR="/etc/pki/ca-trust/source/anchors"
DEST_CRT_FILE="${TRUSTED_CA_DIR}/$(basename "$CRT_FILE")"

echo "Copying certificate to trusted CA directory..."
sudo cp "$CRT_FILE_PATH" "$DEST_CRT_FILE"

# Step 6: Update the system's trusted certificates
echo "Updating trusted certificates..."
sudo update-ca-trust extract

if [[ $? -eq 0 ]]; then
    echo "Certificate successfully added to the system's trusted certificates."
else
    echo "Error: Failed to update the trusted certificates."
    exit 1
fi

Verify or troubleshoot script execution

Use either of the following methods to verify execution of an agent post-delivery script and see any error details for it: