The process of using the westssl tool to automatically update SSL certificates.
Published: 2023-11-02
SSL certificates have a default validity period of either 3 months or 1 year. You must renew and update the certificate within 30 calendar days before the certificate expires in order to extend the certificate's service duration. When renewing the certificate,
a new certificate will be issued. After you receive the new certificate, you need to manually update it on the server. Some certificates support a one-time purchase for multiple years, but a certificate is still issued for one year at a time, and it will be automatically re-issued about 30 days before expiration.
If you manage many certificates, frequent manual updates are not only troublesome but also prone to omissions or errors. Therefore, 西部数码 provides this tool to implement the automatic update process after certificate renewal and re-issuance.
To achieve automatic certificate renewal, the following conditions must be met:
Automated DNS Verification (The SSL certificate and domain are under the same 西部数码 member account. If the domain is a 腾讯 or 阿里 domain, it is supported to complete verification by setting the apikey in our control panel.
If the domain is on a third-party platform, it is recommended to transfer it to us for unified management; otherwise, verification needs to be performed again when the certificate is re-signed.)The certificate can be automatically updated after it is re-issued. (If the certificate is used for 西部数码 virtual hosting/high-defense server/亚数云服务器, after completing certificate renewal and re-issuance,
the system will automatically update the certificate without any operation.When the certificate is used for 西部数码 ordinary cloud servers or third-party server scenarios, automatic updating of the SSL certificate can be achieved through this tool and task scheduling,
To use this tool, your certificate must be applied for with us or hosted with us.)For scenarios that meet the above conditions, select the "Automatic Renewal" function at the time of purchase, and you can get it done once and for all. You need to ensure that the member balance is sufficient.
The Westssl tool has two versions: Windows and Linux. This tool is used for 西部数码 ordinary cloud servers or third-party server scenarios, and can automatically update certificates after certificate re-signing. It also supports calling the API
to purchase new certificates in batches (see the help at the end of the document).
Environment requirements: An SSL certificate must already be deployed on the server, and the web service must be one of IIS/Apache/Nginx.
(The first deployment of a certificate is not covered in this article. Generally, Windows hosts can be deployed through the website Management Assistant provided by us, and Linux hosts are generally deployed through 宝塔面板.)
To use the westssl tool, you need to set the dedicated API key for the SSL certificate. You can set or reset it in "Member Management Center---Account Management---Settings Center---SSL Certificate API Key Settings" .
(Submit a ticket and our company will help you set up westssl automatic update, This API key must be provided in the ticket)

Download method for Linux (CentOS) systems SSH to the remote server, then execute
wget http://downinfo.myhostadmin.net/westssl/westssl.zip -O /root/westssl.zip && unzip -o /root/westssl.zip && rm -f /root/westssl.zip && chmod +x /root/westssl
Enter /root/westssl to use it.
Download method for Windows server systems, remotely connect to the server and use a browser to download http://downinfo.myhostadmin.net/westssl/westssl.exe (If the download prompt says it cannot be downloaded safely, right-click and select "Save link as".) , It is recommended to save it in the d:\cert directory.
Switch to d:\cert in the cmd command line . Enter westssl.exe to use
westssl version number: westssl version 1.0.50
1. After downloading, initialize first (important) After initialization, .westssl\config.ini will be automatically generated; do not delete it
/root/westssl init

For the command to restart/reload the web service, you can select the corresponding number or enter it manually. Please be sure to enter it according to the actual situation!
2. View the current server certificate list /root/westssl show

For web environments created by 宝塔 and 西部数码建站助手, the system will recognize the relevant certificates, so manual addition is not required, and you can ignore this step.
For web environments not created by 宝塔 and 西部数码建站助手, you need to manually add the SSL certificate path to enable automatic SSL certificate updates. Under the show command, enter 1 to add a domain certificate.

3. You can complete automatic certificate updating through scheduled tasks: Certificate update command /root/westssl update
How to set up Linux task scheduling (You must ensure that the server time is the correct Beijing time; otherwise, the update will time out and fail!)
1. In a 宝塔 environment, add a daily scheduled update through the panel's task scheduling.
Script content:
cd /root
/root/westssl update

Save the scheduled task to automatically update the SSL certificate every day.
2. Linux non-宝塔 environment, use the command "crontab -e" to add a scheduled task
30 1 * * * /root/westssl update
The above command means that the automatic SSL certificate update will be executed at 1:30 every day.
It is recommended to add a scheduled task to automatically update the server time in the scheduled tasks.
How to set up Windows task scheduling
Add a scheduled task in Task Scheduler to run this tool periodically.
Run cmd as administrator and execute:

schtasks /create /RU system /SC DAILY /F /TN westssl_auto_update /TR "D:\cert\westssl.exe update -c D:\cert\.westssl\config.ini" /ST 01:00 Where: westssl_auto_update is the scheduled task name "D:\cert\westssl.exe update -c D:\cert\.westssl\config.ini" is the program and parameters to execute /ST 01:00 executes at 1:00 every day
After successfully creating the scheduled task, the SSL certificate will be automatically updated at 1:00 every day.
Note:
api result: token time timeout: please check whether the server time is Beijing time .
1、 Under Windows, westssl update will generate the executable file westcertapp.exe in the subdirectory under .westssl. This is a normal update file and can be used with confidence.
If this file fails to execute, the certificate of the corresponding IIS site will fail to update, which will affect normal website access.
2、The westssl update command will automatically detect the expiration time of all certificates on the current server. If the time until expiration is less than 30 days, or if it has expired within 30 days,
it will automatically call the 西部数码 SSL certificate API interface to check whether a new certificate has been successfully issued for the relevant domain. If so, it will automatically download the new certificate for replacement.
After replacement, it will execute the relevant commands to restart IIS/Apache/ngix so that the new certificate takes effect.
3、If manually importing an SSL certificate through IIS, the certificate store must be selected as Personal; otherwise, westssl cannot recognize it.

-----------------------------------------------------------------------------------------------------------------
Process for using westssl to purchase certificates in batches: (Note: You can enter westssl.exe -h to display help hints; the issue command means applying for a new certificate)
Note: If you need to send your own apikey to a user, allowing the user to update SSL themselves but not wanting the user to have permission to purchase new certificates, please submit a ticket. You can apply to specially disable the permission to purchase certificates through the API for your username.
D:\cert>westssl.exe issue
Missing required parameters!
Apply for certificate
Usage:
westssl issue [flags]
Flags:
-c, --config string Config file (default "config.ini")
--dns SSL certificate DNS verification method [file or dns verification, choose one]
-d, --domain string [Required] Domain name for SSL certificate application; this parameter supports 3 modes:
1) Single domain.
2) Multiple domains, must be separated by commas (,).
3) Batch domain purchase; must be the full path of a domain list file. Put the domains to purchase in this file, one per line.
--file SSL certificate file verification method [file or dns verification, choose one]
-h, --help help for issue
-t, --type string [Required] Common certificate types:
1) General DV: dv-350
2) 90-day trial DV: free-trial
For more product models, please visit the API interface query https://console-docs.apipost.cn/preview/4e5d940c9be19cda/73e3028374812fc5?target_id=9d27cd1e-6bfa-4665-9a8f-e421b7707a1c
D:\cert>westssl.exe issue --dns -t free-trial -d mytest123.com
Or:
D:\cert>westssl.exe issue --dns -t free-trial -d D:\cert\mydomains.txt Put all the domains to purchase in this txt file for batch purchase.
-----------------------------------------------------------------------------------------------------------------
Use westssl to download purchased certificates in batches
D:\cert>westssl.exe online
Online SSL certificate download
Usage:
westssl online [flags]
Flags:
-c, --config string Config file (default "config.ini")
--domain string Download the certificate corresponding to the domain:
1. Multiple domains must be separated by commas (,).
2. all means download all certificates.
3. Full path of the certificate batch download list file. Put the domains of the certificates to download in this file, one per line.
-h, --help help for online
--show View the online certificate list
D:\cert>westssl.exe online --domain mytest123.com
Or:
D:\cert>westssl.exe online --domain D:\cert\mydomains.txt Put all the certificate domains to download in this txt file for batch download.
D:\cert>westssl.exe online --show can view the online certificate list and view verification parameter values
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
