スマホにおけるルート証明書について

ルート証明書とは

端末に予め登録されている「信頼できる認証局」の証明書のこと。SSLによる暗号化通信時に使われるもの。

役割

例: 社内システムで自社端末のみルート証明書を登録しておくことで、社内のサーバにアクセスできる端末を限定可能。

動作原理

1. 端末・ウェブサーバ間で暗号化仕様交渉を行う
2. ウェブサーバは自分自身を証明するSSLサーバ証明書を端末へ送る。端末はSSLサーバ証明書を受け取り、ルート証明書を用いて署名検証を行う。同時にSSLサーバ証明書からウェブサーバの公開鍵を取得
3. 署名検証が完了したら端末はプリマスタシークレットを暗号化し、ウェブサーバへ送る。ウェブサーバは秘密鍵を用いてプリマスタシークレットを復号
4. プリマスタシークレットを元に共通鍵を生成し、以降のセッションでは共通鍵を用いて暗号化・復号して通信を行う。

Sequel ProでMySQLにログインできない

Sequel ProからローカルのMySQLに接続しようとしたところ次のエラーが発生。。

f:id:hoooori:20190313220807p:plain

MySQLの認証プラグインcaching_sha2_passwordにSqquel Proが対応していないことが問題みたい。 ということでMySQLの設定を弄る。

mysql -u root

mysql> select host, user, plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | caching_sha2_password |
+-----------+------------------+-----------------------+

mysql> ALTER USER 'root'@"localhost" IDENTIFIED WITH mysql_native_password BY '';
ERROR 3009 (HY000): Column count of mysql.user is wrong. Expected 51, found 49. Created with MySQL 80012, now running 80015. Please use mysql_upgrade to fix this error.

ここでまたもや問題発生。 mysql_upgradeを実行しろとのこと。

mysql_upgrade -u root

~~~~ 省略 ~~~~
taskleaf_development.tasks                         OK
taskleaf_development.users                         OK
Upgrade process completed successfully.
Checking if update is needed.

気を取り直して再度実行。

mysql> ALTER USER 'root'@"localhost" IDENTIFIED WITH mysql_native_password BY '';
Query OK, 0 rows affected (0.01 sec)

mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> select host, user, plugin from mysql.user;
+-----------+------------------+-----------------------+
| host      | user             | plugin                |
+-----------+------------------+-----------------------+
| localhost | mysql.infoschema | caching_sha2_password |
| localhost | mysql.session    | caching_sha2_password |
| localhost | mysql.sys        | caching_sha2_password |
| localhost | root             | mysql_native_password |
+-----------+------------------+-----------------------+

その後、Sequel ProからMySQLに問題なく接続できた。 めでたしめでたし。

参考文献

yuap.jp

firegoby.jp

Formで自動挿入されるエラー出力タグ<div class="field-with-errors"></div>をどうにかしたい

Railsはフォームでバリデーションエラーが発生すると、 自動でタグをを出力するんだけど、結果的にフォームのレイアウトが崩れてしまう。 これを防ぐには次のコードをconfig/application.rbに追加すれば良い。

config.action_view.field_error_proc = Proc.new do |html_tag, instance|
  %Q(#{html_tag}).html_safe
end

上記は、divタグの挿入自体を向こうにする為のもの。 他にもいろいろカスタマイズできるらしい。

参考文献

blog.naichilab.com

qiita.com

I18nをファイル分割して管理する

アプリケーションをI18n対応する際、1つのyamlファイル(ja.yml)に内容を追加していくと管理が大変になるので、 ファイル分割する方法について調べてみた。

morizyun.github.io

複数のロケールファイルを読み込むには次のコードをconfig/application.rbに追加すれば良い。

config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]

追加後のapplication.rbがこちら

require_relative 'boot'
require 'rails/all'

# Require the gems listed in Gemfile, including any gems
# you've limited to :test, :development, or :production.
Bundler.require(*Rails.groups)

module Media
  class Application < Rails::Application
    # Initialize configuration defaults for originally generated Rails version.
    config.load_defaults 5.2
    config.i18n.default_locale = :ja
    config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
    # Settings in config/environments/* take precedence over those specified here.
    # Application configuration can go into files in config/initializers
    # -- all .rb files in that directory are automatically loaded after loading
    # the framework and any gems in your application.
  end
end

これでいつも通りI18n.t('hoge.foo.bar')I18nが使えます。