@@ -51,8 +51,7 @@ def create_root_context(cacerts:, crls: [], revocation: Puppet[:certificate_revo
51
51
# @raise (see #create_context)
52
52
# @api private
53
53
def create_system_context ( cacerts :, path : Puppet [ :ssl_trust_store ] )
54
- store = create_x509_store ( cacerts , [ ] , false )
55
- store . set_default_paths
54
+ store = create_x509_store ( cacerts , [ ] , false , include_system_store : true )
56
55
57
56
if path
58
57
stat = Puppet ::FileSystem . stat ( path )
@@ -94,19 +93,20 @@ def create_system_context(cacerts:, path: Puppet[:ssl_trust_store])
94
93
# @param client_cert [OpenSSL::X509::Certificate] client's cert whose public
95
94
# key matches the `private_key`
96
95
# @param revocation [:chain, :leaf, false] revocation mode
96
+ # @param include_system_store [true, false] Also trust system CA
97
97
# @return [Puppet::SSL::SSLContext] A context to use to create connections
98
98
# @raise [Puppet::SSL::CertVerifyError] There was an issue with
99
99
# one of the certs or CRLs.
100
100
# @raise [Puppet::SSL::SSLError] There was an issue with the
101
101
# `private_key`.
102
102
# @api private
103
- def create_context ( cacerts :, crls :, private_key :, client_cert :, revocation : Puppet [ :certificate_revocation ] )
103
+ def create_context ( cacerts :, crls :, private_key :, client_cert :, revocation : Puppet [ :certificate_revocation ] , include_system_store : false )
104
104
raise ArgumentError , _ ( "CA certs are missing" ) unless cacerts
105
105
raise ArgumentError , _ ( "CRLs are missing" ) unless crls
106
106
raise ArgumentError , _ ( "Private key is missing" ) unless private_key
107
107
raise ArgumentError , _ ( "Client cert is missing" ) unless client_cert
108
108
109
- store = create_x509_store ( cacerts , crls , revocation )
109
+ store = create_x509_store ( cacerts , crls , revocation , include_system_store : include_system_store )
110
110
client_chain = verify_cert_with_store ( store , client_cert )
111
111
112
112
if !private_key . is_a? ( OpenSSL ::PKey ::RSA ) && !private_key . is_a? ( OpenSSL ::PKey ::EC )
@@ -134,12 +134,13 @@ def create_context(cacerts:, crls:, private_key:, client_cert:, revocation: Pupp
134
134
# @param password [String, nil] If the private key is encrypted, decrypt
135
135
# it using the password. If the key is encrypted, but a password is
136
136
# not specified, then the key cannot be loaded.
137
+ # @param include_system_store [true, false] Also trust system CA
137
138
# @return [Puppet::SSL::SSLContext] A context to use to create connections
138
139
# @raise [Puppet::SSL::CertVerifyError] There was an issue with
139
140
# one of the certs or CRLs.
140
141
# @raise [Puppet::Error] There was an issue with one of the required components.
141
142
# @api private
142
- def load_context ( certname : Puppet [ :certname ] , revocation : Puppet [ :certificate_revocation ] , password : nil )
143
+ def load_context ( certname : Puppet [ :certname ] , revocation : Puppet [ :certificate_revocation ] , password : nil , include_system_store : false )
143
144
cert = Puppet ::X509 ::CertProvider . new
144
145
cacerts = cert . load_cacerts ( required : true )
145
146
crls = case revocation
@@ -151,7 +152,7 @@ def load_context(certname: Puppet[:certname], revocation: Puppet[:certificate_re
151
152
private_key = cert . load_private_key ( certname , required : true , password : password )
152
153
client_cert = cert . load_client_cert ( certname , required : true )
153
154
154
- create_context ( cacerts : cacerts , crls : crls , private_key : private_key , client_cert : client_cert , revocation : revocation )
155
+ create_context ( cacerts : cacerts , crls : crls , private_key : private_key , client_cert : client_cert , revocation : revocation , include_system_store : include_system_store )
155
156
rescue OpenSSL ::PKey ::PKeyError => e
156
157
raise Puppet ::SSL ::SSLError . new ( _ ( "Failed to load private key for host '%{name}': %{message}" ) % { name : certname , message : e . message } , e )
157
158
end
@@ -186,14 +187,16 @@ def default_flags
186
187
end
187
188
end
188
189
189
- def create_x509_store ( roots , crls , revocation )
190
+ def create_x509_store ( roots , crls , revocation , include_system_store : false )
190
191
store = OpenSSL ::X509 ::Store . new
191
192
store . purpose = OpenSSL ::X509 ::PURPOSE_ANY
192
193
store . flags = default_flags | revocation_mode ( revocation )
193
194
194
195
roots . each { |cert | store . add_cert ( cert ) }
195
196
crls . each { |crl | store . add_crl ( crl ) }
196
197
198
+ store . set_default_paths if include_system_store
199
+
197
200
store
198
201
end
199
202
0 commit comments