mirror of https://github.com/aria2/aria2
Remove request pre-authorization again
parent
8f2af33b6d
commit
70a80b1455
|
@ -253,7 +253,6 @@ bool HttpServerBodyCommand::execute()
|
||||||
case RPC_TYPE_JSONP: {
|
case RPC_TYPE_JSONP: {
|
||||||
std::string callback;
|
std::string callback;
|
||||||
std::unique_ptr<ValueBase> json;
|
std::unique_ptr<ValueBase> json;
|
||||||
auto preauthorized = rpc::RpcRequest::MUST_AUTHORIZE;
|
|
||||||
ssize_t error = 0;
|
ssize_t error = 0;
|
||||||
if(httpServer_->getRequestType() == RPC_TYPE_JSONP) {
|
if(httpServer_->getRequestType() == RPC_TYPE_JSONP) {
|
||||||
json::JsonGetParam param = json::decodeGetParams(query);
|
json::JsonGetParam param = json::decodeGetParams(query);
|
||||||
|
@ -284,7 +283,7 @@ bool HttpServerBodyCommand::execute()
|
||||||
}
|
}
|
||||||
Dict* jsondict = downcast<Dict>(json);
|
Dict* jsondict = downcast<Dict>(json);
|
||||||
if(jsondict) {
|
if(jsondict) {
|
||||||
auto res = rpc::processJsonRpcRequest(jsondict, e_, preauthorized);
|
auto res = rpc::processJsonRpcRequest(jsondict, e_);
|
||||||
sendJsonRpcResponse(res, callback);
|
sendJsonRpcResponse(res, callback);
|
||||||
} else {
|
} else {
|
||||||
List* jsonlist = downcast<List>(json);
|
List* jsonlist = downcast<List>(json);
|
||||||
|
@ -296,10 +295,7 @@ bool HttpServerBodyCommand::execute()
|
||||||
Dict* jsondict = downcast<Dict>(*i);
|
Dict* jsondict = downcast<Dict>(*i);
|
||||||
if (jsondict) {
|
if (jsondict) {
|
||||||
auto resp =
|
auto resp =
|
||||||
rpc::processJsonRpcRequest(jsondict, e_, preauthorized);
|
rpc::processJsonRpcRequest(jsondict, e_);
|
||||||
if (resp.code == 0) {
|
|
||||||
preauthorized = rpc::RpcRequest::PREAUTHORIZED;
|
|
||||||
}
|
|
||||||
results.push_back(std::move(resp));
|
results.push_back(std::move(resp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -85,11 +85,9 @@ void RpcMethod::authorize(RpcRequest& req, DownloadEngine* e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!e || (req.authorization != RpcRequest::PREAUTHORIZED &&
|
if (!e || !e->validateToken(token)) {
|
||||||
!e->validateToken(token))) {
|
|
||||||
throw DL_ABORT_EX("Unauthorized");
|
throw DL_ABORT_EX("Unauthorized");
|
||||||
}
|
}
|
||||||
req.authorization = RpcRequest::PREAUTHORIZED;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcResponse RpcMethod::execute(RpcRequest req, DownloadEngine* e)
|
RpcResponse RpcMethod::execute(RpcRequest req, DownloadEngine* e)
|
||||||
|
|
|
@ -1367,7 +1367,6 @@ std::unique_ptr<ValueBase> SystemMulticallRpcMethod::process
|
||||||
|
|
||||||
RpcResponse SystemMulticallRpcMethod::execute(RpcRequest req, DownloadEngine *e)
|
RpcResponse SystemMulticallRpcMethod::execute(RpcRequest req, DownloadEngine *e)
|
||||||
{
|
{
|
||||||
auto preauthorized = RpcRequest::MUST_AUTHORIZE;
|
|
||||||
auto authorized = RpcResponse::AUTHORIZED;
|
auto authorized = RpcResponse::AUTHORIZED;
|
||||||
try {
|
try {
|
||||||
const List* methodSpecs = checkRequiredParam<List>(req, 0);
|
const List* methodSpecs = checkRequiredParam<List>(req, 0);
|
||||||
|
@ -1403,14 +1402,11 @@ RpcResponse SystemMulticallRpcMethod::execute(RpcRequest req, DownloadEngine *e)
|
||||||
methodName->s(),
|
methodName->s(),
|
||||||
std::move(paramsList),
|
std::move(paramsList),
|
||||||
nullptr,
|
nullptr,
|
||||||
preauthorized,
|
|
||||||
req.jsonRpc
|
req.jsonRpc
|
||||||
};
|
};
|
||||||
RpcResponse res = getMethod(methodName->s())->execute(std::move(r), e);
|
RpcResponse res = getMethod(methodName->s())->execute(std::move(r), e);
|
||||||
if(rpc::not_authorized(res)) {
|
if(rpc::not_authorized(res)) {
|
||||||
authorized = RpcResponse::NOTAUTHORIZED;
|
authorized = RpcResponse::NOTAUTHORIZED;
|
||||||
} else {
|
|
||||||
preauthorized = RpcRequest::PREAUTHORIZED;
|
|
||||||
}
|
}
|
||||||
if(res.code == 0) {
|
if(res.code == 0) {
|
||||||
auto l = List::g();
|
auto l = List::g();
|
||||||
|
|
|
@ -39,22 +39,20 @@ namespace aria2 {
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
RpcRequest::RpcRequest()
|
RpcRequest::RpcRequest()
|
||||||
: authorization{RpcRequest::MUST_AUTHORIZE}, jsonRpc{false}
|
: jsonRpc{false}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
RpcRequest::RpcRequest(std::string methodName,
|
RpcRequest::RpcRequest(std::string methodName,
|
||||||
std::unique_ptr<List> params)
|
std::unique_ptr<List> params)
|
||||||
: methodName{std::move(methodName)}, params{std::move(params)},
|
: methodName{std::move(methodName)}, params{std::move(params)}, jsonRpc{false}
|
||||||
authorization{RpcRequest::MUST_AUTHORIZE}, jsonRpc{false}
|
|
||||||
{}
|
{}
|
||||||
|
|
||||||
RpcRequest::RpcRequest(std::string methodName,
|
RpcRequest::RpcRequest(std::string methodName,
|
||||||
std::unique_ptr<List> params,
|
std::unique_ptr<List> params,
|
||||||
std::unique_ptr<ValueBase> id,
|
std::unique_ptr<ValueBase> id,
|
||||||
RpcRequest::preauthorization_t authorization,
|
|
||||||
bool jsonRpc)
|
bool jsonRpc)
|
||||||
: methodName{std::move(methodName)}, params{std::move(params)},
|
: methodName{std::move(methodName)}, params{std::move(params)},
|
||||||
id{std::move(id)}, authorization{authorization}, jsonRpc{jsonRpc}
|
id{std::move(id)}, jsonRpc{jsonRpc}
|
||||||
{}
|
{}
|
||||||
|
|
||||||
} // namespace rpc
|
} // namespace rpc
|
||||||
|
|
|
@ -46,15 +46,9 @@ namespace aria2 {
|
||||||
namespace rpc {
|
namespace rpc {
|
||||||
|
|
||||||
struct RpcRequest {
|
struct RpcRequest {
|
||||||
enum preauthorization_t {
|
|
||||||
MUST_AUTHORIZE,
|
|
||||||
PREAUTHORIZED
|
|
||||||
};
|
|
||||||
|
|
||||||
std::string methodName;
|
std::string methodName;
|
||||||
std::unique_ptr<List> params;
|
std::unique_ptr<List> params;
|
||||||
std::unique_ptr<ValueBase> id;
|
std::unique_ptr<ValueBase> id;
|
||||||
preauthorization_t authorization;
|
|
||||||
bool jsonRpc;
|
bool jsonRpc;
|
||||||
|
|
||||||
RpcRequest();
|
RpcRequest();
|
||||||
|
@ -65,7 +59,6 @@ struct RpcRequest {
|
||||||
RpcRequest(std::string methodName,
|
RpcRequest(std::string methodName,
|
||||||
std::unique_ptr<List> params,
|
std::unique_ptr<List> params,
|
||||||
std::unique_ptr<ValueBase> id,
|
std::unique_ptr<ValueBase> id,
|
||||||
preauthorization_t authorization,
|
|
||||||
bool jsonRpc = false);
|
bool jsonRpc = false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -165,7 +165,6 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx,
|
||||||
// TODO Only process text frame
|
// TODO Only process text frame
|
||||||
ssize_t error = 0;
|
ssize_t error = 0;
|
||||||
auto json = wsSession->parseFinal(nullptr, 0, error);
|
auto json = wsSession->parseFinal(nullptr, 0, error);
|
||||||
auto preauthorized = RpcRequest::MUST_AUTHORIZE;
|
|
||||||
if(error < 0) {
|
if(error < 0) {
|
||||||
A2_LOG_INFO("Failed to parse JSON-RPC request");
|
A2_LOG_INFO("Failed to parse JSON-RPC request");
|
||||||
RpcResponse res
|
RpcResponse res
|
||||||
|
@ -177,7 +176,7 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx,
|
||||||
auto e = wsSession->getDownloadEngine();
|
auto e = wsSession->getDownloadEngine();
|
||||||
if(jsondict) {
|
if(jsondict) {
|
||||||
RpcResponse res =
|
RpcResponse res =
|
||||||
processJsonRpcRequest(jsondict, e, preauthorized);
|
processJsonRpcRequest(jsondict, e);
|
||||||
addResponse(wsSession, res);
|
addResponse(wsSession, res);
|
||||||
} else {
|
} else {
|
||||||
List* jsonlist = downcast<List>(json);
|
List* jsonlist = downcast<List>(json);
|
||||||
|
@ -188,10 +187,7 @@ void onMsgRecvCallback(wslay_event_context_ptr wsctx,
|
||||||
eoi = jsonlist->end(); i != eoi; ++i) {
|
eoi = jsonlist->end(); i != eoi; ++i) {
|
||||||
Dict* jsondict = downcast<Dict>(*i);
|
Dict* jsondict = downcast<Dict>(*i);
|
||||||
if (jsondict) {
|
if (jsondict) {
|
||||||
auto resp = processJsonRpcRequest(jsondict, e, preauthorized);
|
auto resp = processJsonRpcRequest(jsondict, e);
|
||||||
if (resp.code == 0) {
|
|
||||||
preauthorized = RpcRequest::PREAUTHORIZED;
|
|
||||||
}
|
|
||||||
results.push_back(std::move(resp));
|
results.push_back(std::move(resp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,8 +77,7 @@ RpcResponse createJsonRpcErrorResponse(int code,
|
||||||
std::move(id)};
|
std::move(id)};
|
||||||
}
|
}
|
||||||
|
|
||||||
RpcResponse processJsonRpcRequest(Dict* jsondict, DownloadEngine* e,
|
RpcResponse processJsonRpcRequest(Dict* jsondict, DownloadEngine* e)
|
||||||
RpcRequest::preauthorization_t authorization)
|
|
||||||
{
|
{
|
||||||
auto id = jsondict->popValue("id");
|
auto id = jsondict->popValue("id");
|
||||||
if(!id) {
|
if(!id) {
|
||||||
|
@ -102,7 +101,7 @@ RpcResponse processJsonRpcRequest(Dict* jsondict, DownloadEngine* e,
|
||||||
}
|
}
|
||||||
A2_LOG_INFO(fmt("Executing RPC method %s", methodName->s().c_str()));
|
A2_LOG_INFO(fmt("Executing RPC method %s", methodName->s().c_str()));
|
||||||
RpcRequest req =
|
RpcRequest req =
|
||||||
{methodName->s(), std::move(params), std::move(id), authorization, true};
|
{methodName->s(), std::move(params), std::move(id), true};
|
||||||
return getMethod(methodName->s())->execute(std::move(req), e);
|
return getMethod(methodName->s())->execute(std::move(req), e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -64,8 +64,7 @@ RpcResponse createJsonRpcErrorResponse(int code,
|
||||||
std::unique_ptr<ValueBase> id);
|
std::unique_ptr<ValueBase> id);
|
||||||
|
|
||||||
// Processes JSON-RPC request |jsondict| and returns the result.
|
// Processes JSON-RPC request |jsondict| and returns the result.
|
||||||
RpcResponse processJsonRpcRequest(Dict* jsondict, DownloadEngine* e,
|
RpcResponse processJsonRpcRequest(Dict* jsondict, DownloadEngine* e);
|
||||||
RpcRequest::preauthorization_t authorization);
|
|
||||||
|
|
||||||
} // namespace rpc
|
} // namespace rpc
|
||||||
|
|
||||||
|
|
|
@ -200,14 +200,6 @@ void RpcMethodTest::testAuthorize()
|
||||||
auto res = m.execute(std::move(req), e_.get());
|
auto res = m.execute(std::move(req), e_.get());
|
||||||
CPPUNIT_ASSERT_EQUAL(1, res.code);
|
CPPUNIT_ASSERT_EQUAL(1, res.code);
|
||||||
}
|
}
|
||||||
// secret token set and bad token: prefixed parameter is given, but preauthorized
|
|
||||||
{
|
|
||||||
auto req = createReq(GetVersionRpcMethod::getMethodName());
|
|
||||||
req.authorization = RpcRequest::PREAUTHORIZED;
|
|
||||||
req.params->append("token:foo2");
|
|
||||||
auto res = m.execute(std::move(req), e_.get());
|
|
||||||
CPPUNIT_ASSERT_EQUAL(0, res.code);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void RpcMethodTest::testAddUri()
|
void RpcMethodTest::testAddUri()
|
||||||
|
|
Loading…
Reference in New Issue