
    g                         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 d dlmZmZmZ d d	lmZ d
gZ	 d dlZdZdZdZ G d d
e      ZdefdZ G d d      Z y# e$ r dZdZY +w xY w)    N)ContextManagerListOptional)
CLIContext)	CLIConfig)SigningCommandPlugin)loggerreadable_file)ConfigurationError)PKCS11PinEntryModePKCS11SignatureConfigTokenCriteria)SignerPKCS11PluginTFPYHANKO_PKCS11_PINz7This subcommand requires python-pkcs11 to be installed.c                   `    e Zd ZdZdZeZdefdZde	e
j                     fdZdedee   fdZy)	r   pkcs11z"use generic PKCS#11 device to signreturnc                     t         S N)pkcs11_availableselfs    _/var/www/html/Beni/venv/lib/python3.12/site-packages/pyhanko/cli/commands/signing/pkcs11_cli.pyis_availablezPKCS11Plugin.is_available(   s        c                 
   t        j                  ddt        d      t        j                  ddt        d      t        j                  ddt        d      t        j                  d	d
t        dd      t        j                  ddt        d      t        j                  dddt
        d       t        j                  dt        ddddd      t        j                  dt        dd      t        j                  dt        ddd      g	S )N)z--libzpath to PKCS#11 moduleF)helptyperequired)z--token-labelzPKCS#11 token label)z--cert-labelzcertificate label)z--raw-mechanismzinvoke raw PKCS#11 mechanismT)r   r   is_flagr    )z--key-labelz	key label)z	--slot-nozspecify PKCS#11 slot to use)r   r    r   default)z--skip-user-pinz7do not prompt for PIN (e.g. if the token has a PIN pad))r   show_defaultr"   r    r!   r   )z--p11-setupzCname of preconfigured PKCS#11 profile (overrides all other options))r   r    r   )z--other-certz3label of other cert to pull (multiple uses allowed))r   r    r   multiple)clickOptionr
   strboolintr   s    r   click_optionszPKCS11Plugin.click_options+   s   LL-"	 LL"*	 LL!(	 LL$3 LL {u LL2 LL$!N LL !	 LL!Ji;
 ;	
r   contextc                     t        |fi |S r   )_pkcs11_signer_context)r   r+   kwargss      r   create_signerzPKCS11Plugin.create_signeri   s     &g888r   N)__name__
__module____qualname__subcommand_namehelp_summaryUNAVAIL_MSGunavailable_messager(   r   r   r%   r&   r*   r   r   r   r/    r   r   r   r   #   sN    O7L% d  <
tELL1 <
|9!9		9r   ctxc
           
         ddl m}
 |r?| j                  }|t        j                  d      	 t        |      j                  |      }nW|r|st        j                  d      |rt        j                  nt        j                  }t        ||||t        |      |||	      }|j                  }|6t         j"                  j%                  t&        d       }|r|j)                         }|j*                  t        j                  k(  r|t-        j,                  d	      } |
j.                  ||
      S # t        $ r6}d| }t        j                  ||       t        j                  |      d }~ww xY w)Nr   )r   z4The --p11-setup option requires a configuration filez#Error while reading PKCS#11 config )exc_infoz3The parameters --lib and --cert-label are required.)module_path
cert_label	key_labelslot_notoken_criteria
prompt_pinraw_mechanismother_certs_to_pullzPKCS#11 user PIN: )prompt)user_pin)pyhanko.signr   configr%   ClickExceptionModuleConfigWrapperget_pkcs11_configr   r	   errorr   SKIPPROMPTr   r   rD   osenvirongetP11_PIN_ENV_VARstripr@   getpassPKCS11SigningContext)r8   libtoken_labelr<   r=   r>   skip_user_pin	p11_setuprA   
other_certr   
cli_configpkcs11_configemsgpinentry_modepinpin_envs                     r   r-   r-   o   sa    $*-**
&&F 	,/
;MMM 
&&E   ###** 	 .!(5$' *

 
 
 C {**..$7--/C#5#<#<<oo%9:&6&&}sCCM " 	,7	{CCLLq)&&s++	,s   D, ,	E+51E&&E+c                       e Zd ZdefdZd Zy)rH   rF   c                 J    |j                   }|j                  di       | _        y )Nzpkcs11-setups)
raw_configrO   pkcs11_setups)r   rF   config_dicts      r   __init__zModuleConfigWrapper.__init__   s     ''(___bAr   c                     	 | j                   |   }t        j                  |      S # t        $ r t        d| d      w xY w)Nz There's no PKCS#11 setup named '')rc   KeyErrorr   r   from_config)r   namesetups      r   rI   z%ModuleConfigWrapper.get_pkcs11_config   sS    	Q&&t,E %0077  	Q$'GvQ%OPP	Qs   & ?N)r0   r1   r2   r   re   rI   r7   r   r   rH   rH      s    By B8r   rH   )!rR   rM   typingr   r   r   r%   pyhanko.cli._ctxr   pyhanko.cli.configr   pyhanko.cli.plugin_apir   pyhanko.cli.utilsr	   r
   pyhanko.config.errorsr   pyhanko.config.pkcs11r   r   r   rE   r   __all__r   r   ImportErrorrP   r5   r   r-   rH   r7   r   r   <module>ru      s     	 1 1  ' ( 7 3 4 
  
 'GI9' I9X>D	>DB
8 
8m  Fs   A1 1	A=<A=