3
@6^                 @   s<   d dl Z d dlmZ d dlmZmZmZ G dd deZdS )    N)urlparse)
SpiderFootSpiderFootPluginSpiderFootEventc               @   sV   e Zd ZdZdddddZdddd	dZd
Ze fddZdd Z	dd Z
dd Zd
S )sfp_sslcertzSSL Certificates:Footprint,Investigate:Crawling and Scanning::Gather information about SSL certificates used by the target's HTTPS sites.T
      )tryhttpverify
ssltimeoutcertexpiringdaysz6Also try to HTTPS-connect to HTTP sites and hostnames.z5Verify certificate subject alternative names resolve.z1Seconds before giving up trying to HTTPS connect.zNNumber of days in the future a certificate expires to consider it as expiring.Nc             C   s8   || _ | j | _x"t|j D ]}|| | j|< qW d S )N)sftempStorageresultslistkeysopts)selfsfcuserOptsopt r   6/var/www/spiderfoot.crq.systems/modules/sfp_sslcert.pysetup*   s    
zsfp_sslcert.setupc             C   s
   dddgS )NINTERNET_NAMELINKED_URL_INTERNAL
IP_ADDRESSr   )r   r   r   r   watchedEvents6   s    zsfp_sslcert.watchedEventsc             C   s   ddddddddd	d
dddgS )NTCP_PORT_OPENr   INTERNET_NAME_UNRESOLVEDAFFILIATE_INTERNET_NAME"AFFILIATE_INTERNET_NAME_UNRESOLVEDSSL_CERTIFICATE_ISSUEDSSL_CERTIFICATE_ISSUERSSL_CERTIFICATE_MISMATCHSSL_CERTIFICATE_EXPIREDSSL_CERTIFICATE_EXPIRINGSSL_CERTIFICATE_RAWDOMAIN_NAMEAFFILIATE_DOMAIN_NAMEr   )r   r   r   r   producedEvents<   s    zsfp_sslcert.producedEventsc          "   C   s  |j }|j}|j}| jjd| d |  |dkr|j jd rR| jd  rRd S y,t|}d}|j	rl|j	}| jj
|j }W q tk
r } z| jjd|  d S d }~X qX n|}d}|| jkrd| j|< nd S | jjd	| d
 t|  yR| jj||| jd }	|	j  |	jd}
| jj|
}| jjt||| jd }W nB tk
r } z$| jjd| d t| d  d S d }~X nX |d1krtd|d
 t| | j|}| j| |jds| jjd|  d S td|d | j|}| j| |jdrtd|d | j|}| j| |jdrHtd|d | j|}| j| |dkr|jdrtddj|jd| j|}| j| xt|jdt D ]}|jdd }| j j|dd!rd}nd"}| jd# r| jj| r| jjd$| d%  |d&7 }t||| j|}| j| | jj|| jd' r|jd(rVtd)|| j|}| j| ntd*|| j|}| j| qW |jd+rtd,|jd-d.| j|}| j| d S |jd/rtd0|jd-d.| j|}| j| d S d S )2NzReceived event, z, from r   zhttps://r	   i  zCouldn't parse URL: TzTesting SSL for: :r   r   zUnable to SSL-connect to z ()r   r   r   textz!Failed to parse the SSL cert for r'   issuedr"   issuerr#   mismatchr$   z, hostsaltnamesz*. )includeChildrenr    r
   zHost z could not be resolved_UNRESOLVED_internettlds	AFFILIATEr)   r(   expiredr%   	expirystrUnknownexpiringr&   )r   r   ) 	eventTypemoduledatar   debuglower
startswithr   r   porturlFQDNBaseExceptionr   strsafeSSLSocketdo_handshakegetpeercertsslDerToPem	parseCertinfor   __name__notifyListenersgetjoinsetr   replace	getTargetmatchesresolveHostisDomain)r   event	eventNamesrcModuleName	eventDataurB   fqdnesockdercertZpemcertcertxevtrawevtsandomainevt_typer   r   r   handleEventE   s    

 








zsfp_sslcert.handleEvent)rL   
__module____qualname____doc__r   optdescsr   dictr   r   r*   rf   r   r   r   r   r      s   	r   )timeurllib.parser   sflibr   r   r   r   r   r   r   r   <module>   s   