Skip to content

Add sha256 and sha512 support for key fingerprint calculation - #1103

Open
ioparaskev wants to merge 4 commits into
paramiko:mainfrom
ioparaskev:master
Open

ioparaskev wants to merge 4 commits into
paramiko:mainfrom
ioparaskev:master

Conversation

@ioparaskev

@ioparaskev ioparaskev commented Oct 29, 2017 •

Copy link
Copy Markdown
  • Adds methods get_sha256_fingerprint, get_sha512_fingerprint,
    get_md5_fingerprint to support different algorithms for calculating
    key fingerprint. sha1 fingerprint calculation is not added due to recent
    practical collision findings while md5 is still provided for backwards
    compatibility.
  • Adds method get_available_fingerprint_methods that returns a
    dictionary of availabe hash algorithms and their corresponding
    callbacks.
  • Method get_fingerprint now supports an optional algorithm
    parameter to specify the preferred algorithm that will be used for the
    fingerprint calculation. If the algorithm is not supported or not given,
    it falls back to md5.
  • This commit acts as a backwards compatibility step with a future
    projection of changing the default behaviour to return a sha256
    base64-trimmed digest instead of md5 digest. This allows better collision
    resistance. For more info about fast collision attacks on MD5 check
    the paper "Fast Collision Attack on MD5" by Tao Xie1, Fanbao Liu,
    Dengguo Feng. sha256 is also the default behavior of OpenSSH since version
    6.8

@ploxiln

ploxiln commented Oct 29, 2017

Copy link
Copy Markdown
Contributor

ssh-add from OpenSSH-7.4p1 shows auth key fingerprints like so:

$ ssh-add -l
3072 SHA256:k1kzdj2A9DXxs9cc7MRd9TaIzzbcPvqjpEHZtq/wwfk [email protected] (RSA)

Just to say, this PR is consistent with that, and thus seems like a generally good idea.

But this will likely be deferred to a major release because it's a "breaking" output-format change for the get_fingerprint() method.

@ioparaskev

Copy link
Copy Markdown
Author

@ploxiln I agree
Maybe we could keep the fingerprint being md5 but also provide 2 methods for sha512 and sha256?
I also need to make changes for python3 compatibility (forgot to check before making the PR)

@ioparaskev

Copy link
Copy Markdown
Author

Changes made, now it's py2/3 compatible.
As I said, if we consider this a "breaking" change, maybe it's better to make this a 2-part change to avoid delaying the extra methods until a major release.

  1. Provide sha256 & sha512 fingerprint support in minor release
  2. In a major release, push the get_fingerprint to use the sha256 method instead of the md5

@Ismael Ismael mentioned this pull request Nov 10, 2017
@ioparaskev

Copy link
Copy Markdown
Author

any updates for this?

@avidspartan1

Copy link
Copy Markdown

Would love to see this PR accepted.

@ioparaskev

Copy link
Copy Markdown
Author

I'm not sure why after all these years this is still unmerged but if the reason is backwards compatibility, I think we can figure a way to roll this change (maybe still keeping the md5 as default behaviour?). It's really unfortunate that in 2020 paramiko is still stuck with md5

@subodh2691

Copy link
Copy Markdown

I am facing similar issue. can someone help when these changes can be merged?

@jdafont

jdafont commented Jul 20, 2020

Copy link
Copy Markdown

I would also like to see this merged. We use paramiko at work, and since moving to FIPS this has become a big issue. It looks like discussion about this has been on-going since 2014.

@avidspartan1

Copy link
Copy Markdown

@ioparaskev, looks like there are merge conflicts. I'm not sure if that's what's standing in the way, but do you have time to fix those? I'd take a whack at it but I don't have a great way to test at the moment.

@ioparaskev ioparaskev changed the title Use sha256 digest for key fingerprint Add sha256 and sha512 support for key fingerprint calculation Jul 21, 2020
@ioparaskev

ioparaskev commented Jul 21, 2020 •

Copy link
Copy Markdown
Author

@avidspartan1 I'm not sure since I never got any feedback on why this can't be merged.
In any case, I decided to rebase this PR to be in sync with the latest HEAD and I also decided to keep the md5 behaviour as the default for now.
This means that this PR can be merged without introducing any breaking changes and at the same time adding extra options of using the sha256/sha512 hashes. I decided to make this change since from what I understand, changing the default behaviour might break a lot of things for people who relied on the bad md5. So this PR is actually a type of "grace period" for people to convert to the newer algorithms before introducing a breaking change.
I don't know if this was the show-stopper for merging this PR but in any case I considered it better to split this into two parts. So hopefully when/if this is merged a roadmap for rolling out to sha256 can be set.

P.S:

  1. The old changes are still in one of my branches (https://github.com/ioparaskev/paramiko/tree/old_sha256digest) without rebasing
  2. I also created another branch based on this PR that uses sha256 as a default. So people who want to use sha256 as the default behaviour the branch https://github.com/ioparaskev/paramiko/tree/sha256digest is basically one commit ahead of this PR. The extra commit includes the changes needed to use sha256 as the default hashing algorithm

- Adds methods `get_sha256_fingerprint`, `get_sha512_fingerprint`,
  `get_md5_fingerprint` to support different algorithms for calculating
key fingerprint. sha1 fingerprint calculation is not added due to recent
practical collision findings while md5 is still provided for backwards
compatibility.
- Adds method `get_available_fingerprint_methods` that returns a
  dictionary of availabe hash algorithms and their corresponding
callbacks.
- Method `get_fingerprint` now supports an optional `algorithm`
  parameter to specify the preferred algorithm that will be used for the
fingerprint calculation. If the algorithm is not supported or not given,
it falls back to md5.
- This commit acts as a backwards compatibility step with a future
  projection of changing the default behaviour to return a sha256
base64-trimmed digest instead of md5 digest. This allows better collision
resistance. For more info about fast collision attacks on MD5 check
the paper "Fast Collision Attack on MD5" by Tao Xie1, Fanbao Liu,
Dengguo Feng. sha256 is also the default behavior of OpenSSH since version
6.8
Comment thread paramiko/pkey.py Resolved
Comment thread paramiko/pkey.py Resolved
Comment thread paramiko/pkey.py Resolved
Comment thread paramiko/pkey.py Resolved
Co-authored-by: Mateusz Stompór <[email protected]>
Comment thread paramiko/pkey.py Resolved
Comment thread paramiko/pkey.py Resolved
Co-authored-by: Mateusz Stompór <[email protected]>
Comment thread paramiko/pkey.py Resolved
@aronwk-aaron

aronwk-aaron commented Nov 10, 2020 •

Copy link
Copy Markdown

Really need this PR merged for so that FIPS is supported. It's 2020, we shouldn't only be be using MD5

@dfresh613

Copy link
Copy Markdown

This may be a bit of scope creep for this bug. But it would be very nice if the default AutoAddPolicy and AutoReject were also updated to use these new fingerprints by default, and fall back to md5 only if sha is not available

In addition to updating pkey with additional algorithms, may I also suggest sometime in the future the paramiko https://github.com/paramiko/paramiko/blob/master/paramiko/client.py#L805

@malthe

malthe commented Jun 7, 2021

Copy link
Copy Markdown

Bump?

Also – what about using a fingerprint as a host key. That doesn't seem possible today. A StackOverflow answer suggests using a custom FingerprintKey class.

@bitprophet bitprophet modified the milestones: p0, p1 Sep 24, 2021
@nchigwamba

Copy link
Copy Markdown

Is there a view of when this PR will be merged?

@ahawk66

ahawk66 commented Oct 8, 2021

Copy link
Copy Markdown

When?

@michalxo

Copy link
Copy Markdown

Hello! Any news on this PR please?

@bittner

bittner commented Mar 1, 2022 •

Copy link
Copy Markdown

@alex Would you be willing to merge this PR if the author resolved the merge conflicts?

OObasuyi added a commit to OObasuyi/paramiko that referenced this pull request Apr 17, 2022
didib added a commit to didib/ovirt-engine that referenced this pull request Sep 13, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
didib added a commit to didib/ovirt-engine that referenced this pull request Sep 13, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
didib added a commit to didib/ovirt-engine that referenced this pull request Sep 13, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
didib added a commit to didib/ovirt-engine that referenced this pull request Sep 20, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
didib added a commit to didib/ovirt-engine that referenced this pull request Sep 20, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
didib added a commit to oVirt/ovirt-engine that referenced this pull request Sep 20, 2022
In fips mode, we fail with:
  File "/usr/lib/python3.6/site-packages/otopi/context.py", line 132, in _executeMethod
    method['method']()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-setup/ovirt-engine-dwh/core/remote_engine.py", line 83, in _remote_engine_customization
    oenginecons.ConfigEnv.ENGINE_FQDN
  File "/usr/share/ovirt-engine/setup/ovirt_engine_setup/remote_engine.py", line 146, in configure
    self._style.configure(fqdn=fqdn)
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 177, in configure
    self._ssh_connect()
  File "/usr/share/ovirt-engine/setup/bin/../plugins/ovirt-engine-common/base/remote_engine/remote_engine_root_ssh.py", line 153, in _ssh_connect
    osetupcons.ConfigEnv.REMOTE_ENGINE_HOST_CLIENT_KEY
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 416, in connect
    self, server_hostkey_name, server_key
  File "/usr/lib/python3.6/site-packages/paramiko/client.py", line 837, in missing_host_key
    key.get_name(), hostname, hexlify(key.get_fingerprint())
  File "/usr/lib/python3.6/site-packages/paramiko/pkey.py", line 180, in get_fingerprint
    return md5(self.asbytes()).digest()

This is because we use paramiko.WarningPolicy, which uses
get_fingerprint to show the missing key, which uses hashlib.md5 [1],
which is disabled in fips mode.

Create our own policy instead, that does not show the key.

Please note that this isn't a complete fix for [1] - e.g. if you have
any keys in normal locations, such as ~/.ssh/id_rsa, paramiko will fail
later, when mentioning that it's going to try loading them.

[1] paramiko/paramiko#1103

Change-Id: I99a934ceefc707cdff127229d1bebf196aac4140
Signed-off-by: Yedidyah Bar David <[email protected]>
@bskinn

bskinn commented Aug 11, 2023

Copy link
Copy Markdown
Contributor

I'm not deeply familiar with the code here, but per xxx it looks like paramiko 3.2 introduced a fingerprint property that does SHA256... but only SHA256.

I figure the changes in this PR will need to be adapted to this new code... it seems likely that either (i) the existing code will need to be converted to a method, so that the desired fingerprint type can be passed as an argument, or (ii) multiple properties will need to be created, one for each desired fingerprint type.

I'm not sure how bitprophet will want to resolve this. I've flagged it for his policy decision.

@mnasiadka

Copy link
Copy Markdown

I'm not deeply familiar with the code here, but per xxx it looks like paramiko 3.2 introduced a fingerprint property that does SHA256... but only SHA256.

I figure the changes in this PR will need to be adapted to this new code... it seems likely that either (i) the existing code will need to be converted to a method, so that the desired fingerprint type can be passed as an argument, or (ii) multiple properties will need to be created, one for each desired fingerprint type.

I'm not sure how bitprophet will want to resolve this. I've flagged it for his policy decision.

Hello - it's been over a year without a decision - @bskinn is there any way this could progress?

@ioparaskev

Copy link
Copy Markdown
Author

I haven't seen any roadmap plans on integrating this functionality so I'm not extremely enthusiastic on refactoring and syncing the PR so that it can sit waiting for another 4+ years tbh

@mnasiadka

Copy link
Copy Markdown

I haven't seen any roadmap plans on integrating this functionality so I'm not extremely enthusiastic on refactoring and syncing the PR so that it can sit waiting for another 4+ years tbh

I rather wanted to get an insight from the repository maintainers - but thanks for replying!

openstack-mirroring pushed a commit to openstack/networking-generic-switch that referenced this pull request Mar 5, 2025
In order for n-g-s to be able to run on a node in FIPS enforcing mode,
it *must* not use md5. However, paramiko's code has a get_fingerprint
call where it is fingerprinting data for the exchange to identify
a difference, which can use any algorithm realistically.

Anyhow, this is necessary because it appears that paramiko's maintainer
is not really interested in fixing the md5 usage. As a result, we're
forced to monkeypatch paramiko, which is loaded by netmiko, which is
what NGS uses.

This should be fixed in paramiko, but also it seems several changes
been proposed without forward movement.

https: //github.com/paramiko/paramiko/pull/688
https: //github.com/paramiko/paramiko/pull/1103
https: //github.com/paramiko/paramiko/pull/2189
https: //github.com/paramiko/paramiko/pull/2496
https: //github.com/paramiko/paramiko/issues/2383
https: //github.com/paramiko/paramiko/issues/396
Related-Bug: 2098819
Change-Id: Ia3fb9d2baa14be1726197d1115e92adc9ce5ce0a
openstack-mirroring pushed a commit to openstack/openstack that referenced this pull request Mar 5, 2025
* Update networking-generic-switch from branch 'master'
  to b351b9136d569b02c8b94df3e52fdd10038df3c4
  - Merge "don't use paramiko's get_fingerprint (md5)"
  - don't use paramiko's get_fingerprint (md5)
    
    In order for n-g-s to be able to run on a node in FIPS enforcing mode,
    it *must* not use md5. However, paramiko's code has a get_fingerprint
    call where it is fingerprinting data for the exchange to identify
    a difference, which can use any algorithm realistically.
    
    Anyhow, this is necessary because it appears that paramiko's maintainer
    is not really interested in fixing the md5 usage. As a result, we're
    forced to monkeypatch paramiko, which is loaded by netmiko, which is
    what NGS uses.
    
    This should be fixed in paramiko, but also it seems several changes
    been proposed without forward movement.
    
    https: //github.com/paramiko/paramiko/pull/688
    https: //github.com/paramiko/paramiko/pull/1103
    https: //github.com/paramiko/paramiko/pull/2189
    https: //github.com/paramiko/paramiko/pull/2496
    https: //github.com/paramiko/paramiko/issues/2383
    https: //github.com/paramiko/paramiko/issues/396
    Related-Bug: 2098819
    Change-Id: Ia3fb9d2baa14be1726197d1115e92adc9ce5ce0a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.