* All of System.Security.Cryptography.Primitives has been moved
* AsymmericKeyExchangeFormatter moved from S.S.C.Algorithms
* This just starts the process to keep the infrastructure pieces separate from code layout pieces.
With the newest udpate of slngen, the order of elements (configuration, folders, etc.) is in sync with how Visual Studio arranges them.
Also the order is now deterministic.
Based on that, updating all solution files to have the correct ordering of elements. This change also unblocks adding CI protection for
making sure that solution files are up-to-date in regards to their dependencies as slngen is now generating the files deterministically.
In .NET Framework, .NET 5, and .NET Core the block scaling logic was used for
`new byte[inputCount / inputBlockSize * outputBlockSize]` (or swap in/out).
That expression throws an OverflowException when the computed size
overflows.
Earlier in .NET 6 we changed to use ArrayPool.Rent. When ArrayPool.Rent gets a
negative (overflowed) number it instead throws an ArgumentException.
This change restores the OverflowException, so that we're not leaking an
ArgumentException back to the caller. (While the caller can control the
behavior with the arguments they pass to CryptoStream.Read/Write, the
description and paramName don't map in an obvious manner)
Making the scenario work has virtue, but requires a larger test investment than
we can make at this time.
* Fix one-shot CBC documentation.
The CBC one-shot documentation made a few references to the ECB
one shots. This removes them and uses consistent language that is
used on the other one-shot methods.
* Change ECB to be consistent
This change adds SymmetricAlgorithm.EncryptEcb, SymmetricAlgorithm.DecryptEcb, their
respective Try- and -Core methods, derived type implementations thereof, and tests.
There's an open question of should these members on on the base class throw or
"succeed if the Mode property is in agreement with the algorithm". While the latter is "nicer",
just throwing is easier to reason about, and that's the current behavior.
Co-authored-by: Jeremy Barton <[email protected]>
Stream.Read{Async} is supposed to return once at least a byte of data is available, and in particular, if there's any data already available, it shouldn't block. But Read{Async} on DeflateStream (and thus also GZipStream and ZLibStream), BrotliStream, and CryptoStream won't return until either it hits the end of the stream or the caller's buffer is filled. This makes it behave very unexpectedly when used in a context where the app is using a large read buffer but expects to be able to process data as it's available, e.g. in networked streaming scenarios where messages are being sent as part of bidirectional communication.
This fixes that by stopping looping once any data is consumed. Just doing that, though, caused problems for zero-byte reads. Zero-byte reads are typically used by code that's trying to delay-allocate a buffer for the read data until data will be available to read. At present, however, zero-byte reads return immediately regardless of whether data is available to be consumed. I've changed the flow to make it so that zero-byte reads don't return until there's at least some data available as input to the inflater/transform (this, though, doesn't 100% guarantee the inflater/transform will be able to produce output data).
Note that both of these changes have the potential to introduce breaks into an app that erroneously depended on these implementation details:
- If an app passing in a buffer of size N to Read{Async} depended on that call always producing the requested number of bytes (rather than what the Stream contract defines), they might experience behavioral changes.
- If an app passing in a zero-byte buffer expected it to return immediately, it might instead end up waiting until data was actually available.
* add ZeroByteRead_PerformsZeroByteReadOnUnderlyingStreamWhenDataNeeded to stream conformance tests
* remove dead code
* change SslStream zero byte read implementation to issue zero-byte read on underlying stream when appropriate
* ensure buffer is always freed when not needed, and assert this
* create StreamConformanceTests assembly and reference from appropriate test projects
Co-authored-by: Geoffrey Kizer <[email protected]>
* Update dependencies from https://github.com/mono/linker build 20210201.1
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.21079.1 -> To Version 6.0.0-alpha.1.21101.1
* Update dependencies from https://github.com/mono/linker build 20210201.2
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.21079.1 -> To Version 6.0.0-alpha.1.21101.2
* Update dependencies from https://github.com/mono/linker build 20210203.1
Microsoft.NET.ILLink.Tasks
From Version 6.0.0-alpha.1.21079.1 -> To Version 6.0.0-alpha.1.21103.1
* Add warnings to baseline
Co-authored-by: dotnet-maestro[bot] <dotnet-maestro[bot]@users.noreply.github.com>
Co-authored-by: Mateo Torres Ruiz <[email protected]>
Co-authored-by: Marek Safar <[email protected]>
* Use [NotNullWhen(true)] in more places
Did a quick search/audit for methods that returned bool and took nullable object as the first input, and added [NotNullWhen(true)] where it was obviously correct.
* Address PR feedback
* add MultiArrayBuffer and use in StreamBuffer and Http2Stream
* rework EnsureAvailableSpace and add tests for it
* make dispose handling more robust, plus minor tweaks
* add AssertExtensions.SequenceEqual for providing more useful information about sequence differences, and use in StreamConformanceTests
* tweaks
* replace _blockCount with _allocatedEnd
* use uint instead of int internally to assure bitop optimizations
* fix _allocatedEnd calculation
* address PR feedback
* more PR feedback and some minor fixes/improvements
* small test improvements
* Apply suggestions from code review
Co-authored-by: Günther Foidl <[email protected]>
* address review feedback
Co-authored-by: Geoffrey Kizer <[email protected]>
Co-authored-by: Günther Foidl <[email protected]>
We currently have several hundred uses of `Array.Empty<Type>()` and several hundred uses of `Type.EmptyTypes`. This just changes the repo to use the latter consistently.
* Add Stream argument validation helpers and use throughout dotnet/runtime
* Delete unnecessary code in Stream
Stream.Null was using BlockingBegin/EndRead/Write, but the operations are nops (they don't even do argument validation), so the functionality was unnecessary complication. We can just use TaskToApm instead, with already completed tasks, and then also delete the SynchronousAsyncResult that was used by these operations.
Also, the Begin/EndRead/Write methods were checking CanRead/Write and throwing if they return false, but this is a private sealed type with CanRead/Write hardcoded to return true! Delete.
Finally added consistency across Stream.Null to checking for cancellation.
* Clean up some style on Stream
Also consolidate a few resources and use a few existing ThrowHelpers where appropriate.
* Fix a few issues, and remove duplicative tests missed in conformance tests rollout
* Address PR feedback
* Fix invalid assert in StreamBuffer
This can be hit by calling code and thus shouldn't be an assert. As an assert it prevents testing.
* Add ConnectedStreams.CreateUnidirectional
* Add initial set of Stream conformance tests
These primarily focus on "connected streams", ones that can be arranged to communicate with each other in a producer/consumer pattern or as a bidirectional communication mechanism, e.g. NetworkStream, PipeStream, SslStream wrapped around a NetworkStream, FileStream created around pipes, etc. Later we can add more tests focused on standalone streams, e.g. FileStream created for an on-disk file, MemoryStream, etc.
* Add ConnectedStreams tests
These are currently helpers used by many other tests. At some point they could become public API as well.
* Fix NetworkStream argument names
Technically a breaking change, but the current divergence from the base Stream class is a bug, and bringing them into sync means argument exceptions that emerge from the derived type make sense when used via the base type, as well as then being able to use shared validation logic across all streams (subsequent to these changes).
* Add stream conformance tests for NetworkStream
* Add stream conformance tests for QuicStream
* Fix several CryptoStream behaviors
1. Flushing a stream that wraps another stream for writing should always flush that underlying stream, even if no additional data was written as part of the flush.
2. Argument validation should validate buffers are not null rather than null ref'ing on a null buffer.
3. Checks for the CryptoStream mode should come after argument validation.
* Add stream conformance tests for CryptoStream
* Fix FileStream argument names
Technically a breaking change, but the current divergence from the base Stream class is a bug, and bringing them into sync means argument exceptions that emerge from the derived type make sense when used via the base type, as well as then being able to use shared validation logic across all streams (subsequent to these changes).
* Fix BufferedStream argument names
Technically a breaking change, but the current divergence from the base Stream class is a bug, and bringing them into sync means argument exceptions that emerge from the derived type make sense when used via the base type, as well as then being able to use shared validation logic across all streams (subsequent to these changes).
* Add stream conformance tests for FileStream
Specifically when used in a connected fashion, wrapped around an anonymous or named pipe.
* Add stream conformance tests for BufferedStream
Specifically when used in a connected fashion, wrapped around some other connected stream.
* Add stream conformance tests for SslStream and NegotiateStream
* Fix PipeStream.Flush to not fail on readable streams
Consumers may expect Stream.Flush to be a nop if the stream is readable only, but PipeStream.Flush is throwing in that case. Stop doing that.
* Add stream conformance tests for PipeStream
* Fix several BrotliStream behaviors
1. When passed a null buffer, it's throwing an exception with the argument name "array", even though the parameter's name is "buffer".
2. Even if there's no data written as part of the Flush{Async} call on a writeable stream, it should be calling flush on the wrapped stream.
* Fix several DeflateStream (and friends) issues
1. DeflateStream.Flush{Async} when writing needs to always flush the underlying stream, even if there's no data written as part of the flush call itself.
2. Several byte[] array arguments should be byte[] buffer. Technically a breaking change, but the current divergence from the base Stream class is a bug, and bringing them into sync means argument exceptions that emerge from the derived type make sense when used via the base type, as well as then being able to use shared validation logic across all streams (subsequent to these changes).
3. DeflateStream.EndRead/Write needs to do additional state validation.
4. Not a bug, but simplify ReadAsync to match the sync Read implementation flow.
* Add stream conformance tests for Deflate/ZLib/GZip/BrotliStream
* Fix PipeReader/WriterStream argument validation
* Add stream conformance tests for PipeReader/WriterStream
* Remove erroneous asserts from Stream.ReadWriteTask
* Address PR feedback
* Fix a few tests in CI
* [browser][crypto] Remove restraining not supported attribute
- The modules included within the System.Security.Cryptography.Primitives module should still be available for use outside of browser os.
* Address review comments. Remove `<IncludePlatformAttributes>` attribute as well
* Mark System.Security.Cryptography.OpenSsl as unsupported on browser
* Mark other System.Security.Cryptography APIs as unsupported on browser
* Mark System.Data.Odbc.* as unsupported on browser
* Mark System.DirectoryServices.Protocols APIs as unsupported on browser
* Mark System.Drawing.Common APIs as unsupported on browser
* Mark System.IO.Ports as unsupported on browser
This change brings the Cipher Feedback (CFB) mode to .NET 5 with the same behaviors as .NET Framework around the non-standard application of PKCS#7 padding based on the feedback block size and decryption the data be algorithm blocksize-aligned.
* AES: CFB8 and CFB128
* TripleDES: CFB8 and CFB64
* DES: CFB8
* RC2: Not supported
Additionally, due to a lack of support in CNG, CFB is not supported on Windows 7.
- Remove depprojs which currently binplace external references into the RefPath folders in favor of PackageReference and PackageDownload items.
- Build all configurations by default when building an individual project (either on the CLI or inside VS) same as with the official SDK. This enables .NETFramework Test Explorer support.
- Centrally define libraries that compose the shared framework instead of in each Directory.Build.props file to be able to build the targeting pack first and consume it in the OOB libraries.
- Use ProjectReferences to reference OOB projects. Compile against the reference assembly but use the implementation assembly app-local during runtime.
- Remove OOBs from the testhost and remove the testhost folder for .NETFramework as it isn't required anymore.
- Only binplace for $(NetCoreAppCurrent) to compose a) the targeting pack, b) the runtime pack, c) the testhost, d) a full closure for the shims.
- Use Targeting Packs for OOB projects (with their implicit assembly references) but still explicitly define granular references for .NETCoreApp configurations (DisableImplicitAssemblyReferences switch). Use the implicit targeting pack references in some Microsoft.Extensions.* cases.
- Remove placeholder configurations as they aren't needed anymore with explicit P2Ps vs Targeting Pack references.
- Remove implicit assembly references (ie for .NETFramework, mscorlib)
- Remove AssemblySearchPath hacks that were introduced with b7c4cb7 as the targeting pack is now used by default.
- Reduce unnecessary .NETFramework configurations that were added to run tests in favor of the already existing ref&src configurations.
- Stop hardcoding the paths for wasm assemblies and use the returned TargetPath of the ProjectReferences.
- Addressed formatting (ItemGroups, References at the bottom of the project file, ordering of references, use LibrariesProjectRoot instead of a relative path, unnecessary AssemblyName and RootNamespace properties which are identical to the project name, ordering of tfms)
- Revert "fix clean (#33758)"
We sometimes used `... is not supported on Browser.` and elsewhere `... is not supported on this platform.`
Standardize on the latter one as it can potentially be reused for other targets.
* Mark new obsoletions for .NET 5; update existing obsoletions
* Exclude DirectoryServicesPermission/DirectoryServicesPermissionAttribute from obsoletions for now
* No need to restore SYSLIB0003 at end of Forwards files
* Use a common Obsoletions.cs file for all SYSLIB obsoletions
* Resurrect CER code behind #ifdef in EventSource
* Mark GlobalAssemblyCache overrides as Obsolete
* Suppress Thread.Abort() error in ImageAnimator.Unix.cs
* Unconditionally mark RoAssembly.GlobalAssemblyCache as obsolete
* Rename MSLIB0001 to SYSLIB0001 in ref assembly
* Suppress obsoletion warnings in tests
* Adopt a uniform #ifdef for NET50_OBSOLETIONS
* Fix BinaryFormatter obsoletion message after the rebase
* Use SYSTEM_PRIVATE_CORELIB constant instead of NETCOREAPP
* Remove the code comment on the ifdef
* Apply feedback related to CER obsoletions
* Apply feedback related to CAS
* Update ref assembly to reflect SecurityManager obsoletion
* Fix regression in System.IO.Pipes.NamedPipeServerStream.Windows.RunAsClient
Since the entire set of System.Security.Cryptography.* tests has been disabled on WASM recently in https://github.com/dotnet/runtime/pull/37723, we need to let everyone know that those areas are not quite supported on WASM at the moment. In that case System.Security.Cryptography classes could throw PlatformNotSupportedException until some solution comes (https://github.com/dotnet/runtime/issues/37669)
This has three primary benefits:
1. In some cases, in particular for static fields where other static fields have non-default initialization, the C# compiler can't elide the default initialization, resulting in more IL.
2. It highlights places where the field is otherwise unused and can be deleted, but where the presence of the initialization was silencing the C# compiler's warnings about the unused field.
3. It increases consistency and decreases maintenance / code size / etc.
* Added generic overloads for MethodInfo.CreateDelegate<>()
* Added full support of CreateDelegate<T> and the necessary tests.
* Refactored to apply the new CreateDelegate overloads as necessary throughout runtime.
* Reverted Linq.Expressions changes and fully qualified Delegate to System.Delegate