
     h!                        d dl Z d dlZd dlmZmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZmZ d dlmZmZmZ d dlmZ d d	lmZmZ d d
lmZmZmZ ddgZ G d d          Z G d de          ZdefdZ  G d de          Z!defdZ"dS )    N)ContextManagerListOptional)
CLIContext)
grab_certs)	CLIConfig)SigningCommandPluginregister_signing_plugin)_warn_empty_passphraseloggerreadable_file)ConfigurationError)PemDerSignatureConfigPKCS12SignatureConfig)Signersigner_from_p12_configsigner_from_pemder_configPemderPluginPKCS12Pluginc                   &    e Zd ZdefdZd Zd ZdS )KeyFileConfigWrapperconfigc                     |j         }|                    di           | _        |                    di           | _        d S )Nzpemder-setupszpkcs12-setups)
raw_configgetpemder_setupspkcs12_setups)selfr   config_dicts      _/var/www/html/Sam_Eipo/venv/lib/python3.11/site-packages/pyhanko/cli/commands/signing/simple.py__init__zKeyFileConfigWrapper.__init__   s<    '(___bAA(___bAA    c                     	 | j         |         }n!# t          $ r t          d| d          w xY wt          j        |          S )Nz There's no PKCS#12 setup named '')r   KeyErrorr   r   from_configr   namesetups      r    get_pkcs12_configz&KeyFileConfigWrapper.get_pkcs12_config    a    	Q&t,EE 	Q 	Q 	Q$%O%O%O%OPPP	Q$0777    .c                     	 | j         |         }n!# t          $ r t          d| d          w xY wt          j        |          S )Nz There's no PEM/DER setup named 'r$   )r   r%   r   r   r&   r'   s      r    get_pemder_configz&KeyFileConfigWrapper.get_pemder_config'   r+   r,   N)__name__
__module____qualname__r   r!   r*   r.    r"   r    r   r      sR        By B B B B
8 8 88 8 8 8 8r"   r   c                   T    e Zd ZdZdZdeej                 fdZde	de
e         fdZdS )r   pemderz$read key material from PEM/DER filesreturnc                 v   t          j        ddt          d          t          j        ddt          d          t          j        dt          dd	
          t          j        dt          dd          t          j        dddt          j        d          d          t          j        ddt
          ddd          gS )N)z--keyz)file containing the private key (PEM/DER)F)helptyperequired)z--certz2file containing the signer's certificate (PEM/DER)z--chainTzkfile(s) containing the chain of trust for the signer's certificate (PEM/DER). May be passed multiple times.r8   multipler7   )z--pemder-setupzCname of preconfigured PEM/DER profile (overrides all other options)r8   r9   r7   z
--passfilez2file containing the passphrase for the private keyrstdinr7   r9   r8   show_defaultz	--no-passz*assume the private key file is unencryptedr7   r8   is_flagdefaultrB   )clickOptionr   strFileboolr   s    r    click_optionszPemderPlugin.click_options3   s    L@"	   LM"	   L")	   L#!	   LLZ__$   LA!  K-
 -	
r"   contextc                 J    t           j        fd            } |            S )Nc               3   *   K   t           fi V  d S N)_pemder_signerrN   kwargss   r    _mz&PemderPlugin.create_signer.<locals>._mf   )       33F3333333r"   
contextlibcontextmanagerr   rN   rT   rU   s    `` r    create_signerzPemderPlugin.create_signerc   ?     
	"	4 	4 	4 	4 	4 
#	"	4 rttr"   N)r/   r0   r1   subcommand_namehelp_summaryr   rG   rH   rM   r   r   r   r[   r2   r"   r    r   r   /   sj        O9L.
tEL1 .
 .
 .
 .
`!		     r"   ctxc                    |r| j         }|t          j        d          	 t          |                              |          }n~# t
          $ r4}	d| }
t          j        |
|	           t          j        |
          d }	~	ww xY w|r|st          j        d          t          ||t          |          | j
                  }|j        |j        }n|N|                                                                                    d          }|                                 nF|j        r=|s;t#          j        d                              d          }|st%                       d }nd }t'          ||	          S )
Nz7The --pemder-setup option requires a configuration filez"Error while reading PEM/DER setup exc_infozXEither both the --key and --cert options, or the --pemder-setup option must be provided.)key_file	cert_fileother_certs
prefer_pssutf-8zKey passphrase: prompt)provided_key_passphrase)r   rG   ClickExceptionr   r.   r   r   errorr   r   rf   key_passphrasereadlinestripencodecloseprompt_passphrasegetpassr   r   )r_   keycertchainpemder_setuppassfileno_pass
cli_configpemder_configemsg
passphrases               r    rR   rR   m   s     
Z
&I  	,0<<NN MM " 	, 	, 	,E|EECLq))))&s+++	,  
d 
"'
 
 	

 ."5))~	
 
 
 #/"1

		&&((..0077@@
		(  _,>???FFwOO
 	"$$$J
$z      "A 
B/A==Bc                   v    e Zd ZdZdZdeej                 fdZdeej	                 fdZ
dedee         fdZdS )	r   pkcs12z$read key material from PKCS#12 filesr5   c                 <    t          j        dt          d          gS )N)pfxF)r8   r9   )rG   Argumentr   rL   s    r    click_extra_argumentsz"PKCS12Plugin.click_extra_arguments   s    xmeLLLMMr"   c                    t          j        dt          dd          t          j        dt          dd          t          j        d	d
dt          j        d          d          t          j        ddt
          ddd          gS )N)z--p12-setupFzCname of preconfigured PKCS#12 profile (overrides all other options)r=   r:   TzPEM/DER file(s) containing extra certificates to embed (e.g. chain of trust not embedded in the PKCS#12 file)May be passed multiple times.r;   r>   z4file containing the passphrase for the PKCS#12 file.r?   r@   rA   rC   z&assume the PKCS#12 file is unencryptedrD   )rG   rH   rI   r   rJ   rK   rL   s    r    rM   zPKCS12Plugin.click_options   s    L !	   L"0	   LKZ__$   L=!  /
 	
r"   rN   c                 J    t           j        fd            } |            S )Nc               3   *   K   t           fi V  d S rQ   )_pkcs12_signerrS   s   r    rU   z&PKCS12Plugin.create_signer.<locals>._m   rV   r"   rW   rZ   s    `` r    r[   zPKCS12Plugin.create_signer   r\   r"   N)r/   r0   r1   r]   r^   r   rG   r   r   rH   rM   r   r   r   r[   r2   r"   r    r   r      s        O9LNtEN'; N N N N 
tEL1  
  
  
  
D!		     r"   c                    |r| j         }|t          j        d          	 t          |                              |          }n{# t
          $ r4}d| }	t          j        |	|           t          j        |	          d }~ww xY w|st          j        d          t          |t          |          | j
                  }|j        |j        }
n|N|                                                                                    d          }
|                                 nF|j        r=|s;t#          j        d                              d          }
|
st%                       d }
nd }
t'          ||
	          S )
Nz4The --p12-setup option requires a configuration filez#Error while reading PKCS#12 config ra   zCEither the PFX argument or the --p12-setup option must be provided.)pfx_filere   rf   rg   zPKCS#12 passphrase: rh   )provided_pfx_passphrase)r   rG   rk   r   r*   r   r   rl   r   r   rf   pfx_passphrasern   ro   rp   rq   rr   rs   r   r   )r_   r   rv   rx   	p12_setupry   rz   pkcs12_configr|   r}   r~   s              r    r   r      s     
*-*
&F  	,0<<NN MM " 	, 	, 	,C	CCCLq))))&s+++	,  

" 
 
 	

 ."5))~
 
 
 #/"1

		&&((..0077@@
		(  _,BCCCJJ
 

  	"$$$J
!z   r   )#rX   rs   typingr   r   r   rG   pyhanko.cli._ctxr   pyhanko.cli._trustr   pyhanko.cli.configr   pyhanko.cli.plugin_apir	   r
   pyhanko.cli.utilsr   r   r   pyhanko.config.errorsr   pyhanko.config.local_keysr   r   pyhanko.sign.signers.pdf_cmsr   r   r   __all__r   r   rR   r   r   r2   r"   r    <module>r      s        1 1 1 1 1 1 1 1 1 1  ' ' ' ' ' ' ) ) ) ) ) ) ( ( ( ( ( ( P P P P P P P P K K K K K K K K K K 4 4 4 4 4 4                 >
*8 8 8 8 8 8 8 8*; ; ; ; ;' ; ; ;|3	3 3 3 3l0 0 0 0 0' 0 0 0f/
 / / / / / /r"   