Class: SignedForm::GateKeeper
- Inherits:
-
Object
- Object
- SignedForm::GateKeeper
- Defined in:
- lib/signed_form/gate_keeper.rb
Instance Attribute Summary collapse
-
#allowed_attributes ⇒ Object
readonly
Returns the value of attribute allowed_attributes.
Instance Method Summary collapse
- #extract_and_verify_form_signature ⇒ Object
-
#initialize(controller) ⇒ GateKeeper
constructor
A new instance of GateKeeper.
- #options ⇒ Object
- #verify_destination ⇒ Object
- #verify_digest ⇒ Object
Constructor Details
#initialize(controller) ⇒ GateKeeper
Returns a new instance of GateKeeper.
5 6 7 8 9 10 11 12 13 |
# File 'lib/signed_form/gate_keeper.rb', line 5 def initialize(controller) @controller = controller @params = controller.params @request = controller.request extract_and_verify_form_signature verify_destination verify_digest end |
Instance Attribute Details
#allowed_attributes ⇒ Object (readonly)
Returns the value of attribute allowed_attributes.
3 4 5 |
# File 'lib/signed_form/gate_keeper.rb', line 3 def allowed_attributes @allowed_attributes end |
Instance Method Details
#extract_and_verify_form_signature ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/signed_form/gate_keeper.rb', line 19 def extract_and_verify_form_signature data, signature = @params['form_signature'].split('--', 2) hmac = SignedForm::HMAC.new secret_key: SignedForm.secret_key signature ||= '' raise Errors::InvalidSignature, "Form signature is not valid" unless hmac.verify signature, data @allowed_attributes = Marshal.load Base64.strict_decode64(data) @options = allowed_attributes.delete(:_options_) end |
#options ⇒ Object
15 16 17 |
# File 'lib/signed_form/gate_keeper.rb', line 15 def @options ||= {} end |
#verify_destination ⇒ Object
31 32 33 34 35 36 |
# File 'lib/signed_form/gate_keeper.rb', line 31 def verify_destination return unless [:method] && [:url] raise Errors::InvalidURL if [:method].to_s.casecmp(@request.request_method) != 0 url = @controller.url_for([:url]) raise Errors::InvalidURL if url != @request.fullpath && url != @request.url end |
#verify_digest ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/signed_form/gate_keeper.rb', line 38 def verify_digest return unless [:digest] return if [:digest_expiration] && Time.now < [:digest_expiration] digestor = [:digest] given_digest = digestor.to_s digestor.view_paths = @controller.view_paths.map(&:to_s) digestor.refresh raise Errors::ExpiredForm unless given_digest == digestor.to_s end |