Git Product home page Git Product logo

Comments (1)

alexforster avatar alexforster commented on July 29, 2024
def onConnectionPrompt(prompt, state, logger):
    """
    :type prompt: str
    :type state: dict[str, object]
    :type logger: logging.Logger
    :rtype: str|None
    """

    prompt = prompt.lower()

    state.setdefault('triedPassword', 0)

    state.setdefault('triedKeys', {})

    if 'enter passphrase for key' in prompt:

        key = re.findall( r'key \'(.+)\':\s*$', prompt, flags = re.IGNORECASE | re.MULTILINE )
        if key is None or len(key) != 1: key = '???'
        else: key = key[0]

        state['triedKeys'].setdefault(key, 0)

        if state['triedKeys'][key] > 2:

            logger.error('Connect failed: incorrect passphrase')
            return None

        else:

            state['triedKeys'][key] += 1
            state['triedPassword'] = 0

            logger.debug('Trying key \'{}\''.format(key))

            return state['passphrase']

    if 'password:' in prompt:

        if state['triedPassword'] > 2:

            logger.error('Connect failed: incorrect password')
            return None

        else:

            state['triedPassword'] += 1
            state['triedKeys'] = {}

            logger.debug('Trying password')

            return state['password']

    return None

from sisqo.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.