@@ -7,15 +7,35 @@ module Localhost
77 module System
88 # Linux specific system operations.
99 module Linux
10+ # This appears to be the standard path for the system trust store on many Linux distributions.
11+ ANCHORS_PATH = "/etc/ca-certificates/trust-source/anchors/"
12+ UPDATE_CA_TRUST = "update-ca-trust"
13+
14+ # This is an older method for systems that do not use `update-ca-trust`.
15+ LOCAL_CERTIFICATES_PATH = "/usr/local/share/ca-certificates/"
16+ UPDATE_CA_CERTIFICATES = "update-ca-certificates"
17+
1018 # Install a certificate into the system trust store.
1119 #
1220 # @parameter certificate [String] The path to the certificate file.
1321 def self . install ( certificate )
1422 filename = File . basename ( certificate )
15- destination = "/usr/local/share/ca-certificates/localhost- #{ filename } "
23+ command = nil
1624
25+ if File . exist? ( ANCHORS_PATH )
26+ # For systems using `update-ca-trust`.
27+ destination = File . join ( ANCHORS_PATH , filename )
28+ command = UPDATE_CA_TRUST
29+ elsif File . exist? ( LOCAL_CERTIFICATES_PATH )
30+ # For systems using `update-ca-certificates`.
31+ destination = File . join ( LOCAL_CERTIFICATES_PATH , filename )
32+ command = UPDATE_CA_CERTIFICATES
33+ else
34+ raise "No known system trust store found. Please install the certificate manually."
35+ end
36+
1737 system ( "sudo" , "cp" , certificate , destination )
18- system ( "sudo" , "update-ca-certificates" )
38+ system ( "sudo" , command )
1939 end
2040 end
2141 end
0 commit comments