activesupport错误,因为'cipher.key'= @secret的密钥必须是32个字节

时间:2017-03-14 15:50:12

标签: ruby-on-rails ruby openssl activesupport

我在Consul app上工作,我在this branche添加了一个SSO模块,用于连接另一个网站,其中加密的URL使用gem Openssl和AesEncryptDecrypt类创建

  class AesEncryptDecrypt
  SSOKEY = '12345678901234567890123456789012'
  CIPHER_METHOD = 'AES-256-CBC'

  def self.ssoencrypt(str)
    cipher = OpenSSL::Cipher.new(CIPHER_METHOD)
    cipher.encrypt
    cipher.key = SSOKEY
    data = cipher.update(str) + cipher.final
    return Base64.urlsafe_encode64(data)
  end
  def self.ssodecrypt(str)
    data = Base64.urlsafe_decode64(str)
    cipher = OpenSSL::Cipher.new(CIPHER_METHOD)
    cipher.decrypt
    cipher.key = SSOKEY
    return cipher.update(data) + cipher.final
  end
end

由于我添加了这个模块,因此我无法访问我的应用,因为我在activesupport中有错误,因为'cipher.key'的密钥必须是32个字节= @secret

这是当地合作中的痕迹:

    Started GET "/" for ::1 at 2017-03-14 16:27:45 +0100
Processing by BudgetsController#index as HTML
   (7.1ms)  SELECT "settings"."value" FROM "settings" WHERE "settings"."key" = $1  ORDER BY "settings"."id" ASC  [["key", "feature.budgets"]]
  Budget Load (11.8ms)  SELECT  "budgets".* FROM "budgets" WHERE "budgets"."id" = $1 LIMIT 1  [["id", 1]]
  CACHE (0.0ms)  SELECT  "budgets".* FROM "budgets" WHERE "budgets"."id" = $1 LIMIT 1  [["id", 1]]
  Budget::Heading Load (0.9ms)  SELECT "budget_headings".* FROM "budget_headings" INNER JOIN "budget_groups" ON "budget_headings"."group_id" = "budget_groups"."id" WHERE "budget_groups"."budget_id" = $1  [["budget_id", 1]]
  Budget::Ballot Load (6.3ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  CACHE (0.0ms)  SELECT  "budget_ballots".* FROM "budget_ballots" WHERE "budget_ballots"."user_id" IS NULL AND "budget_ballots"."budget_id" = 1  ORDER BY "budget_ballots"."id" ASC LIMIT 1
  Rendered budgets/investments/_home_rivp.html.erb (72.2ms)
  Budget Load (2.3ms)  SELECT "budgets".* FROM "budgets" WHERE ('t'='t')  ORDER BY "budgets"."created_at" ASC
  Rendered budgets/index.html.erb within layouts/application (84.6ms)
  Rendered layouts/_tracking_data.html.erb (0.7ms)
  Setting Load (1.3ms)  SELECT "settings".* FROM "settings"  ORDER BY "settings"."id" ASC
  Rendered layouts/_meta_tags.html.erb (10.5ms)
  Rendered shared/_locale_switcher.html.erb (1.3ms)
  Rendered shared/_top_links.html.erb (4.3ms)
  Rendered shared/_admin_login_items.html.erb (0.6ms)
  Rendered devise/menu/_login_items.html.erb (1.0ms)
  Rendered shared/_subnavigation.html.erb (1.2ms)
  Rendered shared/_subnavigation.html.erb (0.7ms)
  Rendered layouts/_header.html.erb (19.5ms)
  Rendered layouts/_flash.html.erb (1.6ms)
  Rendered layouts/_footer.html.erb (1.4ms)
Completed 200 OK in 607ms (Views: 502.6ms | ActiveRecord: 29.9ms)
/usr/local/opt/rbenv/versions/2.3.2/lib/ruby/gems/2.3.0/gems/activesupport-4.2.7.1/lib/active_support/message_encryptor.rb:100: warning: constant OpenSSL::Cipher::Cipher is deprecated

ArgumentError (key must be 32 bytes):
  activesupport (4.2.7.1) lib/active_support/message_encryptor.rb:72:in `key='
  activesupport (4.2.7.1) lib/active_support/message_encryptor.rb:72:in `_encrypt'
  activesupport (4.2.7.1) lib/active_support/message_encryptor.rb:58:in `encrypt_and_sign'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/cookies.rb:527:in `[]='
  actionpack (4.2.7.1) lib/action_dispatch/middleware/session/cookie_store.rb:110:in `set_cookie'
  rack (1.6.5) lib/rack/session/abstract/id.rb:351:in `commit_session'
  rack (1.6.5) lib/rack/session/abstract/id.rb:226:in `context'
  rack (1.6.5) lib/rack/session/abstract/id.rb:220:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/cookies.rb:560:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activerecord (4.2.7.1) lib/active_record/query_cache.rb:36:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activerecord (4.2.7.1) lib/active_record/connection_adapters/abstract/connection_pool.rb:653:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activerecord (4.2.7.1) lib/active_record/migration.rb:377:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:29:in `block in call'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:88:in `__run_callbacks__'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:778:in `_run_call_callbacks'
  activesupport (4.2.7.1) lib/active_support/callbacks.rb:81:in `run_callbacks'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/callbacks.rb:27:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/reloader.rb:73:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/remote_ip.rb:78:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rollbar (2.14.0) lib/rollbar/middleware/rails/rollbar.rb:24:in `block in call'
  rollbar (2.14.0) lib/rollbar.rb:145:in `scoped'
  rollbar (2.14.0) lib/rollbar/middleware/rails/rollbar.rb:22:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/debug_exceptions.rb:17:in `call'
  rollbar (2.14.0) lib/rollbar/middleware/rails/show_exceptions.rb:22:in `call_with_rollbar'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  web-console (3.3.0) lib/web_console/middleware.rb:131:in `call_app'
  web-console (3.3.0) lib/web_console/middleware.rb:28:in `block in call'
  web-console (3.3.0) lib/web_console/middleware.rb:18:in `catch'
  web-console (3.3.0) lib/web_console/middleware.rb:18:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/show_exceptions.rb:30:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.7.1) lib/rails/rack/logger.rb:38:in `call_app'
  railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `block in call'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `block in tagged'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:26:in `tagged'
  activesupport (4.2.7.1) lib/active_support/tagged_logging.rb:68:in `tagged'
  railties (4.2.7.1) lib/rails/rack/logger.rb:20:in `call'
  ahoy_matey (1.5.3) lib/ahoy/engine.rb:22:in `call_with_quiet_ahoy'
  quiet_assets (1.1.0) lib/quiet_assets.rb:27:in `call_with_quiet_assets'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  request_store (1.3.1) lib/request_store/middleware.rb:9:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/request_id.rb:21:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.5) lib/rack/methodoverride.rb:22:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.5) lib/rack/runtime.rb:18:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  activesupport (4.2.7.1) lib/active_support/cache/strategy/local_cache_middleware.rb:28:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.5) lib/rack/lock.rb:17:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  actionpack (4.2.7.1) lib/action_dispatch/middleware/static.rb:120:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.5) lib/rack/sendfile.rb:113:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  railties (4.2.7.1) lib/rails/engine.rb:518:in `call'
  railties (4.2.7.1) lib/rails/application.rb:165:in `call'
  newrelic_rpm (3.17.2.327) lib/new_relic/agent/instrumentation/middleware_tracing.rb:96:in `call'
  rack (1.6.5) lib/rack/lock.rb:17:in `call'
  rack (1.6.5) lib/rack/content_length.rb:15:in `call'
  rack (1.6.5) lib/rack/handler/webrick.rb:88:in `service'
  /usr/local/opt/rbenv/versions/2.3.2/lib/ruby/2.3.0/webrick/httpserver.rb:140:in `service'
  /usr/local/opt/rbenv/versions/2.3.2/lib/ruby/2.3.0/webrick/httpserver.rb:96:in `run'
  /usr/local/opt/rbenv/versions/2.3.2/lib/ruby/2.3.0/webrick/server.rb:296:in `block in start_thread'

Picture of trace

我的BudgetController是:

class BudgetsController < ApplicationController
  include FeatureFlags
  feature_flag :budgets

  load_and_authorize_resource
  respond_to :html, :js

  def show
  end

  def index
    @budgets = @budgets.order(:created_at)
  end

end

你有什么想要帮助我吗?

我的环境是: Ruby 2.3.2 / Rails 4.2.7.1 / OpenSSL 0.9.8zh 2016年1月14日/ activesupport 4.2.7.1

0 个答案:

没有答案