Module: Reedb::Daemon

Includes:
Reedb
Defined in:
lib/reedb.rb

Overview

module vault end

Constant Summary

Constants included from Reedb

CERT_PATH, DEBOUNCE_DELTA, DEB_ADD, DEB_REM, DEFAULT_PATH, EXIT_CORRUPT_FS, EXIT_HTTP_MALFUNCT, EXIT_MISSING_USER_CODE, EXIT_OS_PARSE, EXIT_PANIC_INTERUPT, EXIT_STILL_LOCKED, FILE_CACHE_TIME, KEY_CACHE_TIME, KEY_PATH, NET_PORT, THREAD_TIMEOUT_TIME, TOKEN_BYTE_SIZE, VERSION

Class Method Summary collapse

Methods included from Reedb

archos, daemon?, included, passlength, verbose?

Class Method Details

.access_with_token(uuid, token, passphrase) ⇒ Object

This function should be used by recurring applications that already own an authentication token for a vault.

Raises:



902
903
904
905
# File 'lib/reedb.rb', line 902

def access_with_token(uuid, token, passphrase)
	token.delete!('\n')
	raise UnknownTokenError.new, 'Unknown Token!' unless @@config['tokens'][uuid]
end

.free_token(token, batch = false) ⇒ Object

Call this function to free a token and remove it from the access tree. This means that the vault it used to access are not removed or unloaded for other applications to use. But the token can no longer be used for file access.

Parameters:

  • token (String)

    Token to be freed

Raises:



914
915
916
917
918
919
920
921
922
923
924
925
# File 'lib/reedb.rb', line 914

def free_token(token, batch = false)
	token.delete!("\n")

	# Throw a warning if the token isn't valid in the first place.
	raise UnknownTokenError.new, 'The token you provided is unknown to this system' unless @@tokens.include?(token)

	@@tokens[token].each do |uuid|
		@@config[:vaults][uuid][:tokens].delete(token)
	end

	write_config unless batch
end

.request_token(uuid, passphrase, permanent = false) ⇒ Object

Request token for a vault permanently. Only used if @@no_token == false. Unlocks a vault as well with the user passphrase

Parameters:

  • uuid (String)

    Internal UUID of the vault

  • passphrase (String)

    Passphrase of the vault.

  • permanent (Boolean) (defaults to: false)

    Indicates whether or not the app intends to come back



874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
# File 'lib/reedb.rb', line 874

def request_token(uuid, passphrase, permanent = false)
	# If the vault is not currently open
	unless @@active_vaults.include?(uuid)
		unless @@config[:vaults][uuid]
			DaemonLogger.write('The requested vault is unknown to this system. Aborting operation!', 'error')
			raise VaultNotScopedError.new, "Requested vault #{uuid} is unknown to reedb. Has it been scoped before?"
		end

		# Continue by initialising the vault according to saved information
		name = @@config[:vaults][uuid][:meta].name
		path = @@config[:vaults][uuid][:meta].path
		@@active_vaults[uuid] = ReeVault.new("#{name}", "#{path}", :auto).load("#{passphrase}")
	end

	token = generate_token(uuid, path, permanent)

	# Adds a token to the debouncer if it needs one, removes it again if it already knows and tracks the vault.
	debouncer_token = generate_token(uuid, path)
	check = mirror_debounce(uuid, debouncer_token, Reedb::DEB_ADD)
	remove_token(uuid, debouncer_token) unless check

	# puts "Tokens: #{@@tokens}"
	return token
end