bunsenbrowser / bunsen

🔥 Bunsen Browser provides easy to use offline P2P application and file distribution that is verifiable on Android devices. https://bunsenbrowser.github.io/
117 stars 7 forks source link

IOS version of Bunsen browser #71

Open chrisekelley opened 5 years ago

chrisekelley commented 5 years ago

I'm really close to having an IOS version of Bunsen browser available; however, I've run into a roadblock: IOS won't resolve domain names like long-uuid.localhost:3000, which are created by dat-gateway in order to ensure cookie security for each dat.

ios-bunsen-loading

I have added a link to the dat-gateway home inside the loading div so I can try to fetch a dat directly from there. Here is the error message I receive:

Failed to load resource: A server with the specified hostname could not be found.  http://m7aektrwckgzylm6uzrfyaatin34na4tfqbp7fgyieimhipdvawa.localhost:3000/

screenshot 2018-11-25 at 15 19 43

screenshot 2018-11-25 at 15 37 35

Is there a way to do this on IOS without using a subdomain? Or - is there a way to register a localhost subdomain on the local IOS DNS lookup? Would Bonjour be an option? watson/bonjour looks pretty easy to bolt into dat-gateway.

On a side note, there is another error, but I don't think it is related to the domain issue:

[Error] Couldn't register protocol handler
    registerProtocol (localhost:21)
    handleLoaded (localhost:9)
    onload (localhost:43)
[Error] TypeError: navigator.registerProtocolHandler is not a function. (In 'navigator.registerProtocolHandler(
          "dat",
          location.href + "?url=%s",
          "Dat Gateway Redirection"
        )', 'navigator.registerProtocolHandler' is undefined) — localhost:15
    registerProtocol (localhost:22)
    handleLoaded (localhost:9)
    onload (localhost:43)

Looks like there is no Safari support for registerProtocolHandler.

chrisekelley commented 5 years ago

Testing on my iPad

screenshot 2018-11-25 at 18 38 31

It progresses a little further on this real device compared to the emulator: it displays a "Server error" message after trying to load the Bunsen UI dat. Log:

2018-11-25 18:39:08.093250+0100 Bunsen[248:4453] Loading Bunsen UI from datUri:http://localhost:3000/bunsen.hashbase.io/
2018-11-25 18:39:08.144133+0100 Bunsen[248:4453] connected
2018-11-25 18:39:08.144242+0100 Bunsen[248:4453] pingstatus: connected
2018-11-25 18:39:08.243682+0100 Bunsen[248:4511] WF: === Starting WebFilter logging for process Bunsen
2018-11-25 18:39:08.243776+0100 Bunsen[248:4511] WF: _userSettingsForUser mobile: {
    filterBlacklist =     (
    );
    filterWhitelist =     (
    );
    noOverridingAllowed = 1;
    restrictWeb = 1;
    useContentFilter = 0;
    useContentFilterOverrides = 0;
    whitelistEnabled = 0;
}
2018-11-25 18:39:08.243967+0100 Bunsen[248:4511] WF: _WebFilterIsActive returning: NO
2018-11-25 18:39:08.253131+0100 Bunsen[248:4453] iframe onload

I'm pretty sure this is the same very-longuuid.localhost:3000 error as before.

chrisekelley commented 5 years ago

Taking a deeper look at dat-gateway, which is a proxy server for dats. This may be an opportunity to modify dat-gateway to use bonjour/zeroconf or datdns.

I don't understand the reason for this code:

return DatLibrarian.resolve(address).then((resolvedAddress) => {
            // TODO: Detect DatDNS addresses
            let encodedAddress = hexTo32.encode(resolvedAddress)
            let redirectURL = `http://${encodedAddress}.${urlParts.host}/${path}${urlParts.search || ''}`

@RangerMauve or @rjsteinert : Why do we need to hexTo32 encode the resolved address? Is this a browser limitation?

Update: Nevermind fellas, answer is in the docs: https://github.com/RangerMauve/dat-gateway#subdomain-redirection

Please note that due to limitations in how URLs work, the dat key will be converted to it's base32 representation instead of hexadecimal 

Also - to get the ios version working, I could simply not use the redirect flag.

By default dat-gateway will serve all dats from the same origin. This means that dats using absolute URLs (starting with /) will be broken. This also means that all dats will share the same localStorage and indexedDB instances which can cause security issues.

In order to resolve these issues, you can use the --redirect flag in conjunction with the lvh.me domain to have each dat served on a subdomain.

Still, need to find a way to enable each dat to have their own localStorage and indexedDB instances.

chrisekelley commented 5 years ago

Probably the safest, most direct (quickest) way to do this for IOS is to use an external host as proxy for the dat requests, like @RangerMauve 's mauve.moe, so we can still keep the subdomains.

rjcorwin commented 5 years ago

Does .lvh.me work as opposed to .localhost?