...
Replace /path/to/your/keystore.jks
with the actual path to your Java keystore file and your_keystore_password
with your keystore password. Set appropriate permissions on the script file and execute it in a proper environment.
Please note that this script assumes that the keytool
command is available in your environment (usually comes with Java installations). Also, ensure that you have the necessary permissions to access the keystore file.
...
Script saving a SSL certificate from an URL to a local file
Bash | PowerShell |
---|
Code Block |
---|
| #!/bin/bash
# Function to download SSL certificate
download_ssl_certificate() {
local url=$1
local port=${2:-443}
local output_file=${3:-certificate.pem}
# Extract the hostname from the URL
local hostname=$(echo $url | awk -F[/:] '{print $4}')
# Use openssl to get the certificate and save it to a file
echo | openssl s_client -connect ${hostname}:${port} -servername ${hostname} 2>/dev/null | openssl x509 > ${output_file}
echo "Certificate downloaded and saved as ${output_file}"
}
# Example usage
download_ssl_certificate "https://mycompany.sealights.co"
|
| Code Block |
---|
| # Function to download SSL certificate
function Download-SSLCertificate {
param (
[string]$url,
[int]$port = 443,
[string]$outputFile = "certificate.cer"
)
$hostname = ([System.Uri]$url).Host
$tcpClient = New-Object Net.Sockets.TcpClient
$tcpClient.Connect($hostname, $port)
$sslStream = New-Object Net.Security.SslStream($tcpClient.GetStream(), $false, ({$true}))
$sslStream.AuthenticateAsClient($hostname)
$cert = $sslStream.RemoteCertificate
$bytes = $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert)
[System.IO.File]::WriteAllBytes($outputFile, $bytes)
$sslStream.Close()
$tcpClient.Close()
Write-Output "Certificate downloaded and saved as $outputFile"
}
# Example usage
Download-SSLCertificate -url "https://mycompany.sealights.co"
|
|
...