64 Commits

Author SHA1 Message Date
mus65 03e28219ba Drop netstandard2.1 target (#1647) 2025-05-29 20:33:02 +02:00
Rob Hague 98982a931e Update docs and remove a leftover DSA certificate algorithm (#1632)
* Update docs and remove a leftover DSA certificate algorithm

* more cleanup
2025-05-04 11:39:54 +02:00
mus65 86dc811458 Drop net6.0 target (#1580)
* Drop net6.0 target

* Update src/Renci.SshNet/Common/TaskToAsyncResult.cs

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* remove redundant #if

for some reason this made the compiler suddenly
realize that the plain text variables are unused.

* use TargetFrameworkIdentifier

this doesn't work in Directory.Build.props, moved it to Directory.Build.targets.

* fix null reference warnings in Benchmarks

seems like the warnings were (somehow) disabled here
before and were fixed by the previous TargetFrameworkIdentifier
change.

* fix unused plainTextOffset in AesGcmCipher.BclImpl

* CI retry

* more cosmetics

* more

* update README

* Revert "use TargetFrameworkIdentifier"

This reverts commit 076ede161d.

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Robert Hague <rh@johnstreetcapital.com>
2025-02-19 13:37:38 +01:00
Scott Xu 7e71bb4192 Add support for mlkem768x25519-sha256 key exchange method (#1563)
Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2025-01-11 15:46:22 +01:00
Scott Xu 14c652cb45 Use System.Security.Cryptography for TripleDesCipher (#1546)
* Use System.Security.Cryptography in DesCipher and TripleDesCipher; Fall back to use BouncyCastle if BCL doesn't support

* Drop DesCipher; Replace PKCS7Padding with BouncyCastle's implementation.

* Restore `CbcCipherMode`

* Restore AesCipherMode; Use BlockImpl instead of BouncyCastleImpl for 3DES-CFB on lower targets.

* Restore the xml doc comment
2024-12-27 13:37:02 +01:00
Scott Xu 3b4f2cfc1c [Private Key] Add support for PuTTY private key file format (V3 and V2) (#1543)
* [Private Key] Add support for PuTTY private key

* add negative test for mac

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-12-02 23:44:44 +01:00
mus65 70c12467dd Replace DiagnosticAbstration with Microsoft.Extensions.Logging.Abstractions (#1509)
* Replace DiagnosticAbstrations with Microsoft.Extensions.Logging.Abstractions

* add documentation

* reduce allocations by SessionId hex conversion

generate the hex string once instead of every log
call and optimize ToHex().

* Update docfx/logging.md

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* reduce log levels

* hook up testcontainers logging

* drop packet logs further down to trace

* add kex traces

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-12-02 23:15:48 +01:00
mus65 f65ca44997 Migrate from AppVeyor to GitHub Actions (#1539)
* Migrate from AppVeyor to GitHub Actions

* also run on pull_request

* small formatting improvements

* add on: workflow_dispatch

this is needed to re-run jobs manually from the web UI

* Publish NuGet package to GitHub Registry

only on develop branch.

* re-add empty appveyor.yml

so it doesn't fail CI until AppVeyor integration is disabled

* fix appveyor

* typo
2024-11-23 17:04:12 +01:00
Scott Xu 548ef23e12 Add support for OpenSSL PKCS#8 private key format (#1496)
* Add support for OpenSSL PKCS#8 private key format

* Update comments

* Convert public key to ssh format

* Convert existing keys instead of generate new keys; Use DataRow for testing

* Minimize the change

* Minimize the change

* Fix build
2024-09-21 16:07:59 +02:00
Scott Xu b067e75f18 Support more ciphers for OpenSSH private key decryption. (#1487) 2024-09-10 08:47:37 +02:00
Scott Xu ebb31bb16e AesGcmCipher uses BouncyCastle as a fallback if BCL does not support. (#1450)
* [AesGcmCipher] Use BouncyCastle as a fallback if BCL does not support.

* Switch back to collection initializer

* Remove conditional compilation

* Throw SshConnectionException with Reason MacError when authentication tag mismatch

* Separate BCL and BouncyCastle implementation

* Update AesGcmCipher.BclImpl.cs

* Naming enhancement

* Remove empty line

* Disable S1199. See https://github.com/sshnet/SSH.NET/pull/1371#discussion_r1704293356

* Set InnerException when MAC error. Remove Message check.

* Store KeyParameter as private field

* Use GcmCipher.ProcessAadBytes to avoid the copy of associated data

* Move nonce to constructor to avoid creating AeadParameters each packet

* Use const int for tag size

---------

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-08-19 14:13:10 +02:00
Scott Xu 486b69dc98 Add support for AEAD ChaCha20Poly1305 Cipher (#1416)
* Implements ChaCha20 cipher algorithm.

* Implements chacha20-poly1305@openssh.com

* Update Cipher.cs

* Update ChaCha20Poly1305Cipher.cs

* Note that the length of the concatenation of 'packet_length',
'padding_length', 'payload', and 'random padding' MUST be a multiple
of the cipher block size or 8, whichever is larger.
See https://www.rfc-editor.org/rfc/rfc4253#section-6

* Use Chaos.Nacl Poly1305Donna

* Fix build. Fix typo. Update README

* Update README.md

* Fix build

* Remove trailing whitespace

* Fix build

* Change to BouncyCastle

* Inherit from SymmetricCipher instead of StreamCipher since StreamCipher is deleted

* Resolve conflicts

* Move field to local variable

* Compute poly key stream once

* Update test/Renci.SshNet.IntegrationTests/CipherTests.cs

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Fix build; Add net48 integration test in CI

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-27 09:43:48 +02:00
Scott Xu c614f54f0a Zlib compression uses BouncyCastle as a fallback if BCL does not support. (#1453)
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-25 12:24:44 +02:00
Rob Hague 8ea108af1c Drop legacy algorithms part 1 (#1442)
This drops some of the algorithms long-considered legacy/insecure.

The idea is both to improve the theoretical security of the library by not offering
these algorithms, and to improve the practical security of the library by not having
hand-written, barely tested crypto code.

The overarching goal is for the library to have minimal exposure to crypto
implementation, relying firstly on the .NET base libraries, and secondly on
third-party providers, such as BouncyCastle.

This change covers deleting the cipher algorithms arcfour, blowfish, twofish, cast.
It covers deleting the MD5-based and truncated HMAC algorithms.

These were all disabled in OpenSSH server (sshd) in 2014[^1]:

> sshd(8): The default set of ciphers and MACs has been altered to
> remove unsafe algorithms. In particular, CBC ciphers and arcfour*
> are disabled by default.
>
> The full set of algorithms remains available if configured
> explicitly via the Ciphers and MACs sshd_config options.

and in the client in 2016[^2]:

> This release disables a number of legacy cryptographic algorithms
> by default in ssh:
>
>  * Several ciphers blowfish-cbc, cast128-cbc, all arcfour variants
>    and the rijndael-cbc aliases for AES.
>
>  * MD5-based and truncated HMAC algorithms.
>
> These algorithms are already disabled by default in sshd.

This change also drops PKCS5Padding, which is a line-for-line copy of PKCS7Padding,
and StreamCipher, which is now unused (and useless anyway).

[^1]: https://www.openssh.com/txt/release-6.7
[^2]: https://www.openssh.com/txt/release-7.2

Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2024-07-17 08:20:10 +02:00
Rob Hague 8e8829ef96 Docs updates (#1432)
* Use /// <value> instead of /// <returns> for properties

* misc doc updates in SshCommand

* Update README
2024-07-04 10:31:07 +02:00
Rob Hague 1de33c469e Documentation updates (#1395)
- Update README to point to https://sshnet.github.io/SSH.NET rather than the CHM file
- Add a CONTRIBUTING.md with some how-tos

For https://sshnet.github.io/SSH.NET:

- Use the repo README as the landing page to keep them in sync
- Combine the API-per-TFM pages to just one "API" page
- Add a couple more examples
- Add a GitHub link in the header.
2024-05-10 11:38:47 +02:00
Scott Xu 3dc3fc8b1c Add support for AEAD AES 128/256 GCM Ciphers (.NET 6.0 onward only) (#1369)
* Init AeadCipher

* Move AeadCipher to parent folder. Move EncryptBlock/DecryptBlock from SymmetricCipher to BlockCipher

* simplify parameter name

* Implement AesGcmCipher

* Update README

* Remove protected IV from AeadCipher; Set offset to outbound sequence just like other ciphers

* Rename associatedData to packetLengthField

* Use Span<byte> to avoid unnecessary allocations

* Use `Span` to improve performance when `IncrementCounter()`

* Add `IsAead` property to `CipherInfo`. Include packet length field and tag field in offset and length when call AesGcm's `Decrypt(...)` method. Do not determine HMAC if cipher is AesGcm during kex.

* Fix build

* Fix UT

* Check `AesGcm.IsSupported` before add to the `Encryptions` collection.
Guard AES-GCM with `NET6_0_OR_GREATER`.
Insert AES-GCM ciphers right after AES-CTR ciphers but before AES-CBC ciphers, which is similar with OpenSSH:
```
debug2: ciphers ctos: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
debug2: ciphers stoc: chacha20-poly1305@openssh.com,aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.com,aes256-gcm@openssh.com
```
Although Dictionary's order is not defined, from observation, it is in the same order with add. Anyway that would be another topic.

* Suppress CA1859 "Use concrete types when possible for improved performance" for `ConnectionInfo.Encryptions`.
Test `Aes128Gcm` and `Aes256Gcm` only when `NET6_0_OR_GREATER`

* Update xml doc comments. Do not treat AesGcmCipher separately in Session.cs

* Fix build

* Fix build

* Update the comment as ChaCha20Poly1305 uses a separated key to encypt the packet length and the size it 4.

* Update src/Renci.SshNet/Security/Cryptography/Cipher.cs

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Make `AesGcmCipher` internal.
Assert offset when decrypt.

* Fix nullable error in build

* typos

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-04-18 20:06:19 +02:00
Scott Xu b553f81f8a Add support for Zlib compression (.NET 6.0 onward only) (#1326)
* Integrate `ZLibStream` from .NET 6.0+ with SSH.NET.

* OpenSSH server does not support zlib (pre-auth); OpenSSH client still supports zlib (pre-auth)

* Correct compression algorithm name; Update README.md

* Integrate `ZLibStream` from .NET 6.0+ with SSH.NET.

* OpenSSH server does not support zlib (pre-auth); OpenSSH client still supports zlib (pre-auth)

* Correct compression algorithm name; Update README.md

* Test the compression by upload/download file

* Refactor compression.

* Move delayed compression logic to base class.

* seal Zlib

* update unit test

* update unit test to see if it can trigger integration test

* Flush zlibStream

* Fix integration test

* update test

* Update ConnectionInfo.cs

Co-authored-by: Rob Hague <rob.hague00@gmail.com>

* Update README.md

---------

Co-authored-by: Rob Hague <rob.hague00@gmail.com>
2024-04-17 21:39:27 +02:00
Jean-Sebastien Carle dd36d5b98a Added support for GitHub pages using docfx (#1358)
* Added support for GitHub pages using docfx

* Fixed StyleCop warning.

* Fixed other StyleCop warnings.
2024-04-17 21:32:54 +02:00
mus65 c044fd40c6 fix link to tests in README (#1338) 2024-02-24 12:45:49 +01:00
Wojciech Nagórski 5b9c669f1b Update README.md 2024-02-21 20:29:26 +01:00
Scott Xu 59a0f9030a Drop RIPEMD160 (#1324) 2024-02-18 05:20:57 +01:00
Scott Xu 7cfe62b9f1 Support ETM (Encrypt-then-MAC) variants for HMAC (#1316)
* Support ETM (Encrypt-then-MAC) variants for HMAC

* Support ETM (Encrypt-then-MAC) variants for HMAC

* Remove `ETM` property from `HashInfo`

* Add support for HmacMd5Etm, HmacMd5_96_Etm, HmacSha1Etm and HmacSha1_96_Etm
Explicitly specify etm even if false

* Add Encrypt-then-MAC variants to README.md

* Add back empty span to prevent auto link

* Store ETM in `HashInfo`;
Change `HMAC Create[...]Hash()` to `HashAlgorithm Create[...]Hash(out bool isEncryptThenMAC)`
2024-02-16 13:24:54 +01:00
Rob Hague fdd113022b Enable DSA tests (#1181)
Co-authored-by: Wojciech Nagórski <wojtpl2@gmail.com>
2023-09-25 22:22:15 +02:00
Dāvis Mošenkovs 43329eef28 Support SHA256 fingerprints for host key validation (#1098)
* Add tests for HostKeyEventArgs

* Add SHA256 fingerprint support
2023-09-17 22:44:26 +02:00
Wojciech Nagórski 7cd0487785 ListDirectoryAsync return IAsyncEnumerable (#1126)
* ListDirectoryAsync return IAsyncEnumerable

* Fix documentation

* Update README.md

* Fix

* Add Sftp ListDirectoryAsync test

* Revert

* Integration tests for ListDirectoryAsync with IAsyncEnumerable
2023-08-30 10:22:10 +02:00
Gert Driesen 3ecbd1071d Fix some (lots of) issues reported by analyzers. (#1125)
Fix some (lots of) issues reported by analyzers.
2023-05-24 20:37:46 +02:00
Wojciech Nagórski cf8510013d Removing old target frameworks (#1109)
Remove support for legacy / deprecated target frameworks while adding support for .NET 6.0 (and higher).
The supported target frameworks are now:
* .NETFramework 4.6.2 (and higher)
* .NET Standard 2.0
* .NET 6.0 (and higher)
2023-05-06 22:32:10 +02:00
Stefan Rinkes f072c5f1a1 OPENSSH KeyReader for more keys (#614)
* OPENSSH KeyReader for more keys

Add support to parse OpenSSH Keys with ECDSA 256/384/521 and RSA.

https://github.com/openssh/openssh-portable/blob/master/PROTOCOL.key

Change-Id: Iaa9cce0f2522e5fee377a82cb252f81f0b7cc563

* Fix ED25519Key KeyLength

* Fix ED25519 PubKey-auth

LeadingZeros of BigInteger-Conversion have to be removed
before sending the Key.
2021-04-18 18:49:01 +02:00
Gert Driesen d62594c03f Update README.md 2020-12-31 14:46:08 +01:00
Gert Driesen 9c25cf65ca Update README.md 2020-12-31 14:45:50 +01:00
Gert Driesen b2c36b5e2c Update README.md 2020-12-31 14:45:16 +01:00
Gert Driesen c10277f4d7 Fix typo. 2020-06-07 15:45:45 +02:00
Gert Driesen bde751eb48 Add sponsor info. 2020-06-07 10:26:32 +02:00
drieseng ab827c2eb1 Document support for .NET Standard 2.0. 2020-05-03 20:15:32 +02:00
Gert Driesen 516d982add Fix typo 2020-04-26 10:35:04 +02:00
Mark Moore f262b4aa7b Added documentation section to README (#656) 2020-04-19 14:28:49 +02:00
drieseng 34df3dd725 Support diffie-hellman-group14-sha256 and diffie-hellman-group16-sha512 key exchange methods. 2020-03-15 19:43:45 +01:00
Gert Driesen bc59db5ff4 Avoid autolink 2020-03-06 19:57:26 +01:00
drieseng 982ef10ae7 Update readme for the new key exchange methods, host key algorithms and private key formats. 2020-01-11 17:05:32 +01:00
Gert Driesen 19167e7c80 Fix links 2017-10-09 19:33:00 +02:00
Gert Driesen 5d664bd667 Include NuGet download count 2017-10-09 19:30:25 +02:00
Gert Driesen 5852a96d02 Fix typo. 2017-09-09 13:44:15 +02:00
Gert Driesen 4e9ceadfd3 Add example for host key validation. 2017-09-09 13:35:53 +02:00
Gert Driesen 46966d37cb Precise that we only support SSH-2. 2017-07-21 14:23:30 +02:00
Gert Driesen bdec2d22f9 Update markdown after recent Github changes 2017-03-20 22:16:35 +01:00
Gert Driesen 6cb91f600d Update README.md 2017-03-06 21:52:53 +01:00
Gert Driesen d95276d861 Document the fact that we now use VS 2017 to build the .NET Standard 1.3 flavor of SSH.NET. 2017-01-04 18:53:45 +01:00
Gert Driesen 7f8f3121f0 Added netstandard1.3 TFM. 2016-08-02 10:41:42 +02:00
drieseng 68d9e4fc90 Moved into on conditional compilation symbols to wiki. 2016-07-27 14:16:26 +02:00