ReviewOS

also looking at this

mail-os/mail

Harden encrypted mail storage, recovery, and forwarding

#8
Merged chris wants to merge codex/mail-storage-hardening into main
50 files +1701 -9001
packages/zig/vendor/zig-tls/src/protocol.zigdeleted+0-309
Changes to packages/zig/vendor/zig-tls/src/protocol.zig
@@ -1,309 +0,0 @@
1pub const Version = enum(u16) {
2 tls_1_2 = 0x0303,
3 tls_1_3 = 0x0304,
4 _,
5};
6
7pub const ContentType = enum(u8) {
8 invalid = 0,
9 change_cipher_spec = 20,
10 alert = 21,
11 handshake = 22,
12 application_data = 23,
13 _,
14};
15
16pub const Handshake = enum(u8) {
17 client_hello = 1,
18 server_hello = 2,
19 new_session_ticket = 4,
20 end_of_early_data = 5,
21 encrypted_extensions = 8,
22 certificate = 11,
23 server_key_exchange = 12,
24 certificate_request = 13,
25 server_hello_done = 14,
26 certificate_verify = 15,
27 client_key_exchange = 16,
28 finished = 20,
29 key_update = 24,
30 message_hash = 254,
31 _,
32};
33
34pub const Curve = enum(u8) {
35 named_curve = 0x03,
36 _,
37};
38
39pub const KeyExchangeModes = enum(u8) {
40 psk_ke = 0,
41 psk_dhe_ke = 1,
42};
43
44pub const Extension = enum(u16) {
45 /// RFC 6066
46 server_name = 0,
47 /// RFC 6066
48 max_fragment_length = 1,
49 /// RFC 6066
50 status_request = 5,
51 /// RFC 8422, 7919
52 supported_groups = 10,
53 /// RFC 8446
54 signature_algorithms = 13,
55 /// RFC 5764
56 use_srtp = 14,
57 /// RFC 6520
58 heartbeat = 15,
59 /// RFC 7301
60 application_layer_protocol_negotiation = 16,
61 /// RFC 6962
62 signed_certificate_timestamp = 18,
63 /// RFC 7250
64 client_certificate_type = 19,
65 /// RFC 7250
66 server_certificate_type = 20,
67 /// RFC 7685
68 padding = 21,
69 /// RFC 8446
70 pre_shared_key = 41,
71 /// RFC 8446
72 early_data = 42,
73 /// RFC 8446
74 supported_versions = 43,
75 /// RFC 8446
76 cookie = 44,
77 /// RFC 8446
78 psk_key_exchange_modes = 45,
79 /// RFC 8446
80 certificate_authorities = 47,
81 /// RFC 8446
82 oid_filters = 48,
83 /// RFC 8446
84 post_handshake_auth = 49,
85 /// RFC 8446
86 signature_algorithms_cert = 50,
87 /// RFC 8446
88 key_share = 51,
89
90 _,
91};
92
93pub fn alertFromError(err: anyerror) [2]u8 {
94 return [2]u8{ @backingInt(Alert.Level.fatal), @backingInt(Alert.fromError(err)) };
95}
96
97pub const Alert = enum(u8) {
98 pub const Level = enum(u8) {
99 warning = 1,
100 fatal = 2,
101 _,
102 };
103
104 pub const Error = error{
105 TlsAlertUnexpectedMessage,
106 TlsAlertBadRecordMac,
107 TlsAlertRecordOverflow,
108 TlsAlertHandshakeFailure,
109 TlsAlertBadCertificate,
110 TlsAlertUnsupportedCertificate,
111 TlsAlertCertificateRevoked,
112 TlsAlertCertificateExpired,
113 TlsAlertCertificateUnknown,
114 TlsAlertIllegalParameter,
115 TlsAlertUnknownCa,
116 TlsAlertAccessDenied,
117 TlsAlertDecodeError,
118 TlsAlertDecryptError,
119 TlsAlertProtocolVersion,
120 TlsAlertInsufficientSecurity,
121 TlsAlertInternalError,
122 TlsAlertInappropriateFallback,
123 TlsAlertMissingExtension,
124 TlsAlertUnsupportedExtension,
125 TlsAlertUnrecognizedName,
126 TlsAlertBadCertificateStatusResponse,
127 TlsAlertUnknownPskIdentity,
128 TlsAlertCertificateRequired,
129 TlsAlertNoApplicationProtocol,
130 TlsAlertUnknown,
131 };
132
133 close_notify = 0,
134 unexpected_message = 10,
135 bad_record_mac = 20,
136 record_overflow = 22,
137 handshake_failure = 40,
138 bad_certificate = 42,
139 unsupported_certificate = 43,
140 certificate_revoked = 44,
141 certificate_expired = 45,
142 certificate_unknown = 46,
143 illegal_parameter = 47,
144 unknown_ca = 48,
145 access_denied = 49,
146 decode_error = 50,
147 decrypt_error = 51,
148 protocol_version = 70,
149 insufficient_security = 71,
150 internal_error = 80,
151 inappropriate_fallback = 86,
152 user_canceled = 90,
153 missing_extension = 109,
154 unsupported_extension = 110,
155 unrecognized_name = 112,
156 bad_certificate_status_response = 113,
157 unknown_psk_identity = 115,
158 certificate_required = 116,
159 no_application_protocol = 120,
160 _,
161
162 pub fn toError(alert: Alert) Error!void {
163 return switch (alert) {
164 .close_notify => {}, // not an error
165 .unexpected_message => error.TlsAlertUnexpectedMessage,
166 .bad_record_mac => error.TlsAlertBadRecordMac,
167 .record_overflow => error.TlsAlertRecordOverflow,
168 .handshake_failure => error.TlsAlertHandshakeFailure,
169 .bad_certificate => error.TlsAlertBadCertificate,
170 .unsupported_certificate => error.TlsAlertUnsupportedCertificate,
171 .certificate_revoked => error.TlsAlertCertificateRevoked,
172 .certificate_expired => error.TlsAlertCertificateExpired,
173 .certificate_unknown => error.TlsAlertCertificateUnknown,
174 .illegal_parameter => error.TlsAlertIllegalParameter,
175 .unknown_ca => error.TlsAlertUnknownCa,
176 .access_denied => error.TlsAlertAccessDenied,
177 .decode_error => error.TlsAlertDecodeError,
178 .decrypt_error => error.TlsAlertDecryptError,
179 .protocol_version => error.TlsAlertProtocolVersion,
180 .insufficient_security => error.TlsAlertInsufficientSecurity,
181 .internal_error => error.TlsAlertInternalError,
182 .inappropriate_fallback => error.TlsAlertInappropriateFallback,
183 .user_canceled => {}, // not an error
184 .missing_extension => error.TlsAlertMissingExtension,
185 .unsupported_extension => error.TlsAlertUnsupportedExtension,
186 .unrecognized_name => error.TlsAlertUnrecognizedName,
187 .bad_certificate_status_response => error.TlsAlertBadCertificateStatusResponse,
188 .unknown_psk_identity => error.TlsAlertUnknownPskIdentity,
189 .certificate_required => error.TlsAlertCertificateRequired,
190 .no_application_protocol => error.TlsAlertNoApplicationProtocol,
191 _ => error.TlsAlertUnknown,
192 };
193 }
194
195 pub fn fromError(err: anyerror) Alert {
196 return switch (err) {
197 error.TlsUnexpectedMessage => .unexpected_message,
198 error.TlsBadRecordMac => .bad_record_mac,
199 error.TlsRecordOverflow => .record_overflow,
200 error.TlsHandshakeFailure => .handshake_failure,
201 error.TlsBadCertificate => .bad_certificate,
202 error.TlsUnsupportedCertificate => .unsupported_certificate,
203 error.TlsCertificateRevoked => .certificate_revoked,
204 error.TlsCertificateExpired => .certificate_expired,
205 error.TlsCertificateUnknown => .certificate_unknown,
206 error.TlsIllegalParameter,
207 error.IdentityElement,
208 error.InvalidEncoding,
209 error.TlsNoSupportedCiphers,
210 => .illegal_parameter,
211 error.TlsUnknownCa => .unknown_ca,
212 error.TlsAccessDenied => .access_denied,
213 error.TlsDecodeError => .decode_error,
214 error.TlsDecryptError => .decrypt_error,
215 error.TlsProtocolVersion => .protocol_version,
216 error.TlsInsufficientSecurity => .insufficient_security,
217 error.TlsInternalError => .internal_error,
218 error.TlsInappropriateFallback => .inappropriate_fallback,
219 error.TlsMissingExtension => .missing_extension,
220 error.TlsUnsupportedExtension => .unsupported_extension,
221 error.TlsUnrecognizedName => .unrecognized_name,
222 error.TlsBadCertificateStatusResponse => .bad_certificate_status_response,
223 error.TlsUnknownPskIdentity => .unknown_psk_identity,
224 error.TlsCertificateRequired => .certificate_required,
225 error.TlsNoApplicationProtocol => .no_application_protocol,
226 else => .internal_error,
227 };
228 }
229
230 pub fn parse(buf: [2]u8) Alert {
231 const level: Alert.Level = @fromBackingInt(@intCast(buf[0]));
232 const alert: Alert = @fromBackingInt(@intCast(buf[1]));
233 _ = level;
234 return alert;
235 }
236
237 pub fn closeNotify() [2]u8 {
238 return [2]u8{
239 @backingInt(Alert.Level.warning),
240 @backingInt(Alert.close_notify),
241 };
242 }
243};
244
245pub const SignatureScheme = enum(u16) {
246 // RSASSA-PKCS1-v1_5 algorithms
247 rsa_pkcs1_sha256 = 0x0401,
248 rsa_pkcs1_sha384 = 0x0501,
249 rsa_pkcs1_sha512 = 0x0601,
250
251 // ECDSA algorithms
252 ecdsa_secp256r1_sha256 = 0x0403,
253 ecdsa_secp384r1_sha384 = 0x0503,
254 ecdsa_secp521r1_sha512 = 0x0603,
255
256 // RSASSA-PSS algorithms with public key OID rsaEncryption
257 rsa_pss_rsae_sha256 = 0x0804,
258 rsa_pss_rsae_sha384 = 0x0805,
259 rsa_pss_rsae_sha512 = 0x0806,
260
261 // EdDSA algorithms
262 ed25519 = 0x0807,
263 ed448 = 0x0808,
264
265 // RSASSA-PSS algorithms with public key OID RSASSA-PSS
266 rsa_pss_pss_sha256 = 0x0809,
267 rsa_pss_pss_sha384 = 0x080a,
268 rsa_pss_pss_sha512 = 0x080b,
269
270 // Legacy algorithms
271 rsa_pkcs1_sha1 = 0x0201,
272 ecdsa_sha1 = 0x0203,
273
274 _,
275};
276
277pub const NamedGroup = enum(u16) {
278 // Elliptic Curve Groups (ECDHE)
279 secp256r1 = 0x0017,
280 secp384r1 = 0x0018,
281 secp521r1 = 0x0019,
282 x25519 = 0x001D,
283 x448 = 0x001E,
284
285 // Finite Field Groups (DHE)
286 ffdhe2048 = 0x0100,
287 ffdhe3072 = 0x0101,
288 ffdhe4096 = 0x0102,
289 ffdhe6144 = 0x0103,
290 ffdhe8192 = 0x0104,
291
292 // Hybrid post-quantum key agreements
293 x25519_kyber512d00 = 0xFE30,
294 x25519_kyber768d00 = 0x6399,
295 x25519_ml_kem768 = 0x11EC,
296
297 _,
298};
299
300pub const KeyUpdateRequest = enum(u8) {
301 update_not_requested = 0,
302 update_requested = 1,
303 _,
304};
305
306pub const Side = enum {
307 client,
308 server,
309};