001/*
002 * Copyright (c) 2009 The openGion Project.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *     http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
013 * either express or implied. See the License for the specific language
014 * governing permissions and limitations under the License.
015 */
016package org.opengion.plugin.column;
017
018import org.opengion.fukurou.security.HybsCryptography;
019import org.opengion.fukurou.util.StringUtil;
020import org.opengion.hayabusa.db.AbstractDBType;
021
022/**
023 * パスワード情報など、重要な情報のハッシュコード(SHA-512)を扱う為の、カラム属性を定義します。
024 *
025 * パスワード情報など、重要な情報のハッシュコードに、SHA-512 があります。このクラスは、
026 * MessageDigestにより、SHA-512 でハッシュした文字を作成します。
027 *
028 * MD5やSHA-1は脆弱性が報告されているため、可能であればSHA-512の利用が推奨されます。
029 *
030 * 値としては、標準の X と同じ半角文字列「 c < 0x20 || c > 0x7e 以外」でのみ
031 * 処理することが出来ます。
032 *
033 * タイプチェックとして、以下の条件を判定します。
034 * ・文字列長は、Byte換算での文字数との比較
035 * ・半角文字列チェック「 c < 0x20 || c > 0x7e 以外」エラー
036 * ・文字パラメータの 正規表現チェック
037 * ・クロスサイトスクリプティングチェック
038 *
039 * @og.group データ属性
040 *
041 * @version  7.0
042 * @author   Takahashi Masakazu
043 * @since    JDK11.0,
044 */
045// public class DBType_SHA512 extends AbstractDBType {
046public class DBType_SHA extends AbstractDBType {                                                // 7.1.0.0 (2020/01/27) クラス名変更
047        /** このプログラムのVERSION文字列を設定します。   {@value} */
048        private static final String VERSION = "7.1.0.0 (2020/01/27)" ;
049
050        /**
051         * デフォルトコンストラクター
052         *
053         * @og.rev 7.0.4.0 (2019/05/31) PMD Each class should declare at least one constructor
054         */
055//      public DBType_SHA512() { super(); }             // これも、自動的に呼ばれるが、空のメソッドを作成すると警告されるので、明示的にしておきます。
056        public DBType_SHA() { super(); }                // 7.1.0.0 (2020/01/27)
057
058        /**
059         * String引数の文字列を+1した文字列を返します。
060         * ※ このクラスでは実装されていません。
061         *
062         * @param       value   String引数の文字列
063         * @throws UnsupportedOperationException このクラスを実行すると、必ず発生します。
064         *
065         * @return  String引数の文字列を+1した文字列
066         */
067        @Override
068        public String valueAdd( final String value ) {
069                final String errMsg = "このメソッドは、このクラスからは使用できません。";
070                throw new UnsupportedOperationException( errMsg );
071        }
072
073        /**
074         * MessageDigestにより、SHA-512 でハッシュした文字を返します。
075         *
076         * マイナス時には符号を反転させて、16進数で文字列に変換しています。
077         * よって、このメソッドで変換した文字でのみ突き合わせて正しいかどうかを
078         * 判断してください。
079         *
080         *
081         * @param       value   (一般に編集データとして登録されたデータ)
082         *
083         * @return  修正後の文字列(一般にデータベースに登録するデータ)
084         */
085        @Override
086        public String valueSet( final String value ) {
087                return HybsCryptography.getSHA512( StringUtil.rTrim( value ) );
088        }
089}