Commit 52e6877
Pre-export dev certificate to Aspire cache to avoid macOS keychain prompts (#16282)
* Pre-export dev certificate to Aspire cache to avoid keychain prompts
When the Aspire CLI generates, corrects, or trusts a developer certificate on
macOS, also write the PFX and PEM key material to the Aspire hosting dev-cert
cache (~/.aspire/dev-certs/https/). This lets app-host processes load key
material from disk instead of triggering macOS Keychain access prompts.
Changes:
- MacOSCertificateManager: SaveCertificateCore, CorrectCertificateState, and
TrustCertificateCore now write both the .aspnet and .aspire caches using
ExportCertificate consistently.
- DeveloperCertificateService: Restructured GetKeyMaterialAsync to try cache
reads first, then do a single private key access for any misses (reduces
two keychain prompts to one on cache miss).
- CertificateService: Added TrustCertificateAsync with PreExportKeyMaterialAsync
fallback for certs created before the cache writes existed.
- CertificatesTrustCommand: Refactored to use ICertificateService.TrustCertificateAsync.
- Added tests for trust flow and pre-export behavior.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Update to use pkcs12 file in both places, removed unused cert export method
* Fix macOS dev cert cache prewarming
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Remove Hosting dependency from CLI cert test
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Unify certificate trust path in CLI
Collapse EnsureCertificatesTrustedAsync and TrustCertificateAsync into a
single path used by the apphost, init/template, and 'aspire certs trust'
callers. The service always runs the trust operation so the Aspire cache
stays populated even when the certificate is already trusted, and it emits
the same TrustCancelled / CertificatesMayNotBeFullyTrusted warnings
consistently across all callers. SSL_CERT_DIR handling on Linux partial
trust is unchanged.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Warm Aspire cert cache even when .aspnet PFX missing
WriteAspireCacheFromDiskPfx previously no-op'd when the .aspnet PFX did
not already exist on disk, which meant the Aspire cache would not be
warmed if the .aspnet cache hadn't already been written during trust.
Export the .aspnet PFX on demand in that case so both caches are always
populated together.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Cleanup files that were changed for no reason
* Cleanup an additional file
* Cleanup two more files with unnecessary edits
* Skip interactive cert trust in non-interactive mode
In non-interactive environments on macOS and Windows we can't successfully
prompt for certificate trust (Keychain password / trust dialog) and we
don't want to silently generate an untrusted certificate. Inject
ICliHostEnvironment into CertificateService and, when
SupportsInteractiveInput is false on non-Linux, skip TrustHttpCertificate
but still run CheckHttpCertificate so we can warn with distinct messages
for partially trusted and not trusted states. Linux trust is
non-interactive so the full flow is still run there.
Fixes AspireCliTsStarterSmoke hanging on 'Trusting certificates...' in
Windows CI.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
* Support ECDSA private keys in DeveloperCertificateService.ExportFromPrivateKey
ExportFromPrivateKey silently returned null for non-RSA certificates,
meaning a user-supplied ECDSA certificate would skip cache warming
without any diagnostic. Fall back to GetECDsaPrivateKey when the cert
has no RSA key and throw InvalidOperationException when neither is
available. ExportKeyPem now operates against AsymmetricAlgorithm and
picks the right temporary key type when re-exporting unencrypted PKCS#8.
Added tests covering the ECDSA path (password and no-password variants),
the public-only-certificate failure case, and an RSA sanity check.
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
---------
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>1 parent b94ddc9 commit 52e6877
30 files changed
Lines changed: 794 additions & 533 deletions
File tree
- src
- Aspire.Cli
- Certificates
- CertificateGeneration
- Commands
- Resources
- xlf
- Templating
- Aspire.Hosting
- Dcp
- tests
- Aspire.Cli.Tests
- Certificates
- Templating
- TestServices
- Aspire.Hosting.Tests
Lines changed: 78 additions & 9 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
32 | 33 | | |
33 | 34 | | |
34 | 35 | | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
35 | 40 | | |
36 | 41 | | |
37 | 42 | | |
| |||
84 | 89 | | |
85 | 90 | | |
86 | 91 | | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
87 | 96 | | |
88 | 97 | | |
89 | 98 | | |
| |||
97 | 106 | | |
98 | 107 | | |
99 | 108 | | |
| 109 | + | |
100 | 110 | | |
101 | 111 | | |
102 | 112 | | |
| |||
111 | 121 | | |
112 | 122 | | |
113 | 123 | | |
114 | | - | |
115 | 124 | | |
116 | 125 | | |
117 | 126 | | |
| |||
124 | 133 | | |
125 | 134 | | |
126 | 135 | | |
| 136 | + | |
| 137 | + | |
127 | 138 | | |
128 | 139 | | |
129 | 140 | | |
| |||
137 | 148 | | |
138 | 149 | | |
139 | 150 | | |
140 | | - | |
141 | | - | |
142 | | - | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
143 | 160 | | |
144 | 161 | | |
145 | 162 | | |
| |||
310 | 327 | | |
311 | 328 | | |
312 | 329 | | |
313 | | - | |
314 | | - | |
315 | 330 | | |
316 | 331 | | |
317 | 332 | | |
318 | 333 | | |
319 | 334 | | |
320 | | - | |
321 | | - | |
| 335 | + | |
322 | 336 | | |
323 | | - | |
| 337 | + | |
| 338 | + | |
324 | 339 | | |
325 | 340 | | |
326 | 341 | | |
| |||
373 | 388 | | |
374 | 389 | | |
375 | 390 | | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
| 427 | + | |
| 428 | + | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
| 432 | + | |
| 433 | + | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
| 440 | + | |
| 441 | + | |
| 442 | + | |
| 443 | + | |
| 444 | + | |
376 | 445 | | |
377 | 446 | | |
378 | 447 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | 6 | | |
8 | 7 | | |
9 | 8 | | |
| |||
22 | 21 | | |
23 | 22 | | |
24 | 23 | | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
25 | 39 | | |
26 | 40 | | |
27 | 41 | | |
| |||
33 | 47 | | |
34 | 48 | | |
35 | 49 | | |
36 | | - | |
37 | | - | |
| 50 | + | |
38 | 51 | | |
39 | 52 | | |
40 | | - | |
41 | 53 | | |
42 | 54 | | |
43 | 55 | | |
44 | 56 | | |
45 | 57 | | |
46 | 58 | | |
47 | 59 | | |
48 | | - | |
49 | | - | |
50 | | - | |
51 | | - | |
52 | | - | |
53 | | - | |
54 | | - | |
55 | | - | |
56 | | - | |
57 | | - | |
58 | | - | |
59 | | - | |
60 | | - | |
61 | | - | |
62 | | - | |
63 | | - | |
64 | | - | |
65 | | - | |
66 | | - | |
67 | | - | |
68 | | - | |
69 | | - | |
70 | | - | |
71 | | - | |
72 | | - | |
73 | | - | |
74 | | - | |
75 | | - | |
76 | | - | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
77 | 67 | | |
78 | | - | |
79 | | - | |
| 68 | + | |
80 | 69 | | |
81 | | - | |
| 70 | + | |
| 71 | + | |
82 | 72 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | | - | |
| 73 | + | |
100 | 74 | | |
101 | | - | |
102 | | - | |
103 | | - | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
| 75 | + | |
108 | 76 | | |
109 | | - | |
| 77 | + | |
110 | 78 | | |
111 | | - | |
| 79 | + | |
| 80 | + | |
112 | 81 | | |
113 | | - | |
| 82 | + | |
114 | 83 | | |
115 | 84 | | |
116 | | - | |
117 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
118 | 90 | | |
119 | 91 | | |
120 | | - | |
121 | | - | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
122 | 111 | | |
123 | 112 | | |
124 | 113 | | |
125 | | - | |
126 | 114 | | |
127 | | - | |
128 | | - | |
129 | | - | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
130 | 123 | | |
131 | 124 | | |
132 | 125 | | |
| |||
158 | 151 | | |
159 | 152 | | |
160 | 153 | | |
161 | | - | |
162 | 154 | | |
163 | 155 | | |
164 | 156 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
18 | | - | |
19 | | - | |
20 | | - | |
21 | | - | |
22 | | - | |
23 | 18 | | |
24 | 19 | | |
25 | 20 | | |
| |||
Lines changed: 0 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | | - | |
94 | | - | |
95 | | - | |
96 | | - | |
97 | | - | |
98 | | - | |
99 | 89 | | |
100 | 90 | | |
101 | 91 | | |
| |||
0 commit comments