pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

使用 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:“浮動對象不可下標)
主站蜘蛛池模板: 不锈钢螺丝 - 六角螺丝厂家 - 不锈钢紧固件 - 万千紧固件--紧固件一站式采购 | YAGEO国巨电容|贴片电阻|电容价格|三星代理商-深圳市巨优电子有限公司 | 广州各区危化证办理_危险化学品经营许可证代办 | 无线对讲-无线对讲系统解决方案-重庆畅博通信 | 数控走心机-双主轴走心机厂家-南京建克| 沉降天平_沉降粒度仪_液体比重仪-上海方瑞仪器有限公司 | 杭州ROHS检测仪-XRF测试仪价格-百科 | 世界箱包品牌十大排名,女包小众轻奢品牌推荐200元左右,男包十大奢侈品牌排行榜双肩,学生拉杆箱什么品牌好质量好 - Gouwu3.com | 上海平衡机-单面卧式动平衡机-万向节动平衡机-圈带动平衡机厂家-上海申岢动平衡机制造有限公司 | 拖鞋定制厂家-品牌拖鞋代加工厂-振扬实业中国高端拖鞋大型制造商 | 安徽成考网-安徽成人高考网| 铣床|万能铣床|立式铣床|数控铣床|山东滕州万友机床有限公司 | 电线电缆厂家|沈阳电缆厂|电线厂|沈阳英联塑力线缆有限公司 | 云阳人才网_云阳招聘网_云阳人才市场_云阳人事人才网_云阳人家招聘网_云阳最新招聘信息 | 印刷人才网 印刷、包装、造纸,中国80%的印刷企业人才招聘选印刷人才网! | IHDW_TOSOKU_NEMICON_EHDW系列电子手轮,HC1系列电子手轮-上海莆林电子设备有限公司 | 欧美日韩国产一区二区三区不_久久久久国产精品无码不卡_亚洲欧洲美洲无码精品AV_精品一区美女视频_日韩黄色性爱一级视频_日本五十路人妻斩_国产99视频免费精品是看4_亚洲中文字幕无码一二三四区_国产小萍萍挤奶喷奶水_亚洲另类精品无码在线一区 | 一路商机网-品牌招商加盟优选平台-加盟店排行榜平台 | 防水套管|柔性防水套管|伸缩器|伸缩接头|传力接头-河南伟创管道 防水套管_柔性防水套管_刚性防水套管-巩义市润达管道设备制造有限公司 | 盘古网络技术有限公司| 聚天冬氨酸,亚氨基二琥珀酸四钠,PASP,IDS - 远联化工 | 篷房[仓储-婚庆-展览-活动]生产厂家-江苏正德装配式帐篷有限公司 | 云南标线|昆明划线|道路标线|交通标线-就选云南云路施工公司-云南云路科技有限公司 | 海外仓系统|国际货代系统|退货换标系统|WMS仓储系统|海豚云 | 湖州织里童装_女童男童中大童装_款式多尺码全_织里儿童网【官网】-嘉兴嘉乐网络科技有限公司 | 超细粉碎机|超微气流磨|气流分级机|粉体改性设备|超微粉碎设备-山东埃尔派粉碎机厂家 | 红酒招商加盟-葡萄酒加盟-进口红酒代理-青岛枞木酒业有限公司 | 扬子叉车厂家_升降平台_电动搬运车|堆高车-扬子仓储叉车官网 | 天坛家具官网 | 家庭教育吧-在线家庭教育平台,专注青少年家庭教育 | 流量检测仪-气密性检测装置-密封性试验仪-东莞市奥图自动化科技有限公司 | 塑料瓶罐_食品塑料瓶_保健品塑料瓶_调味品塑料瓶–东莞市富慷塑料制品有限公司 | 3d可视化建模_三维展示_产品3d互动数字营销_三维动画制作_3D虚拟商城 【商迪3D】三维展示服务商 广东健伦体育发展有限公司-体育工程配套及销售运动器材的体育用品服务商 | 万博士范文网-您身边的范文参考网站Vanbs.com | 微波消解仪器_智能微波消解仪报价_高压微波消解仪厂家_那艾 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 广州云仓代发-昊哥云仓专业电商仓储托管外包代发货服务 | 车间除尘设备,VOCs废气处理,工业涂装流水线,伸缩式喷漆房,自动喷砂房,沸石转轮浓缩吸附,机器人喷粉线-山东创杰智慧 | 浙江栓钉_焊钉_剪力钉厂家批发_杭州八建五金制造有限公司 | 低噪声电流前置放大器-SR570电流前置放大器-深圳市嘉士达精密仪器有限公司 | 东莞画册设计_logo/vi设计_品牌包装设计 - 华略品牌设计公司 |