1
0
mirror of https://github.com/apple/swift-nio-extras.git synced 2025-05-31 18:17:44 +08:00

104 Commits

Author SHA1 Message Date
David Evans
548e0d4893
Fix incorrect SOCKS client flushing behaviour ()
* Add buffering test

* Convert to marked buffer

* Soundness

* Re-add fastpath

* Fix
2021-06-17 11:01:54 +01:00
David Evans
93fc12bdb7
Implement SOCKSv5 server handshake ()
* SOCKS handshake handler implementation

* Soundness

* Remove placeholder text

* Sad path tests

* Soundness

* Docs

* Fix workflow tests

* Make handler removable

* Protect methods

* Prevent test crashes

* Cleanup public types

* Add test that writing after auth fails

* Add force handler removal tests

* Remove client and server state from public api

* Explicitly handle states

* Remove promises

* Fix test

* Add data to authentication complete

* Refactor to add authentication complete flag
2021-06-16 15:51:23 +01:00
David Evans
d861f305a1
Fix SOCKS client sending greeting and port/address endianness ()
* Guard channel is active

* Add delayed channel connection test

* Soundness

* Fix endianness

* Add delayed added test

* Soundness

* Apply suggestions from code review

Co-authored-by: George Barnett <gbarnett@apple.com>

Co-authored-by: George Barnett <gbarnett@apple.com>
2021-06-11 15:21:24 +01:00
David Evans
806a0ead2c
Implement a SOCKSv5 client ()
Implement a SOCKSv5 client according to RFC 1928. Server implementation will be added in another PR to keep sizes down.

https://datatracker.ietf.org/doc/html/rfc1928

A few meaningful changes:

Add all relevant types used across SOCKS clients and servers
Add a state machine used to manage a connection from a clients side
Add a channel handler that should be added at the very start of a channel pipeline
2021-06-10 12:12:30 +01:00
Johannes Weiss
cd07a89f5b
Stop publishing the executable products () 2021-06-08 13:18:28 +01:00
David Evans
b8e150416a
Add docker yaml () 2021-06-03 12:28:19 +01:00
Johannes Weiss
0d0af4edd8
docker setup for main nightlies () 2021-05-04 21:21:03 +01:00
Johannes Weiss
9666712c1d
docker: use 5.4 release instead of nightly () 2021-05-04 16:23:33 +01:00
George Barnett
fd8f9dfb11
Add SECURITY.md () 2021-03-09 11:10:43 +00:00
David Nadoba
de1c80ad1f
fix crash in LengthFieldBasedFrameDecoder for malicious length values ()
* fix crash in LengthFieldBasedFrameDecoder for malicious length values

Motivation:

LengthFieldBasedFrameDecoder will cause a fatal error if the length value does not fit into an `Int`.
This can happen if `lengthFieldLength` is set to `.eight` and we are on a 64 bit platform or if `lengthFieldLength` is set to `.four` and we are on a 32-bit platform.
If we then receive a length field value which is greater than `Int.max` the conversion from `UInt` to `Int` will cause a fatal error.
This could be abused to crash a server by only sending 4 or 8 bytes.

Modifications:

safely convert UInt64 & UInt32 to Int and throw an error if they can't be represented as an Int

Result:

- LengthFieldBasedFrameDecoder with lengthFieldLength set to `.eight` can no longer crash the server on a 64-bit platform
- LengthFieldBasedFrameDecoder with lengthFieldLength set to `.four` can no longer crash the server on a 32-bit platform

* use early exit instead of XCTSkipIf

* add support for `.eight` on 32-bit platforms

* limit frame length to `Int32.max`

* change test names

* throw correct error

* fix compilation for Swift 5.0 and add NIO prefix to error enum

* add test for maximum allowed length and one above the maximum allowed length

Signed-off-by: David Nadoba <dnadoba@gmail.com>

* run XCTest script

Signed-off-by: David Nadoba <dnadoba@gmail.com>

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
1.8.0
2021-02-18 12:37:41 +00:00
Johannes Weiss
1ce2e70c08
update code of conduct to version 1.4 () 2021-02-17 14:18:42 +00:00
David Nadoba
3d14afbe3f
add support for a 24 bit (3 byte) length field ()
Motivation:

The RSocket protocol uses a 24 bit length field

Modifications:

- add two new methods readInteger and writeInteger on ByteBuffer that support reading and writing integers of any size.
- add a new case (.three) to ByteLength

Result:

LengthFieldBasedFrameDecoder & LengthFieldPrepender do now support a 24 bit length field

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2021-02-17 09:04:24 +00:00
David Nadoba
f9a828d8b3
Fix link to LengthFieldPrepender.swift in readme () 2021-02-16 09:30:03 +00:00
Fabian Fett
caa96cd4de
Use eventLoop.assertInEventLoop() over assert(eventLoop.inEventLoop) ()
Co-authored-by: Cory Benfield <lukasa@apple.com>
2021-01-22 09:04:46 +00:00
Fabian Fett
e4bbe79d7e
Use welcoming language () 2021-01-22 08:49:59 +00:00
George Barnett
e8d4442cf7
Add watchOS deployment to PodSpec build script ()
Motivation:

We support watchOS 6+ with SwiftNIO Transport Services; as such we should
include watchOS as a deployment target for our CocoaPods.

Modifications:

- Add a watchOS deployment target to `build_podspecs.sh`

Result:

Users can deploy to watchOS 6+ with CocoaPods.
2020-10-21 15:27:58 +01:00
Cory Benfield
5258afd617
This repository now uses main. () 2020-09-24 16:28:47 +01:00
Cory Benfield
2233123ee7
Swift 5.3-RELEASE is here, let's use it () 2020-09-21 10:08:01 +01:00
George Barnett
e5b5d191a8
Forward 'channelInactive' in the RequestResponseHandler ()
Motivation:

As a rule of thumb we should always forward channel events to the next
handler.  added an implementation for `channelInactive` but forgot
to forward it.

Modifications:

- forward `channelInactive` in the `RequestResponseHandler`

Result:

Handlers after the `RequestResponseHandler` will recieve
`channelInactive`.
1.7.0
2020-08-24 13:11:47 +01:00
George Barnett
a8e195bdf8
Fail outstanding promises in channelInactive in the RequestResponseHandler ()
Motivation:

It's possible for channels to be closed without an error; and the
`RequestResponseHandler` should tolerate that by failing any promises
for which it does not have a response for.

Modifications:

- Add `ClosedBeforeReceivingResponseError`
- Fail outstanding promises with `ClosedBeforeReceivingResponseError` in
  `RequestResponseHandler.channelInactive`
- Add a test.

Result:

Outstanding request promises are failed when the channel becomes inactive.
2020-08-24 07:35:13 +01:00
Tanner
0b9eb87b22
Skip HTTPResponseCompressor logic if response is 204 (no content) ()
* Skip HTTPResponseCompressor logic if response is 204 (no content)

* update test manifests

* use mayHaveResponseBody
1.6.1
2020-08-14 17:10:00 +01:00
Karl
f700f5b355
Rename startsWithSameUnicodeScalars -> startsWithExactly, switch to comparing UTF8 bytes. () 2020-08-05 10:47:25 +01:00
Peter Adams
71c5df21bd
Get API breakage script working on Linux for swift-5.2+ ()
Motivation:

Current script always reports sdk errors on 5.2.

Modifications:

Only give -sdk where really necessary on 5.2 linux.

Result:

Script will work on 5.2 (although still reports silent errors)
2020-08-04 14:17:30 +01:00
Peter Adams
0f878f95f0
Performance testing for NIO PCAP logging ()
Motivation:

It's useful to know the overhead we could be adding by including
the PCAP handler.

Modifications:

Add a new executable based on the NIO performance testing executable.

Result:

There is a new executable which runs a short test of sending and receiving
data through the HTTP/1 handler using multiple eventloops and showing
three options.
1) Vanilla
2) With in memory PCAP never written to disk
3) With a disk based PCAP.
2020-08-03 12:13:24 +01:00
gkaindl
d525d3bbd1
Ensures gzip/deflate-compressed responses are properly finalized in all cases ()
Motivation:

Previously, when using the response compressor, doing a flush() right before finishing the
response data would cause the final compression chunk to be omitted. Some strict decompressors
(such as gzip or the zlib functionality exported in nodejs) would refuse to decompress the
incomplete response.

With this change, the generated compressed response is properly finalized.

Modifications:

In HTTPResponseCompressor.swift, a channel write is now also generated if no body data is
added, but a flush is required.

Result:

The response is now correct for this edge case, enabling gzip, nodejs, et al., to
decompress it without errors.
1.6.0
2020-07-28 17:33:35 +01:00
David Evans
6740bf98c2
Silence #file warnings ()
* Wrap in parentheses

* Revert previous changes
2020-07-24 16:54:32 +01:00
David Evans
1cb9e9e24b
Fix #file warnings ()
* Fix #file warnings
2020-07-24 14:54:39 +01:00
Peter Adams
fe17f53108
Capture packets leading upto a user triggered event. ()
Motivation:

Capturing all packets is expensive. Recording to a ring buffer and
then outputting on a triggering event allows this cost to be reduced.

Modifications:

Add a new handler - NIOPCAPRingCaptureHandler.
This derives from the existing NIOWritePCAPHandler and generates PCAP recordings.
A ring buffer contained in this handler stores the captured packets until RecordPreviousPackets
is received as a user message at which point they are flushed to the sink.

Result:

There is a new handler capable of outputting packet captured data only in the build up to
a known event.

Co-authored-by: Cory Benfield <lukasa@apple.com>
Co-authored-by: George Barnett <gbrntt@gmail.com>
2020-07-24 13:55:12 +01:00
Fabian Fett
b8fd38c1db
Support decompression of HTTP responses that do not contain a Content… ()
Fixes 

Co-authored-by: Trevör Anne Denise <trevor.annedenise@icloud.com>
2020-07-24 11:12:09 +01:00
Peter Adams
85f13dd3ba
Don't install jazzy on xenial ()
Motivation:

Ubuntu 16 ruby is too old to support latest cocoapods gem.

Modifications:

Don't install jazzy when on xenial

Result:

Docker image will now build - you need to use bionic images to build documentation.
2020-07-21 16:05:29 +01:00
Johannes Weiss
68af66e329
link swift-nio-extras in docs () 2020-06-17 16:45:20 +01:00
George Barnett
157853a29b
Update build_podspec.sh to not use exact dependency versions ()
Motivation:

The build_podspec.sh script generates a podspec which requires exact
versions of its dependencies. This very quickly turns into unresolvable
dependency graphs.

Modifications:

NIO version passed to script must be in the format MAJOR.MINOR
Podspec dependencies are now '>= MAJOR.MINOR', '< MAJOR+1'

Result:

Looser version requirements for podspecs
2020-06-17 09:32:40 +01:00
Johannes Weiss
7cd24c0efc
WritePCAPHandler: support logging more than 4GiB of data ()
Motivation:

Previously, WritePCAPHandler would crash if more than 4GiB of data were
either received or sent through the same instance of the
WritePCAPHandler because of a UInt32 overflow representing the TCP
sequence/ACK numbers.

Modifications:

Make TCP sequence/ACK numbers wrap around correctly.

Result:

- now you can send/receive up to 16 EiB of data :P.
- fixes rdar://61887658
1.5.1
2020-05-18 11:37:20 +01:00
Trevör
f21a87da13
Merge pull request from GHSA-xhhr-p2r9-jmm7
Motivation:
NIOHTTPRequestDecompressor and HTTPResponseDecompressor are both affected by an issue where the decompression limits defined by their DecompressionLimit property wasn't correctly checked when is was set with DecompressionLimit.size(...), allowing denial of service attacks.

Modifications:
- Update DecompressionLimit.size(...) to correctly check the size of the decompressed data.
- Update test cases to avoid future regressions regarding the size checks.

Result:
Prevents DoS attacks though maliciously crafted compressed data.
1.5.0
2020-05-02 09:29:33 +01:00
Adam Fowler
020e322a65
Added NIOHTTPRequestCompressor to compress requests ()
* Added NIOHTTPRequestCompressor to compress requests

Also moved common code from request and response compressor into separate NIOHTTPCompression enum.

* Updates after comments from @weissi

Also reinstated public enum HTTPResponseCompressor.CompressionError

* algorithms are now let not var

* Catch situation where head is flushed before anything else comes through

Content-encoding was not being set
Added additional tests for header values

* Added documentation around 5 bytes added to buffer size and add them

* Renaming NIOHTTPCompressionSetting to NIOCompression

Also
NIOHTTPCompressionSetting.CompressionAlgorithm is NIOCompression.Algorithm
NIOHTTPCompressionSetting.CompressionError is NIOCompression.Error
Algorithm now conforms to Equatable

* Forgot to run generate_linux_tests

* Fix typos
2020-04-30 17:28:49 +01:00
George Barnett
0f26138ae4
Let 2020 be an acceptable year in license headers ()
Motivation:

It's 2020; our license checking script should believe that that is an
acceptable year.

Modifications:

- Update scripts/sanity.sh

Result:

2020 is okay in license headers.
2020-04-30 16:29:36 +01:00
Johannes Weiss
5e234667a9
fix docker setup ()
Motivation:

We were missing the 5.2 & 5.3 docker compose files and also the syntax
wasn't flexible enough to pull in the new nightlies.

Modifications:

- always specify the full image name
- add 5.2 & 5.3

Result:

More CI & newer Swifts.
2020-04-17 18:40:39 +01:00
Shekhar Rajak
4a71e8ad6e
Get rid of do { ... } catch { ... } for expected errors ()
Co-authored-by: Cory Benfield <lukasa@apple.com>
2020-03-18 07:53:09 +00:00
tomer doron
64cb1e3bbb
add doc generation script ()
motivation: publish api docs for helper modules

changes
* add doc publishing script
* add "shell" docker-compose task to help run document publishing from ci

Co-authored-by: Johannes Weiss <johannesweiss@apple.com>
2020-03-03 10:33:33 +00:00
David Evans
8a48d4d228
Fix typo () 2020-03-02 16:07:23 +01:00
tomer doron
57c869c174
improve docker security ()
motivation: more secured ci setup

changes:
* enable :z selinux flag on bind mounts so we can enable selinux on ci
* drop potentially exploitable capabilities from docker-compose
2020-02-04 10:25:56 +00:00
Andy Trevorah
b4dbfacff4 Add syntax highlighting to installation steps () 1.4.0 2020-01-21 11:43:43 +00:00
Johannes Weiss
a98eabea3f
NIOWritePCAPHandler: make pcap issuing configurable () 2020-01-20 15:15:36 +00:00
Johannes Weiss
698f4f7396 WritePCAPHandler: write outbound data on flush not write () 2020-01-17 14:12:34 +00:00
George Barnett
b1d473d476 Update Code of Conduct project maintainer email address ()
Motivation:

The code-of-conduct email address is out-of-date.

Modifications:

Update code-of-conduct email address to swift-server-conduct@group.apple.com

Result:

- Code of conduct email address is up-to-date.
2019-12-02 12:19:33 +00:00
Johannes Weiss
53808818c2
don't use @tesable import NIO in test suite ()
Motivation:

The test suite for some reason imported NIO as @testable which is
verboten.

Modifications:

Don't do that.

Result:

Feeling better, compatible with the upcoming NIO 2.10.1.
1.3.2
2019-11-13 18:41:37 +00:00
Thomas Krajacic
6d452710b2 Clean up test command in docker config files () 2019-10-30 12:53:35 +01:00
Thomas Krajacic
fa4caf3c93 Add api checker script ()
* Add api checker script

* Fix comment to match the tag in the sample command
2019-10-30 12:27:39 +01:00
Thomas Krajacic
12ed4f0f43 Add --sanitize=thread to test invocation () 2019-10-30 10:15:09 +01:00
Johannes Weiss
4a5cd66d63 test runner: add -x to bash invocations ()
Motivation:

It's important to see the commands that are run in CI.

Modification:

Add -x to the bash invocations.

Result:

More clarity on what is run.
2019-10-26 02:52:39 -07:00