Code Monkey home page Code Monkey logo

Comments (23)

yujincheng08 avatar yujincheng08 commented on July 24, 2024

有这样想过,但是用ip的话,会不能用https,容易被mitm。
不加入依赖的话可以吗?

我的想法是备用服务器要求填上https或者http。这样有域名的可以填https,没有域名的只有ip的可以填http。

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

不,我这相当于修改了对应域名解析时获得的 ip ,完整的 https 的功能都是在的,证书检查还是在的,被 mitm 了也会有正常情况下该有的握手失败。也正因如此,试了半天自带的 httpurlconnection 无法实现,所以才考虑引入 httpclient

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

都用ip了,肯定没有证书呀,这个需求有必要吗?

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

如果说是sniproxy那种,我不推荐使用,因为容易被滥用,不可控

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

这不是“连接的指定的 ip”而是“使用指定的 ip 连接到 host”,主要是方便那些使用 cloudflare service worker 反代解锁港澳台的人,因为 anycast 的特性,可以使用任意一个使用 cloudflare cdn 的域名连接到任意一个 anycast 的 ip ,而 service worker 又是在边缘节点计算的,所以如果使用港澳台 ip 访问 service worker 就可以由 cloudflare 的港澳台节点完成反代,达到解锁的效果

我的实现类似于

curl https://host.under.cf --resolve host.under.cf:443:1.1.1.1

而不是

curl https://1.1.1.1

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

懂了,但是我还是想照顾一下只有ip没有证书的,所以想弄成手动输入https/http
如果使用https的时候,就用你那种方法

另外httpconnection不能用应该是sni/host的问题吧,除了header要有host,还要设置sni的。这样试试,可以就提pr。
我是不想再加依赖了。

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

可以参考这个,用SSLFactory来接管握手 http://javabreaks.blogspot.com/2015/12/java-ssl-handshake-with-server-name.html

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

刚才试了下,遇到了两个问题

  1. sslParameters.serverNamesSNIHostName 需要 api 24 ,现在的最小是 21
  2. b 站的 trust manager 混淆过了,好像设不了 sslSocketFactory ,会报错 Unable to extract the trust manager on b.hnt@216bb86, sslSocketFactory is class me.iacn.biliroaming.network.SSLSocketFactoryWrapper

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

api随便升没关系
自己建一个trust manager,不要用b站自己的,不是同一个classloader,我debug那边有个sslunpin,你或许可以拿来用用

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

试了下,因为b站把 okhttp 混淆了,我无法把b站的一个 okhttpclient as 成一个 okhttpclient 然后再通过 sslSocketFactory 来设 trustmanager ,有些难搞,可能还需要一些时间(主要是因为我太菜了
edit: 好像可以通过b站混淆后的 okhttp 去 setSSLSocketFactory ,稍后试试

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

为什么要用b站的okhttp,直接urlhttpsconnection里面放个factory不就好了吗

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

不知道是 HttpsURLConnection 是被 okhttp “接管”了还是什么,我已经给这个 connection 设了 SSLSocketFactory ,就是日志里的 me.iacn.biliroaming.network.SSLSocketFactoryWrapper ,但一请求就是之前提到的报错, stacktrace 里全是 okhttp 相关的 class

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

好像那个是全局的一个default的trust manager?应该可以自己弄个来改掉?

应该是这东西:HttpsURLConnection.setDefaultSSLSocketFactory

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

应该是这个了,你自己新建的也会复用b站定义的default trustmanger,自己弄一个替换掉就行:
image

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

我听群里人说,cf worker并不能用呀?有没有具体点的做法?

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

wiki 能 pr 吗,想写一下教程放上来

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

临时开放了wiki编辑权限,你试试看能不能编辑?

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

@rhjdvsgsgks 话说你可以弄个tg号加漫游和edxp的群(我同时还是edxp的维护者

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

可以编辑了,教程过几天就写
好,我研究研究 tg

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

如果只用 setDefaultSSLSocketFactory 的话好像没有成功设上,会报错 sslhandshakeexception , stacktrace 里连 HttpsURLConnection 都没出现,最相近的是一个 okhttpurlconnection
如果是和 connection.sslsocketfactory = myfactory(BiliRoamingApi.kt:314) 一起用的话还是和之前报错一样,明明是在给 HttpsURLConnection 设 sslsocketfactory ,下一跳却变成了给 okhttp 设,就像这样

2020-12-30 00:38:48.506 22531-22897/? E/BiliRoaming: java.lang.IllegalStateException: Unable to extract the trust manager on b.hnt@7235d19, sslSocketFactory is class me.iacn.biliroaming.network.SSLSocketFactoryWrapper
    b.hny.b(Unknown Source:41)
    okhttp3.w$a.a(Unknown Source:16)
    com.bilibili.lib.okhttp.huc.d.setSSLSocketFactory(Unknown Source:10)
    me.iacn.biliroaming.network.BiliRoamingApi.getContent(BiliRoamingApi.kt:314)
    me.iacn.biliroaming.network.BiliRoamingApi.getBackupUrl(BiliRoamingApi.kt:233)
    me.iacn.biliroaming.network.BiliRoamingApi.getPlayUrl(BiliRoamingApi.kt:192) 

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

@rhjdvsgsgks 因为okhttp3接管了openconnection,你可以查查 setURLStreamHandlerFactory

from biliroaming.

rhjdvsgsgks avatar rhjdvsgsgks commented on July 24, 2024

写好了,在它设之前把旧的 URLStreamHandler 备份出来,然后指定用旧的 handler 建立连接,自定义的个 factory 把 ip 传进去,建立 socket 的时候用 host 和 ip 自己建个替换掉原来的,就行了,也没有必须 n 以上的要求了
清理一下马上 pr

from biliroaming.

yujincheng08 avatar yujincheng08 commented on July 24, 2024

可以,很强

from biliroaming.

Related Issues (20)

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.