|
Download README_HTTPS.md from SmartySmile/freespace-freemind: direct link, hf CLI and curl.
- Browser
- Download file 8.29 kB
-
https://huggingface.co/datasets/SmartySmile/freespace-freemind/resolve/main/README_HTTPS.md
- Command line
-
hf download hf://datasets/SmartySmile/freespace-freemind/README_HTTPS.md
-
curl -L -o README_HTTPS.md https://huggingface.co/datasets/SmartySmile/freespace-freemind/resolve/main/README_HTTPS.md
8.29 kB
PortWatcher HTTPS Certificate Management - Complete Solution
🎯 Problem Solved
Fixed the warning:
warn: Microsoft.AspNetCore.HttpsPolicy.HttpsRedirectionMiddleware[3]
Failed to determine the https port for redirect.
✨ What's New
Enterprise-Grade HTTPS Management
- ✅ Automatic HTTPS port configuration
- ✅ Self-signed certificate generation
- ✅ Automatic certificate renewal before expiration
- ✅ Certificate backup & restore
- ✅ REST API for certificate diagnostics
- ✅ Background validation every 24 hours
- ✅ Production certificate support
- ✅ Comprehensive logging
🚀 Quick Start
1. Build & Run
dotnet clean
dotnet build
dotnet run --launch-profile https
2. The Certificate Creates Automatically
First run will:
- Create
Data/certificates/directory - Generate self-signed certificate:
port-watcher-cert.pfx - Start background renewal checks
3. Access Application
- Development:
https://localhost:7145 - Production:
https://localhost(port 443)
📋 Certificate Management
Check Certificate Status
# PowerShell
.\ManageCertificates.ps1 -Status
# Batch (Windows)
ManageCertificates.bat
# Then select option 1
# API (curl)
curl -k https://localhost:7145/api/certificatediagnostics/status
Manual Certificate Renewal
# PowerShell
.\ManageCertificates.ps1 -Renew -Force
# API
curl -k -X POST https://localhost:7145/api/certificatediagnostics/renew
Create Backup
.\ManageCertificates.ps1 -Backup
Restore from Backup
.\ManageCertificates.ps1 -ListBackups
.\ManageCertificates.ps1 -Restore
📁 Files Modified & Created
Modified Files
- ✏️
Program.cs- Added Kestrel HTTPS configuration - ✏️
appsettings.json- Added HTTP/HTTPS settings - ✏️
appsettings.Development.json- Development certificate settings - ✏️
Properties/launchSettings.json- Added production profile
New Files
- 🆕
Services/IHttpsCertificateService.cs- Certificate service interface - 🆕
Services/HttpsCertificateService.cs- Certificate management implementation - 🆕
Controllers/CertificateDiagnosticsController.cs- REST API endpoints - 🆕
appsettings.Production.json- Production configuration template - 🆕
ManageCertificates.bat- Windows batch management tool - 🆕
ManageCertificates.ps1- PowerShell management tool - 🆕
HTTPS_CERTIFICATE_GUIDE.md- Detailed configuration guide - 🆕
HTTPS_IMPLEMENTATION_SUMMARY.md- Implementation details - 🆕
QuickStart.sh- Quick start script
⚙️ Configuration
Development (Default)
{
"HttpSettings": {
"HttpPort": 5293,
"HttpsPort": 7145
},
"HttpsCertificate": {
"Enabled": true,
"EnableAutoRenewal": false,
"SubjectName": "CN=localhost",
"ValidityDays": 365
}
}
Production
{
"HttpSettings": {
"HttpPort": 80,
"HttpsPort": 443
},
"HttpsCertificate": {
"Enabled": true,
"EnableAutoRenewal": true,
"AutoRenewThresholdDays": 30,
"UseProductionCert": true,
"ProductionCertPath": "C:/path/to/cert.pfx"
}
}
🔌 REST API Endpoints
All endpoints require HTTPS and return JSON responses.
Get Certificate Status
GET /api/certificatediagnostics/status
Response:
{
"success": true,
"data": {
"subjectName": "CN=localhost",
"issuedDate": "2026-03-03T00:00:00",
"expirationDate": "2027-03-03T00:00:00",
"daysUntilExpiration": 365,
"isExpired": false,
"needsRenewal": false,
"thumbprint": "ABC123..."
}
}
Validate & Auto-Renew
POST /api/certificatediagnostics/validate
Manual Renewal
POST /api/certificatediagnostics/renew
📊 How It Works
Startup Process
- Application starts with Kestrel configured for HTTPS
- Reads HTTP/HTTPS ports from
appsettings.json - Certificate service initializes
- If certificate missing → Create new self-signed certificate
- If certificate exists → Validate expiration
- Start background task for periodic checks
Auto-Renewal Process
- Background task runs every 24 hours
- Checks if certificate expires within 30 days
- If renewal needed → Create new certificate
- Backup old certificate with timestamp
- Log all operations
HTTPS Redirect
- All HTTP requests are redirected to HTTPS
- HSTS headers are set (30 days dev, 365 days prod)
- No more "Failed to determine the https port" warning
🔍 Monitoring & Logging
Check Logs
Application logs are stored in the output console and can be configured in:
appsettings.json→Loggingsection
Watch for These Log Messages
[INF] HTTPS certificate found at Data/certificates/port-watcher-cert.pfx
[INF] Certificate Info: Subject=CN=localhost, Expires=2027-03-03, DaysRemaining=365
[INF] Running automatic certificate validation check...
[WRN] HTTPS certificate expires in 25 days. Auto-renewal will be triggered.
[INF] HTTPS certificate renewed successfully.
API Diagnostics
# Check status
curl -k https://localhost:7145/api/certificatediagnostics/status
# Trigger validation
curl -k -X POST https://localhost:7145/api/certificatediagnostics/validate
🛡️ Security Features
Certificate Security
- RSA-2048 Encryption: Industry standard encryption
- Self-signed: Suitable for development and production
- SANs Included: Supports localhost and 127.0.0.1
- PFX Format: Includes private key protection
Automatic Renewal
- Checks 30 days before expiration
- Creates backups before renewal
- Fails safely with error logging
- No manual intervention required
HSTS Policy
- Development: 30 days
- Production: 365 days (1 year)
- Prevents downgrade attacks
- Preload-ready
🐛 Troubleshooting
Still Getting HTTPS Port Warning?
- Clean build:
dotnet clean - Rebuild:
dotnet build - Run:
dotnet run - Check logs for certificate errors
Certificate Not Created?
- Check directory permissions
- Verify
Data/certificates/directory exists - Check application logs
- Run:
.\ManageCertificates.ps1 -Status
Cannot Connect via HTTPS?
- Check firewall (port 7145 for dev, 443 for prod)
- Access locally first:
https://localhost:7145 - Accept self-signed certificate in browser
- Check certificate validity:
.ps1 -Status
Auto-Renewal Not Working?
- Verify
EnableAutoRenewal: true - Check certificate expiration:
.ps1 -Status - Check logs for renewal task
- Manually renew:
.ps1 -Renew
📚 Documentation
- 📖
HTTPS_CERTIFICATE_GUIDE.md- Complete configuration guide - 📖
HTTPS_IMPLEMENTATION_SUMMARY.md- Implementation details - 📖 This file - Quick reference and overview
🤝 Integration with Enterprise Systems
For eSecSys/nCONNECT OS certificate management:
{
"HttpsCertificate": {
"UseProductionCert": true,
"ProductionCertPath": "/provisioned/path/cert.pfx",
"EnableAutoRenewal": false
}
}
Use the API endpoints to:
- Monitor certificate status
- Trigger renewal when needed
- Track certificate lifecycle
✅ Verification Checklist
- Application starts without HTTPS port warning
- Certificate is created automatically on first run
- Certificate status shows via API
- HTTP redirects to HTTPS
- HTTPS works at
https://localhost:7145(dev) - Certificate auto-renewal is happening in background
- Certificate backups are created
- HSTS headers are present in responses
📞 Support
For detailed configuration:
- Read
HTTPS_CERTIFICATE_GUIDE.md - Check application logs
- Use API diagnostics:
/api/certificatediagnostics/status - Run management scripts with
-Verboseflag
Status: ✅ Implementation Complete Last Updated: March 3, 2026 Framework: .NET 8.0 / ASP.NET Core