Class: SoarSmaak::SecureService

Inherits:
Smaak::SmaakService
  • Object
show all
Defined in:
lib/soar_smaak/secure_service.rb

Constant Summary collapse

@@auditing =
nil

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#dynamicObject (readonly)

Returns the value of attribute dynamic.



3
4
5
# File 'lib/soar_smaak/secure_service.rb', line 3

def dynamic
  @dynamic
end

#trust_storeObject (readonly)

Returns the value of attribute trust_store.



4
5
6
# File 'lib/soar_smaak/secure_service.rb', line 4

def trust_store
  @trust_store
end

Class Method Details

.auditingObject



11
12
13
# File 'lib/soar_smaak/secure_service.rb', line 11

def self.auditing
  @@auditing
end

.auditing=(auditing) ⇒ Object



7
8
9
# File 'lib/soar_smaak/secure_service.rb', line 7

def self.auditing=(auditing)
  @@auditing = auditing
end

.smaak_configured?(configuration) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
18
19
# File 'lib/soar_smaak/secure_service.rb', line 15

def self.smaak_configured?(configuration)
  (not configuration['public_key'].nil?) and
  (not configuration['private_key'].nil?) and
  (not configuration['associations'].nil?)
end

.smaak_dynamic?(configuration) ⇒ Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/soar_smaak/secure_service.rb', line 21

def self.smaak_dynamic?(configuration)
  configuration['smaak'] and (configuration['smaak'].downcase.strip == 'dynamic')
end

Instance Method Details

#configure_services(configuration) ⇒ Object



33
34
35
36
37
38
39
40
41
42
# File 'lib/soar_smaak/secure_service.rb', line 33

def configure_services(configuration)
  if (not SoarSmaak::SecureService::smaak_configured?(configuration) and
      SoarSmaak::SecureService::smaak_dynamic?(configuration))
    seed_dynamic_smaak
  elsif (SoarSmaak::SecureService::smaak_configured?(configuration))
    configure_smaak(configuration)
  else
    debug "SMAAK is neither dynamic nor configured. SMAAK support disabled"
  end
end

#configure_smaak(configuration) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/soar_smaak/secure_service.rb', line 65

def configure_smaak(configuration)
  @smaak_server.set_public_key(configuration['public_key'])
  @smaak_server.set_private_key(configuration['private_key'])
  configuration['associations'].each do |identifier, config|
    @smaak_server.add_association(identifier, config['public_key'], config['psk'], config['encrypt'])
  end
  debug "SMAAK credentials provided. SMAAK configured"
end

#debug(message) ⇒ Object



25
26
27
28
29
30
31
# File 'lib/soar_smaak/secure_service.rb', line 25

def debug(message)
  if SoarSmaak::SecureService::auditing.nil?
    puts message
  else
    SoarSmaak::SecureService::auditing.debug(message)
  end
end

#load_smaak_trust_storeObject



58
59
60
61
62
63
# File 'lib/soar_smaak/secure_service.rb', line 58

def load_smaak_trust_store
  @trust_store = SoarSmaak::SmaakTrustStore.new
  @trust_store.associations.each do |identifier, config|
    @smaak_server.add_association(identifier, config['public_key'], config['psk'], config['encrypt'])
  end
end

#randomize_smaakObject



50
51
52
53
54
55
56
# File 'lib/soar_smaak/secure_service.rb', line 50

def randomize_smaak
  @dynamic = @trust_store.associations.keys[rand(@trust_store.associations.keys.size)]
  debug "Seeding random key-pair and identifier"
  @smaak_server.set_public_key(@trust_store.associations[@dynamic]['public_key'])
  @smaak_server.set_private_key(@trust_store.associations[@dynamic]['private_key'])
  @smaak_server.verify_recipient = false
end

#seed_dynamic_smaakObject



44
45
46
47
48
# File 'lib/soar_smaak/secure_service.rb', line 44

def seed_dynamic_smaak
  debug "SMAAK credentials not provided."
  load_smaak_trust_store
  randomize_smaak
end