
    ;i                         d Z ddl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  ej                  e
      Z G d d      Z G d d      Zy)a  
OpenDrop: an open source AirDrop implementation
Copyright (C) 2018  Milan Stute
Copyright (C) 2018  Alexander Heinrich

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <https://www.gnu.org/licenses/>.
    N)resource_filenamec                   8    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZy)AirDropReceiverFlagsa.  
    Recovered from sharingd`receiverSupportsX methods.
    A valid node needs to either have SUPPORTS_PIPELINING or SUPPORTS_MIXED_TYPES
    according to sharingd`[SDBonjourBrowser removeInvalidNodes:].
    Default flags on macOS: 0x3fb according to sharingd`[SDRapportBrowser defaultSFNodeFlags]
                       @         i   N)__name__
__module____qualname____doc__SUPPORTS_URLSUPPORTS_DVZIPSUPPORTS_PIPELININGSUPPORTS_MIXED_TYPESSUPPORTS_UNKNOWN1SUPPORTS_UNKNOWN2SUPPORTS_IRISSUPPORTS_DISCOVER_MAYBESUPPORTS_UNKNOWN3SUPPORTS_ASSET_BUNDLE     B/home/ubuntu/myenv/lib/python3.12/site-packages/opendrop/config.pyr   r       sF     LNM  !r   r   c                   4    e Zd Z	 	 	 	 	 	 	 	 	 	 ddZd Zd Zy)AirDropConfigNc                    t         j                  j                  |      | _        t         j                  j	                  | j                  d      | _        |t        j                         }|| _        ||}|| _	        |d}|| _
        || _        |t        j                  dd      d}|| _        |	| _        t         j                  j	                  | j                  d      | _        |
d}
|
| _        |g }|| _        |g }|| _        t(        j*                  t(        j,                  z  | _        t1        dd	      | _        t         j                  j5                  | j2                        st7        d
| j2                         t         j                  j	                  | j                  d      | _        t         j                  j	                  | j8                  d      | _        t         j                  j	                  | j8                  d      | _        t         j                  j5                  | j:                        r)t         j                  j5                  | j<                        s%t>        jA                  d       | jC                          t         j                  j	                  | j8                  d      | _"        d | _#        t         j                  j5                  | jD                        rJt>        j                  d       tI        | jD                  d      5 }|jK                         | _#        d d d        y t>        j                  d       y # 1 sw Y   y xY w)Nzdiscover.last.jsonOpenDropr   l    012xdebugawdl0opendropzcerts/apple_root_ca.pemz Need Apple root CA certificate: keyscertificate.pemkey.pemz&Key file or certificate does not existzvalidation_record.cmsz)Using provided Apple ID Validation Recordrbz#No Apple ID Validation Record found)&ospath
expanduserairdrop_dirjoindiscovery_reportsocketgethostname	host_namecomputer_namecomputer_modelportrandomrandint
service_idr%   	debug_dir	interfaceemailphoner   r   r   flagsr   root_ca_fileexistsFileNotFoundErrorkey_dir	cert_filekey_fileloggerinfocreate_default_keyrecord_filerecord_dataopenread)selfr4   r5   r6   server_portr/   r:   r=   r>   r%   r<   fs               r   __init__zAirDropConfig.__init__7   s    77--k: "T-=-=?S T**,I" %M*!'N,	"NN1n=dCJ$
d&6&6@I"=E
=E
 !55"::; 	

 .j:STww~~d//0#243D3D2EF  ww||D$4$4f=dll4EFT\\9=ww~~dnn-RWW^^DMM5RKK@A##%77<<6MN77>>$**+LLDEd&&- ,#$668 , , LL>?, ,s   MM
c                    t         j                  d| j                          t        j                  j                  | j                        st        j                  | j                         t        j                  dddddddd	d
ddddd| j                   g| j                  t        j                  t        j                  d       y )Nz&Create new self-signed certificate in opensslreqz-newkeyzrsa:2048z-nodesz-keyoutr*   z-x509z-days365z-outr)   z-subjz/CN=T)cwdstdoutstderrcheck)rF   rG   rC   r,   r-   rA   makedirs
subprocessrunr5   PIPE)rM   s    r   rH   z AirDropConfig.create_default_key   s    <T\\NKLww~~dll+KK%!t))*+  ????)	
r   c                 B   t        j                  t         j                        }|xj                  t         j                  z  c_        |j                  | j                  | j                         |j                  | j                         t         j                  |_        |S )N)keyfile)cafile)ssl
SSLContextPROTOCOL_TLSoptionsOP_NO_TLSv1load_cert_chainrD   rE   load_verify_locationsr@   	CERT_NONEverify_mode)rM   ctxs     r   get_ssl_contextzAirDropConfig.get_ssl_context   st    nn
 	s&DNNDMMB!!):):!;MM 	 
r   )
NNNiC"  z~/.opendropNNNFN)r   r   r   rP   rH   rj   r   r   r   r!   r!   6   s4     !I@V
6r   r!   )r   loggingr,   r8   r2   r`   rZ   pkg_resourcesr   	getLoggerr   rF   r   r!   r   r   r   <module>rn      sI   &  	   
  +			8	$" ",r rr   