vici 5.5.0 → 6.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/lib/vici.rb +243 -184
- metadata +14 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: b4e651788ef7e0b51150cbd8077bd84a3eef4deb6ea9b1f280840d17b308956a
|
4
|
+
data.tar.gz: a699b0b81a187ebb3395b461c3060315404d79ed7d85d131e1c1fe09beb3e25e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc0ef25e22963a1e74fb65b6ea81412e47b420a196a48a9060453e504f8af025d464ec8067f97250f02be3df1442f83ad157b2f05df10908423368924ff92447
|
7
|
+
data.tar.gz: 794d1de2f2df1d5e191cc76973813532c15032628be3b64e317d5a49ce507f86937cbc56f01f56ac52e49233decfe58f0e30e1123bdc1a39da8bc36d2837f24f
|
data/lib/vici.rb
CHANGED
@@ -3,8 +3,8 @@
|
|
3
3
|
# strongSwan VICI protocol. The Connection class provides a high-level
|
4
4
|
# interface to issue requests or listen for events.
|
5
5
|
#
|
6
|
+
# Copyright (C) 2019 Tobias Brunner
|
6
7
|
# Copyright (C) 2014 Martin Willi
|
7
|
-
# Copyright (C) 2014 revosec AG
|
8
8
|
#
|
9
9
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
10
10
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -25,7 +25,6 @@
|
|
25
25
|
# THE SOFTWARE.
|
26
26
|
|
27
27
|
module Vici
|
28
|
-
|
29
28
|
##
|
30
29
|
# Vici specific exception all others inherit from
|
31
30
|
class Error < StandardError
|
@@ -76,12 +75,10 @@ module Vici
|
|
76
75
|
class StopEventListening < Exception
|
77
76
|
end
|
78
77
|
|
79
|
-
|
80
78
|
##
|
81
79
|
# The Message class provides the low level encoding and decoding of vici
|
82
80
|
# protocol messages. Directly using this class is usually not required.
|
83
81
|
class Message
|
84
|
-
|
85
82
|
SECTION_START = 1
|
86
83
|
SECTION_END = 2
|
87
84
|
KEY_VALUE = 3
|
@@ -90,8 +87,8 @@ module Vici
|
|
90
87
|
LIST_END = 6
|
91
88
|
|
92
89
|
def initialize(data = "")
|
93
|
-
if data
|
94
|
-
@root =
|
90
|
+
if data.nil?
|
91
|
+
@root = {}
|
95
92
|
elsif data.is_a?(Hash)
|
96
93
|
@root = data
|
97
94
|
else
|
@@ -102,18 +99,14 @@ module Vici
|
|
102
99
|
##
|
103
100
|
# Get the raw byte encoding of an on-the-wire message
|
104
101
|
def encoding
|
105
|
-
if @encoded
|
106
|
-
@encoded = encode(@root)
|
107
|
-
end
|
102
|
+
@encoded = encode(@root) if @encoded.nil?
|
108
103
|
@encoded
|
109
104
|
end
|
110
105
|
|
111
106
|
##
|
112
107
|
# Get the root element of the parsed ruby data structures
|
113
108
|
def root
|
114
|
-
if @root
|
115
|
-
@root = parse(@encoded)
|
116
|
-
end
|
109
|
+
@root = parse(@encoded) if @root.nil?
|
117
110
|
@root
|
118
111
|
end
|
119
112
|
|
@@ -124,9 +117,7 @@ module Vici
|
|
124
117
|
end
|
125
118
|
|
126
119
|
def encode_value(value)
|
127
|
-
if value.class != String
|
128
|
-
value = value.to_s
|
129
|
-
end
|
120
|
+
value = value.to_s if value.class != String
|
130
121
|
[value.length].pack("n") << value
|
131
122
|
end
|
132
123
|
|
@@ -150,18 +141,13 @@ module Vici
|
|
150
141
|
def encode(node)
|
151
142
|
encoding = ""
|
152
143
|
node.each do |key, value|
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
encoding = encode_list(encoding, key, value)
|
161
|
-
else
|
162
|
-
encoding = encode_kv(encoding, key, value)
|
163
|
-
end
|
164
|
-
end
|
144
|
+
encoding = if value.is_a?(Hash)
|
145
|
+
encode_section(encoding, key, value)
|
146
|
+
elsif value.is_a?(Array)
|
147
|
+
encode_list(encoding, key, value)
|
148
|
+
else
|
149
|
+
encode_kv(encoding, key, value)
|
150
|
+
end
|
165
151
|
end
|
166
152
|
encoding
|
167
153
|
end
|
@@ -169,63 +155,57 @@ module Vici
|
|
169
155
|
def parse_name(encoding)
|
170
156
|
len = encoding.unpack("c")[0]
|
171
157
|
name = encoding[1, len]
|
172
|
-
|
158
|
+
[encoding[(1 + len)..-1], name]
|
173
159
|
end
|
174
160
|
|
175
161
|
def parse_value(encoding)
|
176
162
|
len = encoding.unpack("n")[0]
|
177
163
|
value = encoding[2, len]
|
178
|
-
|
164
|
+
[encoding[(2 + len)..-1], value]
|
179
165
|
end
|
180
166
|
|
181
167
|
def parse(encoding)
|
182
|
-
stack = [
|
168
|
+
stack = [{}]
|
183
169
|
list = nil
|
184
|
-
|
170
|
+
until encoding.empty?
|
185
171
|
type = encoding.unpack("c")[0]
|
186
172
|
encoding = encoding[1..-1]
|
187
173
|
case type
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
else
|
212
|
-
raise ParseError, "invalid type: #{type}"
|
174
|
+
when SECTION_START
|
175
|
+
encoding, name = parse_name(encoding)
|
176
|
+
stack.push(stack[-1][name] = {})
|
177
|
+
when SECTION_END
|
178
|
+
raise ParseError, "unexpected section end" if stack.length == 1
|
179
|
+
stack.pop
|
180
|
+
when KEY_VALUE
|
181
|
+
encoding, name = parse_name(encoding)
|
182
|
+
encoding, value = parse_value(encoding)
|
183
|
+
stack[-1][name] = value
|
184
|
+
when LIST_START
|
185
|
+
encoding, name = parse_name(encoding)
|
186
|
+
stack[-1][name] = []
|
187
|
+
list = name
|
188
|
+
when LIST_ITEM
|
189
|
+
raise ParseError, "unexpected list item" if list.nil?
|
190
|
+
encoding, value = parse_value(encoding)
|
191
|
+
stack[-1][list].push(value)
|
192
|
+
when LIST_END
|
193
|
+
raise ParseError, "unexpected list end" if list.nil?
|
194
|
+
list = nil
|
195
|
+
else
|
196
|
+
raise ParseError, "invalid type: #{type}"
|
213
197
|
end
|
214
198
|
end
|
215
|
-
if stack.length
|
216
|
-
raise ParseError, "unexpected message end"
|
217
|
-
end
|
199
|
+
raise ParseError, "unexpected message end" if stack.length > 1
|
218
200
|
stack[0]
|
219
201
|
end
|
220
202
|
end
|
221
203
|
|
222
|
-
|
223
204
|
##
|
224
205
|
# The Transport class implements to low level segmentation of packets
|
225
206
|
# to the underlying transport stream. Directly using this class is usually
|
226
207
|
# not required.
|
227
208
|
class Transport
|
228
|
-
|
229
209
|
CMD_REQUEST = 0
|
230
210
|
CMD_RESPONSE = 1
|
231
211
|
CMD_UNKNOWN = 2
|
@@ -239,18 +219,16 @@ module Vici
|
|
239
219
|
# Create a transport layer using a provided socket for communication.
|
240
220
|
def initialize(socket)
|
241
221
|
@socket = socket
|
242
|
-
@events =
|
222
|
+
@events = {}
|
243
223
|
end
|
244
224
|
|
245
225
|
##
|
246
226
|
# Receive data from socket, until len bytes read
|
247
227
|
def recv_all(len)
|
248
228
|
encoding = ""
|
249
|
-
while encoding.length < len
|
229
|
+
while encoding.length < len
|
250
230
|
data = @socket.recv(len - encoding.length)
|
251
|
-
if data.empty?
|
252
|
-
raise TransportError, "connection closed"
|
253
|
-
end
|
231
|
+
raise TransportError, "connection closed" if data.empty?
|
254
232
|
encoding << data
|
255
233
|
end
|
256
234
|
encoding
|
@@ -260,9 +238,7 @@ module Vici
|
|
260
238
|
# Send data to socket, until all bytes sent
|
261
239
|
def send_all(encoding)
|
262
240
|
len = 0
|
263
|
-
while len < encoding.length
|
264
|
-
len += @socket.send(encoding[len..-1], 0)
|
265
|
-
end
|
241
|
+
len += @socket.send(encoding[len..-1], 0) while len < encoding.length
|
266
242
|
end
|
267
243
|
|
268
244
|
##
|
@@ -270,12 +246,8 @@ module Vici
|
|
270
246
|
# specifies the message, the optional label and message get appended.
|
271
247
|
def write(type, label, message)
|
272
248
|
encoding = ""
|
273
|
-
if label
|
274
|
-
|
275
|
-
end
|
276
|
-
if message
|
277
|
-
encoding << message.encoding
|
278
|
-
end
|
249
|
+
encoding << label.length << label if label
|
250
|
+
encoding << message.encoding if message
|
279
251
|
send_all([encoding.length + 1, type].pack("Nc") + encoding)
|
280
252
|
end
|
281
253
|
|
@@ -288,18 +260,20 @@ module Vici
|
|
288
260
|
type = encoding.unpack("c")[0]
|
289
261
|
len = 1
|
290
262
|
case type
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
end
|
299
|
-
if encoding.length == len
|
300
|
-
return type, label, Message.new
|
263
|
+
when CMD_REQUEST, EVENT_REGISTER, EVENT_UNREGISTER, EVENT
|
264
|
+
label = encoding[2, encoding[1].unpack("c")[0]]
|
265
|
+
len += label.length + 1
|
266
|
+
when CMD_RESPONSE, CMD_UNKNOWN, EVENT_CONFIRM, EVENT_UNKNOWN
|
267
|
+
label = nil
|
268
|
+
else
|
269
|
+
raise TransportError, "invalid message: #{type}"
|
301
270
|
end
|
302
|
-
|
271
|
+
message = if encoding.length == len
|
272
|
+
Message.new
|
273
|
+
else
|
274
|
+
Message.new(encoding[len..-1])
|
275
|
+
end
|
276
|
+
[type, label, message]
|
303
277
|
end
|
304
278
|
|
305
279
|
def dispatch_event(name, message)
|
@@ -310,22 +284,17 @@ module Vici
|
|
310
284
|
|
311
285
|
def read_and_dispatch_event
|
312
286
|
type, label, message = read
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
else
|
317
|
-
raise TransportError, "unexpected message: #{type}"
|
318
|
-
end
|
287
|
+
raise TransportError, "unexpected message: #{type}" if type != EVENT
|
288
|
+
|
289
|
+
dispatch_event(label, message)
|
319
290
|
end
|
320
291
|
|
321
292
|
def read_and_dispatch_events
|
322
293
|
loop do
|
323
294
|
type, label, message = read
|
324
|
-
if type
|
325
|
-
|
326
|
-
|
327
|
-
return type, label, message
|
328
|
-
end
|
295
|
+
return type, label, message if type != EVENT
|
296
|
+
|
297
|
+
dispatch_event(label, message)
|
329
298
|
end
|
330
299
|
end
|
331
300
|
|
@@ -334,14 +303,14 @@ module Vici
|
|
334
303
|
# the reply message on success.
|
335
304
|
def request(name, message = nil)
|
336
305
|
write(CMD_REQUEST, name, message)
|
337
|
-
type,
|
306
|
+
type, _label, message = read_and_dispatch_events
|
338
307
|
case type
|
339
|
-
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
308
|
+
when CMD_RESPONSE
|
309
|
+
return message
|
310
|
+
when CMD_UNKNOWN
|
311
|
+
raise CommandUnknownError, name
|
312
|
+
else
|
313
|
+
raise CommandError, "invalid response for #{name}"
|
345
314
|
end
|
346
315
|
end
|
347
316
|
|
@@ -349,18 +318,18 @@ module Vici
|
|
349
318
|
# Register a handler method for the given event name
|
350
319
|
def register(name, handler)
|
351
320
|
write(EVENT_REGISTER, name, nil)
|
352
|
-
type,
|
321
|
+
type, _label, _message = read_and_dispatch_events
|
353
322
|
case type
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
else
|
358
|
-
@events[name] = [handler];
|
359
|
-
end
|
360
|
-
when EVENT_UNKNOWN
|
361
|
-
raise EventUnknownError, name
|
323
|
+
when EVENT_CONFIRM
|
324
|
+
if @events.key?(name)
|
325
|
+
@events[name] += [handler]
|
362
326
|
else
|
363
|
-
|
327
|
+
@events[name] = [handler]
|
328
|
+
end
|
329
|
+
when EVENT_UNKNOWN
|
330
|
+
raise EventUnknownError, name
|
331
|
+
else
|
332
|
+
raise EventError, "invalid response for #{name} register"
|
364
333
|
end
|
365
334
|
end
|
366
335
|
|
@@ -368,19 +337,18 @@ module Vici
|
|
368
337
|
# Unregister a handler method for the given event name
|
369
338
|
def unregister(name, handler)
|
370
339
|
write(EVENT_UNREGISTER, name, nil)
|
371
|
-
type,
|
340
|
+
type, _label, _message = read_and_dispatch_events
|
372
341
|
case type
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
342
|
+
when EVENT_CONFIRM
|
343
|
+
@events[name] -= [handler]
|
344
|
+
when EVENT_UNKNOWN
|
345
|
+
raise EventUnknownError, name
|
346
|
+
else
|
347
|
+
raise EventError, "invalid response for #{name} unregister"
|
379
348
|
end
|
380
349
|
end
|
381
350
|
end
|
382
351
|
|
383
|
-
|
384
352
|
##
|
385
353
|
# The Connection class provides the high-level interface to monitor, configure
|
386
354
|
# and control the IKE daemon. It takes a connected stream-oriented Socket for
|
@@ -393,19 +361,65 @@ module Vici
|
|
393
361
|
# Non-String values that are not a Hash nor an Array get converted with .to_s
|
394
362
|
# during encoding.
|
395
363
|
class Connection
|
396
|
-
|
364
|
+
##
|
365
|
+
# Create a connection, optionally using the given socket
|
397
366
|
def initialize(socket = nil)
|
398
|
-
if socket
|
399
|
-
socket = UNIXSocket.new("/var/run/charon.vici")
|
400
|
-
end
|
367
|
+
socket = UNIXSocket.new("/var/run/charon.vici") if socket.nil?
|
401
368
|
@transp = Transport.new(socket)
|
402
369
|
end
|
403
370
|
|
404
371
|
##
|
405
|
-
#
|
406
|
-
|
407
|
-
|
408
|
-
|
372
|
+
# Get daemon version information
|
373
|
+
def version
|
374
|
+
call("version")
|
375
|
+
end
|
376
|
+
|
377
|
+
##
|
378
|
+
# Get daemon statistics and information.
|
379
|
+
def stats
|
380
|
+
call("stats")
|
381
|
+
end
|
382
|
+
|
383
|
+
##
|
384
|
+
# Reload strongswan.conf settings.
|
385
|
+
def reload_settings
|
386
|
+
call("reload-settings")
|
387
|
+
end
|
388
|
+
|
389
|
+
##
|
390
|
+
# Initiate a connection. The provided closure is invoked for each log line.
|
391
|
+
def initiate(options, &block)
|
392
|
+
call_with_event("initiate", Message.new(options), "control-log", &block)
|
393
|
+
end
|
394
|
+
|
395
|
+
##
|
396
|
+
# Terminate a connection. The provided closure is invoked for each log line.
|
397
|
+
def terminate(options, &block)
|
398
|
+
call_with_event("terminate", Message.new(options), "control-log", &block)
|
399
|
+
end
|
400
|
+
|
401
|
+
##
|
402
|
+
# Initiate the rekeying of an SA.
|
403
|
+
def rekey(options)
|
404
|
+
call("rekey", Message.new(options))
|
405
|
+
end
|
406
|
+
|
407
|
+
##
|
408
|
+
# Redirect an IKE_SA.
|
409
|
+
def redirect(options)
|
410
|
+
call("redirect", Message.new(options))
|
411
|
+
end
|
412
|
+
|
413
|
+
##
|
414
|
+
# Install a shunt/route policy.
|
415
|
+
def install(policy)
|
416
|
+
call("install", Message.new(policy))
|
417
|
+
end
|
418
|
+
|
419
|
+
##
|
420
|
+
# Uninstall a shunt/route policy.
|
421
|
+
def uninstall(policy)
|
422
|
+
call("uninstall", Message.new(policy))
|
409
423
|
end
|
410
424
|
|
411
425
|
##
|
@@ -423,6 +437,19 @@ module Vici
|
|
423
437
|
&block)
|
424
438
|
end
|
425
439
|
|
440
|
+
##
|
441
|
+
# List matching loaded connections. The provided closure is invoked
|
442
|
+
# for each matching connection.
|
443
|
+
def list_conns(match = nil, &block)
|
444
|
+
call_with_event("list-conns", Message.new(match), "list-conn", &block)
|
445
|
+
end
|
446
|
+
|
447
|
+
##
|
448
|
+
# Get the names of connections managed by vici.
|
449
|
+
def get_conns
|
450
|
+
call("get-conns")
|
451
|
+
end
|
452
|
+
|
426
453
|
##
|
427
454
|
# List matching loaded certificates. The provided closure is invoked
|
428
455
|
# for each matching certificate definition.
|
@@ -431,120 +458,144 @@ module Vici
|
|
431
458
|
end
|
432
459
|
|
433
460
|
##
|
434
|
-
#
|
435
|
-
|
436
|
-
|
461
|
+
# List matching loaded certification authorities. The provided closure is
|
462
|
+
# invoked for each matching certification authority definition.
|
463
|
+
def list_authorities(match = nil, &block)
|
464
|
+
call_with_event("list-authorities", Message.new(match), "list-authority",
|
465
|
+
&block)
|
437
466
|
end
|
438
467
|
|
439
468
|
##
|
440
|
-
#
|
441
|
-
def
|
442
|
-
|
469
|
+
# Get the names of certification authorities managed by vici.
|
470
|
+
def get_authorities
|
471
|
+
call("get-authorities")
|
443
472
|
end
|
444
473
|
|
445
474
|
##
|
446
|
-
#
|
447
|
-
def
|
448
|
-
|
475
|
+
# Load a connection into the daemon.
|
476
|
+
def load_conn(conn)
|
477
|
+
call("load-conn", Message.new(conn))
|
449
478
|
end
|
450
479
|
|
451
480
|
##
|
452
|
-
#
|
453
|
-
def
|
454
|
-
|
481
|
+
# Unload a connection from the daemon.
|
482
|
+
def unload_conn(conn)
|
483
|
+
call("unload-conn", Message.new(conn))
|
455
484
|
end
|
456
485
|
|
457
486
|
##
|
458
487
|
# Load a certificate into the daemon.
|
459
488
|
def load_cert(cert)
|
460
|
-
|
489
|
+
call("load-cert", Message.new(cert))
|
461
490
|
end
|
462
491
|
|
463
492
|
##
|
464
493
|
# Load a private key into the daemon.
|
465
494
|
def load_key(key)
|
466
|
-
|
495
|
+
call("load-key", Message.new(key))
|
496
|
+
end
|
497
|
+
|
498
|
+
##
|
499
|
+
# Unload a private key from the daemon.
|
500
|
+
def unload_key(key)
|
501
|
+
call("unload-key", Message.new(key))
|
502
|
+
end
|
503
|
+
|
504
|
+
##
|
505
|
+
# Get the identifiers of private keys loaded via vici.
|
506
|
+
def get_keys
|
507
|
+
call("get-keys")
|
508
|
+
end
|
509
|
+
|
510
|
+
##
|
511
|
+
# Load a private key located on a token into the daemon.
|
512
|
+
def load_token(token)
|
513
|
+
call("load-token", Message.new(token))
|
467
514
|
end
|
468
515
|
|
469
516
|
##
|
470
517
|
# Load a shared key into the daemon.
|
471
518
|
def load_shared(shared)
|
472
|
-
|
519
|
+
call("load-shared", Message.new(shared))
|
473
520
|
end
|
474
521
|
|
475
522
|
##
|
476
|
-
#
|
477
|
-
def
|
478
|
-
|
523
|
+
# Unload a shared key from the daemon.
|
524
|
+
def unload_shared(shared)
|
525
|
+
call("unload-shared", Message.new(shared))
|
479
526
|
end
|
480
527
|
|
481
528
|
##
|
482
|
-
#
|
483
|
-
def
|
484
|
-
|
529
|
+
# Get the unique identifiers of shared keys loaded via vici.
|
530
|
+
def get_shared
|
531
|
+
call("get-shared")
|
485
532
|
end
|
486
533
|
|
487
534
|
##
|
488
|
-
#
|
489
|
-
def
|
490
|
-
|
535
|
+
# Flush credential cache.
|
536
|
+
def flush_certs(match = nil)
|
537
|
+
call("flush-certs", Message.new(match))
|
491
538
|
end
|
492
539
|
|
493
540
|
##
|
494
|
-
#
|
495
|
-
def
|
496
|
-
|
497
|
-
"control-log", &block))
|
541
|
+
# Clear all loaded credentials.
|
542
|
+
def clear_creds
|
543
|
+
call("clear-creds")
|
498
544
|
end
|
499
545
|
|
500
546
|
##
|
501
|
-
#
|
502
|
-
def
|
503
|
-
|
504
|
-
"control-log", &block))
|
547
|
+
# Load a certification authority into the daemon.
|
548
|
+
def load_authority(authority)
|
549
|
+
call("load-authority", Message.new(authority))
|
505
550
|
end
|
506
551
|
|
507
552
|
##
|
508
|
-
#
|
509
|
-
def
|
510
|
-
|
553
|
+
# Unload a certification authority from the daemon.
|
554
|
+
def unload_authority(authority)
|
555
|
+
call("unload-authority", Message.new(authority))
|
511
556
|
end
|
512
557
|
|
513
558
|
##
|
514
|
-
#
|
515
|
-
def
|
516
|
-
|
559
|
+
# Load a virtual IP / attribute pool into the daemon.
|
560
|
+
def load_pool(pool)
|
561
|
+
call("load-pool", Message.new(pool))
|
517
562
|
end
|
518
563
|
|
519
564
|
##
|
520
|
-
#
|
521
|
-
def
|
522
|
-
|
565
|
+
# Unload a virtual IP / attribute pool from the daemon.
|
566
|
+
def unload_pool(pool)
|
567
|
+
call("unload-pool", Message.new(pool))
|
523
568
|
end
|
524
569
|
|
525
570
|
##
|
526
|
-
#
|
527
|
-
def
|
528
|
-
|
571
|
+
# Get the currently loaded pools.
|
572
|
+
def get_pools(options)
|
573
|
+
call("get-pools", Message.new(options))
|
529
574
|
end
|
530
575
|
|
531
576
|
##
|
532
|
-
# Get
|
533
|
-
def
|
534
|
-
|
577
|
+
# Get currently loaded algorithms and their implementation.
|
578
|
+
def get_algorithms
|
579
|
+
call("get-algorithms")
|
535
580
|
end
|
536
581
|
|
537
582
|
##
|
538
|
-
# Get
|
539
|
-
def
|
540
|
-
|
583
|
+
# Get global or connection-specific counters for IKE events.
|
584
|
+
def get_counters(options = nil)
|
585
|
+
call("get-counters", Message.new(options))
|
586
|
+
end
|
587
|
+
|
588
|
+
##
|
589
|
+
# Reset global or connection-specific IKE event counters.
|
590
|
+
def reset_counters(options = nil)
|
591
|
+
call("reset-counters", Message.new(options))
|
541
592
|
end
|
542
593
|
|
543
594
|
##
|
544
595
|
# Listen for a set of event messages. This call is blocking, and invokes
|
545
596
|
# the passed closure for each event received. The closure receives the
|
546
597
|
# event name and the event message as argument. To stop listening, the
|
547
|
-
# closure may raise a StopEventListening exception, the only
|
598
|
+
# closure may raise a StopEventListening exception, the only caught
|
548
599
|
# exception.
|
549
600
|
def listen_events(events, &block)
|
550
601
|
self.class.instance_eval do
|
@@ -567,6 +618,13 @@ module Vici
|
|
567
618
|
end
|
568
619
|
end
|
569
620
|
|
621
|
+
##
|
622
|
+
# Issue a command request. Checks if the reply of a command indicates
|
623
|
+
# "success", otherwise raises a CommandExecError exception.
|
624
|
+
def call(command, request = nil)
|
625
|
+
check_success(@transp.request(command, request))
|
626
|
+
end
|
627
|
+
|
570
628
|
##
|
571
629
|
# Issue a command request, but register for a specific event while the
|
572
630
|
# command is active. VICI uses this mechanism to stream potentially large
|
@@ -574,7 +632,7 @@ module Vici
|
|
574
632
|
# event messages.
|
575
633
|
def call_with_event(command, request, event, &block)
|
576
634
|
self.class.instance_eval do
|
577
|
-
define_method(:call_event) do |
|
635
|
+
define_method(:call_event) do |_label, message|
|
578
636
|
block.call(message.root)
|
579
637
|
end
|
580
638
|
end
|
@@ -584,7 +642,7 @@ module Vici
|
|
584
642
|
ensure
|
585
643
|
@transp.unregister(event, method(:call_event))
|
586
644
|
end
|
587
|
-
reply
|
645
|
+
check_success(reply)
|
588
646
|
end
|
589
647
|
|
590
648
|
##
|
@@ -592,9 +650,10 @@ module Vici
|
|
592
650
|
# CommandExecError exception
|
593
651
|
def check_success(reply)
|
594
652
|
root = reply.root
|
595
|
-
if root["success"] != "yes"
|
653
|
+
if root.key?("success") && root["success"] != "yes"
|
596
654
|
raise CommandExecError, root["errmsg"]
|
597
655
|
end
|
656
|
+
|
598
657
|
root
|
599
658
|
end
|
600
659
|
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: vici
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 6.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
|
-
-
|
8
|
-
autorequire:
|
7
|
+
- strongSwan Project
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2025-03-11 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
|
-
description: "\n
|
14
|
-
\
|
15
|
-
client side implementation of the VICI protocol, well suited to\n
|
16
|
-
tasks in a
|
13
|
+
description: "\n The strongSwan VICI protocol allows external application to monitor,\n
|
14
|
+
\ configure and control the IKE daemon charon. This Ruby Gem provides a\n native
|
15
|
+
client side implementation of the VICI protocol, well suited to\n script automated
|
16
|
+
tasks in a reliable way.\n "
|
17
17
|
email:
|
18
|
-
-
|
18
|
+
- info@strongswan.org
|
19
19
|
executables: []
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- lib/vici.rb
|
24
|
-
homepage: https://
|
24
|
+
homepage: https://docs.strongswan.org/docs/latest/plugins/vici.html
|
25
25
|
licenses:
|
26
26
|
- MIT
|
27
27
|
metadata: {}
|
28
|
-
post_install_message:
|
28
|
+
post_install_message:
|
29
29
|
rdoc_options: []
|
30
30
|
require_paths:
|
31
31
|
- lib
|
@@ -40,9 +40,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
requirements: []
|
43
|
-
|
44
|
-
|
45
|
-
signing_key:
|
43
|
+
rubygems_version: 3.4.20
|
44
|
+
signing_key:
|
46
45
|
specification_version: 4
|
47
|
-
summary: Native
|
46
|
+
summary: Native Ruby interface for strongSwan VICI
|
48
47
|
test_files: []
|