久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 ftplib 連接到 FTP TLS 1.2 服務器

Connect to FTP TLS 1.2 Server with ftplib(使用 ftplib 連接到 FTP TLS 1.2 服務器)
本文介紹了使用 ftplib 連接到 FTP TLS 1.2 服務器的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我嘗試連接到僅支持 TLS 1.2 的 FTP 服務器使用 Python 3.4.1

I try to connect to a FTP Server which only supports TLS 1.2 Using Python 3.4.1

我的代碼:

import ftplib
import ssl
ftps = ftplib.FTP_TLS()

ftps.ssl_version = ssl.PROTOCOL_TLSv1_2
print (ftps.connect('108.61.166.122',31000))
print(ftps.login('test','test123'))
ftps.prot_p()
print (ftps.retrlines('LIST'))

客戶端錯誤:

ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:598)

服務器端出錯:

  Failed TLS negotiation on control channel, disconnected. (SSL_accept(): 
  error:140760FC:SSL routines:SSL23_GET_CLIENT_HELLO:unknown protocol)

示例中的憑據正在用于測試.

The credentials in the example are working for testing.

推薦答案

最終解決方案見文末.其余的是調試問題所需的步驟.

See the end of this post for the final solution. The rest are the steps needed to debug the problem.

我嘗試使用 Python 3.4.1 連接到僅支持 TLS 1.2 的 FTP 服務器

I try to connect to a FTP Server which only supports TLS 1.2 Using Python 3.4.1

你怎么知道的?

ssl.SSLEOFError: EOF 發生違反協議 (_ssl.c:598)

ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:598)

我會建議客戶端和服務器之間的許多 SSL 問題之一,例如服務器不支持 TLS 1.2、沒有通用密碼等.這些問題很難調試,因為您要么只收到一些 SSL 警報,要么服務器將簡單地關閉沒有任何明顯原因的連接.如果您有權訪問服務器,請在服務器端查找錯誤消息.

I would suggest one of the many SSL problems between client and server, like the server not supporting TLS 1.2, no common ciphers etc. These problems are hard to debug because you either get only some SSL alert or the server will simply close the connection without any obvious reason. If you have access to the server look for error messages on the server side.

您也可以嘗試不強制使用 SSL 版本,而是使用默認版本,以便客戶端和服務器同意兩者都支持的最佳 SSL 版本.如果這仍然不起作用,請嘗試使用已知與該服務器一起工作的客戶端,并捕獲好連接和壞連接的數據包并進行比較.如果您需要有關該帖子的幫助,請將數據包捕獲發送到 cloudshark.org.

You may also try to not to enforce an SSL version but use the default instead, so that client and server will agree to the best SSL version both support. If this will still not work try with a client which is known to work with this server and make a packet capture of the good and bad connections and compare. If you need help with that post the packet captures to cloudshark.org.

Edit#1:剛剛在測試服務器上使用 python 3.4.0 和 3.4.2 進行了嘗試:

Edit#1: just tried it with python 3.4.0 and 3.4.2 against a test server:

  • python 3.4.0 執行 TLS 1.0 握手,即忽略設置
  • python 3.4.2 成功與 TLS 1.2 握手

在這兩個版本中,ftplib 都有一個小錯誤,如果 ftps.ssl_version 是別的東西,它會發送 AUTH SSL 而不是 AUTH TLSTLS 1.0,即 SSLv3 或 TLS1.1.+.雖然我懷疑這是問題的根源,但實際上可能是 FTP 服務器以不同方式處理 AUTH TLSAUTH SSL.

In both versions ftplib has the minor bug, that it sends AUTH SSL instead of AUTH TLS if ftps.ssl_version is something else then TLS 1.0, i.e. SSLv3 or TLS1.1.+. While I doubt that this is the origin of the problem it might actually be if the FTP server handles AUTH TLS and AUTH SSL differently.

編輯#2 和解決方案:

數據包捕獲顯示設置 ftps.ssl_version 無效,SSL 握手仍將僅使用 TLS 1.0 完成.查看 3.4.0 中 ftplib 的源代碼:

A packet capture shows that setting ftps.ssl_version has no effect and the SSL handshake will still be done with TLS 1.0 only. Looking at the source code of ftplib in 3.4.0 gives:

    ssl_version = ssl.PROTOCOL_TLSv1

    def __init__(self, host='', user='', passwd='', acct='', keyfile=None,
                 certfile=None, context=None,
                 timeout=_GLOBAL_DEFAULT_TIMEOUT, source_address=None):
        ....
        if context is None:
            context = ssl._create_stdlib_context(self.ssl_version,
                                                 certfile=certfile,
                                                 keyfile=keyfile)
        self.context = context

由于在調用 ftplib.FTP_TLS() 時調用了 __init__,因此 SSL 上下文將使用 ftplib 使用的默認 ssl_version 創建(ssl.PROTOCOL_TLSv1) 而不是你自己的版本.要強制執行另一個 SSL 版本,您必須為您自己的上下文提供所需的 SSL 版本.以下對我有用:

Since __init__ is called when ftplib.FTP_TLS() is called the SSL context will be created with the default ssl_version used by ftplib (ssl.PROTOCOL_TLSv1) and not with your own version. To enforce another SSL version you must to provide your own context with the needed SSL version. The following works for me:

import ftplib
import ssl

ctx = ssl._create_stdlib_context(ssl.PROTOCOL_TLSv1_2)
ftps = ftplib.FTP_TLS(context=ctx)

print (ftps.connect('108.61.166.122',31000))
print(ftps.login('test','test123'))
ftps.prot_p()
print (ftps.retrlines('LIST'))

或者,您可以全局設置協議版本,而不僅僅是為此 FTP_TLS 對象:

Alternatively you could set the protocol version globally instead of only for this FTP_TLS object:

ftplib.FTP_TLS.ssl_version = ssl.PROTOCOL_TLSv1_2
ftps = ftplib.FTP_TLS()

還有一個小而重要的觀察:看起來 ftplib 不進行任何類型的證書驗證,因為它接受了這個與名稱不匹配的自簽名證書而不會抱怨.這使得主動中間人攻擊成為可能.希望他們將來能修復這種不安全的行為,在這種情況下,這里的代碼會因為證書無效而失敗.

And just a small but important observation: it looks like that ftplib does not do any kind of certificate validation, since it accepts this self-signed certificate which does not match the name without complaining. This makes a active man-in-the-middle attack possible. Hopefully they will fix this insecure behavior in the future, in which case the code here will fail because of an invalid certificate.

這篇關于使用 ftplib 連接到 FTP TLS 1.2 服務器的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Why I cannot make an insert to Python list?(為什么我不能插入 Python 列表?)
Insert a column at the beginning (leftmost end) of a DataFrame(在 DataFrame 的開頭(最左端)插入一列)
Python psycopg2 not inserting into postgresql table(Python psycopg2 沒有插入到 postgresql 表中)
list extend() to index, inserting list elements not only to the end(list extend() 索引,不僅將列表元素插入到末尾)
How to add element in Python to the end of list using list.insert?(如何使用 list.insert 將 Python 中的元素添加到列表末尾?)
TypeError: #39;float#39; object is not subscriptable(TypeError:“浮動對象不可下標)
主站蜘蛛池模板: 在线免费黄色小视频 | av中文字幕网 | 韩国av影院 | 免费的一级视频 | 久久久久久久久综合 | 香蕉视频91 | 亚洲精品成人网 | 久久久久国产一区二区三区 | 精品免费| 91精品国产一区二区三区蜜臀 | 精品亚洲一区二区三区四区五区 | 欧美一级毛片久久99精品蜜桃 | 国产目拍亚洲精品99久久精品 | 亚洲一区二区三 | 欧美综合一区 | 蜜臀久久99精品久久久久久宅男 | 福利国产 | 亚洲一区二区三区在线视频 | 欧美日韩在线一区二区三区 | 国产精品高潮呻吟久久av野狼 | 国产精品久久国产愉拍 | 国产精品久久久久久久一区探花 | 高清亚洲| 亚洲国产一区二区在线 | 日本成人片在线观看 | 亚洲视频免费 | 欧美成年网站 | 国产亚洲一区二区三区在线 | 中文字幕成人在线 | 一区二区三区国产精品 | 在线免费观看黄色网址 | 91国在线高清视频 | 国产精品亚洲一区二区三区在线 | 国产毛片毛片 | 精品一区二区电影 | 欧美日韩成人在线 | 一级做受毛片免费大片 | 午夜久久久久久久久久一区二区 | 91综合网| 91精品久久久 | 亚洲精品性视频 |