
    Vht                    L   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	Z	ddl
Z
ddlZddlZddlZddlmZmZ ddlmZmZ ej,                  rdd	lmZ dAd
Zd Zd Z edd       G d de             Z edd       G d de             Z edd       G d de             Z edd       G d de             Z  edd       G d de             Z! edd       G d de             Z" edd       G d de             Z# edd       G d de             Z$ edd       G d d e             Z% edd       G d! d"e             Z& edd       G d# d$e             Z' edd       G d% d&e             Z( edd       G d' d(e             Z) edd       G d) d*e             Z* edd       G d+ d,e             Z+ edd       G d- d.e             Z, edd       G d/ d0e             Z-i d1ed2ed3e d4e!d5e"d6e#d7e$d8e%d9e&d:e'd;e(d<e)d=e*d>e+d?e,d@e-Z.y)BzSignature verification helpers.    )annotations)AnsibleError)
user_agent)open_urlN)	dataclassfields)	HTTPErrorURLError)Displayc                    ||j                  d|         	 t        | t               dd      5 }|j                         }d d d        |S # 1 sw Y   S xY w# t        t
        f$ r}t        d|  d|       |d }~ww xY w)NzUsing signature at Tsafe)
http_agentvalidate_certsfollow_redirectsz:Failed to get signature for collection verification from '': )vvvvr   r   readr	   r
   r   )sourcedisplayresp	signaturees        M/home/dcms/DCMS/lib/python3.12/site-packages/ansible/galaxy/collection/gpg.pyget_signature_from_sourcer      s    *6(34!|#	
 	$
 		I	$ 	$  x  HPSTUSVW
	s4   A A
 A 
AA A A=&A88A=c           
        t        j                         \  }}t         j                  j                  |       }dd| ddddd| d| g	}d	j	                  |      }|j                  d
| d       	 t        j                  |t        j                  t        j                  t        j                  |fd      }	|	j                  |      \  }
}	 t        j                  |       |r7t        j                  t               5  t        j"                  |       d d d        t        j$                  |      5 }|j'                         }
|j                  d|
 d| d|	j(                   d       |
|	j(                  fcd d d        S # t        t        j                  f$ r}t        d| d|       |d }~ww xY w# t        j                  |       w xY w# 1 sw Y   xY w# 1 sw Y   y xY w)Ngpgz--status-fd=z--verifyz--batchz--no-ttyz--no-default-keyringz
--keyring=- zRunning command ''utf8)stdinstdoutstderrpass_fdsencoding)inputz/Failed during GnuPG verification with command 'r   z	stdout: 
z

stderr: 
z
(exit code ))ospipepathexistsjoinr   
subprocessPopenPIPEcommunicateFileNotFoundErrorSubprocessErrorr   close
contextlibsuppressOSErrorremovefdopenr   
returncode)manifest_filer   keyringr   status_fd_readstatus_fd_writeremove_keyboxcmdcmd_strpr"   r#   errfs                 r   run_gpg_verifyrD   +   s    ')ggi#NO w//M 	
'(
WI
C hhsmGLL$SE+,"//????%'
 Y7
!  ) 	IIg	 
>	" $aVHM!,,qQ	
 q||#$ $ z99: =gYc#O
	 	!	 	$ $sD   0AE< 6F/ <G	/AG<F,F''F,,F/ /G	GGc              #  l  K   | j                         D ]h  }|s	 |j                  d      \  }}}	 t        |   }|g}|r6|j                  |j                  d t        t        |            dz
                ||  j y # t        $ r |j                  d      \  }}d }Y qw xY w# t        $ r Y w xY ww)N   )maxsplit   )
splitlinessplit
ValueErrorGPG_ERROR_MAPKeyErrorextendlen	dc_fields)
status_outline_dummystatus	remainderclsr   s          r   parse_gpg_errorsrW   b   s     %%' 	(,

A
(>%FFI
	'C MM	#'!+ 6l/
  	!ZZZ3NFFI	  		sE   B4A?	B%AB4? B"B4!B""B4%	B1.B40B11B4T)frozenslotsc                  <     e Zd ZU ded<   edd       Z fdZ xZS )GpgBaseErrorstrrT   c                T    dj                  | j                  j                               S )z%Return the current class description.r   )r,   __doc__rJ   )rV   s    r   get_gpg_error_descriptionz&GpgBaseError.get_gpg_error_description   s      xx))+,,    c           
         t        j                  t        |       d      j                         D ])  \  }}t        t
        |   | |t        | |                   + y )NT)eval_str)inspectget_annotationstypeitemssuperr[   __setattr__getattr)self
field_name
field_type	__class__s      r   __post_init__zGpgBaseError.__post_init__   sS    &-&=&=d4jSW&X&^&^&` 	e"J
,1*jQUWaIb>cd	er`   )returnr\   )__name__
__module____qualname____annotations__classmethodr_   rn   __classcell__)rm   s   @r   r[   r[   }   s&    K- -e er`   r[   c                  &    e Zd ZU dZded<   ded<   y)	GpgExpSigzCThe signature with the keyid is good, but the signature is expired.r\   keyidusernameNrp   rq   rr   r^   rs    r`   r   rw   rw      s    MJMr`   rw   c                  &    e Zd ZU dZded<   ded<   y)GpgExpKeySigzSThe signature with the keyid is good, but the signature was made by an expired key.r\   rx   ry   Nrz   r{   r`   r   r}   r}      s    ]JMr`   r}   c                  &    e Zd ZU dZded<   ded<   y)GpgRevKeySigzRThe signature with the keyid is good, but the signature was made by a revoked key.r\   rx   ry   Nrz   r{   r`   r   r   r      s    \JMr`   r   c                  &    e Zd ZU dZded<   ded<   y)	GpgBadSigz8The signature with the keyid has not been verified okay.r\   rx   ry   Nrz   r{   r`   r   r   r      s    BJMr`   r   c                  X    e Zd ZU dZded<   ded<   ded<   ded<   ded<   ded	<   ded
<   y)	GpgErrSigz"It was not possible to check the signature.  This may be caused by
    a missing public key or an unsupported algorithm.  A RC of 4
    indicates unknown algorithm, a 9 indicates a missing public
    key.
    r\   rx   intpkalgohashalgo	sig_classtimercfprNrz   r{   r`   r   r   r      s,    
 JKMN
IG	Hr`   r   c                      e Zd ZU dZded<   y)GpgNoPubkeyz The public key is not available.r\   rx   Nrz   r{   r`   r   r   r      
    *Jr`   r   c                      e Zd ZdZy)GpgMissingPassPhrasezNo passphrase was supplied.Nrp   rq   rr   r^   r{   r`   r   r   r      s    %r`   r   c                      e Zd ZU dZded<   y)GpgBadPassphrasez/The supplied passphrase was wrong or not given.r\   rx   Nrz   r{   r`   r   r   r      s
    9Jr`   r   c                      e Zd ZU dZded<   y)	GpgNoData  No data has been found.  Codes for WHAT are:
    - 1 :: No armored data.
    - 2 :: Expected a packet but did not find one.
    - 3 :: Invalid packet found, this may indicate a non OpenPGP
           message.
    - 4 :: Signature expected but not found.
    r\   whatNrz   r{   r`   r   r   r           Ir`   r   c                      e Zd ZU dZded<   y)GpgUnexpectedr   r\   r   Nrz   r{   r`   r   r   r      r   r`   r   c                  4    e Zd ZU dZded<   ded<   dZded<   y)	GpgErrorz]This is a generic error status message, it might be followed by error location specific data.r\   locationr   code moreN)rp   rq   rr   r^   rs   r   r{   r`   r   r   r      s    gM
ID#Nr`   r   c                  &    e Zd ZU dZded<   ded<   y)
GpgFailurezJThis is the counterpart to SUCCESS and used to indicate a program failure.r\   r   r   r   Nrz   r{   r`   r   r   r      s    TM
Ir`   r   c                      e Zd ZdZy)GpgBadArmorzThe ASCII armor is corrupted.Nr   r{   r`   r   r   r      s    'r`   r   c                      e Zd ZU dZded<   y)GpgKeyExpiredzThe key has expired.r   	timestampNrz   r{   r`   r   r   r      s
    Nr`   r   c                      e Zd ZdZy)GpgKeyRevokedz+The used key has been revoked by its owner.Nr   r{   r`   r   r   r      s    5r`   r   c                      e Zd ZU dZded<   y)GpgNoSecKeyz The secret key is not available.r\   rx   Nrz   r{   r`   r   r   r      r   r`   r   EXPSIG	EXPKEYSIG	REVKEYSIGBADSIGERRSIG	NO_PUBKEYMISSING_PASSPHRASEBAD_PASSPHRASENODATA
UNEXPECTEDERRORFAILUREBADARMOR
KEYEXPIRED
KEYREVOKED	NO_SECKEY)N)/r^   
__future__r   ansible.errorsr   ansible.galaxy.user_agentr   ansible.module_utils.urlsr   r4   rc   r(   r-   typingtdataclassesr   r   rP   urllib.errorr	   r
   TYPE_CHECKINGansible.utils.displayr   r   rD   rW   	Exceptionr[   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rL   r{   r`   r   <module>r      sO   & " ' 0 .   	   6 ,??-&4$n6 $d#
e9 
e $
e $d#  $ $d#<  $ $d#<  $ $d#  $ $d#  $ $d#,  $
 $d#&< & $& $d#|  $
 $d#  $ $d#L  $ $d#|  $ $d#  $ $d#(, ( $( $d#L  $
 $d#6L 6 $6 $d#,  $
i  i	
 i  . & i - X z  - -  !r`   