[Opalvoip-svn] SF.net SVN: opalvoip:[34642] opal/trunk
Brought to you by:
csoutheren,
rjongbloed
From: <rjo...@us...> - 2016-02-24 15:02:12
|
Revision: 34642 http://sourceforge.net/p/opalvoip/code/34642 Author: rjongbloed Date: 2016-02-24 15:02:09 +0000 (Wed, 24 Feb 2016) Log Message: ----------- Added ability to have separate passwords for each H.323 alias on gatekeeper registration, thanks Andrea Guardascione Modified Paths: -------------- opal/trunk/include/h323/h323ep.h opal/trunk/samples/server/h323serv.cxx opal/trunk/src/h323/h323ep.cxx Modified: opal/trunk/include/h323/h323ep.h =================================================================== --- opal/trunk/include/h323/h323ep.h 2016-02-22 12:13:39 UTC (rev 34641) +++ opal/trunk/include/h323/h323ep.h 2016-02-24 15:02:09 UTC (rev 34642) @@ -351,6 +351,13 @@ const PString & username = PString::Empty() ); + /** Set the password for specific alias. + */ + void SetAliasPasswords( + const PStringToString & aliasPasswords, + const PString & defaultAddress + ); + /**Get the H.235 username for the gatekeeper. */ virtual const PString & GetGatekeeperUsername() const { return m_gatekeeperUsername; } @@ -1354,6 +1361,7 @@ bool InternalStartGatekeeper(const H323TransportAddress & remoteAddress, const PString & localAddress); bool InternalRestartGatekeeper(bool adjustingRegistrations = true); bool InternalCreateGatekeeper(const H323TransportAddress & remoteAddress, const PStringList & aliases); + void InternalSetGatekeeperPassword(H323Gatekeeper& gatekeeper, const OpalTransportAddress& gatekeeperAddress) const; H323Connection * InternalMakeCall( OpalCall & call, @@ -1451,6 +1459,8 @@ bool m_gatekeeperSimulatePattern; bool m_gatekeeperRasRedirect; PTimedMutex m_gatekeeperMutex; + PStringToString m_aliasPasswords; + PString m_aliasPwdDefaultAddress; #if OPAL_H450 H323CallIdentityDict m_secondaryConnectionsActive; Modified: opal/trunk/samples/server/h323serv.cxx =================================================================== --- opal/trunk/samples/server/h323serv.cxx 2016-02-22 12:13:39 UTC (rev 34641) +++ opal/trunk/samples/server/h323serv.cxx 2016-02-24 15:02:09 UTC (rev 34642) @@ -82,12 +82,43 @@ static const char AliasRouteMapsName[] = "Gatekeeper Alias Route Maps"; static const char AliasRouteMapsKey[] = "Route Maps\\Mapping %u\\"; +#define H323RegistrationSection "H.323 Registration\\" +#define H323RegistrationNewSection H323RegistrationSection"New" +#define H323RegistrationEncryptedSection H323RegistrationSection"Encrypted" + +static const PINDEX H323GatekeeperPasswordSize = 30; + #define PTraceModule() "OpalServer" #define new PNEW /////////////////////////////////////////////////////////////// +static PStringToString GetMyAliasPasswords(PConfig & cfg) +{ + PStringToString clearPwd; + + PStringToString encryptedPwd = cfg.GetAllKeyValues(H323RegistrationEncryptedSection); + for (PStringToString::iterator encryptedPwdIter = encryptedPwd.begin(); encryptedPwdIter != encryptedPwd.end(); ++encryptedPwdIter) + { + clearPwd.SetAt(encryptedPwdIter->first, PHTTPPasswordField::Decrypt(encryptedPwdIter->second)); + } + + PStringToString newPwd = cfg.GetAllKeyValues(H323RegistrationNewSection); + for (PStringToString::iterator newPwdIter = newPwd.begin(); newPwdIter != newPwd.end(); ++newPwdIter) + { + PHTTPPasswordField encryptedValue("", H323GatekeeperPasswordSize, newPwdIter->second); + cfg.SetString(H323RegistrationEncryptedSection, newPwdIter->first, encryptedValue.GetValue()); + cfg.DeleteKey(H323RegistrationNewSection, newPwdIter->first); + } + + clearPwd.Merge(newPwd, PStringToString::MergeAction::e_MergeOverwrite); + return clearPwd; +} + + +/////////////////////////////////////////////////////////////// + MyH323EndPoint::MyH323EndPoint(MyManager & mgr) : H323ConsoleEndPoint(mgr) , m_manager(mgr) @@ -158,6 +189,8 @@ PString gkAddress = rsrc->AddStringField(GatekeeperAddressKey, 0, PString::Empty(), "IP/hostname of gatekeeper to register with, if blank a broadcast is used", 1, 30); + SetAliasPasswords(GetMyAliasPasswords(cfg), gkAddress); + PString gkIdentifier = rsrc->AddStringField(RemoteGatekeeperIdentifierKey, 0, PString::Empty(), "Gatekeeper identifier to register with, if blank any gatekeeper is used", 1, 30); @@ -167,7 +200,7 @@ PString gkPassword = PHTTPPasswordField::Decrypt(cfg.GetString(GatekeeperPasswordKey)); if (!gkPassword) SetGatekeeperPassword(gkPassword); - rsrc->Add(new PHTTPPasswordField(GatekeeperPasswordKey, 30, gkPassword, + rsrc->Add(new PHTTPPasswordField(GatekeeperPasswordKey, H323GatekeeperPasswordSize, gkPassword, "Password for gatekeeper authentication, user is the first alias")); SetGkAccessTokenOID(rsrc->AddStringField(GatekeeperTokenOIDKey, 0, GetGkAccessTokenOID(), Modified: opal/trunk/src/h323/h323ep.cxx =================================================================== --- opal/trunk/src/h323/h323ep.cxx 2016-02-22 12:13:39 UTC (rev 34641) +++ opal/trunk/src/h323/h323ep.cxx 2016-02-24 15:02:09 UTC (rev 34642) @@ -641,7 +641,8 @@ gatekeeper->m_aliases += alias->GetPointer(); // Don't make reference gatekeeper->m_aliasMutex.Signal(); - gatekeeper->SetPassword(GetGatekeeperPassword(), GetGatekeeperUsername()); + InternalSetGatekeeperPassword(*gatekeeper, remoteAddress); + m_gatekeepers.Append(gatekeeper); if (remoteAddress.IsEmpty()) @@ -720,10 +721,39 @@ m_gatekeeperPassword = password; for (GatekeeperList::iterator it = m_gatekeepers.begin(); it != m_gatekeepers.end(); ++it) - it->SetPassword(GetGatekeeperPassword(), GetGatekeeperUsername()); + InternalSetGatekeeperPassword(*it, it->transport->GetRemoteAddress()); } +void H323EndPoint::SetAliasPasswords(const PStringToString & aliasPasswords, const PString & defaultAddress) +{ + m_aliasPasswords = aliasPasswords; + m_aliasPwdDefaultAddress = defaultAddress; +} + + +void H323EndPoint::InternalSetGatekeeperPassword(H323Gatekeeper& gatekeeper, const OpalTransportAddress& gatekeeperAddress) const +{ + PString alias; + gatekeeper.m_aliasMutex.Wait(); + if (gatekeeper.m_aliases.size() == 1) + alias = gatekeeper.m_aliases[0]; + gatekeeper.m_aliasMutex.Signal(); + + if (!alias.IsEmpty()) { + PIPSocket::Address ip; + PString gkAddress = (gatekeeperAddress.GetIpAddress(ip) && !ip.IsAny()) ? ip.AsString() : m_aliasPwdDefaultAddress; + PStringToString::const_iterator pwdIter = m_aliasPasswords.find(alias + '@' + gkAddress); + if (pwdIter != m_aliasPasswords.end()) { + gatekeeper.SetPassword(pwdIter->second, GetGatekeeperUsername()); + return; + } + } + + gatekeeper.SetPassword(GetGatekeeperPassword(), GetGatekeeperUsername()); +} + + void H323EndPoint::SetGatekeeperAliasLimit(PINDEX limit) { PWaitAndSignal mutex(m_gatekeeperMutex); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |