Skip to content

Commit 6dc1e8a

Browse files
committed
fix(transport): split the requirement for both private and client certs
1 parent 3b3e03e commit 6dc1e8a

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

shard.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: placeos-driver
2-
version: 7.11.7
2+
version: 7.11.8
33

44
dependencies:
55
action-controller:

src/placeos-driver/transport.cr

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,39 +237,57 @@ abstract class PlaceOS::Driver::Transport
237237
end
238238

239239
# allow for certificate based authentication
240-
if configure_client_certificates
240+
if configure_private_key
241241
tls.private_key = private_key_file
242+
end
243+
244+
if configure_client_certificate
242245
tls.certificate_chain = client_cert_file
243246
end
244247

245248
tls
246249
end
247250

248-
protected def configure_client_certificates : Bool
249-
if (private_key = @settings.get { setting?(String, :https_private_key).presence }) &&
250-
(client_cert = @settings.get { setting?(String, :https_client_cert).presence })
251+
protected def configure_private_key : Bool
252+
if (private_key = @settings.get { setting?(String, :https_private_key).presence })
251253
key_contents = begin
252254
File.read(private_key_file)
253255
rescue error
254256
logger.debug { "will write private key" }
255257
""
256258
end
257259

260+
if private_key != key_contents
261+
File.write(private_key_file, private_key)
262+
end
263+
true
264+
else
265+
false
266+
end
267+
rescue error
268+
logger.error(exception: error) { "issue configuring TLS private key" }
269+
false
270+
end
271+
272+
protected def configure_client_certificate : Bool
273+
if (client_cert = @settings.get { setting?(String, :https_client_cert).presence })
258274
cer_contents = begin
259275
File.read(client_cert_file)
260276
rescue error
261277
logger.debug { "will write client certificate" }
262278
""
263279
end
264280

265-
if private_key != key_contents || cer_contents != client_cert
266-
File.write(private_key_file, private_key)
281+
if cer_contents != client_cert
267282
File.write(client_cert_file, client_cert)
268283
end
269284
true
270285
else
271286
false
272287
end
288+
rescue error
289+
logger.error(exception: error) { "issue configuring TLS client certificate" }
290+
false
273291
end
274292

275293
private def process(data : Bytes) : Nil

0 commit comments

Comments
 (0)