2011-03-06 60 views
3

我一直在嘗試覆蓋扭曲的海螺模塊中的默認身份驗證方案。一些我認爲我明白該怎麼做的事情。該腳本本身就是this 問題的答案。我以下列方式繼承SSHUserAuthClient扭曲的海螺,重寫身份驗證

class ClientUserAuth(SSHUserAuthClient): 
    def getPassword(self, prompt = None): 
     return defer.succeed("*****") 

,我明明在劇本上我的課的調用替換SSHUserAuthClient電話。由於我無法理解的原因,腳本沒有在我的課程中執行getPassword方法,而是在超類getPassword方法中執行。有誰知道我做錯了什麼? 其他唯一的變化我做的是腳本添加以下模塊進口

from twisted.internet import defer 

謝謝!

編輯:奇怪的是正確調用子類方法getPublicKey。這只是表現怪異的getPassword方法。

回答

3

您可能實際上看到鍵盤互動身份驗證發生。這就像密碼認證,但是是分開的。您在Linux和OS X之間看到不同行爲的原因只是您的Linux和OS X SSH服務器配置不同。

重寫getGenericAnswers來處理這一個。

+0

嗯,我是一個白癡。您的建議完美起作用......再次感謝:) – rymurr 2011-03-06 23:52:14

3

有關如何實現鍵盤交互式身份驗證的一些其他詳細信息。

我以爲我第一次有這個工作,但我的服務器發送兩個交互式請求。第一個請求包含提示= [('Password: ', False)]
第二包含空提示= []

下面的代碼每到目前爲止,我已經測試服務器(紅帽,Ubuntu的,openSUSE當中)的作品

from twisted.conch.ssh import keys, userauth

class ClientUserAuth(userauth.SSHUserAuthClient): 
    def getPassword(self, prompt = None): 
     #normal password authentication 
     print "PASSWORD AUTH" 
     return defer.succeed('*****') # <-- YOUR PASSWORD 

    def getGenericAnswers(self, name, instruction, prompts): 
     #interactive password authentication 
     print "INTERACTIVE AUTH" 
     response = ['']*len(prompts) 
     for i, p in enumerate(prompts): 
      try: 
       if('password' in p[0].lower()): 
        response[i] = '*****' # <-- YOUR PASSWORD 
      except: 
       pass 
     #The response is always a sequence, and the length of it is always 
     #identical to the length of prompts 
     return defer.succeed(response) 

在扭曲啓用日誌記錄是爲調試有用海螺在引擎蓋下也在做什麼。

from twisted.python import log 
log.msg('Started Logging for A Conch Program') 
log.startLogging(sys.stdout)