OwlCyberSecurity - MANAGER
Edit File: util.pyc
� �t�ac @ s� d d l m Z d d l m Z m Z m Z d d l Z d d l m Z d d l Z d � Z d � Z d � Z d � Z d � Z d e f d � � YZ d e f d � � YZ d S( i����( t Logger( t getPasswordFromKeychaint KeychainAccessErrort KeychainPasswordNotFoundN( t cryptoc C s� t t d � r� | j r� t j j | j � } | r] t d j d | d | j d | � � � n | j s� t | j � } | | _ n | j s� t d j d | � � � q� q�t d j d | � � � n� t j j | j � s� t d j d | d | j � � � n | j s t | j � } | | _ n | j sDt d j d | � � � n | j s�y t | � } | | _ Wq�t k ryq�t k r�t d j d | � � � q�Xn d S( s+ Given the APNS protocol config, extract the APN topic. @param accountName: account name @type accountName: L{str} @param protocol: APNS protocol name @type protocol: L{str} @param protoConfig: APNS specific config @type protoConfig: L{dict} @raise: ValueError t __SecureTransport__sD The {proto} APNS Keychain Identity ({cert}) cannot be used: {reason}t protot certt reasons! Cannot extract {proto} APNS topics) No {proto} APNS Keychain Identity was sets0 The {proto} APNS certificate ({cert}) is missings5 Cannot retrieve {proto} APNS passphrase from keychainN( t hasattrt OpenSSLt KeychainIdentityR t check_keychain_identityt ValueErrort formatt Topict getAPNTopicFromIdentityt ost patht existst CertificatePatht getAPNTopicFromCertificatet PassphraseR R R ( t protocolt accountNamet protoConfigt errort topict passphrase( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyt getAPNTopicFromConfig sD c C s: t | � � } | j � } Wd QXt t j t j | � � S( s( Given the path to a certificate, extract the UID value portion of the subject, which in this context is used for the associated APN topic. @param certPath: file path of the certificate @type certPath: C{str} @return: C{str} topic, or empty string if value is not found N( t opent readt getAPNTopicFromX509R t load_certificatet FILETYPE_PEM( t certPatht ft certData( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyR ` s c C s t t j d | � � S( s- Given a keychain identity certificate, extract the UID value portion of the subject, which in this context is used for the associated APN topic. @param identity: keychain identity to lookup @type identity: C{str} @return: C{str} topic, or empty string if value is not found N( R R R! t None( t identity( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyR o s c C sC | j � } | j � } x$ | D] \ } } | d k r | Sq Wd S( s Given an L{X509} certificate, extract the UID value portion of the subject, which in this context is used for the associated APN topic. @param x509: the certificate @type x509: L{X509} @return: C{str} topic, or empty string if value is not found t UIDt ( t get_subjectt get_components( t x509t subjectt componentst namet value( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyR | s c C s4 | s t Sy | j d � Wn t k r/ t SXt S( sN Return True if token is in hex and is not empty, False otherwise t hex( t Falset decodet TypeErrort True( t token( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyt validToken� s t TokenHistoryc B s, e Z d Z d d � Z d � Z d � Z RS( s� Manages a queue of tokens and corresponding identifiers. Queue is always kept below maxSize in length (older entries removed as needed). i� c C s | | _ d | _ g | _ d S( s� @param maxSize: How large the history is allowed to grow. Once this size is reached, older entries are pruned as needed. @type maxSize: C{int} i N( t maxSizet identifiert history( t selfR9 ( ( s+ /opt/cpanel-ccs/calendarserver/push/util.pyt __init__� s c C s= | j d 7_ | j j | j | f � | j | j 4| j S( s� Add a token to the history, and return the new identifier associated with this token. Identifiers begin at 1 and increase each time this is called. If the number of items in the history exceeds maxSize, older entries are removed to get the size down to maxSize. @param token: The token to store @type token: C{str} @returns: the message identifier associated with this token, C{int} i ( R: R; t appendR9 ( R<