
    Bwg                         d dl mZmZmZmZ d dlZd dlZd dlZddlm	Z	 ddl
mZmZmZmZmZmZmZmZmZmZ ddlmZmZmZmZ ddlmZ d	d
gZd ZddZd Zy)    )unicode_literalsdivisionabsolute_importprint_functionN   )Certificate)
array_from_pointerbuffer_from_bytesbytes_from_buffercastderefis_nullnewnullstruct_from_bufferunwrap   )crypt32Crypt32Const	get_errorhandle_error)str_clsextract_from_systemsystem_pathc                       y )N r       O/var/www/horilla/myenv/lib/python3.12/site-packages/oscrypto/_win/trust_list.pyr   r      s    r   c           
         i }i }t         j                   j                         }dD ]  }t        j                  t	               |      }t        |       t	               }	 t        j                  ||      }t        |      rnXt        |      }d}	d}
d}|j                  t        j                  k7  rSt        |j                  t        |j                              }
t!        j"                  |
      j%                         }||v rd||<   t        |j&                        }t)        |j*                        }	 t         j                   j-                  |      }||kD  r | r | t/        j0                  |
      d       	 t)        |j6                        }	 t         j                   j-                  |      }||k  r | r | t/        j0                  |
      d       s	 t=               }t=               }t?        t        d
d      }t        j@                  |t        jB                  t	               |      }tE               \  }}|s|t        jF                  k7  rt        |       |t        jF                  k(  rd}	ntI        tK        |            }t        j@                  |t        jB                  tM        t        d|      |      }t        |       tO        t        d|      }t        |      }|jP                  dk(  r | r | t/        j0                  |
      d       tS        t        d|jT                  |jP                        }|D ]"  }|jW                  |jY                  d             $ d}|	sTt/        j0                  |
      }|jZ                  r3|jZ                  D ]$  }|j\                  }||vs|jW                  |       & | r"|s |t/        j0                  |
      } | |d       |
||f||<   {t        j^                  |d      } t        |        d} |ja                         S # t2        t4        f$ r Y w xY w# t2        t4        f$ rH}|dk  r8|j8                  d   dz   t;        |      z   }|f|j8                  d	d z   |_        |Y d}~d}~ww xY w)a  
    Extracts trusted CA certificates from the Windows certificate store

    :param cert_callback:
        A callback that is called once for each certificate in the trust store.
        It should accept two parameters: an asn1crypto.x509.Certificate object,
        and a reason. The reason will be None if the certificate is being
        exported, otherwise it will be a unicode string of the reason it won't.

    :param callback_only_on_failure:
        A boolean - if the callback should only be called when a certificate is
        not exported.

    :raises:
        OSError - when an error is returned by the OS crypto library

    :return:
        A list of 3-element tuples:
         - 0: a byte string of a DER-encoded certificate
         - 1: a set of unicode strings that are OIDs of purposes to trust the
              certificate for
         - 2: a set of unicode strings that are OIDs of purposes to reject the
              certificate for
    )ROOTCATFNznot yet validzno longer validr   z - r   zDWORD *zCERT_ENHKEY_USAGE *CERT_ENHKEY_USAGEzexplicitly distrustedLPCSTRascii)1datetimeutcnowr   CertOpenSystemStoreWr   r   CertEnumCertificatesInStorer   r   dwCertEncodingTyper   X509_ASN_ENCODINGr   pbCertEncodedintcbCertEncodedhashlibsha1digest	pCertInfo_convert_filetime_to_timestamp	NotBeforefromtimestampr   load
ValueErrorOSErrorNotAfterargsr   setr   CertGetEnhancedKeyUsage%CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAGr   CRYPT_E_NOT_FOUNDr
   r   r   r   cUsageIdentifierr	   rgpszUsageIdentifieradddecodeextended_key_usage_valuedottedCertCloseStorevalues)!cert_callbackcallback_only_on_failurecertificates	processednowstorestore_handlecontext_pointercontext	trust_alldatar0   	cert_infonot_before_seconds
not_beforenot_after_seconds	not_afteremessage
trust_oidsreject_oidsto_readres
error_code_usage_bufferkey_usage_pointer	key_usageoidsoidcertcert_oidresults!                                    r   r   r   #   sA   4 LI



"
"
$C E33DFEB\"&%AA,P_`O'_-GIDF))\-K-KK$W%:%:C@U@U<VWD\\$'..0F" $Ifw001I!?	@S@S!T
%..<<=OP
#$%k&6&6t&<oN $ !?y?Q?Q R$--;;<MN	s?$%k&6&6t&<>OP # J%K '9a0G11BB	C &KMJ:)G)GGS!\;;; 	0w@55# FF"7F	 S!$6w@SUa$b!"#45	 --2$%k&6&6t&<>UV)22..	   8CNN3::g#678 D "''-00$($A$A 1&ooj0'OOC01
 %=<&++D1DdD)$(*k#BL y | ''a8VKEN   M (  	 ( 	 %q(ffQi%/':K2LLG%Z!&&*4AFG )	s,   0APAP$P! P!$Q;3=Q66Q;c                     t        j                  dt        j                  d| j                  | j                              d   }|dz  }|dz
  S )a  
    Windows returns times as 64-bit unsigned longs that are the number
    of hundreds of nanoseconds since Jan 1 1601. This converts it to
    a datetime object.

    :param filetime:
        A FILETIME struct object

    :return:
        An integer unix timestamp
    s   >Qs   >LLr   i l    !l
 )structunpackpackdwHighDateTimedwLowDateTime)filetimehundreds_nano_secondsseconds_since_1601s      r   r2   r2      sY     #MM##""	
 	 /9++r   )NF) 
__future__r   r   r   r   r%   r.   rg   _asn1r   _ffir	   r
   r   r   r   r   r   r   r   r   _crypt32r   r   r   r   _typesr   __all__r   r   r2   r   r   r   <module>ru      sR    R R       E D  f!R,r   