parseSNI extracts the server name from SNI extension.
(data []byte)
| 795 | |
| 796 | // parseSNI extracts the server name from SNI extension. |
| 797 | func parseSNI(data []byte) string { |
| 798 | if len(data) < 5 { |
| 799 | return "" |
| 800 | } |
| 801 | |
| 802 | // List length (2 bytes) |
| 803 | offset := 2 |
| 804 | |
| 805 | // Name type (1 byte, should be 0 for hostname) |
| 806 | if data[offset] != 0 { |
| 807 | return "" |
| 808 | } |
| 809 | offset++ |
| 810 | |
| 811 | // Name length (2 bytes) |
| 812 | nameLen := int(data[offset])<<8 | int(data[offset+1]) |
| 813 | offset += 2 |
| 814 | |
| 815 | if offset+nameLen > len(data) { |
| 816 | return "" |
| 817 | } |
| 818 | |
| 819 | return string(data[offset : offset+nameLen]) |
| 820 | } |
| 821 | |
| 822 | // parseALPN extracts protocol names from ALPN extension. |
| 823 | func parseALPN(data []byte) []string { |
no outgoing calls
no test coverage detected