3 ft` @s<ddlmZddlmZddlmZddlmZddlZddlZddl Zddl Zddl Z ddl Z ddl Z ddlZyddlmZddlmZWn<ek rddlZGdd d eZGd d d eZYnXd Ze jd ZddZddZddZddZddZddZejddZddZ d"ddZ!Gd d!d!eZ"dS)#)print_function)absolute_import)unicode_literals)_N)Context)Datac@sVeZdZddZddZddZeddZejd dZd d Z d d Z ddZ dS)rcCstj|jd<dS)Nctx)gpgmer__dict__)selfr /usr/lib/python3.6/crypto.py__init__*szContext.__init__cCs|S)Nr )r r r r __enter__-szContext.__enter__cCsdS)Nr )r typevaluetbr r r __exit__0szContext.__exit__cCs|jjS)N)rarmor)r r r r r3sz Context.armorcCs ||j_dS)N)rr)r rr r r r7scCs$t|trtj|}|jj|dS)N) isinstanceZ basestringioBytesIOrimport_)r key_for r r op_import;s  zContext.op_importcCs|jj||dS)N)rZexport)r patternmodeZkeydatar r r op_export@szContext.op_exportcCs t|j|S)N)getattrr)r namer r r __getattr__CszContext.__getattr__N) __name__ __module__ __qualname__rrrpropertyrsetterrrr r r r r r)s rc@s4eZdZddZddZddZddZd d Zd S) rcCstj|jd<dS)Nbuf)rrr )r r r r rHsz Data.__init__cCs|S)Nr )r r r r rKszData.__enter__cCsdS)Nr )r rrrr r r rNsz Data.__exit__cCs |jjS)N)r&getvalue)r r r r readQsz Data.readcCs t|j|S)N)rr&)r rr r r r TszData.__getattr__N)r!r"r#rrrr(r r r r r rGs rZ GNUPGHOMEdnfcCstjjdd|jDS)Ncss|]}|jr|VqdS)N)Zcan_sign).0subkeyr r r ]sz*_extract_signing_subkey..)r)utilfirstZsubkeys)keyr r r _extract_signing_subkey\sr0cs(fddtdtdD}dj|S)Nc3s|]}||dVqdS)Nr )r*i)fpr_hexr r r,asz)_printable_fingerprint..rr1 )rangelenjoin)r3Zsegmentsr )r3r _printable_fingerprint`sr8cCs|j}t|}x|jD]x}xrt||D]d}|j}||krNtjtd|j|q&|j j |s\q&t j j j|j|j|ddtjtd|j|q&WqWdS)Nzrepo %s: 0x%s already importedF)gpgdirZ make_ro_copyzrepo %s: imported key 0x%s.)Z _pubring_dirkeyids_from_pubringZgpgkeyretrieveid_loggerdebugridZ _key_importZ_confirmr)ZyumZmiscZimport_key_to_pubringraw_keyshort_id)repor9Z known_keyskeyurlkeyinfokeyidr r r import_repo_keyses   rFcCsltjj|sgSt|Jt8}g}x,|jD] }t|}|dk r0|j|jq0W|SQRXWdQRXdS)N) ospathexists pubring_dirrkeylistr0appendrE)r9rZkeyidskr+r r r r:vs r:cCs8td|j|jt|j|jjddf}tjd|dS)NzLImporting GPG key 0x%s: Userid : "%s" Fingerprint: %s From : %szfile://z%s) rrAuseridr8 fingerprinturlreplacer=critical)rDmsgr r r log_key_imports rUcCs8t||tjjjkr&tjtdntjtddS)Nz0Verified using DNS record with DNSSEC signature.zNOT verified using DNS record.)rUr)ZdnssecZValidityZVALIDr=rSr)rDZ dns_resultr r r log_dns_key_importsrVc csFtjjtd}|tjt<z dVWd|dkr6tjt=n |tjt<XdS)N)rGenvironget GPG_HOME_ENV)rJZorigr r r rJs   rJcCstj}g}t|t}|j|x2|jD]&}t|}|dkrHq2|jt||q2Wd|_ xF|D]>}t .}|j |j d||j dtj|j|_WdQRXqhWWdQRXWdQRXtjj||S)NTr)tempfileZmkdtemprJrrrKr0rLKeyrrrr<seekrGSEEK_SETr(r@r)r-Zrm_rf)rZpb_dirkeyinfosrr/r+infoZsinkr r r rawkey2infoss"  , r`c CsZ|jdrtjtd|j|tjj||d}t|}WdQRXx|D] }||_ qHW|S)Nzhttp:z.retrieving repo key for %s unencrypted from %s)rB) startswithr=Zwarningrr?r)r-Z_urlopenr`rQ)rCrBZhandler^rDr r r r;s   r;c@s,eZdZddZeddZeddZdS)r[cCs6|j|_|j|_d|_|j|_d|_|jdj|_ dS)Nr) rEr<ZfprrPr@Z timestamprQZuidsZuidrO)r r/r+r r r rs z Key.__init__cCs&tjjr dnd}|jddjd|S)N00i)r)ZpycompZPY3r<rjust)r Zrjr r r rAsz Key.short_idcCs |jjS)N)rAlower)r r r r rpm_idsz Key.rpm_idN)r!r"r#rr$rArgr r r r r[s r[)N)#Z __future__rrrZdnf.i18nr contextlibZ dnf.pycompr)Zdnf.utilZ dnf.yum.miscrZloggingrGrZZgpgrr ImportErrorr objectrYZ getLoggerr=r0r8rFr:rUrVcontextmanagerrJr`r;r[r r r r s<