acts_as_securely_transferable 0.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.
- data/js/acts_as_securely_transferable.js +30 -0
 - data/lib/acts_as_securely_transferable.rb +14 -0
 - data/lib/acts_as_securely_transferable/acts_as_securely_transferable.rb +43 -0
 - data/lib/acts_as_securely_transferable/configuration.rb +11 -0
 - data/lib/acts_as_securely_transferable/form_helper.rb +18 -0
 - metadata +86 -0
 
| 
         @@ -0,0 +1,30 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            var ActsAsSecurelyTransferable = {
         
     | 
| 
      
 2 
     | 
    
         
            +
              encryptForm: function(form) {
         
     | 
| 
      
 3 
     | 
    
         
            +
                // find model name
         
     | 
| 
      
 4 
     | 
    
         
            +
                var model;
         
     | 
| 
      
 5 
     | 
    
         
            +
                $('input', form).each(function(i,e) {
         
     | 
| 
      
 6 
     | 
    
         
            +
                  var m = $(e).attr('name').match(/^(.+)\[public_modulus\]$/);
         
     | 
| 
      
 7 
     | 
    
         
            +
                  if (m) model = m[1];
         
     | 
| 
      
 8 
     | 
    
         
            +
                });
         
     | 
| 
      
 9 
     | 
    
         
            +
             
     | 
| 
      
 10 
     | 
    
         
            +
                if (model == undefined) {
         
     | 
| 
      
 11 
     | 
    
         
            +
                  alert("encryptForm(): Couldn't find model");
         
     | 
| 
      
 12 
     | 
    
         
            +
                  return false;
         
     | 
| 
      
 13 
     | 
    
         
            +
                }
         
     | 
| 
      
 14 
     | 
    
         
            +
             
     | 
| 
      
 15 
     | 
    
         
            +
                var rsa = new RSAKey();
         
     | 
| 
      
 16 
     | 
    
         
            +
                rsa.setPublic($('#'+model+'_public_modulus').val(), $('#'+model+'_public_exponent').val());
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
                $('input', form).each(function(i,elem) {
         
     | 
| 
      
 19 
     | 
    
         
            +
                  if (elem.id) {
         
     | 
| 
      
 20 
     | 
    
         
            +
                    var m = elem.id.match(/^(.+)_encrypted$/);
         
     | 
| 
      
 21 
     | 
    
         
            +
                    if (m) {
         
     | 
| 
      
 22 
     | 
    
         
            +
                      $(elem).val(hex2b64(rsa.encrypt($('#'+m[1]).val())));
         
     | 
| 
      
 23 
     | 
    
         
            +
                      $('#'+m[1]).val('');
         
     | 
| 
      
 24 
     | 
    
         
            +
                    }
         
     | 
| 
      
 25 
     | 
    
         
            +
                  }
         
     | 
| 
      
 26 
     | 
    
         
            +
                });
         
     | 
| 
      
 27 
     | 
    
         
            +
             
     | 
| 
      
 28 
     | 
    
         
            +
                return true;
         
     | 
| 
      
 29 
     | 
    
         
            +
              }
         
     | 
| 
      
 30 
     | 
    
         
            +
            }
         
     | 
| 
         @@ -0,0 +1,14 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            require 'acts_as_securely_transferable/acts_as_securely_transferable'
         
     | 
| 
      
 2 
     | 
    
         
            +
            require 'acts_as_securely_transferable/form_helper'
         
     | 
| 
      
 3 
     | 
    
         
            +
             
     | 
| 
      
 4 
     | 
    
         
            +
            module ActsAsSecurelyTransferable
         
     | 
| 
      
 5 
     | 
    
         
            +
              def self.configuration
         
     | 
| 
      
 6 
     | 
    
         
            +
                @configuration ||= Configuration.new
         
     | 
| 
      
 7 
     | 
    
         
            +
              end
         
     | 
| 
      
 8 
     | 
    
         
            +
             
     | 
| 
      
 9 
     | 
    
         
            +
              def self.configure
         
     | 
| 
      
 10 
     | 
    
         
            +
                yield(configuration)
         
     | 
| 
      
 11 
     | 
    
         
            +
              end
         
     | 
| 
      
 12 
     | 
    
         
            +
            end
         
     | 
| 
      
 13 
     | 
    
         
            +
             
     | 
| 
      
 14 
     | 
    
         
            +
            ActiveRecord::Base.send :include, ActsAsSecurelyTransferable::ActsAsSecurelyTransferable
         
     | 
| 
         @@ -0,0 +1,43 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module ActsAsSecurelyTransferable
         
     | 
| 
      
 2 
     | 
    
         
            +
              module ActsAsSecurelyTransferable
         
     | 
| 
      
 3 
     | 
    
         
            +
                def self.included(base)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  base.send :extend, ClassMethods
         
     | 
| 
      
 5 
     | 
    
         
            +
                end
         
     | 
| 
      
 6 
     | 
    
         
            +
             
     | 
| 
      
 7 
     | 
    
         
            +
                module ClassMethods
         
     | 
| 
      
 8 
     | 
    
         
            +
                  def acts_as_securely_transferable(*fields)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    cattr_accessor :secure_fields
         
     | 
| 
      
 10 
     | 
    
         
            +
                    self.secure_fields = fields.is_a?(Array) ? fields : [ fields ]
         
     | 
| 
      
 11 
     | 
    
         
            +
             
     | 
| 
      
 12 
     | 
    
         
            +
                    for field in self.secure_fields
         
     | 
| 
      
 13 
     | 
    
         
            +
                      define_method "#{field}_encrypted" do
         
     | 
| 
      
 14 
     | 
    
         
            +
                        nil
         
     | 
| 
      
 15 
     | 
    
         
            +
                      end
         
     | 
| 
      
 16 
     | 
    
         
            +
                      define_method "#{field}_encrypted=" do |value|
         
     | 
| 
      
 17 
     | 
    
         
            +
                        send "#{field}=", ::ActsAsSecurelyTransferable.configuration.rsa_key.private_decrypt(Base64.decode64(value))
         
     | 
| 
      
 18 
     | 
    
         
            +
                      end
         
     | 
| 
      
 19 
     | 
    
         
            +
                    end
         
     | 
| 
      
 20 
     | 
    
         
            +
             
     | 
| 
      
 21 
     | 
    
         
            +
                    send :include, InstanceMethods
         
     | 
| 
      
 22 
     | 
    
         
            +
                  end
         
     | 
| 
      
 23 
     | 
    
         
            +
                end
         
     | 
| 
      
 24 
     | 
    
         
            +
             
     | 
| 
      
 25 
     | 
    
         
            +
                module InstanceMethods
         
     | 
| 
      
 26 
     | 
    
         
            +
                  def public_exponent
         
     | 
| 
      
 27 
     | 
    
         
            +
                    ::ActsAsSecurelyTransferable.configuration.rsa_key.public_key.e.to_s(16)
         
     | 
| 
      
 28 
     | 
    
         
            +
                  end
         
     | 
| 
      
 29 
     | 
    
         
            +
             
     | 
| 
      
 30 
     | 
    
         
            +
                  def public_exponent=(value)
         
     | 
| 
      
 31 
     | 
    
         
            +
                    errors.add_to_base "public exponent has changed" if value != public_exponent
         
     | 
| 
      
 32 
     | 
    
         
            +
                  end
         
     | 
| 
      
 33 
     | 
    
         
            +
             
     | 
| 
      
 34 
     | 
    
         
            +
                  def public_modulus
         
     | 
| 
      
 35 
     | 
    
         
            +
                    ::ActsAsSecurelyTransferable.configuration.rsa_key.public_key.n.to_s(16)
         
     | 
| 
      
 36 
     | 
    
         
            +
                  end
         
     | 
| 
      
 37 
     | 
    
         
            +
             
     | 
| 
      
 38 
     | 
    
         
            +
                  def public_modulus=(value)
         
     | 
| 
      
 39 
     | 
    
         
            +
                    errors.add_to_base "public modulus has changed" if value != public_modulus
         
     | 
| 
      
 40 
     | 
    
         
            +
                  end
         
     | 
| 
      
 41 
     | 
    
         
            +
                end
         
     | 
| 
      
 42 
     | 
    
         
            +
              end
         
     | 
| 
      
 43 
     | 
    
         
            +
            end
         
     | 
| 
         @@ -0,0 +1,18 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            module ActsAsSecurelyTransferable
         
     | 
| 
      
 2 
     | 
    
         
            +
              module FormHelper
         
     | 
| 
      
 3 
     | 
    
         
            +
                def securely_transferable_form_for(*args, &block)
         
     | 
| 
      
 4 
     | 
    
         
            +
                  options = args.last.is_a?(Hash) ? args.pop : { }
         
     | 
| 
      
 5 
     | 
    
         
            +
                  options = options.merge({ :html => { :onsubmit => 'return ActsAsSecurelyTransferable.encryptForm(this);' } })
         
     | 
| 
      
 6 
     | 
    
         
            +
                  form_for args, options do |f|
         
     | 
| 
      
 7 
     | 
    
         
            +
                    concat f.hidden_field(:public_modulus)
         
     | 
| 
      
 8 
     | 
    
         
            +
                    concat f.hidden_field(:public_exponent)
         
     | 
| 
      
 9 
     | 
    
         
            +
                    for field in f.object_name.camelize.constantize.secure_fields
         
     | 
| 
      
 10 
     | 
    
         
            +
                      concat f.hidden_field("#{field}_encrypted")
         
     | 
| 
      
 11 
     | 
    
         
            +
                    end
         
     | 
| 
      
 12 
     | 
    
         
            +
                    block.call(f)
         
     | 
| 
      
 13 
     | 
    
         
            +
                  end
         
     | 
| 
      
 14 
     | 
    
         
            +
                end
         
     | 
| 
      
 15 
     | 
    
         
            +
              end
         
     | 
| 
      
 16 
     | 
    
         
            +
            end
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            ActionView::Base.send :include, ActsAsSecurelyTransferable::FormHelper
         
     | 
    
        metadata
    ADDED
    
    | 
         @@ -0,0 +1,86 @@ 
     | 
|
| 
      
 1 
     | 
    
         
            +
            --- !ruby/object:Gem::Specification 
         
     | 
| 
      
 2 
     | 
    
         
            +
            name: acts_as_securely_transferable
         
     | 
| 
      
 3 
     | 
    
         
            +
            version: !ruby/object:Gem::Version 
         
     | 
| 
      
 4 
     | 
    
         
            +
              hash: 29
         
     | 
| 
      
 5 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 6 
     | 
    
         
            +
              segments: 
         
     | 
| 
      
 7 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 8 
     | 
    
         
            +
              - 0
         
     | 
| 
      
 9 
     | 
    
         
            +
              - 1
         
     | 
| 
      
 10 
     | 
    
         
            +
              version: 0.0.1
         
     | 
| 
      
 11 
     | 
    
         
            +
            platform: ruby
         
     | 
| 
      
 12 
     | 
    
         
            +
            authors: 
         
     | 
| 
      
 13 
     | 
    
         
            +
            - Richard Hirner
         
     | 
| 
      
 14 
     | 
    
         
            +
            autorequire: 
         
     | 
| 
      
 15 
     | 
    
         
            +
            bindir: bin
         
     | 
| 
      
 16 
     | 
    
         
            +
            cert_chain: []
         
     | 
| 
      
 17 
     | 
    
         
            +
             
     | 
| 
      
 18 
     | 
    
         
            +
            date: 2011-08-11 00:00:00 +02:00
         
     | 
| 
      
 19 
     | 
    
         
            +
            default_executable: 
         
     | 
| 
      
 20 
     | 
    
         
            +
            dependencies: 
         
     | 
| 
      
 21 
     | 
    
         
            +
            - !ruby/object:Gem::Dependency 
         
     | 
| 
      
 22 
     | 
    
         
            +
              name: rails
         
     | 
| 
      
 23 
     | 
    
         
            +
              prerelease: false
         
     | 
| 
      
 24 
     | 
    
         
            +
              requirement: &id001 !ruby/object:Gem::Requirement 
         
     | 
| 
      
 25 
     | 
    
         
            +
                none: false
         
     | 
| 
      
 26 
     | 
    
         
            +
                requirements: 
         
     | 
| 
      
 27 
     | 
    
         
            +
                - - ">="
         
     | 
| 
      
 28 
     | 
    
         
            +
                  - !ruby/object:Gem::Version 
         
     | 
| 
      
 29 
     | 
    
         
            +
                    hash: 7
         
     | 
| 
      
 30 
     | 
    
         
            +
                    segments: 
         
     | 
| 
      
 31 
     | 
    
         
            +
                    - 3
         
     | 
| 
      
 32 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 33 
     | 
    
         
            +
                    - 0
         
     | 
| 
      
 34 
     | 
    
         
            +
                    version: 3.0.0
         
     | 
| 
      
 35 
     | 
    
         
            +
              type: :runtime
         
     | 
| 
      
 36 
     | 
    
         
            +
              version_requirements: *id001
         
     | 
| 
      
 37 
     | 
    
         
            +
            description: 
         
     | 
| 
      
 38 
     | 
    
         
            +
            email: hirner@bitfire.at
         
     | 
| 
      
 39 
     | 
    
         
            +
            executables: []
         
     | 
| 
      
 40 
     | 
    
         
            +
             
     | 
| 
      
 41 
     | 
    
         
            +
            extensions: []
         
     | 
| 
      
 42 
     | 
    
         
            +
             
     | 
| 
      
 43 
     | 
    
         
            +
            extra_rdoc_files: []
         
     | 
| 
      
 44 
     | 
    
         
            +
             
     | 
| 
      
 45 
     | 
    
         
            +
            files: 
         
     | 
| 
      
 46 
     | 
    
         
            +
            - lib/acts_as_securely_transferable.rb
         
     | 
| 
      
 47 
     | 
    
         
            +
            - lib/acts_as_securely_transferable/configuration.rb
         
     | 
| 
      
 48 
     | 
    
         
            +
            - lib/acts_as_securely_transferable/acts_as_securely_transferable.rb
         
     | 
| 
      
 49 
     | 
    
         
            +
            - lib/acts_as_securely_transferable/form_helper.rb
         
     | 
| 
      
 50 
     | 
    
         
            +
            - js/acts_as_securely_transferable.js
         
     | 
| 
      
 51 
     | 
    
         
            +
            has_rdoc: true
         
     | 
| 
      
 52 
     | 
    
         
            +
            homepage: 
         
     | 
| 
      
 53 
     | 
    
         
            +
            licenses: []
         
     | 
| 
      
 54 
     | 
    
         
            +
             
     | 
| 
      
 55 
     | 
    
         
            +
            post_install_message: 
         
     | 
| 
      
 56 
     | 
    
         
            +
            rdoc_options: []
         
     | 
| 
      
 57 
     | 
    
         
            +
             
     | 
| 
      
 58 
     | 
    
         
            +
            require_paths: 
         
     | 
| 
      
 59 
     | 
    
         
            +
            - lib
         
     | 
| 
      
 60 
     | 
    
         
            +
            required_ruby_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 61 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 62 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 63 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 64 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 65 
     | 
    
         
            +
                  hash: 3
         
     | 
| 
      
 66 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 67 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 68 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 69 
     | 
    
         
            +
            required_rubygems_version: !ruby/object:Gem::Requirement 
         
     | 
| 
      
 70 
     | 
    
         
            +
              none: false
         
     | 
| 
      
 71 
     | 
    
         
            +
              requirements: 
         
     | 
| 
      
 72 
     | 
    
         
            +
              - - ">="
         
     | 
| 
      
 73 
     | 
    
         
            +
                - !ruby/object:Gem::Version 
         
     | 
| 
      
 74 
     | 
    
         
            +
                  hash: 3
         
     | 
| 
      
 75 
     | 
    
         
            +
                  segments: 
         
     | 
| 
      
 76 
     | 
    
         
            +
                  - 0
         
     | 
| 
      
 77 
     | 
    
         
            +
                  version: "0"
         
     | 
| 
      
 78 
     | 
    
         
            +
            requirements: []
         
     | 
| 
      
 79 
     | 
    
         
            +
             
     | 
| 
      
 80 
     | 
    
         
            +
            rubyforge_project: 
         
     | 
| 
      
 81 
     | 
    
         
            +
            rubygems_version: 1.3.7
         
     | 
| 
      
 82 
     | 
    
         
            +
            signing_key: 
         
     | 
| 
      
 83 
     | 
    
         
            +
            specification_version: 3
         
     | 
| 
      
 84 
     | 
    
         
            +
            summary: On-the-fly RSA encryption for secure transmission of forms/resources over non-secure connection
         
     | 
| 
      
 85 
     | 
    
         
            +
            test_files: []
         
     | 
| 
      
 86 
     | 
    
         
            +
             
     |