connectors/PYRO/PSK_Adapter.py
changeset 2544 640d639d9bd8
parent 2543 2befed4d6ca8
child 2588 25f19b76c7b6
equal deleted inserted replaced
2543:2befed4d6ca8 2544:640d639d9bd8
       
     1 #!/usr/bin/env python
       
     2 # -*- coding: utf-8 -*-
       
     3 
       
     4 # This file is part of Beremiz, a Integrated Development Environment for
       
     5 # programming IEC 61131-3 automates supporting plcopen standard and CanFestival.
       
     6 #
       
     7 # Copyright (C) 2019: Edouard TISSERANT
       
     8 #
       
     9 # See COPYING file for copyrights details.
       
    10 #
       
    11 # This program is free software; you can redistribute it and/or
       
    12 # modify it under the terms of the GNU General Public License
       
    13 # as published by the Free Software Foundation; either version 2
       
    14 # of the License, or (at your option) any later version.
       
    15 #
       
    16 # This program is distributed in the hope that it will be useful,
       
    17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
       
    18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    19 # GNU General Public License for more details.
       
    20 #
       
    21 # You should have received a copy of the GNU General Public License
       
    22 # along with this program; if not, write to the Free Software
       
    23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
       
    24 
       
    25 
       
    26 """
       
    27 The TLS-PSK adapter that handles SSL connections instead of regular sockets,
       
    28 but using Pre Shared Keys instead of Certificates
       
    29 """
       
    30 
     1 from __future__ import absolute_import
    31 from __future__ import absolute_import
     2 from __future__ import print_function
    32 from __future__ import print_function
     3 
    33 
     4 import socket
    34 import socket
     5 import re
    35 import re
    10 from Pyro.protocol import _connect_socket, TCPConnection, PYROAdapter
    40 from Pyro.protocol import _connect_socket, TCPConnection, PYROAdapter
    11 from Pyro.errors import ConnectionDeniedError, ProtocolError
    41 from Pyro.errors import ConnectionDeniedError, ProtocolError
    12 from Pyro.util import Log
    42 from Pyro.util import Log
    13 
    43 
    14 
    44 
    15 # The TLS-PSK adapter that handles SSL connections instead of regular sockets,
       
    16 # but using Pre Shared Keys instead of Certificates
       
    17 #
       
    18 class PYROPSKAdapter(PYROAdapter):
    45 class PYROPSKAdapter(PYROAdapter):
    19     # This is essentialy the same as in Pyro/protocol.py
    46     """
    20     # only raw_sock wrapping into sock through sslpsk.wrap_socket was added
    47     This is essentialy the same as in Pyro/protocol.py
    21     # Pyro unfortunately doesn't allow cleaner customization
    48     only raw_sock wrapping into sock through sslpsk.wrap_socket was added
       
    49     Pyro unfortunately doesn't allow cleaner customization
       
    50     """
       
    51 
    22     def bindToURI(self, URI):
    52     def bindToURI(self, URI):
    23         with self.lock:   # only 1 thread at a time can bind the URI
    53         with self.lock:   # only 1 thread at a time can bind the URI
    24             try:
    54             try:
    25                 self.URI = URI
    55                 self.URI = URI
    26 
    56