2020-05-28 11:07:32 +00:00
|
|
|
#pragma once
|
|
|
|
#include <optional>
|
|
|
|
#include <string>
|
2020-05-28 11:21:47 +00:00
|
|
|
#include <functional>
|
2020-05-28 11:07:32 +00:00
|
|
|
#include "address.hpp"
|
|
|
|
#include "handler.hpp"
|
2020-06-05 19:01:42 +00:00
|
|
|
#include <crypto/types.hpp>
|
2020-05-28 11:07:32 +00:00
|
|
|
|
|
|
|
namespace llarp::service
|
|
|
|
{
|
|
|
|
/// authentication status
|
2020-05-28 11:21:47 +00:00
|
|
|
enum AuthResult
|
2020-05-28 11:07:32 +00:00
|
|
|
{
|
|
|
|
/// explicitly accepted
|
2020-05-28 11:21:47 +00:00
|
|
|
eAuthAccepted = 0,
|
2020-05-28 11:07:32 +00:00
|
|
|
/// explicitly rejected
|
2020-05-28 11:21:47 +00:00
|
|
|
eAuthRejected = 1,
|
2020-05-28 11:07:32 +00:00
|
|
|
/// attempt failed
|
2020-05-28 11:21:47 +00:00
|
|
|
eAuthFailed = 2,
|
2020-05-28 11:07:32 +00:00
|
|
|
/// attempt rate limited
|
2020-05-28 11:21:47 +00:00
|
|
|
eAuthRateLimit = 3,
|
2020-05-28 11:07:32 +00:00
|
|
|
/// need mo munny
|
2020-05-28 11:21:47 +00:00
|
|
|
eAuthPaymentRequired = 4
|
2020-05-28 11:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/// maybe get auth result from string
|
|
|
|
std::optional<AuthResult>
|
|
|
|
ParseAuthResult(std::string data);
|
|
|
|
|
|
|
|
struct IAuthPolicy
|
|
|
|
{
|
|
|
|
~IAuthPolicy() = default;
|
|
|
|
|
|
|
|
/// asynchronously determine if we accept new convotag from remote service, call hook with
|
|
|
|
/// result later
|
|
|
|
virtual void
|
|
|
|
AuthenticateAsync(
|
2020-06-17 13:07:05 +00:00
|
|
|
std::shared_ptr<llarp::service::ProtocolMessage> msg,
|
|
|
|
std::function<void(AuthResult)> hook) = 0;
|
2020-05-28 11:07:32 +00:00
|
|
|
};
|
2020-06-24 13:24:07 +00:00
|
|
|
|
|
|
|
/// info needed by clients in order to authenticate to a remote endpoint
|
|
|
|
struct AuthInfo
|
|
|
|
{
|
|
|
|
std::string token;
|
|
|
|
};
|
|
|
|
|
2020-06-30 16:02:29 +00:00
|
|
|
/// what kind of backend to use for auth
|
|
|
|
enum class AuthType
|
|
|
|
{
|
|
|
|
/// no authentication
|
|
|
|
eAuthTypeNone,
|
|
|
|
/// manual whitelist
|
|
|
|
eAuthTypeWhitelist,
|
|
|
|
/// LMQ server
|
|
|
|
eAuthTypeLMQ
|
|
|
|
};
|
|
|
|
|
|
|
|
/// get an auth type from a string
|
|
|
|
/// throws std::invalid_argument if arg is invalid
|
|
|
|
AuthType
|
|
|
|
ParseAuthType(std::string arg);
|
|
|
|
|
2020-05-28 11:07:32 +00:00
|
|
|
} // namespace llarp::service
|