U
K��^� � @ sN d dl Z d dlmZ e �d�Zdd� Zed�ZdZed�Z d d
� Z
dd� ZdS )
� N)�run_commandzsubiquitycore.sshc C s� t ddg�} | jdkr(t�d| j� g S g }| j�� D ]$}|�d�r6|�|� dd�d � q6g }|D ]`}t dd |g�}|jdkr�t�d
||j� qd|j�
� � � }|\}}} }
|
�
d�}
|�|
|f� qd|S )zzQuery sshd to find the host keys and then fingerprint them.
Returns a sequence of (key-type, fingerprint) pairs.
Zsshdz-Tr zsshd -T failed %rzhostkey N� z
ssh-keygenz-lfzssh-keygen -lf %s failed %rz())r �
returncode�log�debug�stderr�stdout�
splitlines�
startswith�append�split�strip)ZconfigZkeyfiles�line�infoZkeyfileZcp�partsZlength�fingerprintZhost�keytype� r �)/usr/share/subiquity/subiquitycore/ssh.py�host_key_fingerprints s& |