PKI/TLS

TLS ์™€ DTLS ๋ฒ„์ „ 1.2 ์— ๊ด€ํ•œ ํŠน์„ฑ

JayKim๐Ÿ™‚ 2023. 4. 11. 11:30

์ด ๊ธ€์€ ๋‚ด๊ฐ€ ECDSA ๊ธฐ๋ฐ˜ TLS 1.2 ์™€ DTLS 1.2 ์ŠคํŽ™์„ ๊ตฌํ˜„ ํ•˜๋ฉด์„œ ์•Œ๊ฒŒ ๋œ ๋‚ด์šฉ์ด๋‹ค.
๊ทธ๋Ÿฌ๋‹ค ๋ณด๋‹ˆ ์•Œ๊ฒŒ ๋œ ๋ฉ”๋ชจ๊ธ€์ด๋ผ ์ˆ˜์‹œ๋กœ ์—…๋ฐ์ดํŠธ ํ•  ์˜ˆ์ •์ด๋‹ค.

๊ธฐ์กด์— TLS ๊ด€๋ จ ์ง€์‹์€ ๋‹ค์Œ ๋งํฌ๋ฅผ ์ฐธ์กฐ ํ•˜๋ฉด ๋œ๋‹ค.
์—ฌ๊ธฐ์„œ๋Š” ๋‹จ์ง€ ๊ฐœ๋ฐœ ํ•˜๋ฉด์„œ ํŒŒ์•…๋œ ๋‚ด์šฉ์„ ๊ฐ„๋‹จํžˆ ๊ธฐ๋ก ํ•˜์˜€๋‹ค.

๋งŒ์•ฝ์— TLS์— ๊ด€ํ•œ ๊ธฐ๋ณธ ์ง€์‹์„ ํŒŒ์•…ํ•˜๊ณ  ์‹ถ์œผ๋ฉด ์•„๋ž˜ ๋งํฌ๋ฅผ ์ฐธ์กฐ ํ•˜์„ธ์š”.

TLS ์— ๊ด€ํ•œ ์ •๋ณด ๋งํฌ

https://dokydoky.tistory.com/462
https://dokydoky.tistory.com/463
https://dokydoky.tistory.com/464

DTLS ํŠน์„ฑ

DTLS ( Datagram Transformt Layer ) ๋Š” UDP ํ™˜๊ฒฝ์—์„œ TLS ์ „์†ก์„ ํ•˜๊ธฐ ์œ„ํ•œ ํ”„๋กœํ† ์ฝœ์ด๋‹ค.
๊ทธ๋ฆฌ๊ณ  DTLS 1.0์€ TLS 1.1 ์„ ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด ์กŒ๊ตฌ. DTLS 1.2 ๋Š” TLS 1.2 ๊ธฐ๋ฐ˜์œผ๋กœ ๋งŒ๋“ค์–ด ์กŒ๋‹ค.

DTLS 1.2 ํ‘œ์ค€ ์ŠคํŽ™์€ [RFC6347] ์„ ์ฐธ์กฐ ํ•˜๋ฉด ๋œ๋‹ค.
TLS 1.2 ํ‘œ์ค€์ŠคํŽ™์€ [RFC5246] ์„ ์ฐธ์กฐ ํ•˜๋ฉด ๋œ๋‹ค.
ECC CipherSuite [RFC4492] ํ‘œ์ค€ ์ŠคํŽ™

์ฐธ๊ณ ๋กœ ๊ณต๊ฐœํ‚ค ๊ธฐ๋ฐ˜ ๊ตฌ์กฐ๋กœ DTLS ๋ฅผ ๊ตฌํ˜„ํ•œ ์˜คํ”ˆ์†Œ์Šค ์‚ฌ์ดํŠธ๋Š” ์•„๋ž˜๋ฅผ ์ฐธ์กฐ ํ•˜๋ฉด๋œ๋‹ค.
[TinyDTLS] ์ฐธ๊ณ ๋กœ ์ด ์‚ฌ์ดํŠธ๋Š” ๋‚˜๋„ Github ์—์„œ ํฌํฌํ•ด์„œ ๊ฐ€์ ธ์˜จ ์†Œ์Šค์ด๋‹ค.

DTLS์—์„œ๋Š” HelloVerifyRequest ๋ถ€๋ถ„์ด ์กด์žฌ ํ•˜๊ตฌ
TLS์—์„œ๋Š” ์ด ๊ณผ์ •์€ ์กด์žฌ ํ•˜์ง€ ์•Š๋Š”๋‹ค.

DTLS์—์„œ๋Š” ์ „์†ก์— ๋Œ€ํ•œ ๋ณด์žฅ์ด ์—†๊ธฐ ๋•Œ๋ฌธ์— ํŒจํ‚ท์— ๋Œ€ํ•œ sequence ์™€ epoch ๊ฐ’์„ ์‚ฌ์šฉํ•˜์—ฌ ํ•ด๋‹น ํŒจํ‚ท์˜ ์žฌ์ „์†ก์„ ํ†ตํ•œ
๊ฐ’์— ํ™•์ธ ํ•˜๋Š” ๋ถ€๋ถ„์ด ์กด์žฌํ•œ๋‹ค.

DTLS ํŒจํ‚ท ํ”„๋ ˆ์ž„์„ ๋ณด๋ฉด
Type(1) | Version(2) | Epoch(2) | Sequence Number(6) | Length(3) | ...

TLS ํŒจํ‚ท ํ”„๋ ˆ์ž„์€
Type(1) | Version(2) | Length(3) | ...

์ด๋ ‡๊ฒŒ epoch ์™€ sequence number ๊ฐ’์˜ ์œ ๋ฌด๊ฐ€ ์ฐจ์ด ๋‚œ๋‹ค.
epoch ๊ฐ’์€ DTLS์—์„œ๋งŒ ์‚ฌ์šฉํ•˜๋Š” ๊ฐ’์œผ๋กœ Cipher ์ƒํƒœ๊ฐ€ ๋ณ€ํ™”๊ฐ€ ์ผ์–ด ๋‚ ๋•Œ ๋งˆ๋‹ค 1์”ฉ ์ฆ๊ฐ€ ํ•˜๋Š” ๊ฐ’์ด๋‹ค.

TLS ํŠน์„ฑ

TLS ํ”„๋กœํ† ์ฝœ์€ ์ƒํ˜ธ์ธ์ฆ ๋ฐ ๋‹จ๋ฐฉํ–ฅ ์ธ์ฆ ๋‘๊ฐ€์ง€๊ฐ€ ์ง€์› ๋œ๋‹ค.
๋‹จ๋ฐฉํ–ฅ ์ธ์ฆ์ด์•ผ ์ƒํ˜ธ ์ธ์ฆ์ด๋ƒ๋Š” ์„œ๋ฒ„ ์ชฝ์—์„œ ๊ฒฐ์ • ํ•œ๋‹ค.

๋‹จ๋ฐฉํ–ฅ ์ธ์ฆ์—์„œ๋Š” CertificateRequest๋ž‘ Client Certificate, CertificateVerify ๊ฐ€ ์—†์Œ
๋Œ€์นญํ‚ค ์•Œ๊ณ ๋ฆฌ์ฆ˜์˜ ํ‚ค ๊ธธ์ด๋ฅผ 256 ๋น„ํŠธ๋ฅผ ์‚ฌ์šฉ ํ•˜๊ฒŒ ๋˜๋ฉด SHA-2 ์•Œ๊ณ ๋ฆฌ์ฆ˜ ๊ฒฝ์šฐ SHA-384 ๋งŒ ๊ฐ€๋Šฅํ•˜๋‹ค.
ํ‚ค ๊ธธ์ด 128 ๋น„ํŠธ์ธ ๊ฒฝ์šฐ๋Š” SHA-256 ๋น„ํŠธ์˜ ๋ฌด๊ฒฐ์„ฑ ์•Œ๊ณ ๋ฆฌ์ฆ˜์„ ์‚ฌ์šฉํ•œ๋‹ค.

ECDH ์™€ ECDHE ์ฐจ์ด์ 

ECDH ๋ฅผ ์‚ฌ์šฉ ํ•  ๊ฒฝ์šฐ ์„œ๋ฒ„ ์ธ์ฆ์„œ์—์„œ KeyUsage ํ•„๋“œ์— Key Agreement ๊ฐ€ ํ•„์š” ํ•จ
ECDH ๋ฅผ ํ•˜๊ฒŒ ๋˜๋ฉด ServerKeyExchange ๋ฉ”์„ธ์ง€๋Š” ๋ณด๋‚ด์ง€ ์•Š์Œ ํ•˜์ง€๋งŒ ClientKeyExchange ๋Š” ๋ณด๋ƒ„

HandShake ๊ณผ์ •

DTLS 1.2 ์ƒํ˜ธ ์ธ์ฆ

TLS 1.2 ์ƒํ˜ธ ์ธ์ฆ

TLS 1.2 ์„œ๋ฒ„ ์ธ์ฆ

์ผ๋ฐ˜์ ์œผ๋กœ HTTPS ์ฃผ์†Œ๋กœ ์ ‘๊ทผ์‹œ ์„œ๋ฒ„ ์ธ์ฆ ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•œ๋‹ค.
์„œ๋ฒ„ ์ธ์ฆ์ธ ๊ฒฝ์šฐ ํด๋ผ์ด์–ธํŠธ์—์„œ๋Š” ํŠน๋ณ„ํžˆ ์ธ์ฆ์„œ๋ฅผ ์‚ฌ์šฉํ•˜์ง€ ์•Š๋Š” ๋ฐฉ์‹์ด๋‹ค.

ClientHello

ํด๋ผ์ด์–ธํŠธ์—์„œ ์ฒ˜์Œ TLS ์‹œ์ž‘์„ ์•Œ๋ฆฌ๋Š” ๋ฉ”์ œ์ง€ ์ด๋‹ค.
์‚ฌ์šฉํ•˜๋Š” ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์•Œ๋ ค์คŒ

         struct {
             uint32 gmt_unix_time;
             opaque random_bytes[28];
         } Random;

HelloVerifyRequest

์„œ๋ฒ„์—์„œ ์ฟ ํ‚ค ๊ฐ’์„ ์•Œ๋ ค์คŒ DTLS๋Š” ์—ฐ๊ฒฐ์„ ๋ณด์žฅ ํ•˜์ง€ ์•Š๋‹ค ๋ณด๋‹ˆ ์—ฐ๊ฒฐ์— ๋Œ€ํ•œ ๊ตฌ๋ณ„ ๊ฐ’
DTLS์—์„œ๋งŒ ์‚ฌ์šฉ ํ•จ

   struct {
     ProtocolVersion server_version;
     opaque cookie<0..2^8-1>;
   } HelloVerifyRequest;

ServerHello

์„œ๋ฒ„์—์„œ ํ—ˆ๊ฐ€ ํ•œ ์•Œ๊ณ ๋ฆฌ์ฆ˜ ์ด๋ž‘ Random ๊ฐ’ ์•Œ๋ ค์คŒ

      struct {
          ProtocolVersion server_version;
          Random random;
          SessionID session_id;
          CipherSuite cipher_suite;
          CompressionMethod compression_method;
          select (extensions_present) {
              case false:
                  struct {};
              case true:
                  Extension extensions<0..2^16-1>;
          };
      } ServerHello;

Certificate

์„œ๋ฒ„ ๋˜๋Š” ํด๋ผ์ด์–ธํŠธ์—์„œ ์‚ฌ์šฉํ•˜๋Š” ์ธ์ฆ์„œ ๊ฐ’์„ ๋ณด๋‚ด์คŒ
ํด๋ผ์ด์–ธํŠธ์—์„œ๋Š” ์„œ๋ฒ„๊ฐ€ CertificateRequest๋ฅผ ๋ณด๋‚ด์•ผ๋งŒ ํด๋ผ์ด์–ธํŠธ์—์„œ๋Š” ์ „์†ก ํ•จ
์„œ๋ฒ„ ๊ฒฝ์šฐ ์ธ์ฆ์„œ ์ฒด์ธ์œผ๋กœ ์ „๋‹ฌ ํ•จ. ์ฒซ๋ฒˆ์งธ๊ฐ€ ์‹ค์ œ ์„œ๋ช…์šฉ ์ธ์ฆ์„œ ์ž„

      opaque ASN.1Cert<1..2^24-1>;

      struct {
          ASN.1Cert certificate_list<0..2^24-1>;
      } Certificate;

ServerKeyExchange

pre master secret ์ƒ์„ฑ์„ ์œ„ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ ์ •๋ณด๋ฅผ ๋ณด๋‚ด์คŒ

      struct {
          select (KeyExchangeAlgorithm) {
              case dh_anon:
                  ServerDHParams params;
              case dhe_dss:
              case dhe_rsa:
                  ServerDHParams params;
                  digitally-signed struct {
                      opaque client_random[32];
                      opaque server_random[32];
                      ServerDHParams params;
                  } signed_params;
              case rsa:
              case dh_dss:
              case dh_rsa:
                  struct {} ;
                 /* message is omitted for rsa, dh_dss, and dh_rsa */
              /* may be extended, e.g., for ECDH -- see [TLSECC] */
          };
      } ServerKeyExchange;

CertificateRequest

ํด๋ผ์ด์–ธํŠธ ์ธ์ฆ์„œ ์š”์ฒญ ํ•˜๋Š” ๊ฒฝ์šฐ ๋ณด๋ƒ„

      struct {
          ClientCertificateType certificate_types<1..2^8-1>;
          SignatureAndHashAlgorithm
            supported_signature_algorithms<2^16-1>;
          DistinguishedName certificate_authorities<0..2^16-1>;
      } CertificateRequest;

ServerHelloDone

์„œ๋ฒ„์—์„œ ๋ฉ”์„ธ์ง€๋ฅผ ๋‹ค ๋ณด๋ƒˆ๋‹ค๊ตฌ ์•Œ๋ ค์คŒ

struct { } ServerHelloDone;

ClientKeyExchange

ํด๋ผ์ด์–ธํŠธ ๋ณด์•ˆ ํŒŒ๋ผ๋ฏธํ„ฐ๋ฅผ ๋ณด๋‚ด์คŒ

      struct {
          select (KeyExchangeAlgorithm) {
              case rsa:
                  EncryptedPreMasterSecret;
              case dhe_dss:
              case dhe_rsa:
              case dh_dss:
              case dh_rsa:
              case dh_anon:
                  ClientDiffieHellmanPublic;
          } exchange_keys;
      } ClientKeyExchange

CertificateVerify

ํ˜„์žฌ ๊นŒ์ง€ ๋ณด๋‚ธ ๋ฉ”์„ธ์ง€์˜ ํ•ด์‰ฌ๊ฐ’์— ๋Œ€ํ•œ ์ „์ž ์„œ๋ช…์„ ๋ณด๋ƒ„
์ง€๊ธˆ ๊นŒ์ง€ ๋ณด๋‚ธ Handshake์˜ ๋ชจ๋“  ๋ฉ”์„ธ์ง€์— ๋Œ€ํ•œ ์„œ๋ช… ๊ฐ’์„ ๋„ฃ์–ด์„œ ๋ณด๋ƒ„.

      struct {
           digitally-signed struct {
               opaque handshake_messages[handshake_messages_length];
           }
      } CertificateVerify;

ChangeCipherSpec

์„ฑ๊ณต์  ํ‚ค ๊ณต์œ  ํ–ˆ์Œ๊ณผ ์ดํ›„ ๋ฉ”์„ธ์ง€๋Š” ์•”ํ˜ธํ™” ์ž„์„ ์•Œ๋ฆผ

      struct {
          enum { change_cipher_spec(1), (255) } type;
      } ChangeCipherSpec;

Finished

ํ•ธ๋“œ์‰์ดํฌ์˜ ์„ฑ๊ณต์„ ์•”ํ˜ธํ™”๋กœ ์•Œ๋ฆผ
์ง€๊ธˆ ๊นŒ์ง€ ๋ชจ๋“  Handshake ๋ฉ”์„ธ์ง€์— ๋Œ€ํ•œ Hash ๊ฐ’์„ ํฌํ•จ ํ•˜์—ฌ ์ „๋‹ฌ

      struct {
          opaque verify_data[verify_data_length];
      } Finished;

์ด๋ ‡๊ฒŒ Handshake ๊ฐ€ ๋๋‚˜๊ณ  ๋‚˜๋ฉด ApplicationData ์ „์†ก์„ ํ†ตํ•œ ๋ฐ์ดํƒ€ ์ „์†ก์ด ์ด๋ฃจ์–ด ์ง„๋‹ค.
์ด๋•Œ ApplicationData ๊ฒฝ์šฐ๋„ Sequence ๋ฒˆํ˜ธ๋ฅผ ์‚ฌ์šฉํ•˜์—ฌ ์ˆœ์„œ์— ๋Œ€ํ•œ ๋ณด์žฅ์ด ์ด๋ฃจ์–ด ์ €์•ผ ํ•œ๋‹ค.

๋ฐ˜์‘ํ˜•