Loading...
Loading...
Guides the creation of self-signed SSL/TLS certificates using OpenSSL, including key generation, certificate creation, combined PEM files, and verification scripts. This skill should be used when tasks involve generating self-signed certificates, creating SSL certificate infrastructure, or writing certificate verification scripts.
npx skill4agent add letta-ai/skills openssl-selfsigned-certmkdir -p /path/to/certsopenssl genrsa -out /path/to/certs/server.key 2048openssl req -new -x509 -key /path/to/certs/server.key -out /path/to/certs/server.crt -days 365 -subj "/CN=localhost"-subj/CN=/O=/OU=/C=/ST=/L=cat /path/to/certs/server.key /path/to/certs/server.crt > /path/to/certs/combined.pem# Verify certificate
openssl x509 -in /path/to/certs/server.crt -text -noout
# Verify key
openssl rsa -in /path/to/certs/server.key -check -noout
# Verify key matches certificate (modulus should match)
openssl x509 -noout -modulus -in /path/to/certs/server.crt | openssl md5
openssl rsa -noout -modulus -in /path/to/certs/server.key | openssl md5cryptographysubprocessimport subprocess
def verify_certificate(cert_path):
"""Verify certificate using OpenSSL subprocess calls."""
result = subprocess.run(
["openssl", "x509", "-in", cert_path, "-text", "-noout"],
capture_output=True,
text=True
)
return result.returncode == 0, result.stdoutsslimport ssl
def load_certificate(cert_path):
"""Load and parse certificate using ssl module."""
context = ssl.create_default_context()
context.load_cert_chain(certfile=cert_path)
return Truepip install cryptography # Not: uv add, pip install in venvpython /path/to/script.pyuv run python#!/usr/bin/env python3
"""Certificate verification script using only standard library."""
import subprocess
import sys
import os
def verify_certificate(cert_path):
"""Verify a certificate file exists and is valid."""
if not os.path.exists(cert_path):
return False, f"Certificate file not found: {cert_path}"
result = subprocess.run(
["openssl", "x509", "-in", cert_path, "-text", "-noout"],
capture_output=True,
text=True
)
if result.returncode != 0:
return False, f"Invalid certificate: {result.stderr}"
return True, result.stdout
def verify_key(key_path):
"""Verify a private key file exists and is valid."""
if not os.path.exists(key_path):
return False, f"Key file not found: {key_path}"
result = subprocess.run(
["openssl", "rsa", "-in", key_path, "-check", "-noout"],
capture_output=True,
text=True
)
if result.returncode != 0:
return False, f"Invalid key: {result.stderr}"
return True, "Key is valid"
def verify_key_cert_match(key_path, cert_path):
"""Verify that a key and certificate match."""
key_modulus = subprocess.run(
["openssl", "rsa", "-noout", "-modulus", "-in", key_path],
capture_output=True,
text=True
)
cert_modulus = subprocess.run(
["openssl", "x509", "-noout", "-modulus", "-in", cert_path],
capture_output=True,
text=True
)
if key_modulus.stdout == cert_modulus.stdout:
return True, "Key and certificate match"
return False, "Key and certificate do not match"
if __name__ == "__main__":
# Example usage - adjust paths as needed
cert_path = "/path/to/server.crt"
key_path = "/path/to/server.key"
success, msg = verify_certificate(cert_path)
print(f"Certificate: {'PASS' if success else 'FAIL'} - {msg[:100] if success else msg}")
success, msg = verify_key(key_path)
print(f"Key: {'PASS' if success else 'FAIL'} - {msg}")
success, msg = verify_key_cert_match(key_path, cert_path)
print(f"Match: {'PASS' if success else 'FAIL'} - {msg}")pip installuv addpip installcat /path/to/file # Verify contents
wc -l /path/to/file # Verify line countuv run python script.pypython script.pypython /app/script.pyimport shutil
if not shutil.which("openssl"):
sys.exit("Error: OpenSSL not found in PATH")openssl x509 -in cert.crt -text -nooutopenssl rsa -in key.key -check -noout