20200917のPHPに関する記事は7件です。

Laravelでログインユーザーメールアドレスを暗号化して保存する

Laravelのユーザー登録に関してですが、
パスワードはハッシュ化して保存されますが、メールアドレスはプレーンテキストで保存されるため、
セキュリティ強化で暗号化して保存させます。

まずはユーザーモデルのメールアドレスを取り出すときに自動で暗号化/復号化されるように設定します。

app/Models/User.php
    public function getEmailAttribute($value)
    {
        return openssl_decrypt($value, 'AES-128-ECB', '暗号化キー');
       }
    public function setEmailAttribute($value)
    {

        $this->attributes['email'] = openssl_encrypt($value, 'AES-128-ECB', '暗号化キー'));
    }

次にログイン時のメールアドレスのチェックに関してですが、そのままだと暗号化前のメールアドレスと、暗号化された文字列でログインチェックがなされるのでログインできません。
そこで、ログインチェックの前にメールアドレスを暗号化してあげます。

app/Http/Controllers/Auth/LoginController.php
    protected function credentials(Request $request)
    {
        $request->merge(['email' => openssl_encrypt($request->input('email'), 'AES-128-ECB', '暗号化キー')]);

        return $request->only($this->username(), 'password');
    }

これでログインまでできるはずです。
デフォルトのままだと、ログイン失敗した後、暗号化されたメールアドレスが表示されてしまいますので適当に修正してください。

暗号化で毎回同じ文字列が作成されるためセキュリティ的にはそんなに大丈夫なわけではありませんが、平文で保存するよりはましかと思います。
また暗号化のアルゴリズムに関してですが、可逆式で毎回同じ結果で暗号化する必要があります。
Crypt::encryptStringは毎回異なる結果になるのでログイン時の処理にもうひと手間かける必要があります。

おわり。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

phpMyAdminが対応するPHPとMySQLのバージョン

phpMyAdmin PHP MySQL
5.0.2 7.1 and newer 5.5 and newer
5.0.1 7.1 and newer 5.5 and newer
5.0.0 7.1 and newer 5.5 and newer
5.0.0-rc1 7.1 and newer 5.5 and newer
5.0.0-alpha1 7.1 and newer 5.5 and newer
4.9.5 5.5 to 7.4 5.5 and newer
4.9.4 5.5 to 7.4 5.5 and newer
4.9.3 5.5 to 7.4 5.5 and newer
4.9.2 5.5 to 7.4 5.5 and newer
4.9.1 5.5 to 7.4 5.5 and newer
4.9.0.1 5.5 to 7.4 5.5 and newer
4.9.0 5.5 to 7.4 5.5 and newer
4.8.5 5.5 to 7.2 5.5 and newer
4.8.4 5.5 to 7.2 5.5 and newer
4.8.3 5.5 to 7.2 5.5 and newer
4.8.2 5.5 to 7.2 5.5 and newer
4.8.1 5.5 to 7.2 5.5 and newer
4.8.0.1 5.5 to 7.2 5.5 and newer
4.8.0 5.5 to 7.2 5.5 and newer
4.8.0-rc1 5.5 to 7.2 5.5 and newer
4.8.0-alpha1 5.5 to 7.2 5.5 and newer
4.7.9 5.5 to 7.2 5.5 and newer
4.7.8 5.5 to 7.2 5.5 and newer
4.7.7 5.5 to 7.2 5.5 and newer
4.7.6 5.5 to 7.2 5.5 and newer
4.7.5 5.5 to 7.2 5.5 and newer
4.7.4 5.5 to 7.2 5.5 and newer
4.7.3 5.5 to 7.1 5.5 and newer
4.7.2 5.5 to 7.1 5.5 and newer
4.7.1 5.5 to 7.1 5.5 and newer
4.7.0 5.5 to 7.1 5.5 and newer
4.7.0-rc1 5.5 to 7.1 5.5 and newer
4.7.0-beta1 5.5 to 7.1 5.5 and newer
4.6.6 5.5 to 7.1 5.5 and newer
4.6.5.2 5.5 to 7.1 5.5 and newer
4.6.5.1 5.5 to 7.1 5.5 and newer
4.6.5 5.5 to 7.1 5.5 and newer
4.6.4 5.5 to 7.1 5.5 and newer
4.6.3 5.5 to 7.1 5.5 and newer
4.6.2 5.5 to 7.1 5.5 and newer
4.6.1 5.5 to 7.1 5.5 and newer
4.6.0 5.5 to 7.1 5.5 and newer
4.6.0-rc2 5.5 to 7.1 5.5 and newer
4.6.0-rc1 5.5 to 7.1 5.5 and newer
4.6.0-alpha1 5.5 to 7.1 5.5 and newer
4.5.5.1 5.5 to 7.0 5.5
4.5.5 5.5 to 7.0 5.5
4.5.4.1 5.5 to 7.0 5.5
4.5.4 5.5 to 7.0 5.5
4.5.3.1 5.5 to 7.0 5.5
4.5.3 5.5 to 7.0 5.5
4.5.2 5.5 to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.5
4.3.0 5.3 5.5
4.2.13.3 5.3 5.5
4.2.13.2 5.3 5.5
4.2.13.1 5.3 5.5
4.2.13 5.3 5.5
4.2.12 5.3 5.5
4.2.11 5.3 5.5
4.2.10.1 5.3 5.5
4.2.10 5.3 5.5
4.2.9.1 5.3 5.5
4.2.9 5.3 5.5
4.2.8.1 5.3 5.5
4.2.8 5.3 5.5
4.2.7.1 5.3 5.5
4.2.7 5.3 5.5
4.2.6 5.3 5.5
4.2.5 5.3 5.5
4.2.4 5.3 5.5
4.2.3 5.3 5.5
4.2.2 5.3 5.5
4.2.1 5.3 5.5
4.2.0 5.3 5.5
4.1.14.8 5.3 5.5
4.1.14.7 5.3 5.5
4.1.14.6 5.3 5.5
4.1.14.5 5.3 5.5
4.1.14.4 5.3 5.5
4.1.14.3 5.3 5.5
4.1.14.2 5.3 5.5
4.1.14.1 5.3 5.5
4.1.14 5.3 5.5
4.1.13 5.3 5.5
4.1.12 5.3 5.5
4.1.11 5.3 5.5
4.1.10 5.3 5.5
4.1.9 5.3 5.5
4.1.8 5.3 5.5
4.1.7 5.3 5.5
4.1.6 5.3 5.5
4.1.5 5.3 5.5
4.1.4 5.3 5.5
4.1.3 5.3 5.5
4.1.2 5.3 5.5
4.1.1 5.3 5.5
4.1.0 5.3 5.5
4.0.10.20 5.2 (Does not support 5.5 or newer) 5
4.0.10.19 5.2 (Does not support 5.5 or newer) 5
4.0.10.18 5.2 (Does not support 5.5 or newer) 5
4.0.10.17 5.2 (Does not support 5.5 or newer) 5
4.0.10.16 5.2 (Does not support 5.5 or newer) 5
4.0.10.15 5.2 (Does not support 5.5 or newer) 5
4.0.10.14 5.2 (Does not support 5.5 or newer) 5
4.0.10.13 5.2 (Does not support 5.5 or newer) 5
4.0.10.12 5.2 (Does not support 5.5 or newer) 5
4.0.10.11 5.2 (Does not support 5.5 or newer) 5
4.0.10.10 5.2 (Does not support 5.5 or newer) 5
4.0.10.9 5.2 (Does not support 5.5 or newer) 5
4.0.10.8 5.2 (Does not support 5.5 or newer) 5
4.0.10.7 5.2 (Does not support 5.5 or newer) 5
4.0.10.6 5.2 (Does not support 5.5 or newer) 5
4.0.10.5 5.2 (Does not support 5.5 or newer) 5
4.0.10.4 5.2 (Does not support 5.5 or newer) 5
4.0.10.3 5.2 (Does not support 5.5 or newer) 5
4.0.10.2 5.2 (Does not support 5.5 or newer) 5
4.0.10.1 5.2 (Does not support 5.5 or newer) 5
4.0.10 5.2 (Does not support 5.5 or newer) 5
4.0.9 5.2 (Does not support 5.5 or newer) 5
4.0.8 5.2 (Does not support 5.5 or newer) 5
4.0.7 5.2 (Does not support 5.5 or newer) 5
4.0.6 5.2 (Does not support 5.5 or newer) 5
4.0.5 5.2 (Does not support 5.5 or newer) 5
4.0.4.2 5.2 (Does not support 5.5 or newer) 5
4.0.4.1 5.2 (Does not support 5.5 or newer) 5
4.0.4 5.2 (Does not support 5.5 or newer) 5
4.0.3 5.2 (Does not support 5.5 or newer) 5
4.0.2 5.2 (Does not support 5.5 or newer) 5
4.0.1 5.2 (Does not support 5.5 or newer) 5
4.0.0 5.2 (Does not support 5.5 or newer) 5
3.5.8.2 5.2 5
3.5.8.1 5.2 5
3.5.8 5.2 5
3.5.7 5.2 5
3.5.6 5.2 5
3.5.5 5.2 5
3.5.4 5.2 5
3.5.3 5.2 5
3.5.2.2 5.2 5
3.5.2.1 5.2 5
3.5.2 5.2 5
3.5.1 5.2 5
3.5.0 5.2 5
3.4.11.1 5.2 5
3.4.11 5.2 5
3.4.10.2 5.2 5
3.4.10.1 5.2 5
3.4.10 5.2 5
3.4.9 5.2 5
3.4.8 5.2 5
3.4.7.1 5.2 5
3.4.7 5.2 5
3.4.6 5.2 5
3.4.5 5.2 5
3.4.4 5.2 5
3.4.3.2 5.2 5
3.4.3.1 5.2 5
3.4.3 5.2 5
3.4.2 5.2 5
3.4.1 5.2 5
3.4.0 5.2 5
3.3.10.5 5.2 5
3.3.10.4 5.2 5
3.3.10.3 5.2 5
3.3.10.2 5.2 5
3.3.10.1 5.2 5
3.3.10 5.2 5
3.3.9.2 5.2 5
3.3.9.1 5.2 5
3.3.9 5.2 5
3.3.8.1 5.2 5
3.3.8 5.2 5
3.3.7 5.2 5
3.3.6 5.2 5
3.3.5.1 5.2 5
3.3.0 5.2 5
3.2.0 5.2 5
3.1.0 5.2 5
3.0.0 5.2 5
2.11.11.3 4+ 3+
2.11.11.2 4+ 3+
2.11.11.1 4+ 3+
2.11.11 4+ 3+
2.11.10.1 4+ 3+
2.10.3 4+ 3+
2.10.2 4+ 3+
2.9.0 4+ 3+
2.8.0 4+ 3+
2.7.0 4+ 3+
2.6.0 4+ 3+
2.5.0 4+ 3+
2.4.0 4+ 3+
2.3.0 4+ 3+
2.2.0 4+ 3+
2.1.0 4+ 3+
2.0.5 4+ 3+
1.3.1
1.3.0
1.2.0
1.1.0
0.9.0
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

phpMyAdminが対応するPHPとMySQLのバージョン一覧

phpMyAdmin PHP MySQL
5.0.2 7.1 and newer 5.5 and newer
5.0.1 7.1 and newer 5.5 and newer
5.0.0 7.1 and newer 5.5 and newer
5.0.0-rc1 7.1 and newer 5.5 and newer
5.0.0-alpha1 7.1 and newer 5.5 and newer
4.9.5 5.5 to 7.4 5.5 and newer
4.9.4 5.5 to 7.4 5.5 and newer
4.9.3 5.5 to 7.4 5.5 and newer
4.9.2 5.5 to 7.4 5.5 and newer
4.9.1 5.5 to 7.4 5.5 and newer
4.9.0.1 5.5 to 7.4 5.5 and newer
4.9.0 5.5 to 7.4 5.5 and newer
4.8.5 5.5 to 7.2 5.5 and newer
4.8.4 5.5 to 7.2 5.5 and newer
4.8.3 5.5 to 7.2 5.5 and newer
4.8.2 5.5 to 7.2 5.5 and newer
4.8.1 5.5 to 7.2 5.5 and newer
4.8.0.1 5.5 to 7.2 5.5 and newer
4.8.0 5.5 to 7.2 5.5 and newer
4.8.0-rc1 5.5 to 7.2 5.5 and newer
4.8.0-alpha1 5.5 to 7.2 5.5 and newer
4.7.9 5.5 to 7.2 5.5 and newer
4.7.8 5.5 to 7.2 5.5 and newer
4.7.7 5.5 to 7.2 5.5 and newer
4.7.6 5.5 to 7.2 5.5 and newer
4.7.5 5.5 to 7.2 5.5 and newer
4.7.4 5.5 to 7.2 5.5 and newer
4.7.3 5.5 to 7.1 5.5 and newer
4.7.2 5.5 to 7.1 5.5 and newer
4.7.1 5.5 to 7.1 5.5 and newer
4.7.0 5.5 to 7.1 5.5 and newer
4.7.0-rc1 5.5 to 7.1 5.5 and newer
4.7.0-beta1 5.5 to 7.1 5.5 and newer
4.6.6 5.5 to 7.1 5.5 and newer
4.6.5.2 5.5 to 7.1 5.5 and newer
4.6.5.1 5.5 to 7.1 5.5 and newer
4.6.5 5.5 to 7.1 5.5 and newer
4.6.4 5.5 to 7.1 5.5 and newer
4.6.3 5.5 to 7.1 5.5 and newer
4.6.2 5.5 to 7.1 5.5 and newer
4.6.1 5.5 to 7.1 5.5 and newer
4.6.0 5.5 to 7.1 5.5 and newer
4.6.0-rc2 5.5 to 7.1 5.5 and newer
4.6.0-rc1 5.5 to 7.1 5.5 and newer
4.6.0-alpha1 5.5 to 7.1 5.5 and newer
4.5.5.1 5.5 to 7.0 5.5
4.5.5 5.5 to 7.0 5.5
4.5.4.1 5.5 to 7.0 5.5
4.5.4 5.5 to 7.0 5.5
4.5.3.1 5.5 to 7.0 5.5
4.5.3 5.5 to 7.0 5.5
4.5.2 5.5 to 7.0 5.5
4.5.1 5.5 to 7.0 5.5
4.5.0.2 5.5 to 7.0 5.5
4.5.0.1 5.5 to 7.0 5.5
4.5.0 5.5 to 7.0 5.5
4.4.15.10 5.3.7 to 7.0 5.5
4.4.15.9 5.3.7 to 7.0 5.5
4.4.15.8 5.3.7 to 7.0 5.5
4.4.15.7 5.3.7 to 7.0 5.5
4.4.15.6 5.3.7 to 7.0 5.5
4.4.15.5 5.3.7 to 7.0 5.5
4.4.15.4 5.3.7 to 7.0 5.5
4.4.15.3 5.3.7 to 7.0 5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
4.2.2 5.3 5.5
4.2.1 5.3 5.5
4.2.0 5.3 5.5
4.1.14.8 5.3 5.5
4.1.14.7 5.3 5.5
4.1.14.6 5.3 5.5
4.1.14.5 5.3 5.5
4.1.14.4 5.3 5.5
4.1.14.3 5.3 5.5
4.1.14.2 5.3 5.5
4.1.14.1 5.3 5.5
4.1.14 5.3 5.5
4.1.13 5.3 5.5
4.1.12 5.3 5.5
4.1.11 5.3 5.5
4.1.10 5.3 5.5
4.1.9 5.3 5.5
4.1.8 5.3 5.5
4.1.7 5.3 5.5
4.1.6 5.3 5.5
4.1.5 5.3 5.5
4.1.4 5.3 5.5
4.1.3 5.3 5.5
4.1.2 5.3 5.5
4.1.1 5.3 5.5
4.1.0 5.3 5.5
4.0.10.20 5.2 (Does not support 5.5 or newer) 5
4.0.10.19 5.2 (Does not support 5.5 or newer) 5
4.0.10.18 5.2 (Does not support 5.5 or newer) 5
4.0.10.17 5.2 (Does not support 5.5 or newer) 5
4.0.10.16 5.2 (Does not support 5.5 or newer) 5
4.0.10.15 5.2 (Does not support 5.5 or newer) 5
4.0.10.14 5.2 (Does not support 5.5 or newer) 5
4.0.10.13 5.2 (Does not support 5.5 or newer) 5
4.0.10.12 5.2 (Does not support 5.5 or newer) 5
4.0.10.11 5.2 (Does not support 5.5 or newer) 5
4.0.10.10 5.2 (Does not support 5.5 or newer) 5
4.0.10.9 5.2 (Does not support 5.5 or newer) 5
4.0.10.8 5.2 (Does not support 5.5 or newer) 5
4.0.10.7 5.2 (Does not support 5.5 or newer) 5
4.0.10.6 5.2 (Does not support 5.5 or newer) 5
4.0.10.5 5.2 (Does not support 5.5 or newer) 5
4.0.10.4 5.2 (Does not support 5.5 or newer) 5
4.0.10.3 5.2 (Does not support 5.5 or newer) 5
4.0.10.2 5.2 (Does not support 5.5 or newer) 5
4.0.10.1 5.2 (Does not support 5.5 or newer) 5
4.0.10 5.2 (Does not support 5.5 or newer) 5
4.0.9 5.2 (Does not support 5.5 or newer) 5
4.0.8 5.2 (Does not support 5.5 or newer) 5
4.0.7 5.2 (Does not support 5.5 or newer) 5
4.0.6 5.2 (Does not support 5.5 or newer) 5
4.0.5 5.2 (Does not support 5.5 or newer) 5
4.0.4.2 5.2 (Does not support 5.5 or newer) 5
4.0.4.1 5.2 (Does not support 5.5 or newer) 5
4.0.4 5.2 (Does not support 5.5 or newer) 5
4.0.3 5.2 (Does not support 5.5 or newer) 5
4.0.2 5.2 (Does not support 5.5 or newer) 5
4.0.1 5.2 (Does not support 5.5 or newer) 5
4.0.0 5.2 (Does not support 5.5 or newer) 5
3.5.8.2 5.2 5
3.5.8.1 5.2 5
3.5.8 5.2 5
3.5.7 5.2 5
3.5.6 5.2 5
3.5.5 5.2 5
3.5.4 5.2 5
3.5.3 5.2 5
3.5.2.2 5.2 5
3.5.2.1 5.2 5
3.5.2 5.2 5
3.5.1 5.2 5
3.5.0 5.2 5
3.4.11.1 5.2 5
3.4.11 5.2 5
3.4.10.2 5.2 5
3.4.10.1 5.2 5
3.4.10 5.2 5
3.4.9 5.2 5
3.4.8 5.2 5
3.4.7.1 5.2 5
3.4.7 5.2 5
3.4.6 5.2 5
3.4.5 5.2 5
3.4.4 5.2 5
3.4.3.2 5.2 5
3.4.3.1 5.2 5
3.4.3 5.2 5
3.4.2 5.2 5
3.4.1 5.2 5
3.4.0 5.2 5
3.3.10.5 5.2 5
3.3.10.4 5.2 5
3.3.10.3 5.2 5
3.3.10.2 5.2 5
3.3.10.1 5.2 5
3.3.10 5.2 5
3.3.9.2 5.2 5
3.3.9.1 5.2 5
3.3.9 5.2 5
3.3.8.1 5.2 5
3.3.8 5.2 5
3.3.7 5.2 5
3.3.6 5.2 5
3.3.5.1 5.2 5
3.3.0 5.2 5
3.2.0 5.2 5
3.1.0 5.2 5
3.0.0 5.2 5
2.11.11.3 4+ 3+
2.11.11.2 4+ 3+
2.11.11.1 4+ 3+
2.11.11 4+ 3+
2.11.10.1 4+ 3+
2.10.3 4+ 3+
2.10.2 4+ 3+
2.9.0 4+ 3+
2.8.0 4+ 3+
2.7.0 4+ 3+
2.6.0 4+ 3+
2.5.0 4+ 3+
2.4.0 4+ 3+
2.3.0 4+ 3+
2.2.0 4+ 3+
2.1.0 4+ 3+
2.0.5 4+ 3+
1.3.1
1.3.0
1.2.0
1.1.0
0.9.0
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

Laravel ToDoアプリチュートリアルで発生した エラーUnexpected data found. Data missing

初めに

仕事でLaravelの知識が必要となり、下記リンクの良さげなチュートリアルをやっていまた。
https://www.hypertextcandy.com/laravel-tutorial-create-task

チュートリアル通りにやっていてもエラーってやっぱり起きるのですよね〜。。。

環境

上記リンクのチュートリアルはv5らしいです。私はv6だったので発生したエラーだと思われる。。。:persevere:

$ php artisan --version
Laravel Framework 6.18.40

:point_down:同じようなエラーです。。
Laravel getFormattedDueDateAttributeでTrailing data のエラーが出た場合

発生した問題

上記リンクのチュートリアル通りにやっても、「タスクを保存する」の段階でこのようなエラーが発生しました。

Carbon\Exceptions\InvalidFormatException
Unexpected data found. Unexpected data found. Data missing (View: /Users/xxx/resources/views/tasks/index.blade.php)

解決方法

https://qiita.com/koukonko/items/420a95e6e98915b8a38b
上記を参考にTaskController.phpを編集したところ、正常に保存されて表示できました。

TaskController.php
//変更前
 $task->due_date = $request->due_date;
//変更後
 $task->due_date = $request->due_date = date('Y-m-d H:i:s');
TaskController.php
/**
     * GET /folders/{id}/tasks/create
     */
    public function showCreateForm(int $id)
    {
        return view('tasks/create', [
            'folder_id' => $id
        ]);
    }

    public function create(int $id, CreateTask $request)
    {
        $current_folder = Folder::find($id);

        $task = new Task();
        $task->title = $request->title;
            // date('Y-m-d H:i:s')を追加!
        $task->due_date = $request->due_date = date('Y-m-d H:i:s');

        $current_folder->tasks()->save($task);

        return redirect()->route('tasks.index', [
            'id' => $current_folder->id,
        ]);
  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

ページングのSQL実行時にハマった事 

商品テーブルから名前の情報を取ってくる際のSQL

SELECT name FROM product LIMIT :span OFFSET :p_num

いつものように

$data = array(':span' => $span,'p_num' => $p_num);

と書いてexecuteすると

ERROR!SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near

というエラーが出てきて怒られる。

要は':span' => $span のようにすると、入れられる値は文字の数字になってしまうので、
数値を入れるべきSQL文でエラーが起きた。

解消法

$stmt->bindValue(':span', $span, PDO::PARAM_INT);
$stmt->bindValue('p_num', $p_id, PDO::PARAM_INT);

とすることで、数値として値をSQLに入れられる。
似たものでbindParamというものがあるが、違いは後で調べて追記しておく。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

PHPからFTPS接続:暗号化モード(Explicit/Implicit)について・実装方法の違い

PHPからFTPSへ接続するプログラムを実装する機会があったので、その時に学んだことのメモ。

FTPについて

FTPはFile Transfer Protocolの略で、「ファイル(file)を転送する(transfer)ためのプロトコル(protocol:決まりごと)」のことをいう。

FTPの通信では、FTPサーバー(インターネット側)とFTPクライアント(コンピュータ側)の間でファイルを転送されている。例えば、インターネットにWEBサイトを公開するために、手元のPCからHTMLファイルをサーバーにアップロードしたり、逆にサーバーにあるファイルをダウンロードしたり。

FTPの通信の仕組み

FTPでは20番(データコネクション)21番のポート(制御コネクション)が使われる。
それぞれのポートには役割があって、データコネクションはデータを転送するために使われるポート。制御コネクションは、データを送るための始まりと終わりの合図のようなものを送るために使われるポート。

FTP通信を行う時には、21番ポート経由で「今からFTPでファイル送るよー、ログインするよー」とサーバーに合図する。サーバーから「認証したから送っていいよー」とOKもらったら、20番ポート経由でファイルのデータを送る。データ送ったらまた21番ポート経由で「終わったよー」って合図する。みたいなイメージ。

FTPのデメリットとして、ユーザー名やパスワード、データを暗号化せずに通信してしまうので、セキュリティ的にあまり好ましくない。そのため、今ではFTPSやSFTPといった通信が使われることのほうが多い。

FTPSについて

FTPS (File Transfer Protocol over SSL/TLS) は、FTPで送受信するデータをTLSまたはSSLで暗号化する通信プロトコル。FTPの延長版みたいなもので、FTPで暗号化していなかったデータを、暗号化して送るようにした仕組み。延長版なので、データ送る流れは上のFTPの時とほぼ同じ。

FTPSには2つの暗号化モードがある。一つは、Explicit(明示的な)モード、もう一つはImplicit(暗黙的な)モード。それぞれのモードで、接続の仕方が異なるのに加えて、制御コネクションとして使われるポートが違う。

Explicitモード

サーバの21/tcpポートに接続した後にクライアントがAUTHコマンドを実行して、使用するプロトコル(SSLまたはTLS)のネゴシエーションをおこない、適合したプロトコルでのハンドシェイク完了後に暗号化された通信がおこなわれる。 つまりExplicitモードの場合、クライアントがAUTHコマンドを実行しなければ通常のFTPとして機能する
FTPS - Wikipedia

通信の仕組みとしては、まず暗号化しない状態で接続した後に、AUTHコマンドという認証コマンドを実行した後に、暗号化通信が始まる。認証コマンドで明示的に暗号化した通信を始めるので、Explicit(明示的な)モード。Explicitモードで使われる制御コネクションは21番。

Implicitモード

サーバの990/tcpポートに接続した直後にSSLまたはTLSによるハンドシェイクがおこなわれる。 Implicitモードで動作するサーバに接続する場合、クライアントはサーバが採用している暗号化プロトコルに適合したFTPSクライアントソフトを使用する必要がある。 また、データ転送チャネル(PORTまたはPASVコマンドで作成されるチャネル)での通信を暗号化する場合、PROTコマンドを用いて保護レベルをP (Private) に設定する必要がある。
FTPS - Wikipedia

それに対してImplicitモードは、最初から暗号化した状態で接続をする。制御コネクションには990番ポートが使われる。

PHPでFTPSに接続する

PHPでFTPSへ接続する際に、ftp_connectの代わりにftp_ssl_connectを使えばFTPの時のように接続できるだろうと思っていたら、この関数はExplicitモードにしか対応していないらしい。
PHP: ftp_ssl_connect - Manual

なのでPHPでFTPSへ接続するプログラムを実装する場合、

Explicitモード

  • ftp_ssl_connect使う
  • Curlを使う

Implicitモード

  • Curl使う

と、暗号化モードによって実装の方法が異なってくる。

[参考] Implicitモードがゆえ、ftp_ssl_connectが使えない系エラー
php - ftp_ssl_connect with implicit ftp over tls - Stack Overflow
PHPでFTPS接続でなぜかタイムアウトして辛かった - Qiita

PHPでFTPSに接続する:Explicitモード(ftp_ssl_connect)

これはFTPの時とほとんど変わらないのでわかりやすい。downloadディレクトリ内のファイル一覧をダウンロードする例。(エラーハンドリングなどは省略)

public function downloadFiles()
{
 $host = 'hostname';
 $username = 'ftpuser';
 $userpass = 'password';

 $remoteDir = 'download';
 $localDir = '/home/user/download';

 $stream = ftp_ssl_connect($host);
 ftp_login($stream, $username, $userpass);

 // パッシブモードON
 ftp_pasv($stream, true);

 // ディレクトリ内のファイル一覧を取得
 $remoteFilePaths = ftp_nlist($stream, $remoteDir);

 foreach ($remoteFilePaths as $filePath) {
  $localFilePath = $localDir . '/' . basename($filePath);
  // ファイルをダウンロード
  $result = ftp_get($stream, $localFilepath, $filepath, FTP_BINARY);
 }
 ftp_close($stream);
}

PHPでFTPSに接続する:Explicitモード(Curl)

上と同じ処理をCurlを使ってやってみる。

private $host;
private $username;
private $userpass;

public __construct()
{
 $this->host = 'hostname';
 $this->username = 'ftpuser';
 $this->userpass = 'password';
}

public function downloadFiles()
{
 $remoteDir = 'download';
 $localDir = '/home/user/download';

 // ディレクトリ内のファイル一覧を取得
 $remoteFilePaths = $this->_getFiles($remoteDir);
 foreach ($remoteFilePaths as $filePath) {
  $localFilePath = $localDir . '/' . basename($filePath);
  // ファイルをダウンロード
  $result = $this->_download($localFilePath, $remoteDir);
 }
}

private function _getFiles($dir)
{
 $url = 'ftp://ftptest.com/' . $dir . '/'; // ディレクトリ指定の場合、最後の'/'を忘れずに

 $options = array(
   CURLOPT_URL            => $url,
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FTPLISTONLY    => true,
   CURLOPT_RETURNTRANSFER => true,
  );

 $ch = curl_init();
 curl_setopt_array($ch, $options);
 $result = curl_exec($ch);
 $fileList = explode("\n", trim($result));
 curl_close($ch);

 return $fileList;
}

private function _download($localFilepath, $dir)
{
 $url = 'ftp://ftptest.com/' . $dir . '/' . basename($localFilepath);

 $file = fopen($localFilepath, "w");

 $options = array(
   CURLOPT_URL            => $url, // ダウンロードするファイルパス
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_FILE           => $file, // ローカルの出力先ファイル
 );

 $ch = curl_init();
 curl_setopt_array($ch, $options);
 $result = curl_exec($ch);
 curl_close($ch);
 fclose($file);

 return $result;
}

CurlでExplicitモードで通信する場合、CURLOPT_URLでセットするURLはftp://で始まる値になる。

PHPでFTPSに接続する:Implicitモード(Curl)

一方、Implicitモードで通信する場合。CURLOPT_URLでセットするURLはftps://で始まる値になる。他は上と一緒。

ポートは指定しない場合990番で自動的に繋がる気がするけど、一応CURLOPT_PORTでポートを指定した。

// (略)

private function _getFiles($dir)
{
 $url = 'ftps://ftptest.com/' . $dir . '/'; // ディレクトリ指定の場合、最後の'/'を忘れずに

 $options = array(
   CURLOPT_URL            => $url,
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FTPLISTONLY    => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_PORT           => 990,
 );

// (略)

private function _download($localFilepath, $dir)
{
 $url = 'ftps://ftptest.com/' . $dir . '/' . basename($localFilepath);

 $options = array(
   CURLOPT_URL            => $url, // ダウンロードするファイルパス
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_FILE           => $file, // ローカルの出力先ファイル
   CURLOPT_PORT           => 990,
 );

// (略)

こちらのライブラリが参考になりました。
https://github.com/nalindaDJ/php-FTP-implicit-ssl-tls

[参考]
PHP curl FTPes w/ explicit TLS/SSL - Stack Overflow

まとめ

PHPでFTPS通信する際に、暗号化モードによって実装の方法を使い分けなければいけないことを知らなかったので、勉強になった。

ローカルでテストする際にvsftpdを使ってサーバーを構築したのですが、設定や認証の仕組みとか、まだ漠然としていて理解が足りていないので、もっと勉強します。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む

PHPからFTPS接続:暗号化モード(Explicit/Implicit)による実装方法の違い

PHPからFTPSへ接続するプログラムを実装する機会があったので、その時に学んだことのメモ。

FTPについて

FTPはFile Transfer Protocolの略で、「ファイル(file)を転送する(transfer)ためのプロトコル(protocol:決まりごと)」のことをいう。

FTPの通信では、FTPサーバー(インターネット側)とFTPクライアント(コンピュータ側)の間でファイルを転送されている。例えば、インターネットにWEBサイトを公開するために、手元のPCからHTMLファイルをサーバーにアップロードしたり、逆にサーバーにあるファイルをダウンロードしたり。

FTPの通信の仕組み

FTPでは20番(データコネクション)21番のポート(制御コネクション)が使われる。
それぞれのポートには役割があって、データコネクションはデータを転送するために使われるポート。制御コネクションは、データを送るための始まりと終わりの合図のようなものを送るために使われるポート。

FTP通信を行う時には、21番ポート経由で「今からFTPでファイル送るよー、ログインするよー」とサーバーに合図する。サーバーから「認証したから送っていいよー」とOKもらったら、20番ポート経由でファイルのデータを送る。データ送ったらまた21番ポート経由で「終わったよー」って合図する。みたいなイメージ。

FTPのデメリットとして、ユーザー名やパスワード、データを暗号化せずに通信してしまうので、セキュリティ的にあまり好ましくない。そのため、今ではFTPSやSFTPといった通信が使われることのほうが多い。

FTPSについて

FTPS (File Transfer Protocol over SSL/TLS) は、FTPで送受信するデータをTLSまたはSSLで暗号化する通信プロトコル。FTPの延長版みたいなもので、FTPで暗号化していなかったデータを、暗号化して送るようにした仕組み。延長版なので、データ送る流れは上のFTPの時とほぼ同じ。

FTPSには2つの暗号化モードがある。一つは、Explicit(明示的な)モード、もう一つはImplicit(暗黙的な)モード。それぞれのモードで、接続の仕方が異なるのに加えて、制御コネクションとして使われるポートが違う。

Explicitモード

サーバの21/tcpポートに接続した後にクライアントがAUTHコマンドを実行して、使用するプロトコル(SSLまたはTLS)のネゴシエーションをおこない、適合したプロトコルでのハンドシェイク完了後に暗号化された通信がおこなわれる。 つまりExplicitモードの場合、クライアントがAUTHコマンドを実行しなければ通常のFTPとして機能する
FTPS - Wikipedia

通信の仕組みとしては、まず暗号化しない状態で接続した後に、AUTHコマンドという認証コマンドを実行した後に、暗号化通信が始まる。認証コマンドで明示的に暗号化した通信を始めるので、Explicit(明示的な)モード。Explicitモードで使われる制御コネクションは21番。

Implicitモード

サーバの990/tcpポートに接続した直後にSSLまたはTLSによるハンドシェイクがおこなわれる。 Implicitモードで動作するサーバに接続する場合、クライアントはサーバが採用している暗号化プロトコルに適合したFTPSクライアントソフトを使用する必要がある。 また、データ転送チャネル(PORTまたはPASVコマンドで作成されるチャネル)での通信を暗号化する場合、PROTコマンドを用いて保護レベルをP (Private) に設定する必要がある。
FTPS - Wikipedia

それに対してImplicitモードは、最初から暗号化した状態で接続をする。制御コネクションには990番ポートが使われる。

PHPでFTPSに接続する

PHPでFTPSへ接続する際に、ftp_connectの代わりにftp_ssl_connectを使えばFTPの時のように接続できるだろうと思っていたら、この関数はExplicitモードにしか対応していないらしい。
PHP: ftp_ssl_connect - Manual

なのでPHPでFTPSへ接続するプログラムを実装する場合、

Explicitモード

  • ftp_ssl_connect使う
  • Curlを使う

Implicitモード

  • Curl使う

と、暗号化モードによって実装の方法が異なってくる。

[参考] Implicitモードがゆえ、ftp_ssl_connectが使えない系エラー
php - ftp_ssl_connect with implicit ftp over tls - Stack Overflow
PHPでFTPS接続でなぜかタイムアウトして辛かった - Qiita

PHPでFTPSに接続する:Explicitモード(ftp_ssl_connect)

これはFTPの時とほとんど変わらないのでわかりやすい。downloadディレクトリ内のファイル一覧をダウンロードする例。(エラーハンドリングなどは省略)

public function downloadFiles()
{
 $host = 'hostname';
 $username = 'ftpuser';
 $userpass = 'password';

 $remoteDir = 'download';
 $localDir = '/home/user/download';

 $stream = ftp_ssl_connect($host);
 ftp_login($stream, $username, $userpass);

 // パッシブモードON
 ftp_pasv($stream, true);

 // ディレクトリ内のファイル一覧を取得
 $remoteFilePaths = ftp_nlist($stream, $remoteDir);

 foreach ($remoteFilePaths as $filePath) {
  $localFilePath = $localDir . '/' . basename($filePath);
  // ファイルをダウンロード
  $result = ftp_get($stream, $localFilepath, $filepath, FTP_BINARY);
 }
 ftp_close($stream);
}

PHPでFTPSに接続する:Explicitモード(Curl)

上と同じ処理をCurlを使ってやってみる。

private $host;
private $username;
private $userpass;

public __construct()
{
 $this->host = 'hostname';
 $this->username = 'ftpuser';
 $this->userpass = 'password';
}

public function downloadFiles()
{
 $remoteDir = 'download';
 $localDir = '/home/user/download';

 // ディレクトリ内のファイル一覧を取得
 $remoteFilePaths = $this->_getFiles($remoteDir);
 foreach ($remoteFilePaths as $filePath) {
  $localFilePath = $localDir . '/' . basename($filePath);
  // ファイルをダウンロード
  $result = $this->_download($localFilePath, $remoteDir);
 }
}

private function _getFiles($dir)
{
 $url = 'ftp://ftptest.com/' . $dir . '/'; // ディレクトリ指定の場合、最後の'/'を忘れずに

 $options = array(
   CURLOPT_URL            => $url,
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FTPLISTONLY    => true,
   CURLOPT_RETURNTRANSFER => true,
  );

 $ch = curl_init();
 curl_setopt_array($ch, $options);
 $result = curl_exec($ch);
 $fileList = explode("\n", trim($result));
 curl_close($ch);

 return $fileList;
}

private function _download($localFilepath, $dir)
{
 $url = 'ftp://ftptest.com/' . $dir . '/' . basename($localFilepath);

 $file = fopen($localFilepath, "w");

 $options = array(
   CURLOPT_URL            => $url, // ダウンロードするファイルパス
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_FILE           => $file, // ローカルの出力先ファイル
 );

 $ch = curl_init();
 curl_setopt_array($ch, $options);
 $result = curl_exec($ch);
 curl_close($ch);
 fclose($file);

 return $result;
}

CurlでExplicitモードで通信する場合、CURLOPT_URLでセットするURLはftp://で始まる値になる。

PHPでFTPSに接続する:Implicitモード(Curl)

一方、Implicitモードで通信する場合、CURLOPT_URLでセットするURLはftps://で始まる値になる。他は上と一緒。

ポートは指定しない場合990番で自動的に繋がる気がするけど、一応CURLOPT_PORTでポートを指定した。

// (略)

private function _getFiles($dir)
{
 $url = 'ftps://ftptest.com/' . $dir . '/'; // ディレクトリ指定の場合、最後の'/'を忘れずに

 $options = array(
   CURLOPT_URL            => $url,
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FTPLISTONLY    => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_PORT           => 990,
 );

// (略)

private function _download($localFilepath, $dir)
{
 $url = 'ftps://ftptest.com/' . $dir . '/' . basename($localFilepath);

 $file = fopen($localFilepath, "w");

 $options = array(
   CURLOPT_URL            => $url, // ダウンロードするファイルパス
   CURLOPT_USERPWD        => $this->username . ':' . $this->userpass,
   CURLOPT_SSL_VERIFYPEER => false,
   CURLOPT_SSL_VERIFYHOST => false,
   CURLOPT_FTP_SSL        => CURLFTPSSL_ALL,
   CURLOPT_FTPSSLAUTH     => CURLFTPAUTH_DEFAULT,
   CURLOPT_UPLOAD         => false,
   CURLOPT_FOLLOWLOCATION => true,
   CURLOPT_RETURNTRANSFER => true,
   CURLOPT_FILE           => $file, // ローカルの出力先ファイル
   CURLOPT_PORT           => 990,
 );

// (略)

こちらのライブラリが参考になりました。
https://github.com/nalindaDJ/php-FTP-implicit-ssl-tls

[参考]
PHP curl FTPes w/ explicit TLS/SSL - Stack Overflow

まとめ

PHPでFTPS通信する際に、暗号化モードによって実装の方法を使い分けなければいけないことを知らなかったので、勉強になった。

ローカルでテストする際にvsftpdを使ってサーバーを構築したのですが、設定や認証の仕組みとか、まだ漠然としていて理解が足りていないので、もっと勉強します。

  • このエントリーをはてなブックマークに追加
  • Qiitaで続きを読む