安全套接字、dns 和 getnameinfo 超时
就在昨天,在调试我的 Android 应用程序时,我发现每当无法进行反向 dns 查找时,我的连接就会花费大量时间来启动(大约 20-30 秒)。
我设法将源范围缩小到 InetAddress.getHostName() 调用(这就是花费大量时间的地方),但我(不幸的是)对如何解决它一无所知。据我所知,没有 DNS 验证的 SSL 连接更容易受到 MITM 攻击;在这种情况下,我宁愿通知用户有关问题,而不是让他永远等待应用程序加载和连接。我一直在浏览网络来寻找答案,我可以找到在java中解决这个问题的方法,但它们都不适用于android(至少我无法缓存inetaddress,也无法使用替代类来解析我的主机名具有 impl 属性)。
有什么办法可以将超时限制在一些合理的超时(例如:2-3秒)?我想节省将 ssl 套接字重写为 android 本机代码所需的时间。
谢谢!
just yesterday while debugging my android app i figured out that whenever reverse dns lookup is not possible my connection takes bunch loads of time to initiate (roughly about 20-30 seconds).
i managed to narrow down the source to InetAddress.getHostName() call (that's where it takes so much time) but i am (unfortunately) clueless on how i could work it around. I understand that SSL connections with no DNS verification are more prone to MITM attacks; in such cases i would prefer to notify the user about issues rather than make him wait forever for the application to load and connect. i've been browsing the web back and forth looking for the answer, i could find ways to fix that in java, but none of them applies to android (at least i couldn't cache inetaddress nor use alternative classes to resolve my host names with impl property).
is there any way i could limit the timeout to some reasonable timeouts (say: 2-3 seconds)? i would like to save the time i'd need to spend re-writing ssl sockets as android native code.
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这与 GLIBC 中的一个错误有关,即使没有配置 ipv6 接口,该错误也会尝试反向查找 ipv6 主机名。
这里讨论问题和修复:
https://bugs.launchpad.net /ubuntu/+source/eglibc/+bug/417757
如果更新 /etc/hosts 文件以覆盖特定 IP 地址,它应该可以工作
this is (was) related to a bug in GLIBC trying to reverse lookup ipv6 host names even if no ipv6 interfaces were configured.
the problem and fix are discussed here:
https://bugs.launchpad.net/ubuntu/+source/eglibc/+bug/417757
it should work if /etc/hosts file is updated to cover particular IP address