-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.conf
54 lines (40 loc) · 1.47 KB
/
default.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
error_log logs/error.log info;
server {
server_name localhost;
listen 8080;
charset utf-8;
charset_types application/json;
default_type application/json;
location / {
resolver 127.0.0.11;
access_by_lua_block {
local cjson = require "cjson"
local gotipathPolicy = ngx.var.cookie_gotipath_policy
local gotipathSignature = ngx.var.cookie_gotipath_signature
local b64 = require("ngx.base64")
local res, err
res, err = b64.decode_base64url(gotipathPolicy)
if not res then
ngx.log(ngx.ERR, err)
end
local str = require('resty.string')
local sha256 = require('resty.sha256')
-- dynamic call from tm portal
local secret = "npkj0qkaczlkapq5uuzr2yh1cftut4zdz8o6ifb0dff4xq4vh0comb82tdt506fh"
-- TODO expire times checking
local hasher = sha256:new()
local msg = secret .. gotipathPolicy
hasher:update(msg)
local hmac_str = str.to_hex(hasher:final())
local signature = '0'..hmac_str:sub(0,20)
if gotipathSignature ~= signature then
ngx.status = 401
ngx.header.content_type = 'application/json'
ngx.print('{"error":"not authorized"}')
ngx.exit(401)
end
}
## Upstram pulling from tm portal
proxy_pass https://console.gotipath.com;
}
}