Commit 071d9bba authored by Sylvain Berfini's avatar Sylvain Berfini 🎩

Moved module-auth to public headers

parent d5d248a8
Pipeline #2145 passed with stages
in 14 minutes and 1 second
......@@ -22,6 +22,8 @@
set(HEADER_FILES
agent.hh
auth-module.hh
auth-status.hh
common.hh
configmanager.hh
event.hh
......@@ -35,6 +37,7 @@ set(HEADER_FILES
forkmessagecontext.hh
global.hh
logmanager.hh
module-auth.hh
module-registrar.hh
module-router.hh
module.hh
......
......@@ -22,7 +22,7 @@
#include <sofia-sip/auth_module.h>
#include "auth-status.hh"
#include <flexisip/auth-status.hh>
namespace flexisip {
......
......@@ -18,7 +18,7 @@
#pragma once
#include "auth/flexisip-auth-module.hh"
#include <flexisip/auth-module.hh>
#include <flexisip/module.hh>
namespace flexisip {
......@@ -35,7 +35,7 @@ public:
void onDeclare(GenericStruct *mc) override;
void onLoad(const GenericStruct *mc) override;
FlexisipAuthModule *findAuthModule(const std::string name);
AuthModule *findAuthModule(const std::string name);
static bool containsDomain(const std::list<std::string> &d, const char *name);
bool handleTestAccountCreationRequests(std::shared_ptr<RequestSipEvent> &ev);
bool isTrustedPeer(std::shared_ptr<RequestSipEvent> &ev);
......@@ -47,24 +47,13 @@ public:
bool doOnConfigStateChanged(const ConfigValue &conf, ConfigState state) override;
private:
class RequestAuthStatus : public FlexisipAuthStatus {
public:
RequestAuthStatus(const std::shared_ptr<RequestSipEvent> &ev): FlexisipAuthStatus(), mEv(ev) {}
~RequestAuthStatus() override = default;
const std::shared_ptr<RequestSipEvent> &getRequestEvent() const {return mEv;}
private:
std::shared_ptr<RequestSipEvent> mEv;
};
void processAuthModuleResponse(AuthStatus &as);
bool empty(const char *value) {return value == NULL || value[0] == '\0';}
const char *findIncomingSubjectInTrusted(std::shared_ptr<RequestSipEvent> &ev, const char *fromDomain);
void loadTrustedHosts(const ConfigStringList &trustedHosts);
static ModuleInfo<Authentication> sInfo;
std::map<std::string, std::unique_ptr<FlexisipAuthModule>> mAuthModules;
std::map<std::string, std::unique_ptr<AuthModule>> mAuthModules;
std::list<std::string> mDomains;
std::list<BinaryIp> mTrustedHosts;
std::list<std::string> mTrustedClientCertificates;
......
......@@ -24,7 +24,7 @@
#include <flexisip/logmanager.hh>
#include "auth-module.hh"
#include <flexisip/auth-module.hh>
using namespace std;
using namespace flexisip;
......
......@@ -26,7 +26,7 @@
#include <sofia-sip/msg_types.h>
#include <sofia-sip/su_wait.h>
#include "auth-module.hh"
#include <flexisip/auth-module.hh>
#include "flexisip-auth-status.hh"
#include "nonce-store.hh"
......
......@@ -26,7 +26,7 @@
#include <sofia-sip/msg_types.h>
#include <sofia-sip/su_wait.h>
#include "auth-module.hh"
#include <flexisip/auth-module.hh>
#include "authdb.hh"
#include "flexisip-auth-module-base.hh"
#include "flexisip-auth-status.hh"
......
......@@ -22,7 +22,7 @@
#include <memory>
#include <string>
#include "auth-status.hh"
#include <flexisip/auth-status.hh>
#include <flexisip/event.hh>
namespace flexisip {
......
......@@ -21,10 +21,26 @@
#include <sofia-sip/sip_status.h>
#include "module-auth.hh"
#include "auth/flexisip-auth-module.hh"
using namespace std;
using namespace flexisip;
namespace flexisip {
class RequestAuthStatus : public FlexisipAuthStatus {
public:
RequestAuthStatus(const std::shared_ptr<RequestSipEvent> &ev): FlexisipAuthStatus(), mEv(ev) {}
~RequestAuthStatus() override = default;
const std::shared_ptr<RequestSipEvent> &getRequestEvent() const {return mEv;}
private:
std::shared_ptr<RequestSipEvent> mEv;
};
}
// ====================================================================================================================
// Authentication class
// ====================================================================================================================
......@@ -201,7 +217,7 @@ void Authentication::onLoad(const GenericStruct *mc) {
AuthDbBackend::get();//force instanciation of the AuthDbBackend NOW, to force errors to arrive now if any.
}
FlexisipAuthModule *Authentication::findAuthModule(const string name) {
AuthModule *Authentication::findAuthModule(const string name) {
auto it = mAuthModules.find(name);
if (it == mAuthModules.end())
it = mAuthModules.find("*");
......@@ -405,7 +421,7 @@ void Authentication::onRequest(shared_ptr<RequestSipEvent> &ev) {
LOGD("There is no p-preferred-identity");
}
FlexisipAuthModule *am = findAuthModule(fromDomain);
AuthModule *am = findAuthModule(fromDomain);
if (am == NULL) {
LOGI("Unknown domain [%s]", fromDomain);
SLOGUE << "Registration failure, domain is forbidden: " << fromDomain;
......@@ -470,10 +486,11 @@ void Authentication::onResponse(shared_ptr<ResponseSipEvent> &ev) {
auto *as = new FlexisipAuthStatus();
as->realm(proxyRealm.get()->c_str());
as->userUri(sip->sip_from->a_url);
FlexisipAuthModule *am = findAuthModule(as->realm());
if (am) {
am->challenge(*as, &mProxyChallenger);
am->nonceStore().insert(as->response());
AuthModule *am = findAuthModule(as->realm());
FlexisipAuthModule *fam = dynamic_cast<FlexisipAuthModule *>(am);
if (fam) {
fam->challenge(*as, &mProxyChallenger);
fam->nonceStore().insert(as->response());
msg_header_insert(ev->getMsgSip()->getMsg(), (msg_pub_t *)sip, (msg_header_t *)as->response());
} else {
LOGD("Authentication module for %s not found", as->realm());
......@@ -486,7 +503,9 @@ void Authentication::onResponse(shared_ptr<ResponseSipEvent> &ev) {
void Authentication::onIdle() {
for (auto &it : mAuthModules) {
it.second->nonceStore().cleanExpired();
AuthModule *am = it.second.get();
FlexisipAuthModule *fam = dynamic_cast<FlexisipAuthModule *>(am);
fam->nonceStore().cleanExpired();
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment