From 67ec57b119474d8fcdd46a1f35535e82a6258329 Mon Sep 17 00:00:00 2001 From: alan Date: Fri, 28 Feb 2025 13:54:37 +0100 Subject: [PATCH] =?UTF-8?q?simplification=20de=20la=20v=C3=A9rification=20?= =?UTF-8?q?de=20l'empreinte?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit utilisation de la propriété fingerprint sur l'objet key https://docs.paramiko.org/en/latest/api/keys.html#paramiko.pkey.PKey.fingerprint --- .../commands/fetch_export_agricoll_contacts_file.py | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/core/management/commands/fetch_export_agricoll_contacts_file.py b/core/management/commands/fetch_export_agricoll_contacts_file.py index 04a2634b..4281bb97 100644 --- a/core/management/commands/fetch_export_agricoll_contacts_file.py +++ b/core/management/commands/fetch_export_agricoll_contacts_file.py @@ -1,6 +1,5 @@ import base64 import datetime -import hashlib import os import subprocess import tempfile @@ -47,20 +46,10 @@ class CleverCloudSftpVerifier(paramiko.MissingHostKeyPolicy): def __init__(self, expected_hostname): self.expected_hostname = expected_hostname - def _get_key_fingerprint(self, key): - """Génère l'empreinte SHA256 d'une clé au format similaire à SSH""" - hash_obj = hashlib.sha256(key.asbytes()) - fingerprint = "SHA256:" + base64.b64encode(hash_obj.digest()).decode("utf-8").rstrip("=") - return fingerprint - def missing_host_key(self, client, hostname, key): - # Vérification du hostname if hostname != self.expected_hostname: raise paramiko.SSHException("Connexion refusée - host non autorisé") - - # Vérification de l'empreinte à partir de la clé publique - key_fingerprint = self._get_key_fingerprint(key) - if key_fingerprint not in self.CLEVER_CLOUD_FINGERPRINTS: + if key.fingerprint not in self.CLEVER_CLOUD_FINGERPRINTS: raise paramiko.SSHException("Connexion refusée - empreinte de clé non reconnue")