6303 Commits

Author SHA1 Message Date
Jens Goldberg
b89158d6fd Don't initialize the static TLS area in single-threaded builds 2023-01-05 02:20:23 -07:00
Casey Banner
09ff03a57a
debug: replace RtlCaptureStackBackTrace (which was spuriously failing) with a new implementation which uses RtlVirtualUnwind instead (#12740)
windows: add RtlCaptureContext, RtlLookupFunctionEntry, RtlVirtualUnwind and supporting types
windows: fix alignment of CONTEXT structs to match winnt.h as required by RtlCaptureContext (fxsave instr)
windows aarch64: fix __chkstk being defined twice if libc is not linked on msvc

Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2023-01-04 14:54:49 -05:00
Maciej 'vesim' Kuliński
2b9478ce12 Sema: implement AVR address spaces
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2023-01-04 01:26:50 +02:00
Felix Queißner
fd0fb26aba
Implements std.ArenaAllocator.reset() (#12590)
Co-authored-by: Felix "xq" Queißner <xq@random-projects.net>
2023-01-03 15:15:20 -05:00
Andrew Kelley
8d64e5283a
Merge pull request #12586 from MasterQ32/std_memory_pool
Adds std.heap.MemoryPool
2023-01-03 14:53:54 -05:00
Jordan Lewis
1ec74f1b70 math: implement absInt for integer vectors
This commit adds support to absInt for integer vectors.
2023-01-03 13:30:24 +02:00
Lee Cannon
93bdd04e88 std.log: add functionality to check if a specific log level and scope are enabled 2023-01-03 13:02:32 +02:00
Sizhe Zhao
4fa027a3cc docs: Clarify that std.fs.path.resolve doesn't resolve relative path to
absolute path
2023-01-03 12:49:05 +02:00
Chris Boesch
1de96a2cc4 Add the two functions 'getLast' and 'getLastOrNull' to ArrayListAligned/ArrayListAlignedUnmanaged. 2023-01-03 12:48:20 +02:00
mlugg
8094fa5d48 std: add meta.FieldType
This is simply a small convenience wrapper around
'meta.fieldInfo(T, .field).type'. However, this operation is common
enough that it makes sense to have its own function for.
2023-01-03 12:47:48 +02:00
Andrew Kelley
c9ef277fa7
Merge pull request #13980 from ziglang/std.net
networking: delete std.x; add std.crypto.tls and std.http.Client
2023-01-03 02:43:50 -05:00
Andrew Kelley
7178451d62 std.crypto.tls.Client: make close_notify optional
Although RFC 8446 states:

> Each party MUST send a "close_notify" alert before closing its write
> side of the connection

In practice many servers do not do this. Also in practice, truncation
attacks are thwarted at the application layer by comparing the amount of
bytes received with the amount expected via the HTTP headers.
2023-01-02 18:27:38 -07:00
Michael Dusan
7798af7461
dragonfly: pass test: lib/std/std.zig 2023-01-02 19:18:33 -05:00
Michael Dusan
571b817abc
freebsd: add std.c.arc4random_buf 2023-01-02 19:18:33 -05:00
Michael Dusan
69553d60da
dragonfly: add std.c.arc4random_buf
This allows for a more optimal std.crypto.tlcsprng codepath.

Without it a an "incorrect alignment" panic is triggered from
crypto.tlcsprng which aligns a threadlocal but it's actually
not aligned, thus detected by the safety check.

It appears that LLVM-IR does attribute the storage with alignment
but it is ultimately not respected in the final binary for netbsd
and dragonfly.
2023-01-02 19:18:33 -05:00
Michael Dusan
46c3b09165
std.Target: bump semver max for BSDs
- freebsd, netbsd, openbsd, dragonfly
2023-01-02 19:18:33 -05:00
Michael Dusan
e752606464
netbsd: getFdPath: F_GETPATH implementation 2023-01-02 19:18:33 -05:00
Michael Dusan
7da9348637
dragonfly: getFdPath: F_GETPATH implementation 2023-01-02 19:18:33 -05:00
Michael Dusan
7f012eef0b
freebsd: memfd_create: < 13.0 version check
- add conditional compile error
- add conditional skip test
2023-01-02 19:18:33 -05:00
Michael Dusan
bd071c98a5
freebsd: getFdPath: handle NameTooLong 2023-01-02 19:18:33 -05:00
Michael Dusan
537624734c
freebsd: getFdPath: < 13.1 fallback impl 2023-01-02 19:18:32 -05:00
Michael Dusan
4cdbde55b4
macos: getFdPath: handle E.NOSPC
- per darwin-xnu source, fcntl F_GETPATH will return ENOSPC when path
  exceeds either user-supplied buffer or system MAXPATHLEN
- macOS does not document this (and other) possible errno values
2023-01-02 19:18:32 -05:00
Michael Dusan
e872c72c55
std.fs: add NAME_MAX for openbsd and netbsd 2023-01-02 19:18:32 -05:00
Andrew Kelley
9ca6d67345 std.crypto.tls.Certificate: make the current time a parameter 2023-01-02 16:57:16 -07:00
Andrew Kelley
97acdeeca8 std.crypto.tls: verify via Subject Alt Name
Previously, the code only checked Common Name, leading to unable to
validate valid certificates which relied on the subject_alt_name
extension for host name verification.

This commit also adds rsa_pss_rsae_* back to the signature algorithms
list in the ClientHello.
2023-01-02 16:57:16 -07:00
Andrew Kelley
3127bd79fb std.http.Client: don't send TLS close_notify
It appears to be implemented incorrectly in the wild and causes the read
connection to be closed even though that is a direct violation of RFC
8446 Section 6.1.

The writeEnd function variants are still there, ready to be used.
2023-01-02 16:57:16 -07:00
Andrew Kelley
611a1fdd6d std.crypto.tls: add API for sending close_notify
This commit adds `writeEnd` and `writeAllEnd` in order to send data and
also notify the server that there will be no more data written.

Unfortunately, it seems most TLS implementations in the wild get this
wrong and immediately close the socket when they see a close_notify,
rather than only ending the data stream on the application layer.
2023-01-02 16:57:16 -07:00
Andrew Kelley
b3c8c383bb std.os: add missing handling of ECONNRESET in readv 2023-01-02 16:57:16 -07:00
Andrew Kelley
66b07fd672 std.crypto.Certificate: bump RSA needed memory 2023-01-02 16:57:16 -07:00
Andrew Kelley
0fb78b15aa std.crypto.tls: use a Decoder abstraction
This commit introduces tls.Decoder and then uses it in tls.Client. The
purpose is to make it difficult to introduce vulnerabilities in the
parsing code. With this abstraction in place, bugs in the TLS
implementation will trip checks in the decoder, regardless of the actual
length of packets sent by the other party, so that we can have
confidence when using ReleaseFast builds.
2023-01-02 16:57:16 -07:00
Andrew Kelley
341e68ff8f std.crypto.tls.Client: remove debug prints 2023-01-02 16:57:16 -07:00
Andrew Kelley
79b41dbdbf std.crypto.tls: avoid heap allocation
The code we are borrowing from https://github.com/shiguredo/tls13-zig
requires an Allocator for doing RSA certificate verification. As a
stopgap measure, this commit uses a FixedBufferAllocator to avoid heap
allocation for these functions.

Thank you to @naoki9911 for providing this great resource which has been
extremely helpful for me when working on this standard library TLS
implementation. Until Zig has std.crypto.rsa officially, we will borrow
this implementation of RSA. 🙏
2023-01-02 16:57:16 -07:00
Andrew Kelley
2d090f61be add std.http.Headers
This is a streaming HTTP header parser. All it currently does is detect
the end of headers. This will be a non-allocating parser where one can
bring supply their own buffer if they want to handle custom headers.

This commit also improves std.http.Client to not return the HTTP headers
with the read functions.
2023-01-02 16:57:16 -07:00
Andrew Kelley
05fee3b22b std.crypto.tls.Client: fix eof logic
Before this, it incorrectly returned true when there was still cleartext
to be read.
2023-01-02 16:57:16 -07:00
Andrew Kelley
22e2aaa283 crypto.tls: support rsa_pss_rsae_sha256 and fixes
* fix eof logic
 * fix read logic
 * fix VecPut logic
 * add some debug prints to remove later
2023-01-02 16:57:16 -07:00
Andrew Kelley
e4a9b19a14 std.crypto.tls.Client: rework the read function
Here's what I landed on for the TLS client. It's 16896 bytes
(max_ciphertext_record_len is 16640). I believe this is the theoretical
minimum size, give or take a few bytes.

These constraints are satisfied:
 * a call to the readvAdvanced() function makes at most one call to the
   underlying readv function
 * iovecs are provided by the API, and used by the implementation for
   underlying readv() calls to the socket
 * the theoretical minimum number of memcpy() calls are issued in all
   circumstances
 * decryption is only performed once for any given TLS record
 * large read buffers are fully exploited

This is accomplished by using the partial read buffer to storing both
cleartext and ciphertext.
2023-01-02 16:57:16 -07:00
Andrew Kelley
7391df2be5 std.crypto: make proper use of undefined 2023-01-02 16:57:16 -07:00
Andrew Kelley
1d20ada366 std.crypto.tls.Client: refactor to reduce namespace bloat 2023-01-02 16:57:16 -07:00
Andrew Kelley
16af6286c8 std.crypto.tls.Client: support SignatureScheme.ecdsa_secp384r1_sha384 2023-01-02 16:57:16 -07:00
Andrew Kelley
940d368e7e std.crypto.tls.Client: fix the read function
The read function has been renamed to readAdvanced since it has slightly
different semantics than typical read functions, specifically regarding
the end-of-file. A higher level read function is implemented on top.

Now, API users may pass small buffers to the read function and
everything will work fine. This is done by re-decrypting the same
ciphertext record with each call to read() until the record is finished
being transmitted.

If the buffer supplied to read() is large enough, then any given
ciphertext record will only be decrypted once, since it decrypts
directly to the read() buffer and therefore does not need any memcpy. On
the other hand, if the buffer supplied to read() is small, then the
ciphertext is decrypted into a stack buffer, a subset is copied to the
read() buffer, and then the entire ciphertext record is saved for the
next call to read().
2023-01-02 16:57:16 -07:00
Andrew Kelley
21ab99174e std.crypto.tls.Client: use enums more 2023-01-02 16:57:16 -07:00
Andrew Kelley
477864dca5 std.crypto.tls.Client: fix truncation attack vulnerability 2023-01-02 16:57:16 -07:00
Andrew Kelley
ceb211e65f std.crypto.tls.Client: handle key_update message 2023-01-02 16:57:15 -07:00
Andrew Kelley
5bbedb63cf std.crypto.Certificate: support verifying secp384r1 pub keys 2023-01-02 16:57:15 -07:00
Andrew Kelley
b1cbfa0ec6 std.crypto.Certificate: remove subject_alt_name parsing
I believe this is provided as an extension, not in this location.
2023-01-02 16:57:15 -07:00
Andrew Kelley
b24f178029 std.crypto.tls.Certificate: fix parsing missing subsequent fields
Instead of seeing all the attributed types and values, the code was only
seeing the first one.
2023-01-02 16:57:15 -07:00
Andrew Kelley
a1f6a08dcb std.crypto.Certificate.Bundle: fix 32-bit build 2023-01-02 16:57:15 -07:00
Andrew Kelley
5b8b5f2505 add url parsing to the std lib 2023-01-02 16:57:15 -07:00
Andrew Kelley
c71c562486 remove std.crypto.der
Only a little bit of generalized logic for DER encoding is needed and so
it can live inside the Certificate namespace.

This commit removes the generic "parse object id" function which is no
longer used in favor of more specific, smaller sets of object ids used
with ComptimeStringMap.
2023-01-02 16:57:15 -07:00
Andrew Kelley
642a8b05c3 std.crypto.tls.Certificate: explicit error set for verify 2023-01-02 16:57:15 -07:00