freespace-freemind / HTTPS_CERTIFICATE_GUIDE.md
SmartySmile's picture
Upload 45 files
0e0fe0a verified
|
Raw History Blame Contribute Delete
6.67 kB

HTTPS Certificate Management Configuration Guide

Overview

This application now includes enterprise-grade HTTPS certificate management with automatic renewal capabilities. The system can:

  • ✅ Automatically create self-signed certificates for development
  • ✅ Validate certificates on startup
  • ✅ Automatically renew certificates before expiration
  • ✅ Backup old certificates before renewal
  • ✅ Expose certificate status via API endpoints
  • ✅ Support custom certificate paths for production environments
  • ✅ Provide detailed logging for certificate operations

Configuration

The HTTPS certificate settings are configured in appsettings.json:

{
  "HttpSettings": {
    "HttpPort": 5293,
    "HttpsPort": 7145
  },
  "HttpsCertificate": {
    "Enabled": true,
    "CertificatePath": "Data/certificates",
    "CertificateFileName": "port-watcher-cert",
    "CertificateFormat": "pfx",
    "SubjectName": "CN=localhost",
    "ValidityDays": 365,
    "AutoRenewThresholdDays": 30,
    "CheckIntervalHours": 24,
    "UseProductionCert": false,
    "ProductionCertPath": "",
    "EnableAutoRenewal": true
  }
}

Configuration Options

Option Default Description
Enabled true Enable/disable certificate management
CertificatePath Data/certificates Relative path where certificates are stored
CertificateFileName port-watcher-cert Name of the certificate file (without extension)
CertificateFormat pfx Certificate format (pfx/pem/cer)
SubjectName CN=localhost Certificate subject name
ValidityDays 365 Validity period for new certificates
AutoRenewThresholdDays 30 Days before expiration to trigger renewal
CheckIntervalHours 24 Interval for automatic renewal checks
UseProductionCert false Use production certificate instead of self-signed
ProductionCertPath "" Path to production certificate file
EnableAutoRenewal true Enable automatic certificate renewal

Development Environment

For development (appsettings.Development.json):

{
  "HttpsCertificate": {
    "UseProductionCert": false,
    "EnableAutoRenewal": false,
    "SubjectName": "CN=localhost"
  }
}

Production Environment

For production, you have two options:

Option 1: Use Self-Signed Certificates with Auto-Renewal

{
  "HttpsCertificate": {
    "Enabled": true,
    "EnableAutoRenewal": true,
    "SubjectName": "CN=yourdomain.com",
    "AutoRenewThresholdDays": 30,
    "CheckIntervalHours": 24
  }
}

Option 2: Use Production Certificate (e.g., Let's Encrypt)

{
  "HttpsCertificate": {
    "UseProductionCert": true,
    "ProductionCertPath": "C:\\path\\to\\your\\certificate.pfx",
    "EnableAutoRenewal": false
  }
}

API Endpoints

The application exposes certificate diagnostics via REST API:

Get Certificate Status

GET /api/certificatediagnostics/status

Response:

{
  "success": true,
  "data": {
    "subjectName": "CN=localhost",
    "issuedDate": "2026-03-03",
    "expirationDate": "2027-03-03",
    "daysUntilExpiration": 365,
    "isExpired": false,
    "needsRenewal": false,
    "thumbprint": "ABC123..."
  }
}

Validate and Auto-Renew

POST /api/certificatediagnostics/validate

Manual Certificate Renewal

POST /api/certificatediagnostics/renew

Automatic Renewal Process

  1. Startup Check: Certificate is validated when the application starts
  2. Background Task: Certificate is checked every 24 hours (configurable)
  3. Renewal Trigger: If certificate expires within the threshold (30 days), renewal is triggered
  4. Backup: Old certificate is backed up with timestamp before renewal
  5. Logging: All operations are logged for audit trail

Certificate Files Location

Certificates are stored in: Data/certificates/port-watcher-cert.pfx

Backup certificates use the naming convention: port-watcher-cert.pfx.backup-20260303-120000

Monitoring Certificate Status

Monitor the application logs for certificate-related messages:

[INF] HTTPS certificate found at Data/certificates/port-watcher-cert.pfx
[INF] Certificate Info: Subject=CN=localhost, Issued=2026-03-03, Expires=2027-03-03, DaysRemaining=365, Thumbprint=ABC123...
[INF] Running automatic certificate validation check...
[WRN] HTTPS certificate expires in 25 days. Auto-renewal will be triggered.
[INF] HTTPS certificate renewed successfully.

Troubleshooting

HTTPS Port Not Determined Error

The warning "Failed to determine the https port for redirect" should now be fixed by:

  • Explicit Kestrel configuration in Program.cs
  • Proper port settings in appsettings.json
  • Enhanced HSTS configuration

Certificate Not Found

  • Check that Data/certificates/ directory exists or will be created on startup
  • Verify write permissions for the application process
  • Check logs for detailed error messages

Cannot Load Certificate

  • Ensure certificate file is valid PFX format
  • Check file permissions
  • Verify certificate hasn't been corrupted

Auto-Renewal Not Triggering

  • Verify EnableAutoRenewal is set to true
  • Check AutoRenewThresholdDays value (default: 30 days)
  • Check application logs for renewal task status
  • Manually trigger renewal via API: POST /api/certificatediagnostics/renew

Security Considerations

  1. Certificate Storage: Keep certificate files in a secure location with restricted access
  2. Backup Strategy: Automatic backups are created during renewal - maintain offline backups for production
  3. Key Protection: Private keys are stored in PFX format - ensure the process has correct permissions
  4. Logging: Certificate operations are logged - review logs regularly for anomalies
  5. Production Certs: Use proper SSL certificates from trusted CAs in production environments

Integration with eSecSys/nCONNECT OS

For integration with enterprise certificate management systems:

  1. Set UseProductionCert to true
  2. Point ProductionCertPath to the provisioned certificate location
  3. Configure your certificate management system to update this path
  4. Set EnableAutoRenewal to false to allow external management

The API endpoints can be called by your enterprise certificate management system to validate certificate status and trigger renewals when needed.


Last Updated: March 3, 2026