Revert "Merge pull request #1831 from SkynetLabs/redirect-base64-skylink-to-base32"

This reverts commit e998882ca8, reversing
changes made to 85dd22a72e.
This commit is contained in:
Karol Wypchlo 2022-03-10 09:55:24 +01:00
parent 6e3f7d76d5
commit a743b625ff
No known key found for this signature in database
GPG Key ID: B515DE9EEBE241E1
5 changed files with 9 additions and 42 deletions

View File

@ -7,7 +7,7 @@ limit_conn downloads_by_ip 100; # ddos protection: max 100 downloads at a time
# ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones) # ensure that skylink that we pass around is base64 encoded (transform base32 encoded ones)
# this is important because we want only one format in cache keys and logs # this is important because we want only one format in cache keys and logs
set_by_lua_block $skylink { return require("skynet.skylink").base64(ngx.var.skylink) } set_by_lua_block $skylink { return require("skynet.skylink").parse(ngx.var.skylink) }
# $skylink_v1 and $skylink_v2 variables default to the same value but in case the requested skylink was: # $skylink_v1 and $skylink_v2 variables default to the same value but in case the requested skylink was:
# a) skylink v1 - it would not matter, no additional logic is executed # a) skylink v1 - it would not matter, no additional logic is executed

View File

@ -338,13 +338,7 @@ location ~ "^/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {
set $skylink $2; set $skylink $2;
set $path $3; set $path $3;
rewrite_by_lua_block { include /etc/nginx/conf.d/include/location-skylink;
local skynet_skylink = require("skynet.skylink")
local base32_skylink = skynet_skylink.base32(ngx.var.skylink)
local base32_url = ngx.var.scheme .. "://" .. base32_skylink .. "." .. ngx.var.skynet_portal_domain .. ngx.var.path .. ngx.var.is_args .. ngx.var.args
return ngx.redirect(base32_url, ngx.HTTP_MOVED_PERMANENTLY)
}
} }
location ~ "^/file/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" { location ~ "^/file/(([a-zA-Z0-9-_]{46}|[a-z0-9]{55})(/.*)?)$" {

View File

@ -37,7 +37,7 @@ location / {
ngx.var.skylink = cache_value ngx.var.skylink = cache_value
end end
ngx.var.skylink = require("skynet.skylink").base64(ngx.var.skylink) ngx.var.skylink = require("skynet.skylink").parse(ngx.var.skylink)
ngx.var.skylink_v1 = ngx.var.skylink ngx.var.skylink_v1 = ngx.var.skylink
ngx.var.skylink_v2 = ngx.var.skylink ngx.var.skylink_v2 = ngx.var.skylink
} }

View File

@ -3,13 +3,10 @@ local _M = {}
local basexx = require("basexx") local basexx = require("basexx")
local hasher = require("hasher") local hasher = require("hasher")
-- use lowercase alphabet since our skylinks are part of urls
local base32_alphabet = "0123456789abcdefghijklmnopqrstuv"
-- parse any skylink and return base64 version -- parse any skylink and return base64 version
function _M.base64(skylink) function _M.parse(skylink)
if string.len(skylink) == 55 then if string.len(skylink) == 55 then
local decoded = basexx.from_basexx(string.lower(skylink), base32_alphabet, 5) local decoded = basexx.from_basexx(string.upper(skylink), "0123456789ABCDEFGHIJKLMNOPQRSTUV", 5)
return basexx.to_url64(decoded) return basexx.to_url64(decoded)
end end
@ -17,21 +14,10 @@ function _M.base64(skylink)
return skylink return skylink
end end
-- parse any skylink and return base32 version
function _M.base32(skylink)
if string.len(skylink) == 46 then
local decoded = basexx.from_url64(skylink)
return basexx.to_basexx(decoded, base32_alphabet, 5)
end
return skylink
end
-- hash skylink into 32 bytes hash used in blocklist -- hash skylink into 32 bytes hash used in blocklist
function _M.hash(skylink) function _M.hash(skylink)
-- ensure that the skylink is base64 encoded -- ensure that the skylink is base64 encoded
local base64Skylink = _M.base64(skylink) local base64Skylink = _M.parse(skylink)
-- decode skylink from base64 encoding -- decode skylink from base64 encoding
local rawSkylink = basexx.from_url64(base64Skylink) local rawSkylink = basexx.from_url64(base64Skylink)

View File

@ -1,28 +1,15 @@
local skynet_skylink = require("skynet.skylink") local skynet_skylink = require("skynet.skylink")
describe("base64", function() describe("parse", function()
local base32 = "0404dsjvti046fsua4ktor9grrpe76erq9jot9cvopbhsvsu76r4r30" local base32 = "0404dsjvti046fsua4ktor9grrpe76erq9jot9cvopbhsvsu76r4r30"
local base64 = "AQBG8n_sgEM_nlEp3G0w3vLjmdvSZ46ln8ZXHn-eObZNjA" local base64 = "AQBG8n_sgEM_nlEp3G0w3vLjmdvSZ46ln8ZXHn-eObZNjA"
it("should return unchanged base64 skylink", function() it("should return unchanged base64 skylink", function()
assert.is.same(skynet_skylink.base64(base64), base64) assert.is.same(skynet_skylink.parse(base64), base64)
end) end)
it("should transform base32 skylink into base64", function() it("should transform base32 skylink into base64", function()
assert.is.same(skynet_skylink.base64(base32), base64) assert.is.same(skynet_skylink.parse(base32), base64)
end)
end)
describe("base32", function()
local base32 = "0404dsjvti046fsua4ktor9grrpe76erq9jot9cvopbhsvsu76r4r30"
local base64 = "AQBG8n_sgEM_nlEp3G0w3vLjmdvSZ46ln8ZXHn-eObZNjA"
it("should return unchanged base32 skylink", function()
assert.is.same(skynet_skylink.base32(base32), base32)
end)
it("should transform base64 skylink into base32", function()
assert.is.same(skynet_skylink.base32(base64), base32)
end) end)
end) end)