1
1
Граф коммитов

4796 Коммитов

Автор SHA1 Сообщение Дата
Andreas Schneider
123db84b2c pki_crypto: Fix a possible null pointer dereference
CID 1401438
CID 1401437

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-28 09:18:23 +02:00
Anderson Toshiyuki Sasaki
30997a098c Update ChangeLog
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-22 15:36:29 +02:00
raminfp
9b1772ecbd sftp: Remove the break statements
They aren't needed and perhaps some compilers will issue "Unreachable
code" warnings.

Signed-off-by: Ramin Farajpour Cami <ramin.blackhat@gmail.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-22 15:35:29 +02:00
Anderson Toshiyuki Sasaki
9fb7fb3fac socket: Use calloc in ssh_socket_new()
This makes sure the content will be zero after successful allocation.

Resolves T134

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-22 15:32:41 +02:00
Anderson Toshiyuki Sasaki
59ba3f1896 dh-gex: Fix memory leak in DH GEX with OpenSSL
When using OpenSSL, the bignums generated during group exchange are
duplicated and don't transfer the memory management responsibility to
the back-end.  The original generated bignums can be freed.

The leak was detectable by running:

$ valgrind --leak-check=full ./tests/pkd/pkd_hello -i1 \
    -t torture_pkd_openssh_rsa_rsa_diffie_hellman_group_exchange_sha256

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-22 15:31:51 +02:00
Anderson Toshiyuki Sasaki
38f9802eec config: Add support for PubkeyAcceptedKeyTypes
The added option is an alias for the previously existing option
PubkeyAcceptedTypes.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:32:25 +02:00
Jakub Jelen
eae971c002 tests: Update knownhost tests with reproducer from T110
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:26:30 +02:00
Jakub Jelen
962bdf806c knownhosts: Handle wildcard ports matches against standard one
Fixes T110

Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:26:27 +02:00
Jakub Jelen
1e22a089eb Reformat ssh_hostport()
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:26:24 +02:00
Jakub Jelen
8152c6aba4 knownhosts: Ignore OpenSSH markers related to certificates
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:26:18 +02:00
Anderson Toshiyuki Sasaki
7cc159d720 cmake,options: Allow to set global client config file
This allows the global client (ssh_session) configuration file path to
be set in configuration time by defining GLOBAL_CLIENT_CONFIG when
calling cmake.  If it is not defined, the default path is set as
"/etc/ssh/ssh_config".

usage example:

$ cmake -DGLOBAL_CLIENT_CONFIG=/etc/my/custom/path ..

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-14 17:20:39 +02:00
Anderson Toshiyuki Sasaki
248e5acd5c pki: Fail to sign when using wrong hash algorithm
Do not allow using SSH_DIGEST_AUTO for any algorithm other than
ed25519.

Do not allow using incompatible hash algorithms when signing or
verifying signatures.

Added negative tests for all combinations of signature and hash
algorithms.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
550a1a7667 pki: Remove unused code
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
db51fa1bc1 pki: Use pki_sign_data() and pki_verify_data_signature()
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
d923dc39c1 tests: Use public key to verify signatures
Previously in the tests the private key structure would be used for
signature verification.  Use the corresponding public key instead.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
88a8b1f57c pki_gcrypt: Added pki_sign_data() and pki_verify_data_signature()
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
7bc53f3957 pki_mbedcrypto: Added pki_sign_data() and pki_verify_data_signature()
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
fd9446553b pki_crypto: Added pki_sign_data() and pki_verify_data_signature()
pki_sign_data() uses the given private key and hash algorithm to sign
the data using the OpenSSL EVP interface.  The corresponding function
pki_verify_data_signature() receives the signature, the signed data, and
the public key to verify the signature.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
33af736555 pki_crypto: Store ECDSA raw signature in ssh_signature
Store the raw signature instead of the internal backend structure.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
132c7bee64 pki_crypto: Store DSA raw signature in ssh_signature
Store the raw signature instead of the internal backend structure.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
ba67555764 pki_crypto: Store raw RSA signature in ssh_signature
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
0ea9e39e81 pki: Add a common place to store raw signatures
This is a preparation to store the raw signature for all algorithms in
the same place in ssh_signature.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
e775182c2e pki: Make DSA signature to use SHA1 instead of AUTO
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
76f9808eb2 auth, pki: Calculate hash internally when signing/verifying
This makes pki_do_sign() and pki_signature_verify() to receive the
original input instead of the pre-calculated hash.  The hash is then
calculated internally.

The hash to be used inside the signature is decided earlier, when all
the information about the signature to be generated/verified is
available.

Simplify ssh_pki_do_sign() and ssh_srv_pki_do_sign_sessionid().

The tests were modified to use pki_do_sign() instead of
pki_do_sign_hash().

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
58b3b2696c pki_crypto: Change SSH_KEYTYPE_ED25519 position in switches
The goal here is to avoid errors due to fall through when
HAVE_OPENSSL_ECC is not defined.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
20c03c289e pki_crypto: Refactor pki_signature_to_blob()
Refactor pki_signature_to_blob() without behaviour changes.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
c27d41df75 pki_crypto: Fixed typos transfered -> transferred
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
99053a6c33 pki_cryto: Refactor pki_signature_from_blob()
Refactor the code without behaviour changes.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
c3b8f9c0ec pki_crypto: Make pki_signature_from_rsa_blob() to return int
The goal of this change is to make pki_signature_from_*_blob()
consistent.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
01e98a6df7 pki: Remove duplicate and unused code
Remove duplicate code previously used only in server side to generate
signatures.  Currently the code used to generate the signature is the
same for both client and server.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
dbf3f962a4 pki: Refactor ssh_srv_pki_do_sign_sessionid()
Refactor ssh_srv_pki_do_sign_sessionid() without behaviour changes.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
3917a5c916 pki: Refactor ssh_pki_do_sign()
Added ECDSA key types to ssh_key_type_to_hash(). Refactor
ssh_pki_do_sign() without behaviour changes.

Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
5f7a3c5c66 wrapper: Make sha{1, 256, 384, 512}() input const
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Anderson Toshiyuki Sasaki
848f59c37e wrapper.h: Add SSH_DIGEST_SHA384 to ssh_digest_e enum
Signed-off-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-13 16:37:51 +02:00
Jon Simons
0849e44220 dh: fix libcrypto leak via ssh_dh_keypair_set_keys
Upon SSH_OK, callers of `ssh_dh_keypair_set_keys` expect for ownership
of the `priv` and `pub` values to be transferred away and eventually
later managed by way of the `struct dh_ctx` at hand.

The mbedTLS and gcrypt builds transfer ownership of these values in
that way, but the libcrypto `ssh_dh_keypair_set_keys` is copying the
given values with `BN_dup`.  This causes a memory leak that can be
seen with pkd and valgrind:

    valgrind --leak-check=full \
      ./pkd_hello -i1 -t torture_pkd_openssh_dsa_rsa_diffie_hellman_group16_sha512

Fix the leak by replacing the `BN_dup` with direct assignment.
Now the bignums will eventually be freed via `ssh_dh_cleanup`.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-09 17:37:33 +02:00
Jon Simons
ee42e3badb dh: fix libcrypto dh_ctx leak in ssh_dh_cleanup
Ensure to free the `dh_ctx` member in `ssh_dh_cleanup` to match
the allocation in `ssh_dh_init_common`.

The before-and-after of this change can be observed with the pkd
tests and valgrind:

    valgrind --leak-check=full \
      ./pkd_hello -i1 -t torture_pkd_openssh_dsa_rsa_diffie_hellman_group16_sha512

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-05-09 17:37:33 +02:00
Andreas Schneider
ee82bab801 auth: Avoid memory on error in ssh_userauth_agent_publickey()
CID 1401095

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2019-05-06 11:41:02 +02:00
Andreas Schneider
db8aca69a7 knownhosts: Avoid possible null pointer dereference
CID 1401096

Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
Reviewed-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Anderson Toshiyuki Sasaki <ansasaki@redhat.com>
2019-05-06 11:40:27 +02:00
Andreas Schneider
3fccb24464 tests:pkd: Fix size comparison (payload.len is size_t)
Signed-off-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 16:52:23 +02:00
Jon Simons
19cb6f1b6c server: fix sending SSH_MSG_EXT_INFO upon rekey
Fix libssh server sending SSH_MSG_EXT_INFO messages upon rekey: clients
do not expect that message during rekey, and OpenSSH in particular will
log error messages along the lines of:

    "kex protocol error: type 7 seq 15"

when the message is received during a rekey.

To fix, check against the session connected flag, which only transitions
to non-zero following the first successful authentication.

bf2c7128ab adds logic to resolve this
issue, but it turns out that checking the session_state to avoid
sending the message is insufficient, because that state is re-set
to SSH_SESSION_STATE_KEXINIT_RECEIVED during rekey.

The before-and-after effects of this change can be observed using the
pkd --rekey flag as so:

    ./pkd_hello -t torture_pkd_openssh_rsa_rsa_sha2_256 \
      -i1 --rekey=16 -v -v -v 2>&1 |
      grep -e 'KEY' -e 'EXT'

^ where before the change, multiple SSH_MSG_EXT_INFO send messages are
logged; after, there is only a single SSH_MSG_EXT_INFO logged once upon
the first initial key exchange.

Cross-reference: https://bugs.libssh.org/T121.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:39 +02:00
Jon Simons
c0f3a96089 server: fix queued USERAUTH_SUCCESS rekey bug
Fix a bug with server-side rekeying where the session state at hand
has been toggled to SSH_SESSION_STATE_AUTHENTICATED before performing
the packet send of the SSH2_MSG_USERAUTH_SUCCESS message.

Before this change, what can happen is that during the packet send,
the SSH2_MSG_USERAUTH_SUCCESS message can end up being queued due
to a small rekey data limit value.  libssh server will then proceed
to attempt to send KEX-related rekeying messages to the client before
the client has received USERAUTH_SUCCESS.  OpenSSH clients do not
expect to undergo rekeying before having been authenticated, and so
will exit with error when this happens.

The behavior before and after can be observed with the pkd test making
use of its new --rekey flag:

    ./pkd_hello -t torture_pkd_openssh_rsa_rsa_default -i1 --rekey=16 -v -v -v

A new CMake test entry is added for the above variation and can be run
with:

    ARGS="-R pkd_hello_rekey" make test

Before the fix, the test will fail; after, the test succeeds while
performing rekeying once every 16 bytes.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:39 +02:00
Jon Simons
7ef2fe7f7b packet: log when data-based rekeying needed
Log an SSH_LOG_PACKET debug message when rekeying is necessary due to
the cipher max_blocks configuration.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:39 +02:00
Jon Simons
175375bc09 tests/pkd: support --rekey to set rekey data limit
Support an optional --rekey input to set the SSH session rekey data
limit using SSH_OPTIONS_REKEY_DATA.  This flag can be used together
with --buffer to test out server rekeying.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:39 +02:00
Jon Simons
03a1f1dd0c tests/pkd: support optional --buffer for test payload
Support an optional --buffer input for the pkd tests to enable testing
with a larger payload than the default "hello\n".

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:34 +02:00
Jon Simons
410f100968 tests/pkd: input test payload buffer
Move the pkd test payload buffer into the arguments struct, to make
way for parameterizing the payload using command-line options.

Signed-off-by: Jon Simons <jon@jonsimons.org>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 14:00:28 +02:00
Jakub Jelen
104c696bca dh-gex: Verify received primes in FIPS mode to match one of the known groups
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 13:18:09 +02:00
Jakub Jelen
e446507352 Provide a function to query crypto backend for FIPS status
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 13:18:09 +02:00
Jakub Jelen
67beaf363f dh-gex: Fall back to known primes when the moduli file is not readable
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 13:18:09 +02:00
Jakub Jelen
4012338862 doc: Update the description of the pki_private_key_decrypt() function to match reality
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 13:18:09 +02:00
Jakub Jelen
bb7920efbc tests: Avoid reading user configuration when running algorithm tests
Signed-off-by: Jakub Jelen <jjelen@redhat.com>
Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
2019-04-29 13:18:09 +02:00