@@ -68,8 +68,7 @@ def create_root_context(cacerts:, crls: [], revocation: Puppet[:certificate_revo
68
68
# @raise (see #create_context)
69
69
# @api private
70
70
def create_system_context ( cacerts :, path : Puppet [ :ssl_trust_store ] )
71
- store = create_x509_store ( cacerts , [ ] , false )
72
- store . set_default_paths
71
+ store = create_x509_store ( cacerts , [ ] , false , include_system_store : true )
73
72
74
73
if path
75
74
stat = Puppet ::FileSystem . stat ( path )
@@ -111,19 +110,20 @@ def create_system_context(cacerts:, path: Puppet[:ssl_trust_store])
111
110
# @param client_cert [OpenSSL::X509::Certificate] client's cert whose public
112
111
# key matches the `private_key`
113
112
# @param revocation [:chain, :leaf, false] revocation mode
113
+ # @param include_system_store [true, false] Also trust system CA
114
114
# @return [Puppet::SSL::SSLContext] A context to use to create connections
115
115
# @raise [Puppet::SSL::CertVerifyError] There was an issue with
116
116
# one of the certs or CRLs.
117
117
# @raise [Puppet::SSL::SSLError] There was an issue with the
118
118
# `private_key`.
119
119
# @api private
120
- def create_context ( cacerts :, crls :, private_key :, client_cert :, revocation : Puppet [ :certificate_revocation ] )
120
+ def create_context ( cacerts :, crls :, private_key :, client_cert :, revocation : Puppet [ :certificate_revocation ] , include_system_store : false )
121
121
raise ArgumentError , _ ( "CA certs are missing" ) unless cacerts
122
122
raise ArgumentError , _ ( "CRLs are missing" ) unless crls
123
123
raise ArgumentError , _ ( "Private key is missing" ) unless private_key
124
124
raise ArgumentError , _ ( "Client cert is missing" ) unless client_cert
125
125
126
- store = create_x509_store ( cacerts , crls , revocation )
126
+ store = create_x509_store ( cacerts , crls , revocation , include_system_store : include_system_store )
127
127
client_chain = verify_cert_with_store ( store , client_cert )
128
128
129
129
if !private_key . is_a? ( OpenSSL ::PKey ::RSA ) && !private_key . is_a? ( OpenSSL ::PKey ::EC )
@@ -151,12 +151,13 @@ def create_context(cacerts:, crls:, private_key:, client_cert:, revocation: Pupp
151
151
# @param password [String, nil] If the private key is encrypted, decrypt
152
152
# it using the password. If the key is encrypted, but a password is
153
153
# not specified, then the key cannot be loaded.
154
+ # @param include_system_store [true, false] Also trust system CA
154
155
# @return [Puppet::SSL::SSLContext] A context to use to create connections
155
156
# @raise [Puppet::SSL::CertVerifyError] There was an issue with
156
157
# one of the certs or CRLs.
157
158
# @raise [Puppet::Error] There was an issue with one of the required components.
158
159
# @api private
159
- def load_context ( certname : Puppet [ :certname ] , revocation : Puppet [ :certificate_revocation ] , password : nil )
160
+ def load_context ( certname : Puppet [ :certname ] , revocation : Puppet [ :certificate_revocation ] , password : nil , include_system_store : false )
160
161
cert = Puppet ::X509 ::CertProvider . new
161
162
cacerts = cert . load_cacerts ( required : true )
162
163
crls = case revocation
@@ -168,7 +169,7 @@ def load_context(certname: Puppet[:certname], revocation: Puppet[:certificate_re
168
169
private_key = cert . load_private_key ( certname , required : true , password : password )
169
170
client_cert = cert . load_client_cert ( certname , required : true )
170
171
171
- create_context ( cacerts : cacerts , crls : crls , private_key : private_key , client_cert : client_cert , revocation : revocation )
172
+ create_context ( cacerts : cacerts , crls : crls , private_key : private_key , client_cert : client_cert , revocation : revocation , include_system_store : include_system_store )
172
173
rescue OpenSSL ::PKey ::PKeyError => e
173
174
raise Puppet ::SSL ::SSLError . new ( _ ( "Failed to load private key for host '%{name}': %{message}" ) % { name : certname , message : e . message } , e )
174
175
end
@@ -203,14 +204,16 @@ def default_flags
203
204
end
204
205
end
205
206
206
- def create_x509_store ( roots , crls , revocation )
207
+ def create_x509_store ( roots , crls , revocation , include_system_store : false )
207
208
store = OpenSSL ::X509 ::Store . new
208
209
store . purpose = OpenSSL ::X509 ::PURPOSE_ANY
209
210
store . flags = default_flags | revocation_mode ( revocation )
210
211
211
212
roots . each { |cert | store . add_cert ( cert ) }
212
213
crls . each { |crl | store . add_crl ( crl ) }
213
214
215
+ store . set_default_paths if include_system_store
216
+
214
217
store
215
218
end
216
219
0 commit comments