スーパードッグ認証機能


設備:開発犬、nスーパー犬
一、インストール環境:スーパードッグサプライヤーが提供する開発キットをインストールする.私が手に入れたのは2.4バージョンです.
二、開発者認証コードの生成:スーパードッグ情報の読み取り操作を書き込む.開発キットのスーパードッグキットを開き、アイデンティティ認証スキーム->認証コード生成ツールをクリックし、開発犬を挿入し、生成認証コードをクリックし、ファイルパスを選択します.生成された認証コードには、開発者id(vendor)、スーパードッグ認証コード(authcode)が含まれています.
三、初期化スーパードッグ:スーパードッグのアカウント、パスワードを初期化します.開発キットのスーパードッグキットを開き、アイデンティティ認証スキーム->初期化ツールをクリックします.
      1、Auth Codeをクリックする File 次のopenボタンは、ステップ2で生成した認証コードファイルを選択します.
       2、Current SO PINの後ろの入力ボックスに、デフォルトの管理者パスワードabcdefghを入力します.
       3、管理者のデフォルトパスワードを変更する必要がない場合は、これを無視します.管理者のデフォルトパスワードを変更する必要がある場合は、Change SO PINをチェックし、New SO PINとConfirm SO PINの後ろの入力ボックスにそれぞれ新しいパスワードと確認パスワードを入力します.注意:管理者パスワードを変更する場合は、新しいパスワードを覚えてください.
     4、スーパードッグユーザーパスワードの設定:Set USER PINをチェックし、New USER PINとConfirm USER PINの後ろの入力ボックスにそれぞれ新しいパスワードと確認パスワードを入力する.
     5、スーパードッグのユーザー名の設定:Set UserNameにチェックマークを付け、UserNameの後ろの入力ボックスに対応する財政部門管理者のアカウントを入力する.
     6、以上の手順が完了したら、Initボタンをクリックします.ポップアップウィンドウに「Init SuperDog Success!」というメッセージが表示されると、初期化に成功します.
四、ブラウザプラグインのインストール:開発キットのスーパードッグツールパッケージを開き、アイデンティティ認証案->ブラウザプラグインインストールツールをクリックする.
五、開発コード:
    1、フロントエンドコード(angular):
    
//   begin

                $scope.dogMessage = "";
                $scope.dogScope = "";
                //         
                $http.get('/web/superdog/authentication/getSuperDogConfig', null).then(function (data) {
                    var data = data.data;
                    if (data.status && data.code === 200) {
                        //    
                        $scope.challenge = data.info.challenge;
                        //    
                        $scope.superdogDefalutPass = data.info.superDogDefaultPass;
                        //      
                        $scope.authCode = data.info.superDogAuthcode;
                    }
                });
                // ie、       html      object
                superDogService.embedTag();
                //         
                $scope.objAuth = superDogService.getAuthObject();


                loadFunc();

                function checkDog()
                {
                    var stat = "";
                    //     
                    if (navigator.userAgent.indexOf("Chrome") > 0) {
                        //          
                        $scope.objAuth.GetUserNameEx($scope.dogScope, $scope.authCode);
                    }
                    else {
                        //        
                        if($scope.objAuth.hasOwnProperty("Open")==false){
                            $scope.dogMessage ="           ";
                            setTimeout(checkDog, 5000);
                            return;
                        }
                        //     
                        stat = $scope.objAuth.Open($scope.dogScope, $scope.authCode);
                        if(0 != stat)
                        {
                            $scope.model.use.useName ="";
                            $scope.dogMessage = superDogService.reportStatus(stat);
                        }
                        else
                        {
                            $scope.dogMessage ="";
                            //          
                            stat = $scope.objAuth.GetUserName();
                            if (stat != 0) {
                                $scope.model.use.useName ="";
                                $scope.dogMessage = superDogService.reportStatus(stat);
                            }else {
                                $scope.model.use.useName = $scope.objAuth.UserNameStr;
                                if($scope.model.use.useName==''){
                                    $scope.dogMessage ="       !";
                                }
                            }
                            $scope.objAuth.Close();
                        }
                    }
                    setTimeout(checkDog, 1000);
                }

                function loadFunc()
                {
                    if (navigator.userAgent.indexOf("Window") > 0)
                    {
                        if (navigator.userAgent.indexOf("Chrome") > 0)  //Chrome
                        {
                            window.addEventListener("message", function (event) {
                                if (event.source != window) {
                                    return;
                                }
                                if (event.data.type == "SNTL_FROM_HOST") {
                                    var ReturnText = event.data.text;
                                    //            
                                    if ("GetUserNameEx" == ReturnText.InvokeMethod) {
                                        if (0 == ReturnText.Status) {
                                            $scope.model.use.useName = ReturnText.UserNameStr;
                                            $scope.dogMessage ="";
                                            if($scope.model.use.useName==''){
                                                $scope.dogMessage ="       !";
                                            }
                                        }
                                        else {
                                            $scope.model.use.useName ="";
                                            $scope.dogMessage = superDogService.reportStatus(parseInt(ReturnText.Status));
                                        }
                                    }
                                    //              ,        
                                    else if ("GetDigestEx" == ReturnText.InvokeMethod) {
                                        if (0 == ReturnText.Status) {
                                            $http.get('/web/superdog/authentication/verifyDigest', {params:{dog_id:ReturnText.DogIdStr,challenge:$scope.challenge,digest:ReturnText.DigestStr}}).then(function (data) {
                                                var data = data.data;
                                                if (data.status && data.code === 200) {
                                                    if (data.info != 0) {
                                                        $scope.dogMessage = superDogService.reportStatus(data.info);
                                                    }
                                                    else {
                                                        //         
                                                        $scope.events.submitUse();
                                                    }
                                                }
                                            });
                                        }
                                        else {
                                            $scope.dogMessage = superDogService.reportStatus(parseInt(ReturnText.Status));
                                        }
                                    }
                                }
                                return;
                            }, false);
                        }
                        else if (window.ActiveXObject || "ActiveXObject" in window)  //IE
                        {
                            //$scope.objAuth.SetCheckDogCallBack("insertDog", "removeDog");
                        }
                        setTimeout(checkDog, 1000);
                    }
                    else if (navigator.userAgent.indexOf("Mac") > 0 || navigator.userAgent.indexOf("Linux") > 0)
                    {
                        setTimeout(checkDog, 1000);
                    }
                }

 

function loginCheck(){

var stat = "";

if (window.ActiveXObject || "ActiveXObject" in window) //IE
{
	//Add onfocus event
	var obj = document.getElementById("password");
	if (Object.hasOwnProperty.call(window, "ActiveXObject") && !window.ActiveXObject) {// is IE11
		obj.addEventListener("onfocus", function () {
			$scope.dogMessage = "";
		}, false);
	}
	else {
		obj.attachEvent("onfocus", function () {
			$scope.dogMessage = "";
		});
	}
}

//Chrome
if (navigator.userAgent.indexOf("Chrome") > 0) {
	//       
	$scope.objAuth.GetDigestEx($scope.dogScope, $scope.authCode, $scope.superdogDefalutPass, $scope.challenge);
	return false;
} else {
	//     
	stat = $scope.objAuth.Open($scope.dogScope, $scope.authCode);
	if (stat != 0) {
		$scope.dogMessage = superDogService.reportStatus(stat);
		return false;
	}

	//       
	stat = $scope.objAuth.VerifyUserPin($scope.superdogDefalutPass);
	if (stat != 0) {
		$scope.objAuth.Close();
		$scope.dogMessage = superDogService.reportStatus(stat);
		return false;
	}

	//     id
	stat = $scope.objAuth.GetDogID();
	if (stat != 0) {
		$scope.objAuth.Close();
		$scope.dogMessage = superDogService.reportStatus(stat);
		return false;
	}

	//          
	stat = $scope.objAuth.GetDigest($scope.challenge);
	if (stat != 0) {
		$scope.objAuth.Close();
		$scope.dogMessage = superDogService.reportStatus(stat);
		return false;
	}

	//          
	$http.get('/web/superdog/authentication/verifyDigest', {
		params: {
			dog_id: $scope.objAuth.DogIdStr,
			challenge: $scope.challenge,
			digest: $scope.objAuth.DigestStr
		}
	}).then(function (data) {
		var data = data.data;
		if (data.status && data.code === 200) {
			stat = data.info;
			if (stat != 0) {
				$scope.objAuth.Close();
				$scope.dogMessage = superDogService.reportStatus(stat);
				return;
			}
			else {
                //         
				$scope.events.submitUse();
			}
		}
	});

	$scope.objAuth.Close();
	
	return true;
}
}
//   end

 上のsuperDogService対応jsファイルコード



//   
define (['angular', 'angularUiRouter', 'uiRouterExtras', 'oclazyload'], function (angular) {

    return angular.module ('superDogFunc', ['ui.router', 'oc.lazyLoad',
            'ct.ui.router.extras'])
        .factory('superDogService',['$rootScope',function($rootScope){
            var superDogService={

            };
            function getAuthObjectChrome(){
                var obj = new AuthObject();
                return obj;
            };
            function AuthObject() {

                if (typeof AuthObject._initialized == "undefined") {

                    // GetUserNameEx
                    AuthObject.prototype.GetUserNameEx = function (scope, authCode) {
                        //console.log("enter GetUserNameEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "GetUserNameEx", "Scope": scope, "AuthCode": authCode} }, "*");
                        return 0;
                    };

                    // GetDigestEx
                    AuthObject.prototype.GetDigestEx = function (scope, authCode, password, challenge) {
                        //console.log("enter GetDigestEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "GetDigestEx", "Scope": scope, "AuthCode": authCode, "UserPin": password, "Challenge": challenge} }, "*");
                        return 0;
                    };

                    // RegisterUserEx
                    AuthObject.prototype.RegisterUserEx = function (scope, authCode, username, password) {
                        //console.log("enter RegisterUserEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "RegisterUserEx", "Scope": scope, "AuthCode": authCode, "Name": username, "UserPin": password } }, "*");
                        return 0;
                    };

                    // ChangeUserPinEx
                    AuthObject.prototype.ChangeUserPinEx = function (scope, authCode, oldPassword, newPassword) {
                        //console.log("enter ChangeUserPinEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "ChangeUserPinEx", "Scope": scope, "AuthCode": authCode, "OldPin": oldPassword, "NewPin": newPassword } }, "*");
                        return 0;
                    };

                    // SetUserDataEx
                    AuthObject.prototype.SetUserDataEx = function (scope, authCode, password, type, offset, data) {
                        //console.log("enter SetUserDataEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "SetUserDataEx", "Scope": scope, "AuthCode": authCode, "UserPin": password, "Type": type, "Offset": offset, "Data": data } }, "*");
                        return 0;
                    };

                    // GetUserDataEx
                    AuthObject.prototype.GetUserDataEx = function (scope, authCode, type, offset, size) {
                        //console.log("enter GetUserDataEx()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "GetUserDataEx", "Scope": scope, "AuthCode": authCode, "Type": type, "Offset": offset, "Size": size } }, "*");
                        return 0;
                    };

                    // EnumDog
                    AuthObject.prototype.EnumDog = function (authCode) {
                        //console.log("enter EnumDog()");
                        window.postMessage({ type: "SNTL_FROM_PAGE", text: { "InvokeMethod": "EnumDog", "AuthCode": authCode} }, "*");
                        return 0;
                    };

                    AuthObject._initialized = true;
                }
            }

            superDogService.embedTag = function(){
                if (window.ActiveXObject || "ActiveXObject" in window) {//IE
                    ;
                }
                else if (navigator.userAgent.indexOf("Chrome") > 0) {//Chrome
                    ;
                }
                else {
                    var temp = document.body.innerHTML;
                    var tag = "";
                    document.body.innerHTML = tag + temp;
                }
            };

            superDogService.getAuthObject = function(){

                var objAuth;
                if (window.ActiveXObject || "ActiveXObject" in window) //IE
                {
                    objAuth = document.getElementById("AuthIE");
                }
                else if (navigator.userAgent.indexOf("Chrome") > 0) {
                    objAuth = getAuthObjectChrome();
                }
                else {
                    objAuth = document.getElementById("AuthNoIE");
                }

                return objAuth;
            };

            superDogService.reportStatus = function(status){
                var text = "         ";
                switch (status) {
                    case 0: text = "       ";
                        break;
                    case 1: text = "           ";
                        break;
                    case 3: text = "      ";
                        break;
                    case 4: text = "           ";
                        break;
                    case 5: text = "     ";
                        break;
                    case 7: text = "    U-key  !";
                        break;
                    case 8: text = "  /         ";
                        break;
                    case 9: text = "         ";
                        break;
                    case 10: text = "         ";
                        break;
                    case 15: text = "    XML   ";
                        break;
                    case 18: text = "          ";
                        break;
                    case 19: text = "       XML   ,                ";
                        break;
                    case 20: text = "           ";
                        break;
                    case 21: text = "          ";
                        break;
                    case 22: text = "          ";
                        break;
                    case 24: text = "                ";
                        break;
                    case 26: text = "        ,     ack_data   NULL";
                        break;
                    case 27: text = "           ";
                        break;
                    case 29: text = "V2C           ";
                        break;
                    case 30: text = "      ";
                        break;
                    case 31: text = "     ";
                        break;
                    case 33: text = "API         (License Manager)    ";
                        break;
                    case 34: text = "API         ";
                        break;
                    case 35: text = "    XML   ";
                        break;
                    case 36: text = "    XML   ";
                        break;
                    case 37: text = "            ";
                        break;
                    case 39: text = "     ";
                        break;
                    case 41: text = "     ";
                        break;
                    case 42: text = "            ";
                        break;
                    case 43: text = "          USB     ";
                        break;
                    case 45: text = "        ";
                        break;
                    case 46: text = "            ";
                        break;
                    case 50: text = "            ";
                        break;
                    case 54: text = "                           ,      V2C  ";
                        break;
                    case 55: text = "                           ,      V2C  ";
                        break;
                    case 400: text = "    API     ";
                        break;
                    case 401: text = "API       ";
                        break;
                    case 500: text = "         ";
                        break;
                    case 501: text = "       ";
                        break;
                    case 502: text = "         ";
                        break;
                    case 503: text = "         ";
                        break;
                    case 525: text = "           ";
                        break;
                    case 698: text = "         ";
                        break;
                    case 699: text = "API      ";
                        break;
                    case 802: text = "    ";
                        break;
                    case 803: text = "         ";
                        break;
                    case 804: text = "    ";
                        break;
                    case 810: text = "       ";
                        break;
                    case 811: text = "       ";
                        break;
                    case 812: text = "         ";
                        break;
                    case 813: text = "        ";
                        break;
                    case 814: text = "         ";
                        break;
                    /*case 820: text = "Hardware internal error!";
                     break;*/
                    case 821: text = "         ";
                        break;
                    case 822: text = "        ";
                        break;
                    case 823: text = "       ";
                        break;
                    case 824: text = "          ";
                        break;
                    case 825: text = "       ";
                        break;
                    case 831: text = "        (  :1  )";
                        break;
                    case 832: text = "        (  :2  )";
                        break;
                    case 833: text = "        (  :3  )";
                        break;
                    case 834: text = "        (  :4  )";
                        break;
                    case 835: text = "        (  :5  )";
                        break;
                    case 836: text = "        (  :6  )";
                        break;
                    case 837: text = "        (  :7  )";
                        break;
                    case 838: text = "        (  :8  )";
                        break;
                    case 839: text = "        (  :9  )";
                        break;
                    case 840: text = "        (  :10  )";
                        break;
                    case 841: text = "        (  :11  )";
                        break;
                    case 842: text = "        (  :12  )";
                        break;
                    case 843: text = "        (  :13  )";
                        break;
                    case 844: text = "        (  :14  )";
                        break;
                    case 845: text = "        (  :15  ),       ";
                        break;
                    case 900: text = "    UKey    ,      ";
                        break;
                    case 901: text = "    ";
                        break;
                    case 902: text = "        ";
                        break;
                    case 903: text = "           ";
                        break;
                    case 904: text = "     ";
                        break;
                    case 905: text = "       6-16     ";
                        break;
                    case 906: text = "          ";
                        break;
                    case 907: text = "      ";
                        break;
                    case 908: text = "       ";
                        break;
                    case 909: text = "       6-16     ";
                        break;
                    case 910: text = "          ";
                        break;
                    case 911: text = "          ";
                        break;
                    case 912: text = "       ";
                        break;
                    case 913: text = "      ";
                        break;
                    case 914: text = "        1-32     ";
                        break;
                    case 915: text = "         ,       ";
                        break;
                    case 916: text = "  java.library.path          dog_auth_srv    ";
                        break;
                    case 917: text = "        ";
                        break;
                    case 918: text = "        ";
                        break;
                    case 919: text = "       ,                 。";
                        break;
                    case 920: text = "       :dog_auth_srv_php.dll,             ";
                        break;

                }
                return text;
            };



            return superDogService;
        }])


});

    2、バックエンドコード:
 
public class Authentication extends AbstractAction {


    //          
    static {
        try {
            String path = Thread.currentThread().getContextClassLoader().getResource("").toString();
            path = path.replace("file:/", "").replace("classes/", "");
            //      
            Properties prop = System.getProperties();
            String os = prop.getProperty("os.name");
            String dataModel = System.getProperty("sun.arch.data.model");
            //linux  
            if (os != null && os.toLowerCase().indexOf("linux") > -1) {
                log.info("    :" + dataModel + " linux  ");
                path = "/" + path;
                if (dataModel.equals("64")) {
                    System.load(path + "libdog_auth_srv_x64.so");
                } else {
                    System.load(path + "libdog_auth_srv.so");
                }
            } else {
                log.info("    :" + dataModel + " windows  ");
                if (dataModel.equals("64")) {
                    System.load(path + "dog_auth_srv_x64.dll");
                } else {
                    System.load(path + "dog_auth_srv.dll");
                }
            }
        } catch (Exception e) {
            log.info("       :" + e);
            throw new RuntimeException(e);
        }
    }

    /**
     *       
     *
     * @param status
     * @return
     */
    public native static String getChallenge(int status[]);

    /**
     *          
     *
     * @param vendor_id     ID
     * @param dog_id        ID
     * @param challenge     
     * @param digest                   
     * @param factor        
     * @return
     */
    public native static int verifyDigest(int vendor_id, int dog_id, String challenge, String digest, String factor);


    /**
     * Description:         (      、       、      )
     *
     * @param
     * @return java.lang.String
     * @Author: wtl
     * @Date: 2019/3/16 16:54
     */
    @ResponseBody
    @RequestMapping("getSuperDogConfig")
    public Object jsonObject() {
        //      
        String challenge = null;
        try {
            int[] dll_status = {0};
            challenge = getChallenge(dll_status);
        } catch (UnsatisfiedLinkError e1) {
            log.info(e1);
            throw new RuntimeException(e1);
        } catch (NoClassDefFoundError e1) {
            log.info(e1);
            throw new RuntimeException(e1);
        } catch (Exception e1) {
            log.info(e1);
            throw new RuntimeException(e1);
        }
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("challenge", challenge);
        //       
        jsonObject.put("superDogDefaultPass", ConfigConstant.SUPERDOG_DEFALUTPASS);
        //      
        jsonObject.put("superDogAuthcode", ConfigConstant.SUPERDOG_AUTHCODE);
        return jsonObject;
    }

    /**
     * Description:          
     *
     * @param dog_id        id
     * @param challenge      
     * @param digest                    
     * @return int     0      900     UKey     901     
     * @Author: wtl
     * @Date: 2019/3/16 16:54
     */
    @ResponseBody
    @RequestMapping("verifyDigest")
    public int verifyDigest(int dog_id, String challenge, String digest) {
        int status;
        try {
            status = verifyDigest(ConfigConstant.SUPERDOG_VENDOR_ID, dog_id, challenge, digest, ConfigConstant.SUPERDOG_FACTOR);
            log.debug("       :" + status);


        } catch (UnsatisfiedLinkError e1) {
            status = 901;
            log.info(e1);
        } catch (NoClassDefFoundError e1) {
            status = 901;
            log.info(e1);
        } catch (Exception e) {
            status = 901;
            log.info(e);
        }

        return status;
    }
}