commit 098bd6a5ea9759f91659394d8eefa680a25fb814 Author: scnoh(노승철) Date: Thu Jul 7 10:17:08 2022 +0900 socket init diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..549e00a --- /dev/null +++ b/.gitignore @@ -0,0 +1,33 @@ +HELP.md +target/ +!.mvn/wrapper/maven-wrapper.jar +!**/src/main/**/target/ +!**/src/test/**/target/ + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ +build/ +!**/src/main/**/build/ +!**/src/test/**/build/ + +### VS Code ### +.vscode/ diff --git a/.mvn/wrapper/maven-wrapper.jar b/.mvn/wrapper/maven-wrapper.jar new file mode 100644 index 0000000..c1dd12f Binary files /dev/null and b/.mvn/wrapper/maven-wrapper.jar differ diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties new file mode 100644 index 0000000..22f219d --- /dev/null +++ b/.mvn/wrapper/maven-wrapper.properties @@ -0,0 +1,2 @@ +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar diff --git a/mvnw b/mvnw new file mode 100644 index 0000000..8a8fb22 --- /dev/null +++ b/mvnw @@ -0,0 +1,316 @@ +#!/bin/sh +# ---------------------------------------------------------------------------- +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# https://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# ---------------------------------------------------------------------------- + +# ---------------------------------------------------------------------------- +# Maven Start Up Batch script +# +# Required ENV vars: +# ------------------ +# JAVA_HOME - location of a JDK home dir +# +# Optional ENV vars +# ----------------- +# M2_HOME - location of maven2's installed home dir +# MAVEN_OPTS - parameters passed to the Java VM when running Maven +# e.g. to debug Maven itself, use +# set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +# MAVEN_SKIP_RC - flag to disable loading of mavenrc files +# ---------------------------------------------------------------------------- + +if [ -z "$MAVEN_SKIP_RC" ] ; then + + if [ -f /usr/local/etc/mavenrc ] ; then + . /usr/local/etc/mavenrc + fi + + if [ -f /etc/mavenrc ] ; then + . /etc/mavenrc + fi + + if [ -f "$HOME/.mavenrc" ] ; then + . "$HOME/.mavenrc" + fi + +fi + +# OS specific support. $var _must_ be set to either true or false. +cygwin=false; +darwin=false; +mingw=false +case "`uname`" in + CYGWIN*) cygwin=true ;; + MINGW*) mingw=true;; + Darwin*) darwin=true + # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home + # See https://developer.apple.com/library/mac/qa/qa1170/_index.html + if [ -z "$JAVA_HOME" ]; then + if [ -x "/usr/libexec/java_home" ]; then + export JAVA_HOME="`/usr/libexec/java_home`" + else + export JAVA_HOME="/Library/Java/Home" + fi + fi + ;; +esac + +if [ -z "$JAVA_HOME" ] ; then + if [ -r /etc/gentoo-release ] ; then + JAVA_HOME=`java-config --jre-home` + fi +fi + +if [ -z "$M2_HOME" ] ; then + ## resolve links - $0 may be a link to maven's home + PRG="$0" + + # need this for relative symlinks + while [ -h "$PRG" ] ; do + ls=`ls -ld "$PRG"` + link=`expr "$ls" : '.*-> \(.*\)$'` + if expr "$link" : '/.*' > /dev/null; then + PRG="$link" + else + PRG="`dirname "$PRG"`/$link" + fi + done + + saveddir=`pwd` + + M2_HOME=`dirname "$PRG"`/.. + + # make it fully qualified + M2_HOME=`cd "$M2_HOME" && pwd` + + cd "$saveddir" + # echo Using m2 at $M2_HOME +fi + +# For Cygwin, ensure paths are in UNIX format before anything is touched +if $cygwin ; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --unix "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --unix "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --unix "$CLASSPATH"` +fi + +# For Mingw, ensure paths are in UNIX format before anything is touched +if $mingw ; then + [ -n "$M2_HOME" ] && + M2_HOME="`(cd "$M2_HOME"; pwd)`" + [ -n "$JAVA_HOME" ] && + JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" +fi + +if [ -z "$JAVA_HOME" ]; then + javaExecutable="`which javac`" + if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then + # readlink(1) is not available as standard on Solaris 10. + readLink=`which readlink` + if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then + if $darwin ; then + javaHome="`dirname \"$javaExecutable\"`" + javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" + else + javaExecutable="`readlink -f \"$javaExecutable\"`" + fi + javaHome="`dirname \"$javaExecutable\"`" + javaHome=`expr "$javaHome" : '\(.*\)/bin'` + JAVA_HOME="$javaHome" + export JAVA_HOME + fi + fi +fi + +if [ -z "$JAVACMD" ] ; then + if [ -n "$JAVA_HOME" ] ; then + if [ -x "$JAVA_HOME/jre/sh/java" ] ; then + # IBM's JDK on AIX uses strange locations for the executables + JAVACMD="$JAVA_HOME/jre/sh/java" + else + JAVACMD="$JAVA_HOME/bin/java" + fi + else + JAVACMD="`\\unset -f command; \\command -v java`" + fi +fi + +if [ ! -x "$JAVACMD" ] ; then + echo "Error: JAVA_HOME is not defined correctly." >&2 + echo " We cannot execute $JAVACMD" >&2 + exit 1 +fi + +if [ -z "$JAVA_HOME" ] ; then + echo "Warning: JAVA_HOME environment variable is not set." +fi + +CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher + +# traverses directory structure from process work directory to filesystem root +# first directory with .mvn subdirectory is considered project base directory +find_maven_basedir() { + + if [ -z "$1" ] + then + echo "Path not specified to find_maven_basedir" + return 1 + fi + + basedir="$1" + wdir="$1" + while [ "$wdir" != '/' ] ; do + if [ -d "$wdir"/.mvn ] ; then + basedir=$wdir + break + fi + # workaround for JBEAP-8937 (on Solaris 10/Sparc) + if [ -d "${wdir}" ]; then + wdir=`cd "$wdir/.."; pwd` + fi + # end of workaround + done + echo "${basedir}" +} + +# concatenates all lines of a file +concat_lines() { + if [ -f "$1" ]; then + echo "$(tr -s '\n' ' ' < "$1")" + fi +} + +BASE_DIR=`find_maven_basedir "$(pwd)"` +if [ -z "$BASE_DIR" ]; then + exit 1; +fi + +########################################################################################## +# Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +# This allows using the maven wrapper in projects that prohibit checking in binary data. +########################################################################################## +if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found .mvn/wrapper/maven-wrapper.jar" + fi +else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." + fi + if [ -n "$MVNW_REPOURL" ]; then + jarUrl="$MVNW_REPOURL/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + else + jarUrl="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + fi + while IFS="=" read key value; do + case "$key" in (wrapperUrl) jarUrl="$value"; break ;; + esac + done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" + if [ "$MVNW_VERBOSE" = true ]; then + echo "Downloading from: $jarUrl" + fi + wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" + if $cygwin; then + wrapperJarPath=`cygpath --path --windows "$wrapperJarPath"` + fi + + if command -v wget > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found wget ... using wget" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + wget "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + else + wget --http-user=$MVNW_USERNAME --http-password=$MVNW_PASSWORD "$jarUrl" -O "$wrapperJarPath" || rm -f "$wrapperJarPath" + fi + elif command -v curl > /dev/null; then + if [ "$MVNW_VERBOSE" = true ]; then + echo "Found curl ... using curl" + fi + if [ -z "$MVNW_USERNAME" ] || [ -z "$MVNW_PASSWORD" ]; then + curl -o "$wrapperJarPath" "$jarUrl" -f + else + curl --user $MVNW_USERNAME:$MVNW_PASSWORD -o "$wrapperJarPath" "$jarUrl" -f + fi + + else + if [ "$MVNW_VERBOSE" = true ]; then + echo "Falling back to using Java to download" + fi + javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" + # For Cygwin, switch paths to Windows format before running javac + if $cygwin; then + javaClass=`cygpath --path --windows "$javaClass"` + fi + if [ -e "$javaClass" ]; then + if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Compiling MavenWrapperDownloader.java ..." + fi + # Compiling the Java class + ("$JAVA_HOME/bin/javac" "$javaClass") + fi + if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then + # Running the downloader + if [ "$MVNW_VERBOSE" = true ]; then + echo " - Running MavenWrapperDownloader.java ..." + fi + ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") + fi + fi + fi +fi +########################################################################################## +# End of extension +########################################################################################## + +export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} +if [ "$MVNW_VERBOSE" = true ]; then + echo $MAVEN_PROJECTBASEDIR +fi +MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" + +# For Cygwin, switch paths to Windows format before running java +if $cygwin; then + [ -n "$M2_HOME" ] && + M2_HOME=`cygpath --path --windows "$M2_HOME"` + [ -n "$JAVA_HOME" ] && + JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` + [ -n "$CLASSPATH" ] && + CLASSPATH=`cygpath --path --windows "$CLASSPATH"` + [ -n "$MAVEN_PROJECTBASEDIR" ] && + MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` +fi + +# Provide a "standardized" way to retrieve the CLI args that will +# work with both Windows and non-Windows executions. +MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" +export MAVEN_CMD_LINE_ARGS + +WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +exec "$JAVACMD" \ + $MAVEN_OPTS \ + $MAVEN_DEBUG_OPTS \ + -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ + "-Dmaven.home=${M2_HOME}" \ + "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ + ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" diff --git a/mvnw.cmd b/mvnw.cmd new file mode 100644 index 0000000..1d8ab01 --- /dev/null +++ b/mvnw.cmd @@ -0,0 +1,188 @@ +@REM ---------------------------------------------------------------------------- +@REM Licensed to the Apache Software Foundation (ASF) under one +@REM or more contributor license agreements. See the NOTICE file +@REM distributed with this work for additional information +@REM regarding copyright ownership. The ASF licenses this file +@REM to you under the Apache License, Version 2.0 (the +@REM "License"); you may not use this file except in compliance +@REM with the License. You may obtain a copy of the License at +@REM +@REM https://www.apache.org/licenses/LICENSE-2.0 +@REM +@REM Unless required by applicable law or agreed to in writing, +@REM software distributed under the License is distributed on an +@REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +@REM KIND, either express or implied. See the License for the +@REM specific language governing permissions and limitations +@REM under the License. +@REM ---------------------------------------------------------------------------- + +@REM ---------------------------------------------------------------------------- +@REM Maven Start Up Batch script +@REM +@REM Required ENV vars: +@REM JAVA_HOME - location of a JDK home dir +@REM +@REM Optional ENV vars +@REM M2_HOME - location of maven2's installed home dir +@REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands +@REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a keystroke before ending +@REM MAVEN_OPTS - parameters passed to the Java VM when running Maven +@REM e.g. to debug Maven itself, use +@REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 +@REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files +@REM ---------------------------------------------------------------------------- + +@REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' +@echo off +@REM set title of command window +title %0 +@REM enable echoing by setting MAVEN_BATCH_ECHO to 'on' +@if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% + +@REM set %HOME% to equivalent of $HOME +if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") + +@REM Execute a user defined script before this one +if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre +@REM check for pre script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_pre.bat" call "%USERPROFILE%\mavenrc_pre.bat" %* +if exist "%USERPROFILE%\mavenrc_pre.cmd" call "%USERPROFILE%\mavenrc_pre.cmd" %* +:skipRcPre + +@setlocal + +set ERROR_CODE=0 + +@REM To isolate internal variables from possible post scripts, we use another setlocal +@setlocal + +@REM ==== START VALIDATION ==== +if not "%JAVA_HOME%" == "" goto OkJHome + +echo. +echo Error: JAVA_HOME not found in your environment. >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +:OkJHome +if exist "%JAVA_HOME%\bin\java.exe" goto init + +echo. +echo Error: JAVA_HOME is set to an invalid directory. >&2 +echo JAVA_HOME = "%JAVA_HOME%" >&2 +echo Please set the JAVA_HOME variable in your environment to match the >&2 +echo location of your Java installation. >&2 +echo. +goto error + +@REM ==== END VALIDATION ==== + +:init + +@REM Find the project base dir, i.e. the directory that contains the folder ".mvn". +@REM Fallback to current working directory if not found. + +set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% +IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir + +set EXEC_DIR=%CD% +set WDIR=%EXEC_DIR% +:findBaseDir +IF EXIST "%WDIR%"\.mvn goto baseDirFound +cd .. +IF "%WDIR%"=="%CD%" goto baseDirNotFound +set WDIR=%CD% +goto findBaseDir + +:baseDirFound +set MAVEN_PROJECTBASEDIR=%WDIR% +cd "%EXEC_DIR%" +goto endDetectBaseDir + +:baseDirNotFound +set MAVEN_PROJECTBASEDIR=%EXEC_DIR% +cd "%EXEC_DIR%" + +:endDetectBaseDir + +IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig + +@setlocal EnableExtensions EnableDelayedExpansion +for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a +@endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% + +:endReadAdditionalConfig + +SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" +set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" +set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain + +set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + +FOR /F "usebackq tokens=1,2 delims==" %%A IN ("%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties") DO ( + IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B +) + +@REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central +@REM This allows using the maven wrapper in projects that prohibit checking in binary data. +if exist %WRAPPER_JAR% ( + if "%MVNW_VERBOSE%" == "true" ( + echo Found %WRAPPER_JAR% + ) +) else ( + if not "%MVNW_REPOURL%" == "" ( + SET DOWNLOAD_URL="%MVNW_REPOURL%/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar" + ) + if "%MVNW_VERBOSE%" == "true" ( + echo Couldn't find %WRAPPER_JAR%, downloading it ... + echo Downloading from: %DOWNLOAD_URL% + ) + + powershell -Command "&{"^ + "$webclient = new-object System.Net.WebClient;"^ + "if (-not ([string]::IsNullOrEmpty('%MVNW_USERNAME%') -and [string]::IsNullOrEmpty('%MVNW_PASSWORD%'))) {"^ + "$webclient.Credentials = new-object System.Net.NetworkCredential('%MVNW_USERNAME%', '%MVNW_PASSWORD%');"^ + "}"^ + "[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12; $webclient.DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')"^ + "}" + if "%MVNW_VERBOSE%" == "true" ( + echo Finished downloading %WRAPPER_JAR% + ) +) +@REM End of extension + +@REM Provide a "standardized" way to retrieve the CLI args that will +@REM work with both Windows and non-Windows executions. +set MAVEN_CMD_LINE_ARGS=%* + +%MAVEN_JAVA_EXE% ^ + %JVM_CONFIG_MAVEN_PROPS% ^ + %MAVEN_OPTS% ^ + %MAVEN_DEBUG_OPTS% ^ + -classpath %WRAPPER_JAR% ^ + "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^ + %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* +if ERRORLEVEL 1 goto error +goto end + +:error +set ERROR_CODE=1 + +:end +@endlocal & set ERROR_CODE=%ERROR_CODE% + +if not "%MAVEN_SKIP_RC%"=="" goto skipRcPost +@REM check for post script, once with legacy .bat ending and once with .cmd ending +if exist "%USERPROFILE%\mavenrc_post.bat" call "%USERPROFILE%\mavenrc_post.bat" +if exist "%USERPROFILE%\mavenrc_post.cmd" call "%USERPROFILE%\mavenrc_post.cmd" +:skipRcPost + +@REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' +if "%MAVEN_BATCH_PAUSE%"=="on" pause + +if "%MAVEN_TERMINATE_CMD%"=="on" exit %ERROR_CODE% + +cmd /C exit /B %ERROR_CODE% diff --git a/pom.xml b/pom.xml new file mode 100644 index 0000000..a0a3af9 --- /dev/null +++ b/pom.xml @@ -0,0 +1,68 @@ + + + 4.0.0 + + org.springframework.boot + spring-boot-starter-parent + 2.7.1 + + + com.palnet + pav-socket + 0.0.1-SNAPSHOT + pav-socket + pav-socket + + 11 + + + + org.springframework.boot + spring-boot-starter-amqp + + + org.springframework.boot + spring-boot-starter-web + + + + org.projectlombok + lombok + true + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.amqp + spring-rabbit-test + test + + + io.netty + netty-all + 4.1.77.Final + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + org.projectlombok + lombok + + + + + + + + diff --git a/src/main/java/com/palnet/Application.java b/src/main/java/com/palnet/Application.java new file mode 100644 index 0000000..15c9de7 --- /dev/null +++ b/src/main/java/com/palnet/Application.java @@ -0,0 +1,13 @@ +package com.palnet; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class Application { + + public static void main(String[] args) { + SpringApplication.run(Application.class, args); + } + +} diff --git a/src/main/java/com/palnet/comn/collection/AuthCollection.java b/src/main/java/com/palnet/comn/collection/AuthCollection.java new file mode 100644 index 0000000..492719d --- /dev/null +++ b/src/main/java/com/palnet/comn/collection/AuthCollection.java @@ -0,0 +1,45 @@ +package com.palnet.comn.collection; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.List; + +public class AuthCollection { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + private static List authkeyList = new ArrayList(); + + public void reloadAuthkey() { + // 인증키 하드코딩 처리 + authkeyList.add("1cc2e08e-0c5c-43b2-8d4d-cddd3de558e3");// 지텔인증키 + authkeyList.add("35ea4080-a3f2-4e34-8361-78db06bac6fc");// PAL 인증키 + +// authkeyList.add(null) + } + + public boolean checkAuthkey(String authKey) { + boolean result = false; +// logger.debug("authKey ::: " + authKey); + + for(String key : authkeyList) { +// logger.debug("key ::: " + key); + if(authKey.equals(key)) { + result = true; + } + } + + return result; + } + + + public static void main(String [] agrs) { + AuthCollection auth = new AuthCollection(); + auth.reloadAuthkey(); + + System.out.println("1>>>>> " + auth.checkAuthkey("!234")); + System.out.println("2>>>>> " + auth.checkAuthkey("1cc2e08e-0c5c-43b2-8d4d-cddd3de558e3")); + } +} diff --git a/src/main/java/com/palnet/comn/collection/GPCollection.java b/src/main/java/com/palnet/comn/collection/GPCollection.java new file mode 100644 index 0000000..195abbe --- /dev/null +++ b/src/main/java/com/palnet/comn/collection/GPCollection.java @@ -0,0 +1,70 @@ +package com.palnet.comn.collection; + +import com.palnet.comn.utils.ContextUtils; +import com.palnet.comn.utils.DateUtils; +import com.palnet.process.message.producer.MessageProducer; +import com.palnet.process.model.GPDatabaseModel; +import com.palnet.process.model.GPHistoryModel; +import com.palnet.process.model.GPModel; +import lombok.extern.slf4j.Slf4j; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.BeanUtils; + +import java.util.*; + +/** + * 현재 움직이는 물체/비행체에 대한 정보를 전송하기 위해 저장하는 Collection + * @author kang + * + */ + +@Slf4j +public class GPCollection { + private Logger logger = LoggerFactory.getLogger(getClass()); + + private static Map identKeys = Collections.synchronizedMap(new HashMap()); // 기체의 식별 번호 + + private MessageProducer messageProducer; + + public GPCollection() { + this.messageProducer = (MessageProducer) ContextUtils.getBean("messageProducer"); + } + + // 받은 데이터 정보를 데이터구조에 맞게 저장 한다. + // 최초에 데이터를 수신한 경우 관제 ID , 관제시작 시간을 셋팅한다. + public void putData(List paramData) { + + List historyList; + GPModel model = new GPModel(); + + for(GPModel data : paramData) { + data.setServerRcvDt(DateUtils.getCurrentTime()); //서버에서 받은 시간 넣기 + + // History Coordinates Settings + GPHistoryModel historyModel = new GPHistoryModel(); + historyModel.setObjectId(data.getObjectId()); + historyModel.setLat(data.getLat()); + historyModel.setLng(data.getLng()); + + if (data.getPostionHistory() != null) { + historyList = data.getPostionHistory(); + } else { + historyList = new ArrayList<>(); + } + + historyList.add(historyModel); + data.setPostionHistory(historyList); + + /* Message Queue Server 전달 */ + convertModel(model); + } + } + + public void convertModel(GPModel model) { + GPDatabaseModel databaseModel = new GPDatabaseModel(); + + BeanUtils.copyProperties(model, databaseModel); + messageProducer.sendSocketData(databaseModel); + } +} diff --git a/src/main/java/com/palnet/comn/collection/GPDatabaseCollection.java b/src/main/java/com/palnet/comn/collection/GPDatabaseCollection.java new file mode 100644 index 0000000..491331c --- /dev/null +++ b/src/main/java/com/palnet/comn/collection/GPDatabaseCollection.java @@ -0,0 +1,47 @@ +//package com.palnet.comn.collection; +// +//import com.palnet.comn.model.GPDatabaseModel; +//import com.palnet.comn.utils.BeanUtils; +//import com.palnet.server.message.producer.MessageProducer; +//import org.slf4j.Logger; +//import org.slf4j.LoggerFactory; +// +//import java.util.concurrent.ConcurrentLinkedQueue; +// +///** +// * 전송된 원시데이터를 Database 에 넣기 위해 임시 저장해두는 Collection +// * @author kang +// * +// */ +//public class GPDatabaseCollection { +// +// private Logger logger = LoggerFactory.getLogger(getClass()); +// +// private static ConcurrentLinkedQueue dataList = new ConcurrentLinkedQueue(); +// private MessageProducer messageProducer; +// +// public void putData(GPDatabaseModel paramData) { +// dataList.add(paramData); +// +// } +// +//// public void putListData(List paramDataList) { +//// dataList.addAll(paramDataList); +//// } +// +// public ConcurrentLinkedQueue getData(){ +// +// return dataList; +// } +// +//// public static void main(String[] args) { +//// ConcurrentLinkedQueue qe = new ConcurrentLinkedQueue(); +//// +//// } +//// +// public void messageSend(GPDatabaseModel model) { +// messageProducer = (MessageProducer) BeanUtils.getBean("kafkaProducer"); +// messageProducer.send("sample-topic", model); +// } +// +//} diff --git a/src/main/java/com/palnet/comn/utils/ContextUtils.java b/src/main/java/com/palnet/comn/utils/ContextUtils.java new file mode 100644 index 0000000..34ee00b --- /dev/null +++ b/src/main/java/com/palnet/comn/utils/ContextUtils.java @@ -0,0 +1,25 @@ +package com.palnet.comn.utils; + +import org.springframework.beans.BeansException; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.stereotype.Component; + +@Component +public class ContextUtils implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + @Override + public void setApplicationContext(ApplicationContext ctx) throws BeansException { + applicationContext = ctx; + } + + public static ApplicationContext getApplicationContext() { + return applicationContext; + } + + public static Object getBean(String beanName) { + return getApplicationContext().getBean(beanName); + } +} diff --git a/src/main/java/com/palnet/comn/utils/DateUtils.java b/src/main/java/com/palnet/comn/utils/DateUtils.java new file mode 100644 index 0000000..3a1f867 --- /dev/null +++ b/src/main/java/com/palnet/comn/utils/DateUtils.java @@ -0,0 +1,153 @@ +package com.palnet.comn.utils; + +import java.text.SimpleDateFormat; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; +import java.time.format.DateTimeFormatterBuilder; +import java.time.temporal.ChronoField; +import java.util.Date; + +public class DateUtils { + + public static String getCurrentTime(){ + return new SimpleDateFormat("yyyyMMddHHmmss").format(System.currentTimeMillis()); + } + + public static String stringToFormat(String str) { + Date date = stringToDatetime(str); + + return new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(date); + } + + + public static Date stringToDatetime(String date) { + + SimpleDateFormat transFormat = new SimpleDateFormat("yyyyMMddHHmmss"); + Date result = null; + try { + if(date.length() == 14) { + result = transFormat.parse(date); + } + }catch(Exception e) { + e.printStackTrace(); + } + + return result; + } + + public static Date stringToDate(String date) { + SimpleDateFormat transFormat = new SimpleDateFormat("yyyy-MM-dd"); + SimpleDateFormat transFormat2 = new SimpleDateFormat("yyyyMMdd"); + Date result = null; + try { + if(date.length() == 10) { + result = transFormat.parse(date); + }else if(date.length() == 8) { + result = transFormat2.parse(date); + } + }catch(Exception e) { + e.printStackTrace(); + } + + return result; + } + + public static LocalDateTime stringToLocalDateTime(String date) { + + DateTimeFormatter transFormat = DateTimeFormatter.ofPattern("yyyyMMddHHmmss"); + LocalDateTime localDateTime = LocalDateTime.parse(date , transFormat); + + return localDateTime; + + } + + + + public static LocalDateTime stringToLocalDate(String date) { + DateTimeFormatter transFormat = DateTimeFormatter.ofPattern("yyyy-MM-dd"); + + DateTimeFormatter DATEFORMATTER = new DateTimeFormatterBuilder().append(transFormat) + .parseDefaulting(ChronoField.HOUR_OF_DAY, 0) + .parseDefaulting(ChronoField.MINUTE_OF_HOUR, 0) + .parseDefaulting(ChronoField.SECOND_OF_MINUTE, 0) + .toFormatter(); + + + LocalDateTime localDateTime = LocalDateTime.parse(date , DATEFORMATTER); + + return localDateTime; + } + + + public static Date nowDate() { + return new Date(System.currentTimeMillis()); + } + + public static long diffSecond(Date firstDate , Date secondDate) { + + long diffDate = secondDate.getTime() - firstDate.getTime(); + long diffTime = diffDate / (1000); + + return diffTime; + + } + + public static long diffMinute(Date firstDate , Date secondDate) { + + long diffDate = secondDate.getTime() - firstDate.getTime(); + long diffTime = diffDate / (1000 * 60); + + return diffTime; + + } + + + +// public static void main(String[] args) { +// +// Date firstDate = stringToDate("20210630142014"); +// +// Date secondDate = stringToDate("20210630142914"); +// +// LocalDateTime dateTime = stringToLocalDate("2021-07-20"); +// +// System.out.println(">>>>" + dateTime); +// +// +// System.out.println("두 날짜의 차이 분: "+diffMinute(firstDate , secondDate)); +// +// System.out.println(">>>" + stringToFormat("20210630142014")); +// +// +// +// +// +//// List> list = new ArrayList>(); +//// +//// +//// for( double i= 0 ; i < 1000 ; i ++) { +//// Map position = new HashMap(); +//// position.put("lat", 11111.0); +//// position.put("lng", 11111.0); +//// position.put("date", i); +//// list.add(position); +//// } +//// +//// int limitSize = 1000; +//// if(list.size() < 1000) { +//// limitSize = list.size(); +//// } +//// +//// List> lastThreeThings = list.subList(list.size() - limitSize, list.size()); +//// +//// //뒤집기 +//// Collections.reverse(lastThreeThings); +//// +//// for(Map data : lastThreeThings) { +//// +//// +//// System.out.println(data); +//// } +// +// } +} diff --git a/src/main/java/com/palnet/comn/utils/JsonUtils.java b/src/main/java/com/palnet/comn/utils/JsonUtils.java new file mode 100644 index 0000000..6b28ef2 --- /dev/null +++ b/src/main/java/com/palnet/comn/utils/JsonUtils.java @@ -0,0 +1,80 @@ +package com.palnet.comn.utils; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import lombok.extern.slf4j.Slf4j; + +import java.io.IOException; + +@Slf4j +public class JsonUtils { + + private static ObjectMapper getObjectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); + return mapper; + } + + public static String toJson(Object object) { + String json = null; + + try { + json = getObjectMapper().writeValueAsString(object); + } catch (JsonProcessingException e) { + log.error("", e); + } + + return json; + } + + public static T fromJson(String val, Class clazz){ + T object = null; + + try { + object = getObjectMapper().readValue(val, clazz); + } catch (IOException e) { + log.error("", e); + } + + return object; + } + + public static T fromJson(byte[] bytes, Class clazz){ + T object = null; + + try { + object = getObjectMapper().readValue(bytes, clazz); + } catch (IOException e) { + log.error("", e); + } + + return object; + } + + public static T fromJson(String val, TypeReference type){ + T object = null; + + try { + object = getObjectMapper().readValue(val, type); + } catch (IOException e) { + log.error("", e); + } + + return object; + } + + public static T bytesToJson(byte[] bytes, TypeReference type){ + T object = null; + + try { + object = getObjectMapper().readValue(bytes, type); + } catch (IOException e) { + log.error("", e); + } + + return object; + } + +} diff --git a/src/main/java/com/palnet/process/message/config/MessageConfig.java b/src/main/java/com/palnet/process/message/config/MessageConfig.java new file mode 100644 index 0000000..ea310af --- /dev/null +++ b/src/main/java/com/palnet/process/message/config/MessageConfig.java @@ -0,0 +1,61 @@ +package com.palnet.process.message.config; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.core.Binding; +import org.springframework.amqp.core.BindingBuilder; +import org.springframework.amqp.core.Queue; +import org.springframework.amqp.core.TopicExchange; + +import org.springframework.amqp.rabbit.connection.CachingConnectionFactory; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; + +@Configuration +@Slf4j +public class MessageConfig { + + private final Environment env; + + public MessageConfig(Environment env) { + this.env = env; + } + + @Bean + public CachingConnectionFactory cachingConnectionFactory() { + return new CachingConnectionFactory(); + } + + @Bean + public Jackson2JsonMessageConverter converter() { + return new Jackson2JsonMessageConverter(); + } + + @Bean + public TopicExchange droneExchange() { + return new TopicExchange(env.getProperty("message.dron.exchange-name")); + } + + @Bean + public Queue droneQueue() { + return new Queue(env.getProperty("message.dron.queue-name")); + } + + @Bean + public Binding droneBinding(Queue queue, TopicExchange exchange) { + return BindingBuilder.bind(queue).to(exchange).with(env.getProperty("message.dron.routing-key")); + } + + @Bean + public RabbitTemplate rabbitTemplate(CachingConnectionFactory connectionFactory, Jackson2JsonMessageConverter converter) { + RabbitTemplate rabbitTemplate = new RabbitTemplate(); + + rabbitTemplate.setConnectionFactory(connectionFactory); + rabbitTemplate.setMessageConverter(converter); + + return rabbitTemplate; + } + +} diff --git a/src/main/java/com/palnet/process/message/producer/MessageProducer.java b/src/main/java/com/palnet/process/message/producer/MessageProducer.java new file mode 100644 index 0000000..09c2d1b --- /dev/null +++ b/src/main/java/com/palnet/process/message/producer/MessageProducer.java @@ -0,0 +1,31 @@ +package com.palnet.process.message.producer; + + +import com.palnet.process.model.GPDatabaseModel; +import com.palnet.process.model.GPModel; +import lombok.extern.slf4j.Slf4j; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.core.env.Environment; +import org.springframework.stereotype.Component; + +import java.util.Objects; + +@Component +@Slf4j +public class MessageProducer { + + private final RabbitTemplate rabbitTemplate; + private final Environment env; + + public MessageProducer(RabbitTemplate rabbitTemplate, Environment env) { + this.rabbitTemplate = rabbitTemplate; + this.env = env; + } + + public void sendSocketData(GPDatabaseModel model) { + rabbitTemplate.convertAndSend( + Objects.requireNonNull(env.getProperty("message.drone.exchange-name")), + Objects.requireNonNull(env.getProperty("message.drone.routing-key")), + model); + } +} diff --git a/src/main/java/com/palnet/process/model/GPDatabaseModel.java b/src/main/java/com/palnet/process/model/GPDatabaseModel.java new file mode 100644 index 0000000..00db3bf --- /dev/null +++ b/src/main/java/com/palnet/process/model/GPDatabaseModel.java @@ -0,0 +1,65 @@ +package com.palnet.process.model; + +import lombok.Data; + +@Data +public class GPDatabaseModel { + + private String typeCd; // 01 : 최초 들어온 데이터 , 99 : 종료 시킬 데이터 + + private String messageType; + + private String terminalId; + + private Double moveDistance = 0.0; + + private String moveDistanceType; + + private String prodNumber; + + private String controlId; + + private String objectType; + + private String objectId; + + private Double lat = 0.0; + + private Double lng = 0.0; + + private String elevType; + + private Double elev = 0.0; + + private String speedType; + + private Double speed = 0.0; + + private Double betteryLevel = 0.0; + + private Double betteryVoltage = 0.0; + + private String dronStatus; + + private Double heading = 0.0; + + private String terminalRcvDt; + + private String serverRcvDt; + + private String controlStartDt; + + private String controlEndDt; + + private String areaTrnsYn; + + private String endTypeCd; // 01: 일정시간 위치 정보가 들어오지 않는 경우 , 02 : 데이터 베이스에 종료 시점이 명시 되지 않은 경우 + + // 환경센서 필드 + private Double sensorCo = 0.0; + private Double sensorSo2 = 0.0; + private Double sensorNo2 = 0.0; + private Double sensorO3 = 0.0; + private Double sensorDust = 0.0; + +} diff --git a/src/main/java/com/palnet/process/model/GPHistoryModel.java b/src/main/java/com/palnet/process/model/GPHistoryModel.java new file mode 100644 index 0000000..4557984 --- /dev/null +++ b/src/main/java/com/palnet/process/model/GPHistoryModel.java @@ -0,0 +1,15 @@ +package com.palnet.process.model; + +import lombok.Data; + +@Data +public class GPHistoryModel { + + private String objectId; + + private Double lat = 0.0; + + private Double lng = 0.0; + + +} diff --git a/src/main/java/com/palnet/process/model/GPModel.java b/src/main/java/com/palnet/process/model/GPModel.java new file mode 100644 index 0000000..64674c4 --- /dev/null +++ b/src/main/java/com/palnet/process/model/GPModel.java @@ -0,0 +1,70 @@ +package com.palnet.process.model; + +import lombok.Data; + +import java.util.List; + +@Data +public class GPModel { + + private String typeCd; // 01 : 최초 들어온 데이터 , 99 : 종료 시킬 데이터 + + private String messageType; + + private String terminalId; + + private Double moveDistance = 0.0; + + private String moveDistanceType; + + private String controlId; // 처음 위치 데이터가 들어 왔을때 생성 함 + + private String objectType; + + private String objectId; + + private Double lat = 0.0; + + private Double lng = 0.0; + + private String elevType; + + private Double elev = 0.0; + + private String speedType; + + private Double speed = 0.0; + + private Double betteryLevel = 0.0; + + private Double betteryVoltage = 0.0; + + private String dronStatus; + + private Double heading = 0.0; + + private String terminalRcvDt; + + private String serverRcvDt; + + private String controlStartDt; + + private String controlEndDt; + + private String areaTrnsYn; + + // 환경센서 필드 + private Double sensorCo = 0.0; + private Double sensorSo2 = 0.0; + private Double sensorNo2 = 0.0; + private Double sensorO3 = 0.0; + private Double sensorDust = 0.0; + + //최근 5건만 저장 + private List recentPositionHistory; + + // 전체 히스토리 저장 + private List postionHistory; + + +} diff --git a/src/main/java/com/palnet/server/SocketServer.java b/src/main/java/com/palnet/server/SocketServer.java new file mode 100644 index 0000000..8e544a9 --- /dev/null +++ b/src/main/java/com/palnet/server/SocketServer.java @@ -0,0 +1,112 @@ +package com.palnet.server; + +import com.palnet.server.initializer.SocketInitializer; +import io.netty.bootstrap.ServerBootstrap; +import io.netty.channel.Channel; +import io.netty.channel.ChannelFuture; +import io.netty.channel.ChannelOption; +import io.netty.channel.EventLoopGroup; +import io.netty.channel.nio.NioEventLoopGroup; +import io.netty.channel.socket.nio.NioServerSocketChannel; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Component; + +import javax.annotation.PostConstruct; +import javax.annotation.PreDestroy; + +@Component +public class SocketServer { + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Value("${netty.socket.port}") + private int port; + + @Value("${netty.socket.thread.boss}") + private int threadBoss; + + @Value("${netty.socket.thread.worker}") + private int threadWorker; + + + private Channel ch; + + private EventLoopGroup bossGroup ; + private EventLoopGroup workerGroup ; + private ServerBootstrap b = new ServerBootstrap(); + +// @Autowired +// private AdsbClient client; +// + + @PostConstruct + public void postConstruct(){ + start(); + } + + + @PreDestroy + public void preDestroy(){ + + stop(); + } + + public void start(){ + try { + bossGroup = new NioEventLoopGroup(10); + workerGroup =new NioEventLoopGroup(); + + b.group(bossGroup , workerGroup) // bossGroup과 workerGroup은 NioEventLoopGroup의 인스턴스입니다.이 때 스레드 개수를 설정할 수 있음 각각 1, Runtime.getRuntime().availableProcessors() * 2로 설정했습니다. + .channel(NioServerSocketChannel.class) +// .handler(new LoggingHandler(LogLevel.valueOf(logBootstrap))) +// .handler(bootstrapHandler) // 채널이 활성화되면 소켓 서버와 소켓 클라이언트를 구동하게 되는 핸들러를 등록합니다. + .option(ChannelOption.CONNECT_TIMEOUT_MILLIS, 3000) + .option(ChannelOption.SO_BACKLOG, 1000) // 동시에 수용할 수 있는 소켓 연결 요청 수입니다. + +// .option(ChannelOption.RCVBUF_ALLOCATOR, new AdaptiveRecvByteBufAllocator(1024 , 1024 * 16 , 1024 * 1024)) + .childOption(ChannelOption.TCP_NODELAY, false) // 반응속도를 높이기 위해 Nagle 알고리즘을 비활성화 합니다 + + .childOption(ChannelOption.SO_LINGER, 0) // 소켓이 close될 때 신뢰성있는 종료를 위해 4way-handshake가 발생하고 이때 TIME_WAIT로 리소스가 낭비됩니다. 이를 방지하기 위해 0으로 설정합니다. + .childOption(ChannelOption.SO_KEEPALIVE, false) // Keep-alive를 켭니다. + .childOption(ChannelOption.SO_REUSEADDR, false) // SO_LINGER설정이 있으면 안해도 되나 혹시나병(!)으로 TIME_WAIT걸린 포트를 재사용할 수 있도록 설정합니다. + .childHandler(new SocketInitializer()); + + connection(); +// taskProcess(); +// client.start(); + + logger.warn("====== [SOCKET SERVER] Start ====== "); + }catch (Exception e) { + logger.warn("====== [SOCKET SERVER] Fail ====== "); + logger.error(e.getMessage()); + } + + } + + private void connection() { + //서버는 Listen상태로 기다려야하는데, 톰캣이 Timeout이 발생함 + //이를 방지하기 위해 Thread로 처리한다. + new Thread(new Runnable() { + @Override + public void run() { + try { + ChannelFuture future = b.bind(port).sync(); + future.channel().closeFuture().sync(); + + } catch (InterruptedException e) { + logger.error("InterruptedException", e); + } + } + }).start(); + } + + + public void stop(){ + bossGroup.shutdownGracefully(); + workerGroup.shutdownGracefully(); + logger.warn("====== [SOCKET SERVER] STOP ====== "); + + } + +} diff --git a/src/main/java/com/palnet/server/codec/BigIntegerDecoder.java b/src/main/java/com/palnet/server/codec/BigIntegerDecoder.java new file mode 100644 index 0000000..290ac39 --- /dev/null +++ b/src/main/java/com/palnet/server/codec/BigIntegerDecoder.java @@ -0,0 +1,52 @@ +/* + * Copyright 2012 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package com.palnet.server.codec; + +import io.netty.buffer.ByteBuf; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.ByteToMessageDecoder; + +import java.math.BigInteger; +import java.util.List; + +/** + * Decodes the binary representation of a {@link BigInteger} prepended + * with a magic number ('F' or 0x46) and a 32-bit integer length prefix into a + * {@link BigInteger} instance. For example, { 'F', 0, 0, 0, 1, 42 } will be + * decoded into new BigInteger("42"). + */ +public class BigIntegerDecoder extends ByteToMessageDecoder { + + @Override + protected void decode(ChannelHandlerContext ctx, ByteBuf in, List out) { + + + + System.out.println(">>>>>>>>>>>>>>>>>>>>>" + in.readableBytes()); + + if (in.isReadable()) { + byte[] bytes = new byte[in.readableBytes()]; + + int readerIndex = in.readerIndex(); + in.getBytes(readerIndex, bytes); + + System.out.println(">>>" + new String(bytes)); + + } + // Wait until the length prefix is available. + + } +} diff --git a/src/main/java/com/palnet/server/codec/SocketPayLoadDecoder.java b/src/main/java/com/palnet/server/codec/SocketPayLoadDecoder.java new file mode 100644 index 0000000..2d697ab --- /dev/null +++ b/src/main/java/com/palnet/server/codec/SocketPayLoadDecoder.java @@ -0,0 +1,39 @@ +package com.palnet.server.codec; + +import com.palnet.comn.utils.JsonUtils; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageDecoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +@Sharable +public class SocketPayLoadDecoder extends MessageToMessageDecoder { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + @Override + protected void decode(ChannelHandlerContext ctx, Object msg, List out){ +// logger.info("[SocketPayLoadDecoder] Init 2 " ); + SocketPayload payload = null; + + try { + payload = JsonUtils.fromJson((String) msg, SocketPayload.class); + if(payload != null) { + out.add(payload); + + } + }catch(Exception e) { + logger.info("MSG => " + msg ); + logger.error(e.getMessage()); + + } + + + + } + + +} diff --git a/src/main/java/com/palnet/server/codec/SocketPayLoadEncorder.java b/src/main/java/com/palnet/server/codec/SocketPayLoadEncorder.java new file mode 100644 index 0000000..121fe61 --- /dev/null +++ b/src/main/java/com/palnet/server/codec/SocketPayLoadEncorder.java @@ -0,0 +1,36 @@ +package com.palnet.server.codec; + +import com.palnet.comn.utils.JsonUtils; +import io.netty.channel.ChannelHandler.Sharable; +import io.netty.channel.ChannelHandlerContext; +import io.netty.handler.codec.MessageToMessageEncoder; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +@Sharable +public class SocketPayLoadEncorder extends MessageToMessageEncoder { + + private Logger logger = LoggerFactory.getLogger(getClass()); + + + @Override + protected void encode(ChannelHandlerContext ctx, SocketPayloadResponse msg, List out){ + try { + out.add(JsonUtils.toJson(msg)); +// logger.debug("[SocketPayLoadEncorder] Init 11111" ); + logger.info("=== >>>>>>>>>>>>>>" , JsonUtils.toJson(msg)); + }catch(Exception e) { + logger.info("MSG => " + msg ); + logger.error(e.getMessage()); + } + + + + } + + + + +} diff --git a/src/main/java/com/palnet/server/codec/SocketPayload.java b/src/main/java/com/palnet/server/codec/SocketPayload.java new file mode 100644 index 0000000..31feda7 --- /dev/null +++ b/src/main/java/com/palnet/server/codec/SocketPayload.java @@ -0,0 +1,22 @@ +package com.palnet.server.codec; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SocketPayload implements Serializable{ + + private static final long serialVersionUID = 1L; + + private String authKey; + + private String terminalId; + + private String command; + + private Object body; + + + +} diff --git a/src/main/java/com/palnet/server/codec/SocketPayloadResponse.java b/src/main/java/com/palnet/server/codec/SocketPayloadResponse.java new file mode 100644 index 0000000..bf9712a --- /dev/null +++ b/src/main/java/com/palnet/server/codec/SocketPayloadResponse.java @@ -0,0 +1,18 @@ +package com.palnet.server.codec; + +import lombok.Data; + +import java.io.Serializable; + +@Data +public class SocketPayloadResponse implements Serializable{ + + private static final long serialVersionUID = 1L; + + private String rspCode; + + private String rspMessage; + + + +} diff --git a/src/main/java/com/palnet/server/collection/ChannelCollection.java b/src/main/java/com/palnet/server/collection/ChannelCollection.java new file mode 100644 index 0000000..6524690 --- /dev/null +++ b/src/main/java/com/palnet/server/collection/ChannelCollection.java @@ -0,0 +1,26 @@ +package com.palnet.server.collection; + +import io.netty.channel.Channel; +import io.netty.channel.group.ChannelGroup; +import io.netty.channel.group.DefaultChannelGroup; +import io.netty.util.concurrent.GlobalEventExecutor; + + +public class ChannelCollection { + + private static final long serialVersionUID = 1L; + + //접속 되어있는 모든 Channel + private static final ChannelGroup allChannels = new DefaultChannelGroup(GlobalEventExecutor.INSTANCE); + + + public void setAllChannels(Channel ch) { + allChannels.add(ch); + } + + public ChannelGroup getAllChannels() { + return allChannels; + } + + +} diff --git a/src/main/java/com/palnet/server/command/SocketCommand.java b/src/main/java/com/palnet/server/command/SocketCommand.java new file mode 100644 index 0000000..61f6a97 --- /dev/null +++ b/src/main/java/com/palnet/server/command/SocketCommand.java @@ -0,0 +1,137 @@ +package com.palnet.server.command; + +import com.palnet.comn.collection.GPCollection; +import com.palnet.process.model.GPModel; +import com.palnet.server.codec.SocketPayload; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.LinkedHashMap; +import java.util.List; + +public class SocketCommand { + + private Logger logger = LoggerFactory.getLogger(getClass()); + GPCollection collection = new GPCollection(); + + + public void openSkyCollectionPut(SocketPayload payload) { + + /** 전문 설정 ***/ + String messageType = "OPENSKY"; + String objectType = "FLIGHT"; + + List> resultList = new ArrayList>(); + + List dataList = new ArrayList(); + + logger.debug("BODY TYPE :: " + payload.getBody().getClass()); + + resultList = (ArrayList)payload.getBody(); + + GPModel model; + + for(LinkedHashMap obj : resultList) { + model = new GPModel(); + + model.setObjectType(objectType); + model.setMessageType(messageType); + model.setObjectId(obj.get("objectId").toString().trim()); + model.setTerminalId(obj.get("terminalId").toString().trim()); + model.setLat((Double)obj.get("lat")); + model.setLng((Double)obj.get("lng")); + model.setElev((Double)obj.get("elev")); + model.setTerminalRcvDt(obj.get("terminalRcvDt").toString().trim()); + model.setSpeed((Double)obj.get("speed")); + model.setHeading((Double)obj.get("heading")); + model.setSpeedType((String)obj.get("speedType")); + model.setElevType((String)obj.get("elevType")); + model.setMoveDistanceType((String)obj.get("moveDistanceType")); + model.setMoveDistance((Double)obj.get("moveDistance")); + + model.setBetteryLevel((Double)obj.get("betteryLevel")); + model.setBetteryVoltage((Double)obj.get("betteryVoltage")); + model.setDronStatus((String)obj.get("dronStatus")); + + dataList.add(model); + } + + collection.putData(dataList); +// logger.debug("SIZE :: " +collection.getData().size() ); + } + + + /** + * 들어온 데이터를 collection넣는 작업을 한다. + * @param payload + */ + public void sandboxCollectionPut(SocketPayload payload) { + + /** 전문 설정 ***/ + String messageType = "LTEM"; + String objectType = "DRON"; + + List> resultList = new ArrayList>(); + + List dataList = new ArrayList(); + + logger.debug("BODY TYPE :: " + payload.getBody().getClass()); + + resultList = (ArrayList)payload.getBody(); + + GPModel model; + + for(LinkedHashMap obj : resultList) { + + //위,경도 좌표가 0으로 들어오는 것은 무시 처리 + if((Double)obj.get("lat") > 0 && (Double)obj.get("lon") > 0) { + model = new GPModel(); +// logger.debug(">>>>" + obj.toString()); + model.setObjectType(objectType); + model.setMessageType(messageType); + model.setObjectId(obj.get("objectId").toString().trim()); + model.setTerminalId(payload.getTerminalId()); + if(obj.get("lat") != null) model.setLat(Double.valueOf(obj.get("lat").toString())); + if(obj.get("lon") != null) model.setLng(Double.valueOf(obj.get("lon").toString())); + if(obj.get("elev") != null) model.setElev(Double.valueOf(obj.get("elev").toString())); + model.setTerminalRcvDt(obj.get("terminalRcvDt").toString().trim()); + if(obj.get("speed") != null) model.setSpeed(Double.valueOf(obj.get("speed").toString())); + if(obj.get("heading") != null) model.setHeading(Double.valueOf(obj.get("heading").toString())); + model.setSpeedType((String)obj.get("speedType")); + model.setElevType((String)obj.get("elevType")); + model.setMoveDistanceType((String)obj.get("moveDistanceType")); + if(obj.get("moveDistance") != null) model.setMoveDistance(Double.valueOf(obj.get("moveDistance").toString())); + + if(obj.get("betteryLevel") != null) model.setBetteryLevel(Double.valueOf(obj.get("betteryLevel").toString())); + if(obj.get("betteryVoltage") != null) model.setBetteryVoltage(Double.valueOf(obj.get("betteryVoltage").toString())); + model.setDronStatus((String)obj.get("dronStatus")); + + // 환경 데이터 필드 추가 + if(obj.get("sensorCo") != null) model.setSensorCo(Double.valueOf(obj.get("sensorCo").toString())); + if(obj.get("sensorSo2") != null) model.setSensorSo2(Double.valueOf(obj.get("sensorSo2").toString())); + if(obj.get("sensorNo2") != null) model.setSensorNo2(Double.valueOf(obj.get("sensorNo2").toString())); + if(obj.get("sensorO3") != null) model.setSensorO3(Double.valueOf(obj.get("sensorO3").toString())); + if(obj.get("sensorDust") != null) model.setSensorDust(Double.valueOf(obj.get("sensorDust").toString())); + + // TODO 환경 데이터 임의의 데이터로 수정 - 추후 제거(임시코드) +// if(model.getSensorCo() != null){ +// model.setSensorCo(TempUtils.gradualData("co")); +// model.setSensorSo2(TempUtils.gradualData("so2")); +// model.setSensorNo2(TempUtils.gradualData("no2")); +// model.setSensorO3(TempUtils.gradualData("o3")); +// model.setSensorDust(TempUtils.gradualData("dust")); +// } + dataList.add(model); + }else { + logger.info("lat , lon No data "); + } + } + +// collection.putData(dataList); +// logger.debug("SIZE :: " +collection.getData().size() ); + + } + + +} diff --git a/src/main/java/com/palnet/server/encrptn/kisa/KISA_SEED_CBC.java b/src/main/java/com/palnet/server/encrptn/kisa/KISA_SEED_CBC.java new file mode 100644 index 0000000..95cba27 --- /dev/null +++ b/src/main/java/com/palnet/server/encrptn/kisa/KISA_SEED_CBC.java @@ -0,0 +1,1923 @@ +package com.palnet.server.encrptn.kisa; + +public class KISA_SEED_CBC { + + + // DEFAULT : JAVA = BIG_ENDIAN + private static int ENDIAN = Common.BIG_ENDIAN; + + // S-BOX + private static final int SS0[] = + { + 0x2989a1a8, 0x05858184, 0x16c6d2d4, 0x13c3d3d0, 0x14445054, 0x1d0d111c, 0x2c8ca0ac, 0x25052124, + 0x1d4d515c, 0x03434340, 0x18081018, 0x1e0e121c, 0x11415150, 0x3cccf0fc, 0x0acac2c8, 0x23436360, + 0x28082028, 0x04444044, 0x20002020, 0x1d8d919c, 0x20c0e0e0, 0x22c2e2e0, 0x08c8c0c8, 0x17071314, + 0x2585a1a4, 0x0f8f838c, 0x03030300, 0x3b4b7378, 0x3b8bb3b8, 0x13031310, 0x12c2d2d0, 0x2ecee2ec, + 0x30407070, 0x0c8c808c, 0x3f0f333c, 0x2888a0a8, 0x32023230, 0x1dcdd1dc, 0x36c6f2f4, 0x34447074, + 0x2ccce0ec, 0x15859194, 0x0b0b0308, 0x17475354, 0x1c4c505c, 0x1b4b5358, 0x3d8db1bc, 0x01010100, + 0x24042024, 0x1c0c101c, 0x33437370, 0x18889098, 0x10001010, 0x0cccc0cc, 0x32c2f2f0, 0x19c9d1d8, + 0x2c0c202c, 0x27c7e3e4, 0x32427270, 0x03838380, 0x1b8b9398, 0x11c1d1d0, 0x06868284, 0x09c9c1c8, + 0x20406060, 0x10405050, 0x2383a3a0, 0x2bcbe3e8, 0x0d0d010c, 0x3686b2b4, 0x1e8e929c, 0x0f4f434c, + 0x3787b3b4, 0x1a4a5258, 0x06c6c2c4, 0x38487078, 0x2686a2a4, 0x12021210, 0x2f8fa3ac, 0x15c5d1d4, + 0x21416160, 0x03c3c3c0, 0x3484b0b4, 0x01414140, 0x12425250, 0x3d4d717c, 0x0d8d818c, 0x08080008, + 0x1f0f131c, 0x19899198, 0x00000000, 0x19091118, 0x04040004, 0x13435350, 0x37c7f3f4, 0x21c1e1e0, + 0x3dcdf1fc, 0x36467274, 0x2f0f232c, 0x27072324, 0x3080b0b0, 0x0b8b8388, 0x0e0e020c, 0x2b8ba3a8, + 0x2282a2a0, 0x2e4e626c, 0x13839390, 0x0d4d414c, 0x29496168, 0x3c4c707c, 0x09090108, 0x0a0a0208, + 0x3f8fb3bc, 0x2fcfe3ec, 0x33c3f3f0, 0x05c5c1c4, 0x07878384, 0x14041014, 0x3ecef2fc, 0x24446064, + 0x1eced2dc, 0x2e0e222c, 0x0b4b4348, 0x1a0a1218, 0x06060204, 0x21012120, 0x2b4b6368, 0x26466264, + 0x02020200, 0x35c5f1f4, 0x12829290, 0x0a8a8288, 0x0c0c000c, 0x3383b3b0, 0x3e4e727c, 0x10c0d0d0, + 0x3a4a7278, 0x07474344, 0x16869294, 0x25c5e1e4, 0x26062224, 0x00808080, 0x2d8da1ac, 0x1fcfd3dc, + 0x2181a1a0, 0x30003030, 0x37073334, 0x2e8ea2ac, 0x36063234, 0x15051114, 0x22022220, 0x38083038, + 0x34c4f0f4, 0x2787a3a4, 0x05454144, 0x0c4c404c, 0x01818180, 0x29c9e1e8, 0x04848084, 0x17879394, + 0x35053134, 0x0bcbc3c8, 0x0ecec2cc, 0x3c0c303c, 0x31417170, 0x11011110, 0x07c7c3c4, 0x09898188, + 0x35457174, 0x3bcbf3f8, 0x1acad2d8, 0x38c8f0f8, 0x14849094, 0x19495158, 0x02828280, 0x04c4c0c4, + 0x3fcff3fc, 0x09494148, 0x39093138, 0x27476364, 0x00c0c0c0, 0x0fcfc3cc, 0x17c7d3d4, 0x3888b0b8, + 0x0f0f030c, 0x0e8e828c, 0x02424240, 0x23032320, 0x11819190, 0x2c4c606c, 0x1bcbd3d8, 0x2484a0a4, + 0x34043034, 0x31c1f1f0, 0x08484048, 0x02c2c2c0, 0x2f4f636c, 0x3d0d313c, 0x2d0d212c, 0x00404040, + 0x3e8eb2bc, 0x3e0e323c, 0x3c8cb0bc, 0x01c1c1c0, 0x2a8aa2a8, 0x3a8ab2b8, 0x0e4e424c, 0x15455154, + 0x3b0b3338, 0x1cccd0dc, 0x28486068, 0x3f4f737c, 0x1c8c909c, 0x18c8d0d8, 0x0a4a4248, 0x16465254, + 0x37477374, 0x2080a0a0, 0x2dcde1ec, 0x06464244, 0x3585b1b4, 0x2b0b2328, 0x25456164, 0x3acaf2f8, + 0x23c3e3e0, 0x3989b1b8, 0x3181b1b0, 0x1f8f939c, 0x1e4e525c, 0x39c9f1f8, 0x26c6e2e4, 0x3282b2b0, + 0x31013130, 0x2acae2e8, 0x2d4d616c, 0x1f4f535c, 0x24c4e0e4, 0x30c0f0f0, 0x0dcdc1cc, 0x08888088, + 0x16061214, 0x3a0a3238, 0x18485058, 0x14c4d0d4, 0x22426260, 0x29092128, 0x07070304, 0x33033330, + 0x28c8e0e8, 0x1b0b1318, 0x05050104, 0x39497178, 0x10809090, 0x2a4a6268, 0x2a0a2228, 0x1a8a9298 + }; + + private static final int SS1[] = + { + 0x38380830, 0xe828c8e0, 0x2c2d0d21, 0xa42686a2, 0xcc0fcfc3, 0xdc1eced2, 0xb03383b3, 0xb83888b0, + 0xac2f8fa3, 0x60204060, 0x54154551, 0xc407c7c3, 0x44044440, 0x6c2f4f63, 0x682b4b63, 0x581b4b53, + 0xc003c3c3, 0x60224262, 0x30330333, 0xb43585b1, 0x28290921, 0xa02080a0, 0xe022c2e2, 0xa42787a3, + 0xd013c3d3, 0x90118191, 0x10110111, 0x04060602, 0x1c1c0c10, 0xbc3c8cb0, 0x34360632, 0x480b4b43, + 0xec2fcfe3, 0x88088880, 0x6c2c4c60, 0xa82888a0, 0x14170713, 0xc404c4c0, 0x14160612, 0xf434c4f0, + 0xc002c2c2, 0x44054541, 0xe021c1e1, 0xd416c6d2, 0x3c3f0f33, 0x3c3d0d31, 0x8c0e8e82, 0x98188890, + 0x28280820, 0x4c0e4e42, 0xf436c6f2, 0x3c3e0e32, 0xa42585a1, 0xf839c9f1, 0x0c0d0d01, 0xdc1fcfd3, + 0xd818c8d0, 0x282b0b23, 0x64264662, 0x783a4a72, 0x24270723, 0x2c2f0f23, 0xf031c1f1, 0x70324272, + 0x40024242, 0xd414c4d0, 0x40014141, 0xc000c0c0, 0x70334373, 0x64274763, 0xac2c8ca0, 0x880b8b83, + 0xf437c7f3, 0xac2d8da1, 0x80008080, 0x1c1f0f13, 0xc80acac2, 0x2c2c0c20, 0xa82a8aa2, 0x34340430, + 0xd012c2d2, 0x080b0b03, 0xec2ecee2, 0xe829c9e1, 0x5c1d4d51, 0x94148490, 0x18180810, 0xf838c8f0, + 0x54174753, 0xac2e8ea2, 0x08080800, 0xc405c5c1, 0x10130313, 0xcc0dcdc1, 0x84068682, 0xb83989b1, + 0xfc3fcff3, 0x7c3d4d71, 0xc001c1c1, 0x30310131, 0xf435c5f1, 0x880a8a82, 0x682a4a62, 0xb03181b1, + 0xd011c1d1, 0x20200020, 0xd417c7d3, 0x00020202, 0x20220222, 0x04040400, 0x68284860, 0x70314171, + 0x04070703, 0xd81bcbd3, 0x9c1d8d91, 0x98198991, 0x60214161, 0xbc3e8eb2, 0xe426c6e2, 0x58194951, + 0xdc1dcdd1, 0x50114151, 0x90108090, 0xdc1cccd0, 0x981a8a92, 0xa02383a3, 0xa82b8ba3, 0xd010c0d0, + 0x80018181, 0x0c0f0f03, 0x44074743, 0x181a0a12, 0xe023c3e3, 0xec2ccce0, 0x8c0d8d81, 0xbc3f8fb3, + 0x94168692, 0x783b4b73, 0x5c1c4c50, 0xa02282a2, 0xa02181a1, 0x60234363, 0x20230323, 0x4c0d4d41, + 0xc808c8c0, 0x9c1e8e92, 0x9c1c8c90, 0x383a0a32, 0x0c0c0c00, 0x2c2e0e22, 0xb83a8ab2, 0x6c2e4e62, + 0x9c1f8f93, 0x581a4a52, 0xf032c2f2, 0x90128292, 0xf033c3f3, 0x48094941, 0x78384870, 0xcc0cccc0, + 0x14150511, 0xf83bcbf3, 0x70304070, 0x74354571, 0x7c3f4f73, 0x34350531, 0x10100010, 0x00030303, + 0x64244460, 0x6c2d4d61, 0xc406c6c2, 0x74344470, 0xd415c5d1, 0xb43484b0, 0xe82acae2, 0x08090901, + 0x74364672, 0x18190911, 0xfc3ecef2, 0x40004040, 0x10120212, 0xe020c0e0, 0xbc3d8db1, 0x04050501, + 0xf83acaf2, 0x00010101, 0xf030c0f0, 0x282a0a22, 0x5c1e4e52, 0xa82989a1, 0x54164652, 0x40034343, + 0x84058581, 0x14140410, 0x88098981, 0x981b8b93, 0xb03080b0, 0xe425c5e1, 0x48084840, 0x78394971, + 0x94178793, 0xfc3cccf0, 0x1c1e0e12, 0x80028282, 0x20210121, 0x8c0c8c80, 0x181b0b13, 0x5c1f4f53, + 0x74374773, 0x54144450, 0xb03282b2, 0x1c1d0d11, 0x24250521, 0x4c0f4f43, 0x00000000, 0x44064642, + 0xec2dcde1, 0x58184850, 0x50124252, 0xe82bcbe3, 0x7c3e4e72, 0xd81acad2, 0xc809c9c1, 0xfc3dcdf1, + 0x30300030, 0x94158591, 0x64254561, 0x3c3c0c30, 0xb43686b2, 0xe424c4e0, 0xb83b8bb3, 0x7c3c4c70, + 0x0c0e0e02, 0x50104050, 0x38390931, 0x24260622, 0x30320232, 0x84048480, 0x68294961, 0x90138393, + 0x34370733, 0xe427c7e3, 0x24240420, 0xa42484a0, 0xc80bcbc3, 0x50134353, 0x080a0a02, 0x84078783, + 0xd819c9d1, 0x4c0c4c40, 0x80038383, 0x8c0f8f83, 0xcc0ecec2, 0x383b0b33, 0x480a4a42, 0xb43787b3 + }; + + private static final int SS2[] = + { + 0xa1a82989, 0x81840585, 0xd2d416c6, 0xd3d013c3, 0x50541444, 0x111c1d0d, 0xa0ac2c8c, 0x21242505, + 0x515c1d4d, 0x43400343, 0x10181808, 0x121c1e0e, 0x51501141, 0xf0fc3ccc, 0xc2c80aca, 0x63602343, + 0x20282808, 0x40440444, 0x20202000, 0x919c1d8d, 0xe0e020c0, 0xe2e022c2, 0xc0c808c8, 0x13141707, + 0xa1a42585, 0x838c0f8f, 0x03000303, 0x73783b4b, 0xb3b83b8b, 0x13101303, 0xd2d012c2, 0xe2ec2ece, + 0x70703040, 0x808c0c8c, 0x333c3f0f, 0xa0a82888, 0x32303202, 0xd1dc1dcd, 0xf2f436c6, 0x70743444, + 0xe0ec2ccc, 0x91941585, 0x03080b0b, 0x53541747, 0x505c1c4c, 0x53581b4b, 0xb1bc3d8d, 0x01000101, + 0x20242404, 0x101c1c0c, 0x73703343, 0x90981888, 0x10101000, 0xc0cc0ccc, 0xf2f032c2, 0xd1d819c9, + 0x202c2c0c, 0xe3e427c7, 0x72703242, 0x83800383, 0x93981b8b, 0xd1d011c1, 0x82840686, 0xc1c809c9, + 0x60602040, 0x50501040, 0xa3a02383, 0xe3e82bcb, 0x010c0d0d, 0xb2b43686, 0x929c1e8e, 0x434c0f4f, + 0xb3b43787, 0x52581a4a, 0xc2c406c6, 0x70783848, 0xa2a42686, 0x12101202, 0xa3ac2f8f, 0xd1d415c5, + 0x61602141, 0xc3c003c3, 0xb0b43484, 0x41400141, 0x52501242, 0x717c3d4d, 0x818c0d8d, 0x00080808, + 0x131c1f0f, 0x91981989, 0x00000000, 0x11181909, 0x00040404, 0x53501343, 0xf3f437c7, 0xe1e021c1, + 0xf1fc3dcd, 0x72743646, 0x232c2f0f, 0x23242707, 0xb0b03080, 0x83880b8b, 0x020c0e0e, 0xa3a82b8b, + 0xa2a02282, 0x626c2e4e, 0x93901383, 0x414c0d4d, 0x61682949, 0x707c3c4c, 0x01080909, 0x02080a0a, + 0xb3bc3f8f, 0xe3ec2fcf, 0xf3f033c3, 0xc1c405c5, 0x83840787, 0x10141404, 0xf2fc3ece, 0x60642444, + 0xd2dc1ece, 0x222c2e0e, 0x43480b4b, 0x12181a0a, 0x02040606, 0x21202101, 0x63682b4b, 0x62642646, + 0x02000202, 0xf1f435c5, 0x92901282, 0x82880a8a, 0x000c0c0c, 0xb3b03383, 0x727c3e4e, 0xd0d010c0, + 0x72783a4a, 0x43440747, 0x92941686, 0xe1e425c5, 0x22242606, 0x80800080, 0xa1ac2d8d, 0xd3dc1fcf, + 0xa1a02181, 0x30303000, 0x33343707, 0xa2ac2e8e, 0x32343606, 0x11141505, 0x22202202, 0x30383808, + 0xf0f434c4, 0xa3a42787, 0x41440545, 0x404c0c4c, 0x81800181, 0xe1e829c9, 0x80840484, 0x93941787, + 0x31343505, 0xc3c80bcb, 0xc2cc0ece, 0x303c3c0c, 0x71703141, 0x11101101, 0xc3c407c7, 0x81880989, + 0x71743545, 0xf3f83bcb, 0xd2d81aca, 0xf0f838c8, 0x90941484, 0x51581949, 0x82800282, 0xc0c404c4, + 0xf3fc3fcf, 0x41480949, 0x31383909, 0x63642747, 0xc0c000c0, 0xc3cc0fcf, 0xd3d417c7, 0xb0b83888, + 0x030c0f0f, 0x828c0e8e, 0x42400242, 0x23202303, 0x91901181, 0x606c2c4c, 0xd3d81bcb, 0xa0a42484, + 0x30343404, 0xf1f031c1, 0x40480848, 0xc2c002c2, 0x636c2f4f, 0x313c3d0d, 0x212c2d0d, 0x40400040, + 0xb2bc3e8e, 0x323c3e0e, 0xb0bc3c8c, 0xc1c001c1, 0xa2a82a8a, 0xb2b83a8a, 0x424c0e4e, 0x51541545, + 0x33383b0b, 0xd0dc1ccc, 0x60682848, 0x737c3f4f, 0x909c1c8c, 0xd0d818c8, 0x42480a4a, 0x52541646, + 0x73743747, 0xa0a02080, 0xe1ec2dcd, 0x42440646, 0xb1b43585, 0x23282b0b, 0x61642545, 0xf2f83aca, + 0xe3e023c3, 0xb1b83989, 0xb1b03181, 0x939c1f8f, 0x525c1e4e, 0xf1f839c9, 0xe2e426c6, 0xb2b03282, + 0x31303101, 0xe2e82aca, 0x616c2d4d, 0x535c1f4f, 0xe0e424c4, 0xf0f030c0, 0xc1cc0dcd, 0x80880888, + 0x12141606, 0x32383a0a, 0x50581848, 0xd0d414c4, 0x62602242, 0x21282909, 0x03040707, 0x33303303, + 0xe0e828c8, 0x13181b0b, 0x01040505, 0x71783949, 0x90901080, 0x62682a4a, 0x22282a0a, 0x92981a8a + }; + + private static final int SS3[] = + { + 0x08303838, 0xc8e0e828, 0x0d212c2d, 0x86a2a426, 0xcfc3cc0f, 0xced2dc1e, 0x83b3b033, 0x88b0b838, + 0x8fa3ac2f, 0x40606020, 0x45515415, 0xc7c3c407, 0x44404404, 0x4f636c2f, 0x4b63682b, 0x4b53581b, + 0xc3c3c003, 0x42626022, 0x03333033, 0x85b1b435, 0x09212829, 0x80a0a020, 0xc2e2e022, 0x87a3a427, + 0xc3d3d013, 0x81919011, 0x01111011, 0x06020406, 0x0c101c1c, 0x8cb0bc3c, 0x06323436, 0x4b43480b, + 0xcfe3ec2f, 0x88808808, 0x4c606c2c, 0x88a0a828, 0x07131417, 0xc4c0c404, 0x06121416, 0xc4f0f434, + 0xc2c2c002, 0x45414405, 0xc1e1e021, 0xc6d2d416, 0x0f333c3f, 0x0d313c3d, 0x8e828c0e, 0x88909818, + 0x08202828, 0x4e424c0e, 0xc6f2f436, 0x0e323c3e, 0x85a1a425, 0xc9f1f839, 0x0d010c0d, 0xcfd3dc1f, + 0xc8d0d818, 0x0b23282b, 0x46626426, 0x4a72783a, 0x07232427, 0x0f232c2f, 0xc1f1f031, 0x42727032, + 0x42424002, 0xc4d0d414, 0x41414001, 0xc0c0c000, 0x43737033, 0x47636427, 0x8ca0ac2c, 0x8b83880b, + 0xc7f3f437, 0x8da1ac2d, 0x80808000, 0x0f131c1f, 0xcac2c80a, 0x0c202c2c, 0x8aa2a82a, 0x04303434, + 0xc2d2d012, 0x0b03080b, 0xcee2ec2e, 0xc9e1e829, 0x4d515c1d, 0x84909414, 0x08101818, 0xc8f0f838, + 0x47535417, 0x8ea2ac2e, 0x08000808, 0xc5c1c405, 0x03131013, 0xcdc1cc0d, 0x86828406, 0x89b1b839, + 0xcff3fc3f, 0x4d717c3d, 0xc1c1c001, 0x01313031, 0xc5f1f435, 0x8a82880a, 0x4a62682a, 0x81b1b031, + 0xc1d1d011, 0x00202020, 0xc7d3d417, 0x02020002, 0x02222022, 0x04000404, 0x48606828, 0x41717031, + 0x07030407, 0xcbd3d81b, 0x8d919c1d, 0x89919819, 0x41616021, 0x8eb2bc3e, 0xc6e2e426, 0x49515819, + 0xcdd1dc1d, 0x41515011, 0x80909010, 0xccd0dc1c, 0x8a92981a, 0x83a3a023, 0x8ba3a82b, 0xc0d0d010, + 0x81818001, 0x0f030c0f, 0x47434407, 0x0a12181a, 0xc3e3e023, 0xcce0ec2c, 0x8d818c0d, 0x8fb3bc3f, + 0x86929416, 0x4b73783b, 0x4c505c1c, 0x82a2a022, 0x81a1a021, 0x43636023, 0x03232023, 0x4d414c0d, + 0xc8c0c808, 0x8e929c1e, 0x8c909c1c, 0x0a32383a, 0x0c000c0c, 0x0e222c2e, 0x8ab2b83a, 0x4e626c2e, + 0x8f939c1f, 0x4a52581a, 0xc2f2f032, 0x82929012, 0xc3f3f033, 0x49414809, 0x48707838, 0xccc0cc0c, + 0x05111415, 0xcbf3f83b, 0x40707030, 0x45717435, 0x4f737c3f, 0x05313435, 0x00101010, 0x03030003, + 0x44606424, 0x4d616c2d, 0xc6c2c406, 0x44707434, 0xc5d1d415, 0x84b0b434, 0xcae2e82a, 0x09010809, + 0x46727436, 0x09111819, 0xcef2fc3e, 0x40404000, 0x02121012, 0xc0e0e020, 0x8db1bc3d, 0x05010405, + 0xcaf2f83a, 0x01010001, 0xc0f0f030, 0x0a22282a, 0x4e525c1e, 0x89a1a829, 0x46525416, 0x43434003, + 0x85818405, 0x04101414, 0x89818809, 0x8b93981b, 0x80b0b030, 0xc5e1e425, 0x48404808, 0x49717839, + 0x87939417, 0xccf0fc3c, 0x0e121c1e, 0x82828002, 0x01212021, 0x8c808c0c, 0x0b13181b, 0x4f535c1f, + 0x47737437, 0x44505414, 0x82b2b032, 0x0d111c1d, 0x05212425, 0x4f434c0f, 0x00000000, 0x46424406, + 0xcde1ec2d, 0x48505818, 0x42525012, 0xcbe3e82b, 0x4e727c3e, 0xcad2d81a, 0xc9c1c809, 0xcdf1fc3d, + 0x00303030, 0x85919415, 0x45616425, 0x0c303c3c, 0x86b2b436, 0xc4e0e424, 0x8bb3b83b, 0x4c707c3c, + 0x0e020c0e, 0x40505010, 0x09313839, 0x06222426, 0x02323032, 0x84808404, 0x49616829, 0x83939013, + 0x07333437, 0xc7e3e427, 0x04202424, 0x84a0a424, 0xcbc3c80b, 0x43535013, 0x0a02080a, 0x87838407, + 0xc9d1d819, 0x4c404c0c, 0x83838003, 0x8f838c0f, 0xcec2cc0e, 0x0b33383b, 0x4a42480a, 0x87b3b437 + }; + + private static final int BLOCK_SIZE_SEED = 16; + private static final int BLOCK_SIZE_SEED_INT = 4; + + private static final byte GetB0(int A) { return (byte)(A & 0x0ff); } + private static final byte GetB1(int A) { return (byte)((A>>8) & 0x0ff); } + private static final byte GetB2(int A) { return (byte)((A>>16) & 0x0ff); } + private static final byte GetB3(int A) { return (byte)((A>>24) & 0x0ff); } + + // Round function F and adding output of F to L. + // L0, L1 : left input values at each round + // R0, R1 : right input values at each round + // K : round keys at each round + private static final void SeedRound(int[] T, int LR[], int L0, int L1, int R0, int R1, int[] K, int K_offset) { + T[0] = LR[R0] ^ K[K_offset+0]; + T[1] = LR[R1] ^ K[K_offset+1]; + T[1] ^= T[0]; + T[1] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^ + SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff]; + T[0] += T[1]; + T[0] = SS0[GetB0(T[0])&0x0ff] ^ SS1[GetB1(T[0])&0x0ff] ^ + SS2[GetB2(T[0])&0x0ff] ^ SS3[GetB3(T[0])&0x0ff]; + T[1] += T[0]; + T[1] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^ + SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff]; + T[0] += T[1]; + LR[L0] ^= T[0]; LR[L1] ^= T[1]; + } + + + + private static final int EndianChange(int dwS) { return ( (/*ROTL(dwS,8)*/(((dwS) << (8)) | (((dwS) >> (32-(8)))&0x000000ff)) & 0x00ff00ff) | (/*ROTL(dwS,24)*/(((dwS) << (24)) | (((dwS) >> (32-(24)))&0x00ffffff)) & 0xff00ff00) ); } + + /************************ Constants for Key schedule **************************/ + private static final int KC0 = 0x9e3779b9; + private static final int KC1 = 0x3c6ef373; + private static final int KC2 = 0x78dde6e6; + private static final int KC3 = 0xf1bbcdcc; + private static final int KC4 = 0xe3779b99; + private static final int KC5 = 0xc6ef3733; + private static final int KC6 = 0x8dde6e67; + private static final int KC7 = 0x1bbcdccf; + private static final int KC8 = 0x3779b99e; + private static final int KC9 = 0x6ef3733c; + private static final int KC10 = 0xdde6e678; + private static final int KC11 = 0xbbcdccf1; + private static final int KC12 = 0x779b99e3; + private static final int KC13 = 0xef3733c6; + private static final int KC14 = 0xde6e678d; + private static final int KC15 = 0xbcdccf1b; + + + + + private static final int ABCD_A = 0; + private static final int ABCD_B = 1; + private static final int ABCD_C = 2; + private static final int ABCD_D = 3; + + private static final void RoundKeyUpdate0(int T[], int[] K, int K_offset, int ABCD[], int KC) { + T[0] = ABCD[ABCD_A] + ABCD[ABCD_C] - KC; + T[1] = ABCD[ABCD_B] + KC - ABCD[ABCD_D]; + K[K_offset+0] = SS0[GetB0(T[0])&0x0ff] ^ SS1[GetB1(T[0])&0x0ff] ^ SS2[GetB2(T[0])&0x0ff] ^ SS3[GetB3(T[0])&0x0ff]; + K[K_offset+1] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^ SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff]; + T[0] = ABCD[ABCD_A]; + ABCD[ABCD_A] = ((ABCD[ABCD_A]>>8)&0x00ffffff) ^ (ABCD[ABCD_B]<<24); + ABCD[ABCD_B] = ((ABCD[ABCD_B]>>8)&0x00ffffff) ^ (T[0]<<24); + } + + private static final void RoundKeyUpdate1(int T[], int []K, int K_offset, int ABCD[], int KC) { + T[0] = ABCD[ABCD_A] + ABCD[ABCD_C] - KC; + T[1] = ABCD[ABCD_B] + KC - ABCD[ABCD_D]; + K[K_offset+0] = SS0[GetB0(T[0])&0x0ff] ^ SS1[GetB1(T[0])&0x0ff] ^ SS2[GetB2(T[0])&0x0ff] ^ SS3[GetB3(T[0])&0x0ff]; + K[K_offset+1] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^ SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff]; + T[0] = ABCD[ABCD_C]; + ABCD[ABCD_C] = (ABCD[ABCD_C]<<8) ^ ((ABCD[ABCD_D]>>24)&0x000000ff); + ABCD[ABCD_D] = (ABCD[ABCD_D]<<8) ^ ((T[0]>>24)&0x000000ff); + } + + private static void BLOCK_XOR_CBC(int[] OUT_VALUE, int out_value_offset, int[] IN_VALUE1, int in_value1_offset, int[] IN_VALUE2, int in_value2_offset) { + OUT_VALUE[out_value_offset+0] = (in_value1_offset 0) + len = (inLen/4)+1; + else + len = (inLen/4); + + data = new int[len]; + + for(i=0;i> ((i%4)*8)); + } + } else { + for(i=0;i> ((3-(i%4))*8)); + } + } + + return data; + } + + + public static int SEED_CBC_init( KISA_SEED_INFO pInfo, KISA_ENC_DEC enc, byte[] pbszUserKey, byte[] pbszIV ) { + int ABCD[] = new int[4]; // Iuput/output values at each rounds(�� ���� ��/���) + int T[] = new int[2]; // Temporary variable + int K[]; + + if( null == pInfo || + null == pbszUserKey || + null == pbszIV ) + return 0; + + K = pInfo.seed_key.key_data; // Pointer of round keys + pInfo.encrypt = enc.value; // + Common.memcpy(pInfo.ivec, pbszIV, 16, ENDIAN); + pInfo.last_block_flag = pInfo.buffer_length = 0; + + // Set up input values for Key Schedule + ABCD[ABCD_A] = Common.byte_to_int(pbszUserKey, 0*4, ENDIAN); + ABCD[ABCD_B] = Common.byte_to_int(pbszUserKey, 1*4, ENDIAN); + ABCD[ABCD_C] = Common.byte_to_int(pbszUserKey, 2*4, ENDIAN); + ABCD[ABCD_D] = Common.byte_to_int(pbszUserKey, 3*4, ENDIAN); + + // Reorder for big endian + if(Common.BIG_ENDIAN != ENDIAN) { + ABCD[ABCD_A] = EndianChange(ABCD[ABCD_A]); + ABCD[ABCD_B] = EndianChange(ABCD[ABCD_B]); + ABCD[ABCD_C] = EndianChange(ABCD[ABCD_C]); + ABCD[ABCD_D] = EndianChange(ABCD[ABCD_D]); + } + + // i-th round keys( K_i,0 and K_i,1 ) are denoted as K[2*(i-1)] and K[2*i-1], respectively + RoundKeyUpdate0(T, K, 0, ABCD, KC0 ); // K_1,0 and K_1,1 + RoundKeyUpdate1(T, K, 2, ABCD, KC1 ); // K_2,0 and K_2,1 + RoundKeyUpdate0(T, K, 4, ABCD, KC2 ); // K_3,0 and K_3,1 + RoundKeyUpdate1(T, K, 6, ABCD, KC3 ); // K_4,0 and K_4,1 + RoundKeyUpdate0(T, K, 8, ABCD, KC4 ); // K_5,0 and K_5,1 + RoundKeyUpdate1(T, K, 10, ABCD, KC5 ); // K_6,0 and K_6,1 + RoundKeyUpdate0(T, K, 12, ABCD, KC6 ); // K_7,0 and K_7,1 + RoundKeyUpdate1(T, K, 14, ABCD, KC7 ); // K_8,0 and K_8,1 + RoundKeyUpdate0(T, K, 16, ABCD, KC8 ); // K_9,0 and K_9,1 + RoundKeyUpdate1(T, K, 18, ABCD, KC9 ); // K_10,0 and K_10,1 + RoundKeyUpdate0(T, K, 20, ABCD, KC10); // K_11,0 and K_11,1 + RoundKeyUpdate1(T, K, 22, ABCD, KC11); // K_12,0 and K_12,1 + RoundKeyUpdate0(T, K, 24, ABCD, KC12); // K_13,0 and K_13,1 + RoundKeyUpdate1(T, K, 26, ABCD, KC13); // K_14,0 and K_14,1 + RoundKeyUpdate0(T, K, 28, ABCD, KC14); // K_15,0 and K_15,1 + + T[0] = ABCD[ABCD_A] + ABCD[ABCD_C] - KC15; + T[1] = ABCD[ABCD_B] - ABCD[ABCD_D] + KC15; + + K[30] = SS0[GetB0(T[0])&0x0ff] ^ SS1[GetB1(T[0])&0x0ff] ^ // K_16,0 + SS2[GetB2(T[0])&0x0ff] ^ SS3[GetB3(T[0])&0x0ff]; + K[31] = SS0[GetB0(T[1])&0x0ff] ^ SS1[GetB1(T[1])&0x0ff] ^ // K_16,1 + SS2[GetB2(T[1])&0x0ff] ^ SS3[GetB3(T[1])&0x0ff]; + + return 1; + + + } + + + public static int SEED_CBC_Process( KISA_SEED_INFO pInfo, int[] in, int inLen, int[] out, int[] outLen ) { + int nCurrentCount = BLOCK_SIZE_SEED; + int[] pdwXOR = null; + int in_offset = 0; + int out_offset = 0; + int pdwXOR_offset = 0; + + if( null == pInfo || + null == in || + null == out || + 0 > inLen ) + return 0; + + + if( KISA_ENC_DEC._KISA_ENCRYPT == pInfo.encrypt ) { + pdwXOR = pInfo.ivec; + in_offset = 0; + out_offset = 0; + pdwXOR_offset = 0; + + + while( nCurrentCount <= inLen ) + { + BLOCK_XOR_CBC( out, out_offset, in, in_offset, pdwXOR, pdwXOR_offset ); + + KISA_SEED_Encrypt_Block_forCBC( out, out_offset, out, out_offset, pInfo.seed_key ); + + pdwXOR = out; + pdwXOR_offset = out_offset; + + nCurrentCount += BLOCK_SIZE_SEED; + in_offset += BLOCK_SIZE_SEED_INT; + out_offset += BLOCK_SIZE_SEED_INT; + } + + outLen[0] = nCurrentCount - BLOCK_SIZE_SEED; + pInfo.buffer_length = (inLen - outLen[0]); + + Common.memcpy( pInfo.ivec, pdwXOR, pdwXOR_offset, BLOCK_SIZE_SEED ); + Common.memcpy( pInfo.cbc_buffer, in, in_offset, pInfo.buffer_length ); + } + else { + pdwXOR = pInfo.ivec; + in_offset = 0; + out_offset = 0; + pdwXOR_offset = 0; + + while( nCurrentCount <= inLen ) + { + KISA_SEED_Decrypt_Block_forCBC( in, in_offset, out, out_offset, pInfo.seed_key ); + + BLOCK_XOR_CBC( out, out_offset, out, out_offset, pdwXOR, pdwXOR_offset ); + + pdwXOR = in; + pdwXOR_offset = in_offset; + + nCurrentCount += BLOCK_SIZE_SEED; + in_offset += BLOCK_SIZE_SEED_INT; + out_offset += BLOCK_SIZE_SEED_INT; + } + + outLen[0] = nCurrentCount - BLOCK_SIZE_SEED; + + + + Common.memcpy( pInfo.ivec, pdwXOR, pdwXOR_offset, BLOCK_SIZE_SEED ); + Common.memcpy( pInfo.cbc_last_block, out, out_offset-BLOCK_SIZE_SEED_INT, BLOCK_SIZE_SEED ); + + + } + + return 1; + + } + + + public static int SEED_CBC_Close( KISA_SEED_INFO pInfo, int[] out, int out_offset, int[] outLen ) { + int nPaddngLeng; + int i; + + outLen[0] = 0; + + if( null == out ) + return 0; + + if( KISA_ENC_DEC._KISA_ENCRYPT == pInfo.encrypt ) { + nPaddngLeng = BLOCK_SIZE_SEED - pInfo.buffer_length; + + for( i = pInfo.buffer_length; i 0 && nPaddngLeng <= BLOCK_SIZE_SEED ) + { + for(i=nPaddngLeng; i>0; i--) + { + Common.set_byte_for_int(out, out_offset-i, (byte)0x00, ENDIAN); + } + + outLen[0] = nPaddngLeng; + } + else + return 0; + + + } + return 1; + + + } + + + + + + + + public static byte[] SEED_CBC_Encrypt( byte[] pbszUserKey, byte[] pbszIV, byte[] message, int message_offset, int message_length ) { + KISA_SEED_INFO info = new KISA_SEED_INFO(); + int[] outbuf; + int[] data; + byte[] cdata; + int outlen; + int nRetOutLeng[] = new int[] { 0 }; + int nPaddingLeng[] = new int[] { 0 }; + + byte[] pbszPlainText = new byte[message_length]; + System.arraycopy(message, message_offset, pbszPlainText, 0, message_length); + int nPlainTextLen = pbszPlainText.length; + + + int nPlainTextPadding = BLOCK_SIZE_SEED - (nPlainTextLen % BLOCK_SIZE_SEED); + byte []newpbszPlainText = new byte[nPlainTextLen+nPlainTextPadding]; + Common.arraycopy(newpbszPlainText, pbszPlainText, nPlainTextLen); + + byte[] pbszCipherText = new byte[newpbszPlainText.length]; + + + SEED_CBC_init( info, KISA_ENC_DEC.KISA_ENCRYPT, pbszUserKey, pbszIV ); + + outlen = ((newpbszPlainText.length/BLOCK_SIZE_SEED) ) * BLOCK_SIZE_SEED_INT ; + outbuf = new int[outlen]; + data = chartoint32_for_SEED_CBC(newpbszPlainText, nPlainTextLen); + + SEED_CBC_Process( info, data, nPlainTextLen, outbuf, nRetOutLeng ); + SEED_CBC_Close( info, outbuf, (nRetOutLeng[0]/4), nPaddingLeng ); + + cdata = int32tochar_for_SEED_CBC(outbuf, nRetOutLeng[0]+nPaddingLeng[0]); + Common.arraycopy(pbszCipherText, cdata, nRetOutLeng[0]+nPaddingLeng[0]); + + data = null; + cdata = null; + outbuf = null; + + return pbszCipherText; + } + + + + + + + + + + + + public static byte[] SEED_CBC_Decrypt( byte[] pbszUserKey, byte[] pbszIV, byte[] message, int message_offset, int message_length ) { + KISA_SEED_INFO info = new KISA_SEED_INFO(); + int[] outbuf; + int[] data; + byte[] cdata; + int outlen; + int nRetOutLeng[] = new int[] { 0 }; + int nPaddingLeng[] = new int[] { 0 }; + + + + byte[] pbszCipherText = new byte[message_length]; + System.arraycopy(message, message_offset, pbszCipherText, 0, message_length); + int nCipherTextLen = pbszCipherText.length; + + if( (nCipherTextLen%BLOCK_SIZE_SEED) != 0 ) + { + byte result[] = null; + return result; + } + + + byte []newpbszCipherText = new byte[nCipherTextLen]; + Common.arraycopy(newpbszCipherText, pbszCipherText, nCipherTextLen); + + nCipherTextLen = newpbszCipherText.length; + + + SEED_CBC_init( info, KISA_ENC_DEC.KISA_DECRYPT, pbszUserKey, pbszIV ); + + outlen = ((nCipherTextLen/16)) *4 ; + outbuf = new int[outlen]; + data = chartoint32_for_SEED_CBC(newpbszCipherText, nCipherTextLen); + + SEED_CBC_Process( info, data, nCipherTextLen, outbuf, nRetOutLeng ); + + + if( SEED_CBC_Close( info, outbuf, (nRetOutLeng[0]), nPaddingLeng ) == 1 ) + { + cdata = int32tochar_for_SEED_CBC( outbuf, nRetOutLeng[0]-nPaddingLeng[0] ); + + byte[] pbszPlainText = new byte[nRetOutLeng[0]-nPaddingLeng[0]]; + + Common.arraycopy(pbszPlainText, cdata, nRetOutLeng[0]-nPaddingLeng[0]); + + int pdmessage_length = nRetOutLeng[0]-nPaddingLeng[0]; + byte[] result = new byte[pdmessage_length]; + System.arraycopy(pbszPlainText, 0, result, 0, pdmessage_length); + + data = null; + cdata = null; + outbuf = null; + + return result; + + } + else + { + byte result[] = null; + return result; + } + + + } + + + + + + + + + + + + public static final class KISA_ENC_DEC { + public static final int _KISA_DECRYPT = 0; + public static final int _KISA_ENCRYPT = 1; + + public int value; + + public KISA_ENC_DEC(int value ) { + this.value = value; + } + + public static final KISA_ENC_DEC KISA_ENCRYPT = new KISA_ENC_DEC(_KISA_ENCRYPT); + public static final KISA_ENC_DEC KISA_DECRYPT = new KISA_ENC_DEC(_KISA_DECRYPT); + + } + + public static final class KISA_SEED_KEY { + public int[] key_data = new int[32]; + + public void init() { + for(int i=0; i> shift_value; + return (byte)value; + } else { + int shift_value = (b_offset%4)*8; + int mask_value = 0x0ff << shift_value; + int value = (src[b_offset/4] & mask_value) >> shift_value; + return (byte)value; + } + + } + + public static byte[] get_bytes_for_ints(int[] src, int offset, int ENDIAN) { + int iLen = src.length-offset; + byte[] result = new byte[(iLen)*4]; + for(int i=0; i> 24) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+3] = (byte)((src) & 0x0ff); + } else { + dst[dst_offset] = (byte)((src) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+3] = (byte)((src >> 24) & 0x0ff); + } + + } + + public static void int_to_byte_unit_big_endian(byte[] dst, int dst_offset, int src) { + dst[dst_offset] = (byte)((src>> 24) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+3] = (byte)((src) & 0x0ff); + } + + public static int URShift(int x, int n) { + if(n == 0) + return x; + if(n >= 32) + return 0; + int v = x >> n; + int v_mask = ~(0x80000000 >> (n-1)); + return v & v_mask; + } + + public static final long INT_RANGE_MAX = (long)Math.pow(2, 32); + + public static long intToUnsigned(int x) { + if(x >= 0) + return x; + return x + INT_RANGE_MAX; + } + + //Padding : PKSC #7 + //��� : PADDING �� ����(����Ʈ����) + public static int Padding(byte[] pbData, byte[] padData, int length) { + int i; + int padvalue = 16 - (length%16); + Common.arraycopy(padData, pbData, length); + i = length; + do { + padData[i] = (byte)(padvalue); + i++; + }while((i%16) != 0); + return i; + } + + + //1��(128��Ʈ XOR) + public static void BLOCK_XOR_PROPOSAL(int[] OUT_VALUE, int out_value_offset, int[] IN_VALUE1, int in_value1_offset, int[] IN_VALUE2, int in_value2_offset) { + OUT_VALUE[out_value_offset+0] = (in_value1_offset= SHA256_DIGEST_BLOCKLEN) { + Common.arraycopy_offset(Info.szBuffer, 0, pszMessage, pszMessage_offset, SHA256_DIGEST_BLOCKLEN); + SHA256_Transform(Info.szBuffer, Info.uChainVar); + pszMessage_offset += SHA256_DIGEST_BLOCKLEN; + uDataLen -= SHA256_DIGEST_BLOCKLEN; + } + + Common.arraycopy_offset(Info.szBuffer, 0, pszMessage, pszMessage_offset, uDataLen); + } + + /** + @brief �޽��� �����̱�� ���� �����̱⸦ ������ �� ������ �޽��� ����� ������ �����Լ��� ȣ���ϴ� �Լ� + @param Info : SHA256_Init ȣ���Ͽ� �ʱ�ȭ�� ����ü(���������� ���ȴ�.) + @param pszDigest : ��ȣ�� + */ + public static void SHA256_Close( SHA256_INFO Info, byte[] pszDigest ) { + int i, Index; + + Index = Common.URShift(Info.uLowLength, 3) % SHA256_DIGEST_BLOCKLEN; + Info.szBuffer[Index++] = (byte)0x80; + + if (Index > SHA256_DIGEST_BLOCKLEN - 8) { + Common.arrayinit_offset(Info.szBuffer, Index, (byte)0, SHA256_DIGEST_BLOCKLEN - Index); + SHA256_Transform(Info.szBuffer, Info.uChainVar); + Common.arrayinit(Info.szBuffer, (byte)0, SHA256_DIGEST_BLOCKLEN - 8); + } + else { + Common.arrayinit_offset(Info.szBuffer, Index, (byte)0, SHA256_DIGEST_BLOCKLEN - Index - 8); + } + + if(ENDIAN == Common.LITTLE_ENDIAN) { + Info.uLowLength = ENDIAN_REVERSE_ULONG(Info.uLowLength); + Info.uHighLength = ENDIAN_REVERSE_ULONG(Info.uHighLength); + } + + Common.int_to_byte_unit(Info.szBuffer, ((int)(SHA256_DIGEST_BLOCKLEN / 4 - 2))*4, Info.uHighLength, ENDIAN); + Common.int_to_byte_unit(Info.szBuffer, ((int)(SHA256_DIGEST_BLOCKLEN / 4 - 1))*4, Info.uLowLength, ENDIAN); + + SHA256_Transform(Info.szBuffer, Info.uChainVar); + + for (i = 0; i < SHA256_DIGEST_VALUELEN; i += 4) + BIG_D2B((Info.uChainVar)[i / 4], pszDigest, i); + } + + /** + @brief ����� �Է� ���� �ѹ��� ó�� + @param pszMessage : ����� �Է� �� + @param pszDigest : ��ȣ�� + @remarks ���������� SHA256_Init, SHA256_Process, SHA256_Close�� ȣ���Ѵ�. + */ + public static void SHA256_Encrpyt( byte[] pszMessage, int uPlainTextLen, byte[] pszDigest ) { + SHA256_INFO info = new SHA256_INFO(); + SHA256_Init( info ); + SHA256_Process( info, pszMessage, uPlainTextLen ); + SHA256_Close( info, pszDigest ); + } + + + public static class SHA256_INFO { + public int uChainVar[] = new int[SHA256_DIGEST_VALUELEN / 4]; + public int uHighLength; + public int uLowLength; + public byte szBuffer[] = new byte[SHA256_DIGEST_BLOCKLEN]; + } + + public static class Common { + + public static final int BIG_ENDIAN = 0; + public static final int LITTLE_ENDIAN = 1; + + public static void arraycopy(byte[] dst, byte[] src, int length) { + for(int i=0; i> shift_value; + return (byte)value; + } else { + int shift_value = (b_offset%4)*8; + int mask_value = 0x0ff << shift_value; + int value = (src[b_offset/4] & mask_value) >> shift_value; + return (byte)value; + } + + } + + public static byte[] get_bytes_for_ints(int[] src, int offset, int ENDIAN) { + int iLen = src.length-offset; + byte[] result = new byte[(iLen)*4]; + for(int i=0; i> 24) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+3] = (byte)((src) & 0x0ff); + } else { + dst[dst_offset] = (byte)((src) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+3] = (byte)((src >> 24) & 0x0ff); + } + + } + + public static void int_to_byte_unit_big_endian(byte[] dst, int dst_offset, int src) { + dst[dst_offset] = (byte)((src>> 24) & 0x0ff); + dst[dst_offset+1] = (byte)((src >> 16) & 0x0ff); + dst[dst_offset+2] = (byte)((src >> 8) & 0x0ff); + dst[dst_offset+3] = (byte)((src) & 0x0ff); + } + + public static int URShift(int x, int n) { + if(n == 0) + return x; + if(n >= 32) + return 0; + int v = x >> n; + int v_mask = ~(0x80000000 >> (n-1)); + return v & v_mask; + } + + public static final long INT_RANGE_MAX = (long)Math.pow(2, 32); + + public static long intToUnsigned(int x) { + if(x >= 0) + return x; + return x + INT_RANGE_MAX; + } + } + + public static void main(String[] args) + { + byte pbData[] = {(byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05, (byte)0x06, (byte)0x07, + (byte)0x08, (byte)0x09, (byte)0x0A, (byte)0x0B, (byte)0x0C, (byte)0x0D, (byte)0x0E, (byte)0x0F, + (byte)0x08, (byte)0x09, (byte)0x0A, (byte)0x0B, (byte)0x0C, (byte)0x0D, (byte)0x0E, (byte)0x0F, + (byte)0x00, (byte)0x01, (byte)0x02, (byte)0x03, (byte)0x04, (byte)0x05, (byte)0x06, (byte)0x07, + (byte)0x08, (byte)0x09, (byte)0x0A, (byte)0x0B, (byte)0x0C, (byte)0x0D, (byte)0x0E, (byte)0x0F, + (byte)0x08, (byte)0x09, (byte)0x0A, (byte)0x0B, (byte)0x0C, (byte)0x0D, (byte)0x0E, (byte)0x0F}; + byte pbData1[] = {(byte)0x61}; + + byte pbCipher[] = new byte[32]; + byte pbPlain[] = new byte[16]; + + System.out.print("[ Test SHA256 reference code ]"+"\n"); + System.out.print("\n\n"); + System.out.print("[ Test HASH mode ]"+"\n"); + System.out.print("\n"); + + int Plaintext_length = 1; + + for(int k=0; k<30; k++) + { + + System.out.print("Plaintext\t: "); + for (int i=0; i { + + private Logger logger = LoggerFactory.getLogger(getClass()); + private SocketCommand command = new SocketCommand(); + + private AuthCollection auth = new AuthCollection(); + private SocketPayloadResponse res = new SocketPayloadResponse(); + + + @Override + public void channelActive(ChannelHandlerContext ctx) { + auth.reloadAuthkey(); // 채널 활성화 되면 인증키 정보를 다시 불러옴 + + logger.debug("==================== [SocketHandler channelActive ] ==================== "); + ctx.writeAndFlush("Server Connection"); + } + + @Override + protected void channelRead0(ChannelHandlerContext ctx, SocketPayload payload){ + + try { + + logger.debug("==================== [SocketHandler channelRead0 ] ==================== "); + logger.debug("AUTH KEY :: ==== > " +payload.getAuthKey()); +// logger.info(auth.checkAuthkey(payload.getAuthKey().toString().trim())); + + if(StringUtils.isEmpty(payload.getAuthKey())) { + // 인증키가 없을 경우 + logger.debug("AUTH : no key " ); + res.setRspCode("-2000"); + res.setRspMessage("inValidate AuthKey"); + }else if(!auth.checkAuthkey(payload.getAuthKey().toString().trim())) { + // 인증키가 틀린 경우 + logger.debug("AUTH : error key " ); + logger.debug(payload.getAuthKey() ); +// logger.info(auth.checkAuthkey(payload.getAuthKey().toString().trim())); + res.setRspCode("-2000"); + res.setRspMessage("inValidate AuthKey"); + }else{ + logger.warn("MSG :: ==== > " + JsonUtils.toJson(payload)); + + switch(payload.getCommand().trim()) { + case "OPENSKY" : + command.openSkyCollectionPut(payload); + break; + case "SANDBOX": + command.sandboxCollectionPut(payload); + break; + default: + break; + } + + res.setRspCode("0"); + res.setRspMessage("SUCCESS"); + + } + + + }catch(Exception e) { + res.setRspCode("-9999"); + res.setRspMessage("Etc error"); + + e.printStackTrace(); + }finally { + logger.debug("res >>>" + JsonUtils.toJson(res)); + ctx.writeAndFlush(res); + } + + + } + + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + logger.info("=========== [exceptionCaught ] ===================="); + res.setRspCode("-9999"); + res.setRspMessage("Etc error"); + ctx.writeAndFlush(res); + + cause.printStackTrace(); + ctx.close(); + } + + + +} diff --git a/src/main/java/com/palnet/server/initializer/SocketInitializer.java b/src/main/java/com/palnet/server/initializer/SocketInitializer.java new file mode 100644 index 0000000..2814998 --- /dev/null +++ b/src/main/java/com/palnet/server/initializer/SocketInitializer.java @@ -0,0 +1,25 @@ +package com.palnet.server.initializer; + +import com.palnet.server.codec.SocketPayLoadDecoder; +import com.palnet.server.codec.SocketPayLoadEncorder; +import com.palnet.server.handler.SocketHandler; +import io.netty.channel.ChannelInitializer; +import io.netty.channel.ChannelPipeline; +import io.netty.channel.socket.SocketChannel; +import io.netty.handler.codec.json.JsonObjectDecoder; +import io.netty.handler.codec.string.StringDecoder; +import io.netty.handler.codec.string.StringEncoder; +import io.netty.util.CharsetUtil; + +public class SocketInitializer extends ChannelInitializer{ + + @Override + protected void initChannel(SocketChannel ch) throws Exception { + ChannelPipeline pipeline = ch.pipeline() + .addLast(new JsonObjectDecoder(655360)) + .addLast(new StringDecoder(CharsetUtil.UTF_8), new StringEncoder(CharsetUtil.UTF_8)) + .addLast(new SocketPayLoadDecoder() , new SocketPayLoadEncorder()) + .addLast(new SocketHandler()); + } + +} diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml new file mode 100644 index 0000000..d06d428 --- /dev/null +++ b/src/main/resources/application.yml @@ -0,0 +1,27 @@ +spring: + rabbitmq: + host: localhost + port: 5672 + username: guest + password: guest + + +netty: + task: + controlinfoTime: 2000 + socket: + port: 8082 + thread: + boss: 1 + worker: 1 + +server: + port: 8182 + +message: + drone: + queue-name: drone.queue + exchange-name: drone.exchange + routing-key: drone.routing.# + + diff --git a/src/test/java/com/palnet/PavSocketApplicationTests.java b/src/test/java/com/palnet/PavSocketApplicationTests.java new file mode 100644 index 0000000..cc0ad73 --- /dev/null +++ b/src/test/java/com/palnet/PavSocketApplicationTests.java @@ -0,0 +1,13 @@ +package com.palnet; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class PavSocketApplicationTests { + + @Test + void contextLoads() { + } + +}