- * << 개정이력(Modification Information) >> - * - * 수정일 수정자 수정내용 - * ----------- -------- --------------------------- - * 2014.10.08 이기하 최초 생성 - * 2018.10.02 신용호 Facebook 관련 ProviderSignInUtils 초기화 수정 - *- */ - -@Controller -public class EgovSignupController { - - private static final Logger LOGGER = LoggerFactory.getLogger(EgovSignupController.class); - - -// TODO 필요여부 확인할 것 DDDDDDDDDDDDDDDDDDDDDDDDD -// @Resource(name="signupService") -// private EgovSignupService signupService; - - //private ConnectionRepository connectionRepository; - //private final ProviderSignInUtils providerSignInUtils; - // TODO 필요여부 확인할 것 DDDDDDDDDDDDDDDDDDDDD - - @Inject - private OAuthVO naverAuthVO; - - @Inject - private OAuthVO googleAuthVO; - - @Inject - private OAuthVO kakaoAuthVO; - - -// TODO : 필요여부 확인할 것 DDDDDDDDDDDDDDDDDD -// @Inject -// public EgovSignupController(ConnectionFactoryLocator connectionFactoryLocator,UsersConnectionRepository connectionRepository) { -// //this.providerSignInUtils = new ProviderSignInUtils(); -// this.providerSignInUtils = new ProviderSignInUtils(connectionFactoryLocator, connectionRepository); -// } -// -// @RequestMapping(value="/signup", method=RequestMethod.GET) -// public String signupForm(WebRequest request) throws Exception { -// Connection> connection = providerSignInUtils.getConnectionFromSession(request); -// if (connection != null) { -// UserProfile profile = connection.fetchUserProfile(); -// -// String key = EgovStringUtil.remove(connection.getKey().toString(), ':'); -// String account = signupService.signup(profile, request, key); -// if (account != null) { -// providerSignInUtils.doPostSignUp(key, request); -// return "redirect:/"; -// } -// } -// return "redirect:/"; -// } - - @RequestMapping(value = "/uat/uia/oauthLoginUsr", method = RequestMethod.GET) - public String login(Model model) throws Exception { - LOGGER.debug("===>>> OAuth Login ....."); - - OAuthLogin naverLogin = new OAuthLogin(naverAuthVO); - LOGGER.debug("naverLogin.getOAuthURL() = "+naverLogin.getOAuthURL()); - model.addAttribute("naver_url", naverLogin.getOAuthURL()); - - OAuthLogin googleLogin = new OAuthLogin(googleAuthVO); - LOGGER.debug("googleLogin.getOAuthURL() = "+googleLogin.getOAuthURL()); - model.addAttribute("google_url", googleLogin.getOAuthURL()); - - OAuthLogin kakaoLogin = new OAuthLogin(kakaoAuthVO); - LOGGER.debug("kakaoLogin.getOAuthURL() = "+kakaoLogin.getOAuthURL()); - model.addAttribute("kakao_url", kakaoLogin.getOAuthURL()); - - return "egovframework/com/uat/uia/EgovLoginUsrOauth"; - } - - @RequestMapping(value = "/auth/{oauthService}/callback", - method = { RequestMethod.GET, RequestMethod.POST}) - public String oauthLoginCallback(@PathVariable String oauthService, - Model model, @RequestParam String code, HttpSession session) throws Exception { - - LOGGER.debug("oauthLoginCallback: service={}", oauthService); - LOGGER.debug("===>>> code = "+ code); - OAuthVO oauthVO = null; - if (StringUtils.equals(OAuthConfig.GOOGLE_SERVICE_NAME, oauthService)) - oauthVO = googleAuthVO; - else if (StringUtils.equals(OAuthConfig.NAVER_SERVICE_NAME, oauthService)) - oauthVO = naverAuthVO; - else - oauthVO = kakaoAuthVO; - - // 1. code를 이용해서 Access Token 받기 - // 2. Access Token을 이용해서 사용자 제공정보 가져오기 - OAuthLogin oauthLogin = new OAuthLogin(oauthVO); - - OAuthUniversalUser oauthUser = oauthLogin.getUserProfile(code); // 1,2번 동시 - LOGGER.debug("Profile ===>>" + oauthUser); - - // ======================================================================== - // 다음 부분은 업무의 목적에 맞게 커스텀 코드를 작성한다. - // 3. 해당 유저가 DB에 존재하는지 체크 (google, naver, kakao에서 전달받은 ID가 존재하는지 체크) - String resultDBInfo = ""; // DB 체크 결과 - - if ( oauthUser == null || resultDBInfo == null) { - // 미존재시 가입페이지로!! - model.addAttribute("message", "This user does not exist. Please sign up."); - - } else { - // 존재시 로그인 처리 - model.addAttribute("message", "OAuth Sign-in succeeded."); - - } - - return "egovframework/com/uat/uia/EgovLoginUsrOauthResult"; - } - -} diff --git a/src/main/java/nlib/bbs/web/BoardController.java b/src/main/java/nlib/bbs/web/BoardController.java index 5855d1ad..b22375f6 100644 --- a/src/main/java/nlib/bbs/web/BoardController.java +++ b/src/main/java/nlib/bbs/web/BoardController.java @@ -634,7 +634,7 @@ public class BoardController extends NlibCommonController //------------------------------- // 비밀번호 : SHA-256 암호화 처리되어 DB에 저장되며, // 웹 화면에 표출될 때는 Aria로 articleNo를 Salt값으로 하여 재암호화처리하고 BASE64로 다시 한번 인코딩하여 표출함 - String encArticlePassword = StringUtil.encodeBase64(ariaCrypto.encode(shaArticlePassword, articleNo)); + String encArticlePassword = StringUtil.encodeBase64(ariaCrypto.encode(shaArticlePassword)); model.addAttribute("encArticlePassword", encArticlePassword); // 검색 정보 @@ -680,7 +680,7 @@ public class BoardController extends NlibCommonController // 비밀번호 : SHA-256 암호화 처리되어 DB에 저장되며, // 웹 화면에 표출될 때는 Aria로 articleNo를 Salt값으로 하여 재암호화처리하고 BASE64로 다시 한번 인코딩하여 표출함 String encArticlePassword = paramMap.get("encArticlePassword"); - String checkArticlePassword = ariaCrypto.decode(StringUtil.decodeBase64(encArticlePassword), articleNo); + String checkArticlePassword = ariaCrypto.decode(StringUtil.decodeBase64(encArticlePassword)); String articlePassword = paramMap.get("articlePassword"); //------------------------------- diff --git a/src/main/java/nlib/cmm/crypto/AriaCrypto.java b/src/main/java/nlib/cmm/crypto/AriaCrypto.java index f31d8b19..2f2a3479 100644 --- a/src/main/java/nlib/cmm/crypto/AriaCrypto.java +++ b/src/main/java/nlib/cmm/crypto/AriaCrypto.java @@ -3,13 +3,11 @@ package nlib.cmm.crypto; import org.apache.commons.codec.binary.Base64; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; import egovframework.rte.fdl.cryptography.EgovPasswordEncoder; import egovframework.rte.fdl.cryptography.impl.EgovARIACryptoServiceImpl; import nlib.cmm.service.NlibProperty; -import nlib.sample.web.SampleEncoderController; import nlib.util.StringUtil; /** @@ -51,18 +49,40 @@ public class AriaCrypto { * @return */ public static String encode(String value) { - log.info("encode : 암호화에 사용할 키 정보가 없으므로 기본키 정보를 사용합니다 : " + ARIA_DEFAULT_KEY); - return encode(value, ARIA_DEFAULT_KEY); + + String ret = null; + + try { + ret = AriaUtil.ariaEncrypt(value); + } catch(Exception e) { + log.error("ERROR at AriaCrypto.encode : " + e.toString()); + e.printStackTrace(); + ret = null; + } + + return ret; } + /** + * 기본키를 가지고 Egov 모듈을 사용하여 암호화한다. + * + * @param value + * @return + */ + public static String encodeEgov(String value) { + log.info("encode : 암호화에 사용할 키 정보가 없으므로 기본키 정보를 사용합니다 : " + ARIA_DEFAULT_KEY); + return encodeEgov(value, ARIA_DEFAULT_KEY); + } + + /** - * 전달받은 key(사용자고유번호 혹은 메일주소 등 salt값)로 암호화한다. + * 전달받은 key(사용자고유번호 혹은 메일주소 등 salt값)로 Egov 모듈을 사용하여 암호화한다. * * @param value * @param key * @return */ - public static String encode(String value, String key) { + public static String encodeEgov(String value, String key) { if(StringUtil.isEmpty(value)) { log.error("encode : 암호화할 문자열 정보가 없습니다."); @@ -94,17 +114,38 @@ public class AriaCrypto { * @return */ public static String decode(String value) { + + String ret = null; + + try { + ret = AriaUtil.ariaDecrypt(value); + } catch(Exception e) { + log.error("ERROR at AriaCrypto.decode : " + e.toString()); + e.printStackTrace(); + ret = null; + } + + return ret; + } + + /** + * 기본키를 가지고 Egov 모듈을 사용하여 복호화한다. + * + * @param value + * @return + */ + public static String decodeEgov(String value) { log.info("decode : 복호화에 사용할 키 정보가 없으므로 기본키 정보를 사용합니다 : " + ARIA_DEFAULT_KEY); - return decode(value, ARIA_DEFAULT_KEY); + return decodeEgov(value, ARIA_DEFAULT_KEY); } /** - * 전달받은 key(사용자고유번호 혹은 메일주소 등 salt값)로 복호화한다. + * 전달받은 key(사용자고유번호 혹은 메일주소 등 salt값)로 Egov 모듈을 사용하여 복호화한다. * @param value * @param key * @return */ - public static String decode(String value, String key) { + public static String decodeEgov(String value, String key) { if(StringUtil.isEmpty(value)) { log.error("decode : 복호화할 암호문자열 정보가 없습니다."); diff --git a/src/main/java/nlib/cmm/crypto/AriaEngine.java b/src/main/java/nlib/cmm/crypto/AriaEngine.java new file mode 100644 index 00000000..78bff06f --- /dev/null +++ b/src/main/java/nlib/cmm/crypto/AriaEngine.java @@ -0,0 +1,590 @@ +// +// ARIA.java +// +// A pure Java implementation of ARIA +// following the official ARIA specification at +// + +package nlib.cmm.crypto; + +import java.io.PrintStream; +import java.security.InvalidKeyException; + +public class AriaEngine { + + private static final char[] HEX_DIGITS = { + '0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f' + }; + + private static final int[][] KRK = { + {0x517cc1b7, 0x27220a94, 0xfe13abe8, 0xfa9a6ee0}, + {0x6db14acc, 0x9e21c820, 0xff28b1d5, 0xef5de2b0}, + {0xdb92371d, 0x2126e970, 0x03249775, 0x04e8c90e} + }; + + private static final byte[] S1 = new byte[256]; + private static final byte[] S2 = new byte[256]; + private static final byte[] X1 = new byte[256]; + private static final byte[] X2 = new byte[256]; + + private static final int[] TS1 = new int[256]; + private static final int[] TS2 = new int[256]; + private static final int[] TX1 = new int[256]; + private static final int[] TX2 = new int[256]; + + private String publicKey = "CREDIF_MASTERKEY"; + + private String privateKey = ""; + + + // Static initializer. For setting up the tables + static { + int[] exp = new int[256]; + int[] log = new int[256]; + exp[0] = 1; + for (int i=1; i < 256; i++) { + int j = (exp[i-1] << 1) ^ exp[i-1]; + if ((j & 0x100) != 0) j ^= 0x11b; + exp[i] = j; + } + for (int i=1; i < 255; i++) + log[exp[i]] = i; + + int[][] A = { + {1, 0, 0, 0, 1, 1, 1, 1}, + {1, 1, 0, 0, 0, 1, 1, 1}, + {1, 1, 1, 0, 0, 0, 1, 1}, + {1, 1, 1, 1, 0, 0, 0, 1}, + {1, 1, 1, 1, 1, 0, 0, 0}, + {0, 1, 1, 1, 1, 1, 0, 0}, + {0, 0, 1, 1, 1, 1, 1, 0}, + {0, 0, 0, 1, 1, 1, 1, 1} + }; + int[][] B = { + {0, 1, 0, 1, 1, 1, 1, 0}, + {0, 0, 1, 1, 1, 1, 0, 1}, + {1, 1, 0, 1, 0, 1, 1, 1}, + {1, 0, 0, 1, 1, 1, 0, 1}, + {0, 0, 1, 0, 1, 1, 0, 0}, + {1, 0, 0, 0, 0, 0, 0, 1}, + {0, 1, 0, 1, 1, 1, 0, 1}, + {1, 1, 0, 1, 0, 0, 1, 1} + }; + + for (int i=0; i<256; i++) { + int t=0, p; + if (i==0) + p=0; + else + p=exp[255-log[i]]; + for (int j=0; j<8; j++) { + int s=0; + for (int k=0; k<8; k++) { + if (((p>>>(7-k))&0x01)!=0) + s^=A[k][j]; + } + t=(t<<1)^s; + } + t^=0x63; + S1[i]=(byte)t; + X1[t]=(byte)i; + } + for (int i = 0; i < 256; i++) { + int t = 0, p; + if (i==0) + p=0; + else + p=exp[(247*log[i])%255]; + for (int j = 0; j < 8; j++) { + int s = 0; + for (int k = 0; k < 8; k++) { + if (((p >>> k) & 0x01) != 0) + s ^= B[7-j][k]; + } + t = (t << 1) ^ s; + } + t^=0xe2; + S2[i] = (byte) t; + X2[t] = (byte) i; + } + + for (int i = 0; i < 256; i++) { + TS1[i]=0x00010101*(S1[i]&0xff); + TS2[i]=0x01000101*(S2[i]&0xff); + TX1[i]=0x01010001*(X1[i]&0xff); + TX2[i]=0x01010100*(X2[i]&0xff); + } + } + + private int keySize=0; + private int numberOfRounds=0; + private byte[] masterKey=null; + private int[] encRoundKeys=null, decRoundKeys=null; + + public AriaEngine(int keySize) throws InvalidKeyException { + setKeySize(keySize); + } + + /** + * Resets the class so that it can be reused for another master key. + */ + void reset() { + this.keySize=0; + this.numberOfRounds=0; + this.masterKey=null; + this.encRoundKeys=null; + this.decRoundKeys=null; + } + + int getKeySize() { + return this.keySize; + } + + void setKeySize(int keySize) throws InvalidKeyException { + this.reset(); + if (keySize!=128 && keySize!=192 && keySize!=256) + throw new InvalidKeyException("keySize="+keySize); + this.keySize = keySize; + switch (keySize) { + case 128: + this.numberOfRounds = 12; + break; + case 192: + this.numberOfRounds = 14; + break; + case 256: + this.numberOfRounds = 16; + } + } + + void setKey(byte[] masterKey) throws InvalidKeyException { + if (masterKey.length*8