@@ -109,6 +109,13 @@ func (c *Command) run(ctx context.Context, tty termenv.File) error {
109109 SysFS : rootFS ,
110110 }
111111
112+ brewStore := & truststore.Brew {
113+ RootDir : "/" ,
114+
115+ DataFS : rootFS ,
116+ SysFS : rootFS ,
117+ }
118+
112119 for _ , cert := range * certs .Items {
113120 blk , _ := pem .Decode ([]byte (cert .TextualEncoding ))
114121
@@ -150,17 +157,48 @@ func (c *Command) run(ctx context.Context, tty termenv.File) error {
150157 continue
151158 }
152159
153- if installed , err := systemStore .InstallCA (ca ); installed {
154- fmt .Fprintf (tty , " - installed in the system store.\n " )
155- } else if err != nil {
160+ if err := install (tty , ca , systemStore , "system" ); err != nil {
161+ return err
162+ }
163+ if err := install (tty , ca , nssStore , "Network Security Services (NSS)" ); err != nil {
156164 return err
157165 }
158- if installed , err := nssStore .InstallCA (ca ); installed {
159- fmt .Fprintf (tty , " - installed in the Network Security Services (NSS) store.\n " )
160- } else if err != nil {
166+ if err := install (tty , ca , brewStore , "Homebrew OpenSSL (ca-certificates)" ); err != nil {
161167 return err
162168 }
163169 }
164170
165171 return nil
166172}
173+
174+ type trustStore interface {
175+ Check () (bool , error )
176+ CheckCA (* truststore.CA ) (bool , error )
177+ InstallCA (* truststore.CA ) (bool , error )
178+ }
179+
180+ func install (tty termenv.File , ca * truststore.CA , store trustStore , name string ) error {
181+ if ok , err := store .Check (); ! ok {
182+ if err != nil {
183+ fmt .Fprintf (tty , " - skipping the %s store: %s\n " , name , err )
184+ } else {
185+ fmt .Fprintf (tty , " - skipping the %s store\n " , name )
186+ }
187+ return nil
188+ }
189+
190+ if ok , err := store .CheckCA (ca ); err != nil {
191+ fmt .Fprintf (tty , " - skipping the %s store: %s\n " , name , err )
192+ return nil
193+ } else if ok {
194+ fmt .Fprintf (tty , " - already installed in the %s store.\n " , name )
195+ return nil
196+ }
197+
198+ if installed , err := store .InstallCA (ca ); err != nil {
199+ return err
200+ } else if installed {
201+ fmt .Fprintf (tty , " - installed in the %s store.\n " , name )
202+ }
203+ return nil
204+ }
0 commit comments