6.9 KiB
6.9 KiB
Code Signing Certificate Guide for rmtPocketWatcher
This guide explains how to create and use code signing certificates for your Windows application to eliminate security warnings and build user trust.
Quick Start
- Create Certificate:
.\create_certificate.ps1 - Build & Sign:
.\build_windows.ps1 -Release - Distribute: Share the signed executables and optionally the public certificate
Certificate Types
Self-Signed Certificates (Free)
- Cost: Free
- Trust Level: Low (requires manual installation)
- Best For: Development, internal distribution, open source projects
- Limitations: Users see "Unknown Publisher" warnings initially
Commercial Certificates ($100-$500/year)
- Cost: $100-$500 annually
- Trust Level: High (automatically trusted)
- Best For: Commercial software, wide distribution
- Providers: DigiCert, Sectigo, GlobalSign, Entrust
Self-Signed Certificate Setup
Step 1: Create Certificate
.\create_certificate.ps1
This creates:
certificates/rmtPocketWatcher.pfx- Private certificate (keep secure!)certificates/rmtPocketWatcher.cer- Public certificate (for distribution)certificates/CERTIFICATE_INFO.txt- Certificate details
Step 2: Build with Signing
.\build_windows.ps1 -Release
This automatically:
- Builds the application
- Signs the executable with your certificate
- Creates signed MSIX installer
- Packages everything for distribution
Step 3: Manual Signing (if needed)
.\sign_executable.ps1 -ExePath "path\to\your\app.exe"
Certificate Installation for Users
Automatic Installation (Recommended)
When users run your signed app for the first time:
- Windows shows "Unknown Publisher" warning
- User clicks "More info" → "Run anyway"
- Certificate is automatically added to their trusted store
Manual Installation (Optional)
For organizations or power users:
- Distribute the
.cerfile alongside your app - Users double-click the
.cerfile - Click "Install Certificate"
- Choose "Local Machine" (requires admin) or "Current User"
- Select "Trusted Root Certification Authorities"
- Click "Next" and "Finish"
Commercial Certificate Setup
Step 1: Purchase Certificate
Popular providers:
- DigiCert: $474/year (EV), $239/year (OV)
- Sectigo: $199/year (EV), $85/year (OV)
- GlobalSign: $249/year (EV), $127/year (OV)
Step 2: Certificate Validation
- Organization Validation (OV): Business verification (1-3 days)
- Extended Validation (EV): Enhanced verification (1-5 days)
- Individual: Personal ID verification
Step 3: Install Certificate
- Download certificate from provider
- Install to Windows Certificate Store
- Update build scripts with certificate details
Step 4: Update Configuration
# pubspec.yaml
msix_config:
certificate_path: path/to/commercial/cert.pfx
certificate_password: your_secure_password
Security Best Practices
Certificate Storage
- Never commit
.pfxor.p12files to version control - Store certificates in secure, encrypted locations
- Use strong passwords for certificate files
- Backup certificates securely
Password Management
- Use strong, unique passwords for certificates
- Store passwords in secure password managers
- Use environment variables in CI/CD pipelines
- Rotate passwords regularly
CI/CD Integration
# GitHub Actions example
- name: Setup Certificate
run: |
echo "${{ secrets.CERT_BASE64 }}" | base64 -d > cert.pfx
- name: Sign Application
run: |
signtool sign /f cert.pfx /p "${{ secrets.CERT_PASSWORD }}" app.exe
Troubleshooting
"SignTool not found"
Solution: Install Windows SDK
- Download from: https://developer.microsoft.com/windows/downloads/windows-sdk/
- Or install Visual Studio with Windows development tools
"Certificate not valid for code signing"
Solution: Ensure certificate has "Code Signing" usage
# Check certificate usage
Get-PfxCertificate -FilePath cert.pfx | Select-Object -ExpandProperty Extensions
"Timestamp server unavailable"
Solution: Try different timestamp servers
"Access denied" when signing
Solution: Run PowerShell as Administrator
# Check if running as admin
([Security.Principal.WindowsPrincipal] [Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole] "Administrator")
Users still see warnings
Possible causes:
- Certificate not properly installed
- Certificate expired
- System clock incorrect
- Antivirus interference
Certificate Lifecycle
Monitoring Expiration
# Check certificate expiration
$cert = Get-PfxCertificate -FilePath "certificates/rmtPocketWatcher.pfx"
$daysUntilExpiry = ($cert.NotAfter - (Get-Date)).Days
Write-Host "Certificate expires in $daysUntilExpiry days"
Renewal Process
- Self-signed: Run
.\create_certificate.ps1 -Force - Commercial: Renew through certificate provider
- Update build scripts with new certificate
- Re-sign and redistribute applications
Migration to Commercial
- Purchase commercial certificate
- Update
pubspec.yamlconfiguration - Update build scripts
- Re-sign all distributed applications
- Notify users of the change
Cost-Benefit Analysis
Self-Signed Certificates
Pros:
- Free
- Full control
- Good for development/testing
- Suitable for open source projects
Cons:
- Users see warnings initially
- Requires user education
- Not suitable for commercial distribution
Commercial Certificates
Pros:
- Immediate trust
- Professional appearance
- Better user experience
- Required for some distribution channels
Cons:
- Annual cost
- Validation process
- Vendor dependency
Recommendations
For Development/Testing
- Use self-signed certificates
- Document installation process for users
- Consider upgrading for production releases
For Commercial Distribution
- Invest in commercial certificates
- Choose reputable certificate authorities
- Plan for certificate lifecycle management
For Open Source Projects
- Start with self-signed certificates
- Consider community funding for commercial certificates
- Provide clear installation instructions
Scripts Reference
| Script | Purpose | Usage |
|---|---|---|
create_certificate.ps1 |
Create self-signed certificate | .\create_certificate.ps1 |
sign_executable.ps1 |
Sign individual executables | .\sign_executable.ps1 -ExePath app.exe |
build_windows.ps1 |
Build and sign complete package | .\build_windows.ps1 -Release |
Support
For certificate-related issues:
- Check Windows Event Viewer for detailed errors
- Verify certificate validity and usage
- Test on clean Windows installation
- Consult certificate provider documentation