summary refs log tree commit diff
path: root/crypto/src/tls/HandshakeType.cs
blob: ad2c29c0785b36cbd0a612a4f16be8aa7b59f66c (plain) (blame)
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
using System;

namespace Org.BouncyCastle.Tls
{
    public abstract class HandshakeType
    {
        /*
         * RFC 2246 7.4
         */
        public const short hello_request = 0;
        public const short client_hello = 1;
        public const short server_hello = 2;
        public const short certificate = 11;
        public const short server_key_exchange = 12;
        public const short certificate_request = 13;
        public const short server_hello_done = 14;
        public const short certificate_verify = 15;
        public const short client_key_exchange = 16;
        public const short finished = 20;

        /*
         * RFC 3546 2.4
         */
        public const short certificate_url = 21;
        public const short certificate_status = 22;

        /*
         * (DTLS) RFC 4347 4.3.2
         */
        public const short hello_verify_request = 3;

        /*
         * RFC 4680
         */
        public const short supplemental_data = 23;

        /*
         * RFC 8446
         */
        public const short new_session_ticket = 4;
        public const short end_of_early_data = 5;
        public const short hello_retry_request = 6;
        public const short encrypted_extensions = 8;
        public const short key_update = 24;
        public const short message_hash = 254;

        /*
         * RFC 8879
         */
        public const short compressed_certificate = 25;

        public static string GetName(short handshakeType)
        {
            switch (handshakeType)
            {
            case hello_request:
                return "hello_request";
            case client_hello:
                return "client_hello";
            case server_hello:
                return "server_hello";
            case certificate:
                return "certificate";
            case server_key_exchange:
                return "server_key_exchange";
            case certificate_request:
                return "certificate_request";
            case server_hello_done:
                return "server_hello_done";
            case certificate_verify:
                return "certificate_verify";
            case client_key_exchange:
                return "client_key_exchange";
            case finished:
                return "finished";
            case certificate_url:
                return "certificate_url";
            case certificate_status:
                return "certificate_status";
            case hello_verify_request:
                return "hello_verify_request";
            case supplemental_data:
                return "supplemental_data";
            case new_session_ticket:
                return "new_session_ticket";
            case end_of_early_data:
                return "end_of_early_data";
            case hello_retry_request:
                return "hello_retry_request";
            case encrypted_extensions:
                return "encrypted_extensions";
            case key_update:
                return "key_update";
            case message_hash:
                return "message_hash";
            case compressed_certificate:
                return "compressed_certificate";
            default:
                return "UNKNOWN";
            }
        }

        public static string GetText(short handshakeType)
        {
            return GetName(handshakeType) + "(" + handshakeType + ")";
        }

        public static bool IsRecognized(short handshakeType)
        {
            switch (handshakeType)
            {
            case hello_request:
            case client_hello:
            case server_hello:
            case certificate:
            case server_key_exchange:
            case certificate_request:
            case server_hello_done:
            case certificate_verify:
            case client_key_exchange:
            case finished:
            case certificate_url:
            case certificate_status:
            case hello_verify_request:
            case supplemental_data:
            case new_session_ticket:
            case end_of_early_data:
            case hello_retry_request:
            case encrypted_extensions:
            case key_update:
            case message_hash:
            case compressed_certificate:
                return true;
            default:
                return false;
            }
        }
    }
}