Module: Darrrr

Includes:
Constants
Defined in:
lib/darrrr/recovery_token.rb,
lib/darrrr.rb,
lib/darrrr/version.rb,
lib/darrrr/provider.rb,
lib/darrrr/constants.rb,
lib/darrrr/crypto_helper.rb,
lib/darrrr/account_provider.rb,
lib/darrrr/recovery_provider.rb,
lib/darrrr/cryptors/default/encrypted_data.rb,
lib/darrrr/cryptors/default/default_encryptor.rb,
lib/darrrr/cryptors/default/encrypted_data_io.rb,
lib/darrrr/serialization/recovery_token_reader.rb,
lib/darrrr/serialization/recovery_token_writer.rb

Overview

Handles binary serialization/deserialization of recovery token data. It does not manage signing/verification of tokens. Only account providers will ever call the decode function

Defined Under Namespace

Modules: Constants, CryptoHelper, DefaultEncryptor, Provider Classes: AccountProvider, CountersignedTokenError, CryptoError, DelegatedRecoveryError, EncryptedData, EncryptedDataIO, ProviderConfigError, RecoveryProvider, RecoveryToken, RecoveryTokenError, RecoveryTokenReader, RecoveryTokenSerializationError, RecoveryTokenWriter, TokenFormatError, UnknownProviderError

Constant Summary collapse

VERSION =
"0.1.6"

Constants included from Constants

Constants::CLOCK_SKEW, Constants::COUNTERSIGNED_RECOVERY_TOKEN_TYPE, Constants::DIGEST, Constants::GROUP, Constants::PRIME_256_V1, Constants::PROTOCOL_VERSION, Constants::RECOVERY_TOKEN_TYPE, Constants::TOKEN_ID_BYTE_LENGTH, Constants::WELL_KNOWN_CONFIG_PATH

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.account_providersObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def 
  @account_providers
end

.allow_unsafe_urlsObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def allow_unsafe_urls
  @allow_unsafe_urls
end

.authorityObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def authority
  @authority
end

.cacheObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def cache
  @cache
end

.faraday_config_callbackObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def faraday_config_callback
  @faraday_config_callback
end

.icon_152pxObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def icon_152px
  @icon_152px
end

.privacy_policyObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def privacy_policy
  @privacy_policy
end

.recovery_providersObject

recovery provider data is only loaded (and cached) upon use.



60
61
62
# File 'lib/darrrr.rb', line 60

def recovery_providers
  @recovery_providers
end

Class Method Details

.account_and_recovery_provider_configObject

Returns a hash of all configuration values, recovery and account provider.



125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/darrrr.rb', line 125

def 
  provider_data = Darrrr.&.to_h || {}

  if Darrrr.this_recovery_provider
    provider_data.merge!(recovery_provider_config) do |key, lhs, rhs|
      unless lhs == rhs
        raise ArgumentError, "inconsistent config value detected #{key}: #{lhs} != #{rhs}"
      end

      lhs
    end
  end

  provider_data
end

.account_provider(provider_origin, &block) ⇒ Object

Find and load remote account provider configuration data.

provider_origin: the origin that contains the config data in a well-known location.



93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/darrrr.rb', line 93

def (provider_origin, &block)
  unless self.
    raise "No account providers configured"
  end
  if provider_origin == &.origin
    
  elsif self..include?(provider_origin)
    AccountProvider.new(provider_origin).load
  else
    raise UnknownProviderError, "Unknown account provider: #{provider_origin}"
  end
end

.account_provider_configObject

returns the account provider information in hash form



142
143
144
# File 'lib/darrrr.rb', line 142

def 
  &.to_h
end

.recovery_provider(provider_origin) ⇒ Object

Find and load remote recovery provider configuration data.

provider_origin: the origin that contains the config data in a well-known location.



67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/darrrr.rb', line 67

def recovery_provider(provider_origin)
  unless self.recovery_providers
    raise "No recovery providers configured"
  end

  if provider_origin == this_recovery_provider&.origin
    this_recovery_provider
  elsif self.recovery_providers.include?(provider_origin)
    RecoveryProvider.new(provider_origin).load
  else
    raise UnknownProviderError, "Unknown recovery provider: #{provider_origin}"
  end
end

.recovery_provider_configObject

returns the account provider information in hash form



147
148
149
# File 'lib/darrrr.rb', line 147

def recovery_provider_config
  this_recovery_provider&.to_h
end

.register_account_provider(account_origin) ⇒ Object

Permit an origin to act as an account provider.

account_origin: the origin to permit



109
110
111
112
# File 'lib/darrrr.rb', line 109

def ()
  self. ||= []
  self. << 
end

.register_recovery_provider(provider_origin) ⇒ Object

Permit an origin to act as a recovery provider.

provider_origin: the origin to permit



84
85
86
87
# File 'lib/darrrr.rb', line 84

def register_recovery_provider(provider_origin)
  self.recovery_providers ||= []
  self.recovery_providers << provider_origin
end

.this_account_providerObject

Provide a reference to the account provider configuration for this web app



115
116
117
# File 'lib/darrrr.rb', line 115

def 
  AccountProvider.this
end

.this_recovery_providerObject

Provide a reference to the recovery provider configuration for this web app



120
121
122
# File 'lib/darrrr.rb', line 120

def this_recovery_provider
  RecoveryProvider.this
end