0411 ~ 0417


# 0411 ~ 0417

# 0411 - DFS, BFS์˜ ์„ค๋ช…, ์ฐจ์ 

BFS, DFS ๋‘๊ฐ€์ง€ ๋ชจ๋‘ ๊ทธ๋ž˜ํ”„๋ฅผ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

๊ทธ๋ž˜ํ”„๋ž€, ์ •์ (node)์™€ ๊ทธ ์ •์ ์„ ์—ฐ๊ฒฐํ•˜๋Š” ๊ฐ„์„ (edge)์œผ๋กœ ์ด๋ฃจ์–ด์ง„ ์ž๋ฃŒ๊ตฌ์กฐ์˜ ์ผ์ข…์„ ๋งํ•˜๋ฉฐ, ๊ทธ๋ž˜ํ”„๋ฅผ ํƒ์ƒ‰ํ•œ๋‹ค๋Š” ๊ฒƒ์€ ํ•˜๋‚˜์˜ ์ •์ ์œผ๋กœ๋ถ€ํ„ฐ ์‹œ์ž‘ํ•˜์—ฌ ์ฐจ๋ก€๋Œ€๋กœ ๋ชจ๋“  ์ •์ ๋“ค์„ ํ•œ ๋ฒˆ์”ฉ ๋ฐฉ๋ฌธํ•˜๋Š” ๊ฒƒ์„ ๋งํ•œ๋‹ค.

image

๋ฃจํŠธ ๋…ธ๋“œ(ํ˜น์€ ๋‹ค๋ฅธ ์ž„์˜์˜ ๋…ธ๋“œ)์—์„œ ์‹œ์ž‘ํ•ด์„œ ๋‹ค์Œ ๋ถ„๊ธฐ๋กœ ๋„˜์–ด๊ฐ€๊ธฐ ์ „์— ํ•ด๋‹น ๋ถ„๊ธฐ๋ฅผ ์™„๋ฒฝํ•˜๊ฒŒ ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ์‹์„ ๋งํ•œ๋‹ค.
์˜ˆ๋ฅผ ๋“ค์–ด, ๋ฏธ๋กœ์ฐพ๊ธฐ๋ฅผ ํ•  ๋•Œ ์ตœ๋Œ€ํ•œ ํ•œ ๋ฐฉํ–ฅ์œผ๋กœ ๊ฐˆ ์ˆ˜ ์žˆ์„ ๋•Œ๊นŒ์ง€ ์ญ‰ ๊ฐ€๋‹ค๊ฐ€ ๋” ์ด์ƒ ๊ฐˆ ์ˆ˜ ์—†๊ฒŒ ๋˜๋ฉด ๋‹ค์‹œ ๊ฐ€์žฅ ๊ฐ€๊นŒ์šด ๊ฐˆ๋ฆผ๊ธธ๋กœ ๋Œ์•„์™€์„œ ๊ทธ ๊ฐˆ๋ฆผ๊ธธ๋ถ€ํ„ฐ ๋‹ค์‹œ ๋‹ค๋ฅธ ๋ฐฉํ–ฅ์œผ๋กœ ํƒ์ƒ‰์„ ์ง„ํ–‰ํ•˜๋Š” ๊ฒƒ์ด ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰ ๋ฐฉ์‹์ด๋ผ๊ณ  ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•˜๊ณ ์ž ํ•˜๋Š” ๊ฒฝ์šฐ์— ์ด ๋ฐฉ๋ฒ•์„ ์„ ํƒํ•จ
  • ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰(DFS)์ด ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰(BFS)๋ณด๋‹ค ์ข€ ๋” ๊ฐ„๋‹จํ•จ
  • ๊ฒ€์ƒ‰ ์†๋„ ์ž์ฒด๋Š” ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰(BFS)์— ๋น„ํ•ด์„œ ๋Š๋ฆผ

image

๋ฃจํŠธ ๋…ธ๋“œ(ํ˜น์€ ๋‹ค๋ฅธ ์ž„์˜์˜ ๋…ธ๋“œ)์—์„œ ์‹œ์ž‘ํ•ด์„œ ์ธ์ ‘ํ•œ ๋…ธ๋“œ๋ฅผ ๋จผ์ € ํƒ์ƒ‰ํ•˜๋Š” ๋ฐฉ๋ฒ•์œผ๋กœ, ์‹œ์ž‘ ์ •์ ์œผ๋กœ๋ถ€ํ„ฐ ๊ฐ€์žฅ์šด ์ •์ ์„ ๋จผ์ € ๋ฐฉ๋ฌธํ•˜๊ณ  ๋ฉ€๋ฆฌ ๋–จ์–ด์ ธ ์žˆ๋Š” ์ •์ ์„ ๋‚˜์ค‘์— ๋ฐฉ๋ฌธํ•˜๋Š” ์ˆœํšŒ ๋ฐฉ๋ฒ•.
์ฃผ๋กœ ๋‘ ๋…ธ๋“œ ์‚ฌ์ด์˜ ์ตœ๋‹จ ๊ฒฝ๋กœ๋ฅผ ์ฐพ๊ณ  ์‹ถ์„ ๋•Œ ์ด ๋ฐฉ๋ฒ•์„ ์„ ํƒ.
ex) ์ง€๊ตฌ ์ƒ์— ์กด์žฌํ•˜๋Š” ๋ชจ๋“  ์นœ๊ตฌ ๊ด€๊ณ„๋ฅผ ๊ทธ๋ž˜ํ”„๋กœ ํ‘œํ˜„ํ•œ ํ›„ Sam๊ณผ Eddie์‚ฌ์ด์— ์กด์žฌํ•˜๋Š” ๊ฒฝ๋กœ๋ฅผ ์ฐพ๋Š” ๊ฒฝ์šฐ

  • ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰์˜ ๊ฒฝ์šฐ - ๋ชจ๋“  ์นœ๊ตฌ ๊ด€๊ณ„๋ฅผ ๋‹ค ์‚ดํŽด๋ด์•ผ ํ• ์ง€๋„ ๋ชจ๋ฆ„
  • ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰์˜ ๊ฒฝ์šฐ - Sam๊ณผ ๊ฐ€๊นŒ์šด ๊ด€๊ณ„๋ถ€ํ„ฐ ํƒ์ƒ‰

# DFS, BFS ๋น„๊ต

image

  • DFS(๊นŠ์ด์šฐ์„ ํƒ์ƒ‰) : ํ˜„์žฌ ์ •์ ์—์„œ ๊ฐˆ ์ˆ˜ ์žˆ๋Š” ์ ๋“ค๊นŒ์ง€ ๋“ค์–ด๊ฐ€๋ฉด์„œ ํƒ์ƒ‰ -> ์Šคํƒ ๋˜๋Š” ์žฌ๊ท€ํ•จ์ˆ˜๋กœ ๊ตฌํ˜„
  • BFS(๋„ˆ๋น„์šฐ์„ ํƒ์ƒ‰) : ํ˜„์žฌ ์ •์ ์—์„œ ์—ฐ๊ฒฐ๋œ ๊ฐ€๊นŒ์šด ์ ๋“ค๋ถ€ํ„ฐ ํƒ์ƒ‰ -> ํ๋ฅผ ์ด์šฉํ•ด์„œ ๊ตฌํ˜„

# DFS, BFS์˜ ์‹œ๊ฐ„๋ณต์žก๋„

๋‘ ๋ฐฉ์‹ ๋ชจ๋‘ ์กฐ๊ฑด ๋‚ด์˜ ๋ชจ๋“  ๋…ธ๋“œ๋ฅผ ๊ฒ€์ƒ‰ํ•œ๋‹ค๋Š” ์ ์—์„œ ์‹œ๊ฐ„ ๋ณต์žก๋„๋Š” ๋™์ผํ•˜๋‹ค.
DFS์™€ BFS ๋‘˜ ๋‹ค ๋‹ค์Œ ๋…ธ๋“œ๊ฐ€ ๋ฐฉ๋ฌธํ•˜์˜€๋Š”์ง€๋ฅผ ํ™•์ธํ•˜๋Š” ์‹œ๊ฐ„๊ณผ ๊ฐ ๋…ธ๋“œ๋ฅผ ๋ฐฉ๋ฌธํ•˜๋Š” ์‹œ๊ฐ„์„ ํ•ฉํ•˜๋ฉด ๋œ๋‹ค.

# ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰๊ณผ ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰ ํ™œ์š”ํ•œ ๋ฌธ์ œ ์œ ํ˜•/์‘์šฉ

  • ๊ทธ๋ž˜ํ”„์˜ ๋ชจ๋“  ์ •์ ์„ ๋ฐฉ๋ฌธํ•˜๋Š” ๊ฒƒ์ด ์ฃผ์š”ํ•œ ๋ฌธ์ œ
    : ๋‹จ์ˆœํžˆ ๋ชจ๋“  ์ •์ ์„ ๋ฐฉ๋ฌธํ•˜๋Š” ๊ฒƒ์ด ์ค‘์š”ํ•œ ๋ฌธ์ œ์˜ ๊ฒฝ์šฐ ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ• ์ค‘ ์–ด๋Š ๊ฒƒ์„ ์‚ฌ์šฉํ•ด์š” ์ƒ๊ด€์—†๋‹ค.
  • ๊ฒฝ๋กœ์˜ ํŠน์ง•์„ ์ €์žฅํ•ด๋‘ฌ์•ผ ํ•˜๋Š” ๋ฌธ์ œ
    : ์˜ˆ๋ฅผ ๋“ค๋ฉด ๊ฐ ์ •์ ์— ์ˆซ์ž๊ฐ€ ์ ํ˜€์žˆ๊ณ  a๋ถ€ํ„ฐ b๊นŒ์ง€ ๊ฒฝ๋กœ๋ฅผ ๊ตฌํ•˜๋Š”๋ฐ ๊ฒฝ๋กœ์— ๊ฐ™์€ ์ˆซ์ž๊ฐ€ ์žˆ์œผ๋ฉด ์•ˆ๋œ๋‹ค๋Š” ๋ฌธ์ œ ๋“ฑ, ๊ฐ๊ฐ์˜ ๊ฒฝ๋กœ๋งˆ๋‹ค ํŠน์ง•์„ ์ €์žฅํ•ด๋‘ฌ์•ผ ํ•  ๋–„๋Š” DFS๋ฅผ ์‚ฌ์šฉํ•œ๋‹ค.(BFS๋Š” ๊ฒฝ๋กœ์˜ ํŠน์ง•์„ ๊ฐ€์ง€์ง€ ๋ชปํ•œ๋‹ค)
  • ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ๋ฌธ์ œ
    : ๋ฏธ๋กœ ์ฐพ๊ธฐ ๋“ฑ ์ตœ๋‹จ๊ฑฐ๋ฆฌ๋ฅผ ๊ตฌํ•ด์•ผ ํ•˜๋Š” ๊ฒฝ์šฐ, BFS๊ฐ€ ์œ ๋ฆฌํ•˜๋‹ค. ์ด์œ ๋Š” ๊นŠ์ด ์šฐ์„  ํƒ์ƒ‰์œผ๋กœ ๊ฒฝ๋กœ๋ฅผ ๊ฒ€์ƒ‰ํ•  ๊ฒฝ์šฐ ์ฒ˜์Œ๋ถ€ํ„ฐ ๋ฐœ๊ฒฌ๋˜๋Š” ํ•ด๋‹ต์ด ์ตœ๋‹จ๊ฑฐ๋ฆฌ๊ฐ€ ์•„๋‹ ์ˆ˜ ์žˆ์ง€๋งŒ, ๋„ˆ๋น„ ์šฐ์„  ํƒ์ƒ‰์œผ๋กœ ํ˜„์žฌ ๋…ธ๋“œ์—์„œ ๊ฐ€๊นŒ์šด ๊ณณ๋ถ€ํ„ฐ ์ฐพ๊ธฐ ๋•Œ๋ฌธ์— ๊ฒฝ๋กœ๋ฅผ ํƒ์ƒ‰ ์‹œ ๋จผ์ € ์ฐพ์•„์ง€๋Š” ํ•ด๋‹ต์ด ๊ณง ์ตœ๋‹จ๊ฑฐ๋ฆฌ์ด๊ธฐ ๋•Œ๋ฌธ์ด๋‹ค.
  • ๊ฒ€์ƒ‰ ๋Œ€์ƒ ๊ทธ๋ž˜ํ”„๊ฐ€ ์ •๋ง ํฌ๋‹ค๋ฉด -> DFS๋ฅผ ๊ณ ๋ ค
  • ๊ฒ€์ƒ‰๋Œ€์ƒ์˜ ๊ทœ๋ชจ๊ฐ€ ํฌ์ง€ ์•Š๊ณ , ๊ฒ€์ƒ‰ ์‹œ์ž‘ ์ง€์ ์œผ๋กœ๋ถ€ํ„ฐ ์›ํ•˜๋Š” ๋Œ€์ƒ์ด ๋ณ„๋กœ ๋ฉ€์ง€ ์•Š๋‹ค๋ฉด BFS

# 0412 - PasswordEncoder

Spring Security์—์„œ๋Š” ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•ˆ์ „ํ•˜๊ฒŒ ์ €์žฅํ•  ์ˆ˜ ์žˆ๋„๋ก ๋น„๋ฐ€๋ฒˆํ˜ธ์˜ ๋‹จ๋ฐฉํ–ฅ ์•”ํ˜ธํ™”๋ฅผ ์ง€์›ํ•˜๋Š” PasswordEncoder ์ธํ„ฐํŽ˜์ด์Šค์™€ ๊ตฌํ˜„์ฒด๋“ค์„ ์ œ๊ณตํ•œ๋‹ค. ์ด ์ธํ„ฐํŽ˜์ด์Šค๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ์‹ฌํ”Œํ•˜๊ฒŒ ๊ตฌ์„ฑ๋˜์–ด ์žˆ๋‹ค.

public interface PasswordEncoder {
	
ใ€€ใ€€// ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋‹จ๋ฐฉํ–ฅ ์•”ํ˜ธํ™”
ใ€€ใ€€String encode(CharSequence rawPassword);
	
ใ€€ใ€€// ์•”ํ˜ธํ™”๋˜์ง€ ์•Š์€ ๋น„๋ฐ€๋ฒˆํ˜ธ(raw-)์™€ ์•”ํ˜ธํ™”๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ(encoded-)๊ฐ€ ์ผ์น˜ํ•˜๋Š”์ง€ ๋น„๊ต
ใ€€ใ€€boolean matches(CharSequence rawPassword, String encodedPassword);
	
ใ€€ใ€€// ์•”ํ˜ธํ™”๋œ ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ๋‹ค์‹œ ์•”ํ˜ธํ™”ํ•˜๊ณ ์ž ํ•  ๊ฒฝ์šฐ true๋ฅผ returnํ•˜๊ฒŒ ์„ค์ •
ใ€€ใ€€default boolean upgradeEncoding(String encodedPassword) { return false; };
}

Spring Security 5.3.3์—์„œ ๊ณต์‹ ์ง€์›ํ•˜๋Š” PasswordEncoder ๊ตฌํ˜„ ํด๋ž˜์Šค๋“ค์€ ์•„๋ž˜์™€ ๊ฐ™๋‹ค.

  • BcryptPasswordEncoder : BCrypt ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•”ํ˜ธํ™”
  • Argon2PasswordEncoder : Argon2 ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•”ํ˜ธํ™”
  • Pbkdf2PasswordEncoder : PBKDF2 ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•”ํ˜ธํ™”
  • SCryptPasswordEncoder : SCrypt ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ์•”ํ˜ธํ™”

์œ„ 4๊ฐœ์˜ PasswordEncoder๋Š” Password๋ฅผ encodeํ•  ๋•Œ, ๋งค๋ฒˆ ์ž„์˜์˜ salt๋ฅผ ์ƒ์„ฑํ•ด์„œ encodeํ•˜๊ฒŒ ๋˜์–ด ์žˆ๋‹ค.

์˜ˆ๋ฅผ ๋“ค์–ด BCryptPasswordEncoder Class์˜ ์ฝ”๋“œ๋ฅผ ๋ณด๋ฉด ๋‹ค์Œ๊ณผ ๊ฐ™๋‹ค.

/*
* BCryptPasswordEncoder.encode() : ์•”ํ˜ธํ™”
*/
public String encode(CharSequence rawPassword) {

ใ€€ใ€€if (rawPassword == null) {
ใ€€ใ€€ใ€€ใ€€throw new IllegalArgumentException("rawPassword cannot be null");
ใ€€ใ€€}
	
ใ€€ใ€€String salt;
ใ€€ใ€€
   if (random != null) {
   ใ€€ใ€€salt = BCrypt.gensalt(version.getVersion(), strength, random);
   } else {
   ใ€€ใ€€salt = BCrypt.gensalt(version.getVersion(), strength);
   }
   return BCrypt.hashpw(rawPassword.toString(), salt);
}

/**
* BCrypt.gensalt() : Salt ์ƒ์„ฑ
*/
public static String gensalt(String prefix, int log_rounds, SecureRandom random) throws IllegalArgumentException {

ใ€€StringBuilder rs = new StringBuilder();
ใ€€byte rnd[] = new byte[BCRYPT_SALT_LEN]; // 16byte(128bit) ํฌ๊ธฐ์˜ Salt ์ƒ์„ฑ

  if (!prefix.startsWith("$2") || (prefix.charAt(2) != 'a' && prefix.charAt(2) != 'y' && prefix.charAt(2) != 'b')) {
      throw new IllegalArgumentException ("Invalid prefix");
  }
  
  if (log_rounds < 4 || log_rounds > 31) {
      throw new IllegalArgumentException ("Invalid log_rounds");
  }

ใ€€random.nextBytes(rnd);

ใ€€rs.append("$2");
ใ€€rs.append(prefix.charAt(2));
ใ€€rs.append("$");
ใ€€if (log_rounds < 10)
      rs.append("0");
  
  rs.append(log_rounds);
  rs.append("$");
  encode_base64(rnd, rnd.length, rs);

  return rs.toString();
}

# BCryptPasswordEncoder

BCrypt ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•ด์‹œํ•˜๋Š” PasswordEncoder์ด๋‹ค. Bruteforce attack์ด๋‚˜ Rainbow table attack๊ณผ ๊ฐ™์€ Password Cracking์— ๋Œ€ํ•œ ์ €ํ•ญ๋ ฅ์„ ๋†’์ด๊ธฐ ์œ„ํ•ด ์˜๋„์ ์œผ๋กœ ๋Š๋ฆฌ๊ฒŒ ์„ค์ •๋˜์–ด ์žˆ๋‹ค.

์ „๋ฌธ ์žฅ๋น„๋ฅผ ์ด์šฉํ•˜๋ฉด ํ•œ ๊ณ„์ •์— ๋Œ€ํ•œ ๋น„๋ฐ€๋ฒˆํ˜ธ ์ž…๋ ฅ์„ 1์ดˆ์— ์ˆ˜์–ต๋ฒˆ ์ด์ƒ์œผ๋กœ ์‹œ๋„ํ•  ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์ด๋Ÿฐ ์œ ํ˜•์˜ ๊ณต๊ฒฉ์„ ์–ด๋ ต๊ฒŒ ๋งŒ๋“ค๊ธฐ ์œ„ํ•ด 1๊ฐœ์˜ ์•”ํ˜ธ๋ฅผ ํ™•์ธํ•˜๋Š”๋ฐ ์•ฝ 1์ดˆ ์ •๋„์˜ ์‹œ๊ฐ„์ด ๊ฑธ๋ฆฌ๋„๋ก ํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•œ๋‹ค. ๊ฐ ์‹œ์Šคํ…œ๋ณ„๋กœ ์„ฑ๋Šฅ ์ฐจ์ด๊ฐ€ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— PasswordEncoder๊ฐ€ ์•”ํ˜ธ๋ฅผ ํ•ด๋…ํ•˜๋Š”๋ฐ ๊ฑธ๋ฆฌ๋Š” ์‹œ๊ฐ„์€ ๋‹ฌ๋ผ์งˆ ์ˆ˜ ์žˆ๋‹ค. ๋”ฐ๋ผ์„œ ์‹œ์Šคํ…œ์— ๋งž๊ฒŒ ํ…Œ์ŠคํŠธํ•˜๋ฉด์„œ ์†๋„๋ฅผ ์กฐ์ •ํ•ด์ค˜์•ผ ํ•œ๋‹ค.

BCryptPasswordEncoder์˜ ์†๋„๋Š” ๊ฐ•๋„(strength)๋ฅผ ์กฐ์ •ํ•ด์„œ ์กฐ์ ˆํ•  ์ˆ˜ ์žˆ๋‹ค. ๊ฐ•๋„๋Š” 4~31๊นŒ์ง€ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ, BcryptPasswordEncoder๋Š” default ๊ฐ•๋„๋กœ ์•„๋ž˜์™€ ๊ฐ™์ด 10์„ ์‚ฌ์šฉํ•œ๋‹ค.

public BCryptPasswordEncoder(BCryptVersion version, int strength, SecureRandom random) {
  
  if (strength != -1 && (strength < BCrypt.MIN_LOG_ROUNDS || strength > BCrypt.MAX_LOG_ROUNDS)) {
    throw new IllegalArgumentException("Bad strength");
  }
  
  this.version = version;
  this.strength = strength == -1 ? 10 : strength; // ์ง€์ •ํ•˜์ง€ ์•Š์œผ๋ฉด ๊ฐ•๋„๋ฅผ 10์œผ๋กœ ์„ค์ •
  this.random = random;
}

// ๊ฐ•๋„์„ค์ •
// Create an encoder with strength 16
BCryptPasswordEncoder encoder = new BCryptPasswordEncoder(16);
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result));

# Argon2PasswordEncoder

Argon2 ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•ด์‹œํ•˜๋Š” PasswordEncoder์ด๋‹ค. Argon2๋Š” Paasword Hasing Competition์˜ ์šฐ์Šน์ž๋กœ Password Craking์„ ๋ฐฉ์ง€ํ•˜๊ธฐ ์œ„ํ•ด ๋‹ค๋ฅธ PasswordEncoder์™€ ๋งˆ์ฐฌ๊ฐ€์ง€๋กœ ์˜๋„์ ์œผ๋กœ ๋Š๋ฆฌ๊ฒŒ ์‹คํ–‰๋˜๋„๋ก ์„ค์ •๋˜์–ด ์žˆ๋‹ค.

// Create an encoder with all the defaults
Argon2PasswordEncoder encoder = new Argon2PasswordEncoder();
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result));

# Pbkdf2PasswordEncoder

PBKDF2 ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•ด์‹œํ•˜๋Š” PasswordEncoder์ด๋‹ค. FIPS ์ธ์ฆ(Federal Information Processing Standards, ๋ฏธ ์—ฐ๋ฐฉ ์‹œ์Šคํ…œ ๋‚ด์—์„œ ์ค‘์š”ํ•œ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณดํ˜ธํ•˜๊ธฐ ์œ„ํ•œ ํ•„์š” ํ‘œ์ค€)์ด ํ•„์š”ํ•œ ๊ฒฝ์šฐ ์ด PasswordEncoder๋ฅผ ์„ ํƒํ•˜๋Š”๊ฒƒ์ด ์ข‹๋‹ค.

// Create an encoder with all the defaults
Pbkdf2PasswordEncoder encoder = new Pbkdf2PasswordEncoder();
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result));

# SCryptPasswordEncoder

SCrypt ํ•ด์‹œ ํ•จ์ˆ˜๋ฅผ ์‚ฌ์šฉํ•ด ๋น„๋ฐ€๋ฒˆํ˜ธ๋ฅผ ํ•ด์‹œํ•˜๋Š” PasswordEncoder์ด๋‹ค.

SCryptPasswordEncoder encoder = new SCryptPasswordEncoder();
String result = encoder.encode("myPassword");
assertTrue(encoder.matches("myPassword", result);

# 0414 - StringUtils๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ์ด์œ 

.split() .toCharArray() equals() ๋“ฑ String ๋ฉ”์†Œ๋“œ๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ๋ฐ”๋กœ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ๋ณด๋‹ค StringUtils ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ™œ์šฉํ•˜๋Š” ๊ฒƒ์„ ๊ถŒ์žฅํ•œ๋‹ค.

String arr[], str = "hello-world"; 

arr = "hello-world".split("-"); // (X) warning
arr = str.split("-"); // (X) warning

arr = StringUtils.("hello-world", "-"); // (O) null-safe
arr = StringUtils.(str, "-"); // (O) null-safe

# StringUtils ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” Null-Safeํ•˜๋‹ค.

String ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ str1.equals(str2); ์—์„œ str1์ด null์ด๋ฉด NullPointerException ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€๋งŒ, StringUtils ํด๋ž˜์Šค์˜ ๊ฒฝ์šฐ StringUtils.equals(str1,str2) ์—์„œ st1์ด null ์ด์–ด๋„ ์˜ˆ์™ธ๊ฐ€ ๋ฐœ์ƒํ•˜์ง€ ์•Š๊ณ  null์„ ๋ฐ˜ํ™˜ํ•œ๋‹ค.

  • ์ปฌ๋ ‰์…˜์ธ ๊ฒฝ์šฐ CollectionUtils.isEmpty() ๋˜๋Š” CollectionUtils.isNotEmpty()์„ ์‚ฌ์šฉํ•œ๋‹ค.

# 0415 - @Converter

@Converter๋ฅผ ์‚ฌ์šฉํ•˜๋ฉด ์—”ํ‹ฐํ‹ฐ์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ณ€ํ™˜ํ•ด์„œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅํ•  ์ˆ˜ ์žˆ๋‹ค.

# Converter ์‚ฌ์šฉ๋ฒ•

@Entity
class Member{
    @Id @GeneratedValue
    private Integer id;

    @Convert(converter=BooleanToYNConverter.class)
    private boolean useYn;
}

@Converter
class BooleanToYNConverter implements AttributeConverter<Boolean, String>{
    @Override
    public String convertToDatabaseColumn(Boolean attribute){
        return (attribute != null && attribute) ? "Y" : "N";
    }

    @Override
    public Boolean convertToEntityAttribute(String dbData){
        return "Y".eqauls(dbData);
    }
}
  • AttributeConverter<์—”ํ‹ฐํ‹ฐ์ปฌ๋Ÿผํƒ€์ž…, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ปฌ๋Ÿผ ํƒ€์ž…>

# ํด๋ž˜์Šค ๋ ˆ๋ฒจ ์„ค์ •

@Entity
@Converter(converter = BooleanToYNConverter.class, attributeName = "useYn")
class Member{
    // ...
}

# ๊ธ€๋กœ๋ฒŒ ์„ค์ •

@Converter(autoApply = true)
class BooleanToYNConverter implements AttributeConverter<Boolean, String>{
    // ...
}
  • ๋ชจ๋“  Boolean ํƒ€์ž…์— ์„ค์ •

# 0417 - ECS, Fagate

# Amazon ECS(Elastic Container Service)fks?

  • ํด๋Ÿฌ์Šคํ„ฐ์—์„œ ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‰ฝ๊ฒŒ ์‹คํ–‰, ์ค‘์ง€ ๋ฐ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๊ฒŒ ํ•ด์ฃผ๋Š” ์ปจํ…Œ์ด๋„ˆ ๊ด€๋ฆฌ ์„œ๋น„์Šค.
  • ๊ฐ„๋‹จํ•œ API ํ˜ธ์ถœ์„ ์‚ฌ์šฉํ•˜์—ฌ ์ปจํ…Œ์ด๋„ˆ ๊ธฐ๋ฐ˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์‹œ์ž‘ํ•˜๊ณ  ์ค‘์ง€ํ•  ์ˆ˜ ์žˆ๋‹ค.

# AWS Fargate๋ž€

  • ๋ณ„๋„๋กœ ์ธ์Šคํ„ด์Šค๋ฅผ ์ƒ์„ฑ ๊ด€๋ฆฌํ•˜์ง€ ์•Š๊ณ , ์™„์ „ํ•œ ๋งค๋‹ˆ์ง€๋“œ ์„œ๋น„์Šค์˜ ํ˜•ํƒœ๋กœ ๋„์ปค ์ปจํ…Œ์ด๋„ˆ๋ฅผ ์‹คํ–‰์‹œํ‚ฌ ์ˆ˜ ์žˆ๋Š” ์•„๋งˆ์กด์˜ ์„œ๋ฒ„๋ฆฌ์Šค ์ปจํ…Œ์ด๋„ˆ ์ƒํ’ˆ. Docker ์ด๋ฏธ์ง€๊ฐ€ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์— ํ‘ธ์‹œ๋˜์–ด ์žˆ๋‹ค๋ฉด, ํด๋ผ์Šคํ„ฐ -> ์ž‘์—… ์ •์˜ -> ์„œ๋น„์Šค์˜ ์ˆœ์„œ๋กœ ์ƒ์„ฑํ•˜์—ฌ ์™„์ „ํžˆ 24์‹œ๊ฐ„ ์„œ๋น„์Šค ๊ฐ€๋Šฅํ•œ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ธฐ๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.

  • fagate๋ฅผ ์‚ฌ์šฉํ•˜๋ ค๋ฉด ์ƒ์œ„ ๊ฐœ๋…์—์„œ ํŠน์ • ์˜ค์ผ€์œผ์Šค๋ ˆ์ด์…˜ ์ƒํ’ˆ์„ ์„ ํƒํ•ด์•ผํ•œ๋‹ค. ํ˜„์žฌ Amazon ECS, Amazon EKS์—์„œ ์ง€์›, ์‚ฌ์šฉ๊ฐ€๋Šฅํ•˜๋‹ค.

์‚ฌ์šฉ๋ฒ•์€ ์ถ”ํ›„์— ์ž์„ธ์ด ๊ณต๋ถ€

Last update: September 13, 2022 21:44
Contributors: ahnjs