Server Name Indication(SNI)

ยท 983 words ยท 2 minute read

Server Name Indication ๐Ÿ”—

Server Name Indication(์ค„์—ฌ์„œ SNI)๋Š” SSL/TLS ๊ธฐ๋ฐ˜์˜ HTTPS์— ๊ธฐ๋ฐ˜ํ•œ Name-based ๊ฐ€์ƒ ํ˜ธ์ŠคํŒ… ํ™˜๊ฒฝ์—์„œ ์ผ์–ด๋‚  ์ˆ˜ ์žˆ๋Š” ๋ฌธ์ œ์ ์„ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด ๊ตฌํ˜„๋œ HTTPS์˜ Extension์ด๋‹ค. ํ•ด๋‹น ๋ฌธ์ œ์ ์— ๋Œ€ํ•ด ๊ตฌ์ฒด์ ์œผ๋กœ ์„ค๋ช…ํ•˜์ž๋ฉด Name-based ๊ฐ€์ƒ ํ˜ธ์ŠคํŒ… ํ™˜๊ฒฝ์—์„œ ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„๋กœ ์–ด๋–ค vhost๋ฅผ ์‚ฌ์šฉํ•  ๊ฒƒ์ธ์ง€ Request ๋ฉ”์‹œ์ง€์— ๊ฐ™์ด ๋ณด๋‚ธ๋‹ค. ์ด ๋•Œ, ์‚ฌ์šฉํ•˜๋Š” ํ”„๋กœํ† ์ฝœ์ด HTTP๊ฐ€ ์•„๋‹Œ HTTPS๋ผ๋ฉด ์„œ๋ฒ„๋Š” ํด๋ผ์ด์–ธํŠธ๋กœ Server Hello ํŒจํ‚ท์„ ๋ณด๋‚ผ ๋•Œ ํŒจํ‚ท ๋‚ด์— ์ธ์ฆ์„œ ๋ฐ์ดํ„ฐ๋ฅผ ํ•จ๊ป˜ ์ „์†กํ•œ๋‹ค. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋‹ค์‹œ ์„œ๋ฒ„๋กœ Client Hello๋ฅผ ๋ณด๋‚ผ ๋•Œ ํด๋ผ์ด์–ธํŠธ๋Š” ์„œ๋ฒ„์—์„œ ๋ณด๋‚ด์ค€ ์ธ์ฆ์„œ์˜ ๊ณต๊ฐœํ‚ค๋กœ ์•”ํ˜ธํ™”ํ•˜์—ฌ ํŒจํ‚ท์„ ๋ณด๋‚ด๊ฒŒ ๋˜๋Š”๋ฐ ์„œ๋ฒ„ ์ž…์žฅ์—์„œ๋Š” ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์‚ฌ์šฉํ•œ ์ธ์ฆ์„œ๊ฐ€ ์–ด๋–ค ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ์—์„œ ๋ณด๋‚ธ ์ธ์ฆ์„œ์ธ์ง€ ์•Œ ๊ธธ์ด ์—†๋‹ค. ์ด๋Ÿฌํ•œ ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•˜๊ธฐ ์œ„ํ•ด Server Name Indication(SNI)๋ผ๋Š” Extension์„ ์‚ฌ์šฉํ•˜์—ฌ ์•„๋ž˜์™€ ๊ฐ™์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐํ•  ์ˆ˜ ์žˆ๋‹ค.

์„œ๋ฒ„์—์„œ SNI ์„ค์ • ๋ฐฉ๋ฒ•(์˜ˆ์‹œ. Apache ์‚ฌ์šฉ) ๐Ÿ”—

SNI ์„ค์ •์„ ์œ„ํ•ด์„œ๋Š” ๋‘ ๊ฐ€์ง€ ๋ฐฉ๋ฒ•์ด ์žˆ๋‹ค. (์„ค์ • ํŒŒ์ผ ๋ณ€๊ฒฝ ๋ฐฉ๋ฒ•)

์ฒซ ๋ฒˆ์งธ๋Š” ํ•˜๋‚˜์˜ ๊ฐ€์ƒ ํ˜ธ์ŠคํŠธ๋งŒ ์ •์˜ํ•˜๊ณ  ๋‚˜๋จธ์ง€๋Š” SSLSNIMap์„ ํ†ตํ•ด ํ˜ธ์ŠคํŠธ ์ด๋ฆ„๊ณผ ์ธ์ฆ์„œ ๋ ˆ์ด๋ธ”์„ ๋งตํ•‘ํ•˜๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

1
2
3
4
5
6
7
8
<virtualhost *:443>
  ServerName example.com
  SSLEnable SNI
  SSLServerCert default
  SSLSNIMap a.example.com sni1-rsa
  SSLSNIMap a.example.com sni1-ecc
  SSLSNIMap b.example.com sni2
</virtualhost>

๋‘ ๋ฒˆ์งธ๋Š” ๊ฐ€์ƒํ˜ธ์ŠคํŠธ์— ๋งตํ•‘ํ•  ํ˜ธ์ŠคํŠธ๋ช…๊ณผ ์ธ์ฆ์„œ ๋ ˆ์ด๋ธ”์„ ๊ฐ๊ฐ ๋‚˜๋ˆ„์–ด ๋ช…์‹œํ•ด์ฃผ๋Š” ๋ฐฉ๋ฒ•์ด๋‹ค.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
<virtualhost *:443>
  ServerName example.com
  SSLEnable SNI
</virtualhost>
<virtualhost *:443>
  ServerName a.example.com
  SSLEnable
  SSLServerCert sni1
</virtualhost>
<virtualhost *:443>
  ServerName b.example.com
  ServerAlias other.example.com
  SSLEnable
  SSLServerCert sni2
</virtualhost>

์‹ค์ œ SNI ํŒจํ‚ท ๐Ÿ”—

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
const unsigned char good_data_2[] = {
    // TLS record
    0x16, // Content Type: Handshake
    0x03, 0x01, // Version: TLS 1.0
    0x00, 0x6c, // Length (use for bounds checking)
        // Handshake
        0x01, // Handshake Type: Client Hello
        0x00, 0x00, 0x68, // Length (use for bounds checking)
        0x03, 0x03, // Version: TLS 1.2
        // Random (32 bytes fixed length)
        0xb6, 0xb2, 0x6a, 0xfb, 0x55, 0x5e, 0x03, 0xd5,
        0x65, 0xa3, 0x6a, 0xf0, 0x5e, 0xa5, 0x43, 0x02,
        0x93, 0xb9, 0x59, 0xa7, 0x54, 0xc3, 0xdd, 0x78,
        0x57, 0x58, 0x34, 0xc5, 0x82, 0xfd, 0x53, 0xd1,
        0x00, // Session ID Length (skip past this much)
        0x00, 0x04, // Cipher Suites Length (skip past this much)
            0x00, 0x01, // NULL-MD5
            0x00, 0xff, // RENEGOTIATION INFO SCSV
        0x01, // Compression Methods Length (skip past this much)
            0x00, // NULL
        0x00, 0x3b, // Extensions Length (use for bounds checking)
            // Extension
            0x00, 0x00, // Extension Type: Server Name (check extension type)
            0x00, 0x0e, // Length (use for bounds checking)

            /* SNI ์„ค์ • ๋ถ€๋ถ„: ์•„๋ž˜์—์„œ "localhost"๋ผ๊ณ  ์„œ๋ฒ„์˜ ์ด๋ฆ„์„ ์ง์ ‘ ๋ช…์‹œํ•œ๋‹ค. */
            0x00, 0x0c, // Server Name Indication Length
                0x00, // Server Name Type: host_name (check server name type)
                0x00, 0x09, // Length (length of your data)
                // "localhost" (data your after)
                0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x68, 0x6f, 0x73, 0x74,
            // Extension
            0x00, 0x0d, // Extension Type: Signature Algorithms (check extension type)
            0x00, 0x20, // Length (skip past since this is the wrong extension)
            // Data
            0x00, 0x1e, 0x06, 0x01, 0x06, 0x02, 0x06, 0x03,
            0x05, 0x01, 0x05, 0x02, 0x05, 0x03, 0x04, 0x01,
            0x04, 0x02, 0x04, 0x03, 0x03, 0x01, 0x03, 0x02,
            0x03, 0x03, 0x02, 0x01, 0x02, 0x02, 0x02, 0x03,
            // Extension
            0x00, 0x0f, // Extension Type: Heart Beat (check extension type)
            0x00, 0x01, // Length (skip past since this is the wrong extension)
            0x01 // Mode: Peer allows to send requests
};

์ถœ์ฒ˜ ๐Ÿ”—

SNI