(self, *cmd)
return answer
Send a command to server

        *cmd are arbitary byte strings
Send a command to server
Send a command to server
def send_cmd(self, *cmd):
        """Send a command to server

        *cmd are arbitary byte strings

        """
        if self.keyfile is not None:
            with open(self.keyfile, 'rb') as keyfile:
                key = keyfile.read()
        else:
            key = b''
        if self.password is None:
            password = b''
        else:
            password = self.password.encode()

        tmp = [password, key]
        tmp.extend(cmd)
        cmd_chain = build_message(tmp)

        try:
            tmp_conn = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
            if self.context is not None:
                conn = self.context.wrap_socket(tmp_conn)
            else:
                conn = tmp_conn
            conn.connect(self.server_address)
        except:
            raise
        else:
            logging.info('Connected to '+self.server_address[0]+':'+
                         str(self.server_address[1]))
        try:
            conn.settimeout(60)
            if self.context is not None:
                if not isfile(self.tls_dir + '/pin'):
                    sha = sha256()
                    sha.update(conn.getpeercert(True))
                    with open(self.tls_dir + '/pin', 'wb') as pin:
                        pin.write(sha.digest())
                else:
                    with open(self.tls_dir + '/pin', 'rb') as pin:
                        pinned_key = pin.read()
                    sha = sha256()
                    sha.update(conn.getpeercert(True))
                    if pinned_key != sha.digest():
                        return (b'FAIL: Server certificate differs from '
                                b'pinned certificate')
                cert = conn.getpeercert()
                try:
                    ssl.match_hostname(cert, "KeePassC Server")
                except:
                    return b'FAIL: TLS - Hostname does not match'
            sendmsg(conn, cmd_chain)
            answer = receive(conn)
        except:
            raise
        finally:
            conn.shutdown(socket.SHUT_RDWR)
            conn.close()

        return answer
def send_cmd ( self , * cmd ) : if self . keyfile is not None : with open ( self . keyfile , 'rb' ) as keyfile : key = keyfile . read ( ) else : key = b'' if self . password is None : password = b'' else : password = self . password . encode ( ) tmp = [ password , key ] tmp . extend ( cmd ) cmd_chain = build_message ( tmp ) try : tmp_conn = socket . socket ( socket . AF_INET , socket . SOCK_STREAM ) if self . context is not None : conn = self . context . wrap_socket ( tmp_conn ) else : conn = tmp_conn conn . connect ( self . server_address ) except : raise else : logging . info ( 'Connected to ' + self . server_address [ 0 ] + ':' + str ( self . server_address [ 1 ] ) ) try : conn . settimeout ( 60 ) if self . context is not None : if not isfile ( self . tls_dir + '/pin' ) : sha = sha256 ( ) sha . update ( conn . getpeercert ( True ) ) with open ( self . tls_dir + '/pin' , 'wb' ) as pin : pin . write ( sha . digest ( ) ) else : with open ( self . tls_dir + '/pin' , 'rb' ) as pin : pinned_key = pin . read ( ) sha = sha256 ( ) sha . update ( conn . getpeercert ( True ) ) if pinned_key != sha . digest ( ) : return ( b'FAIL: Server certificate differs from ' b'pinned certificate' ) cert = conn . getpeercert ( ) try : ssl . match_hostname ( cert , "KeePassC Server" ) except : return b'FAIL: TLS - Hostname does not match' sendmsg ( conn , cmd_chain ) answer = receive ( conn ) except : raise finally : conn . shutdown ( socket . SHUT_RDWR ) conn . close ( ) return answer