implemented gp-authed lobbies. Still needs some GUI

This commit is contained in:
csoler 2015-08-26 23:35:36 -04:00
parent 260da99955
commit 040b4fb949
5 changed files with 115 additions and 47 deletions

View File

@ -58,10 +58,10 @@ static const uint32_t MAX_MESSAGES_PER_SECONDS_NUMBER = 5 ; // max number o
static const uint32_t MAX_MESSAGES_PER_SECONDS_PERIOD = 10 ; // duration window for max number of messages before messages get dropped.
#define IS_PUBLIC_LOBBY(flags) (flags & RS_CHAT_LOBBY_FLAGS_PUBLIC )
#define IS_ANONYMOUS_LOBBY(flags) (flags & RS_CHAT_LOBBY_FLAGS_ANONYMOUS)
#define IS_CONNEXION_CHALLENGE(flags) (flags & RS_CHAT_LOBBY_FLAGS_CHALLENGE)
#define IS_PGP_SIGNED_LOBBY(flags) (flags & RS_CHAT_LOBBY_FLAGS_PGP_SIGNED)
#define IS_CONNEXION_CHALLENGE(flags) (flags & RS_CHAT_LOBBY_FLAGS_CHALLENGE )
#define EXTRACT_PRIVACY_FLAGS(flags) (ChatLobbyFlags(flags.toUInt32()) & RS_CHAT_LOBBY_FLAGS_PUBLIC)
#define EXTRACT_PRIVACY_FLAGS(flags) (ChatLobbyFlags(flags.toUInt32()) * (RS_CHAT_LOBBY_FLAGS_PUBLIC | RS_CHAT_LOBBY_FLAGS_PGP_SIGNED))
DistributedChatService::DistributedChatService(uint32_t serv_type,p3ServiceControl *sc,p3HistoryMgr *hm, RsGixs *is)
: mServType(serv_type),mDistributedChatMtx("Distributed Chat"), mServControl(sc), mHistMgr(hm),mGixs(is)
@ -145,6 +145,36 @@ bool DistributedChatService::handleRecvChatLobbyMsgItem(RsChatMsgItem *ci)
return false;
}
ChatLobbyFlags fl ;
// delete items that are not for us, as early as possible.
{
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
// send upward for display
std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it = _chat_lobbys.find(cli->lobby_id) ;
if(it == _chat_lobbys.end())
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl;
#endif
return false;
}
fl = it->second.lobby_flags ;
}
if(IS_PGP_SIGNED_LOBBY(fl))
{
RsIdentityDetails details;
if(!rsIdentity->getIdDetails(cli->signature.keyId,details) || !details.mPgpKnown)
{
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (id=" << cli->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
return false ;
}
}
if(!bounceLobbyObject(cli,cli->PeerId())) // forwards the message to friends, keeps track of subscribers, etc.
return false;
@ -209,6 +239,7 @@ bool DistributedChatService::checkSignature(RsChatLobbyBouncingObject *obj,const
return res;
}
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " signature: CHECKS" << std::endl;
#endif
@ -252,7 +283,7 @@ void DistributedChatService::locked_printDebugInfo() const
std::cerr << " Lobby topic\t\t: " << it->second.lobby_topic << std::endl;
std::cerr << " nick name\t\t: " << it->second.gxs_id << std::endl;
std::cerr << " Lobby type\t\t: " << ((IS_PUBLIC_LOBBY(it->second.lobby_flags))?"Public":"Private") << std::endl;
std::cerr << " Lobby policy\t\t: " << ((IS_ANONYMOUS_LOBBY(it->second.lobby_flags))?"Unsigned":"Signature required") << std::endl;
std::cerr << " Lobby security\t\t: " << ((IS_PGP_SIGNED_LOBBY(it->second.lobby_flags))?"PGP-signed IDs required":"Anon IDs accepted") << std::endl;
std::cerr << " Lobby peer id\t: " << it->second.virtual_peer_id << std::endl;
std::cerr << " Challenge count\t: " << it->second.connexion_challenge_count << std::endl;
std::cerr << " Last activity\t: " << now - it->second.last_activity << " seconds ago." << std::endl;
@ -446,7 +477,7 @@ void DistributedChatService::handleRecvChatLobbyListRequest(RsChatLobbyListReque
info.name = it->second.lobby_name ;
info.topic = it->second.lobby_topic ;
info.count = it->second.gxs_ids.size() ;
info.flags = it->second.lobby_flags ;
info.flags = ChatLobbyFlags(EXTRACT_PRIVACY_FLAGS(it->second.lobby_flags)) ;
item->lobbies.push_back(info) ;
}
@ -496,7 +527,7 @@ void DistributedChatService::handleRecvChatLobbyList(RsChatLobbyListItem *item)
rec.total_number_of_peers = std::max(rec.total_number_of_peers,item->lobbies[i].count) ;
rec.last_report_time = now ;
rec.lobby_flags = item->lobbies[i].flags ;
rec.lobby_flags = EXTRACT_PRIVACY_FLAGS(item->lobbies[i].flags) ;
std::map<ChatLobbyId,ChatLobbyFlags>::const_iterator it(_known_lobbies_flags.find(item->lobbies[i].id)) ;
@ -596,19 +627,24 @@ void DistributedChatService::addTimeShiftStatistics(int D)
void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *item)
{
ChatLobbyFlags fl ;
// delete items that are not for us, as early as possible.
{
RsStackMutex stack(mDistributedChatMtx); /********** STACK LOCKED MTX ******/
// send upward for display
if(_chat_lobbys.find(item->lobby_id) == _chat_lobbys.end())
std::map<ChatLobbyId,ChatLobbyEntry>::const_iterator it = _chat_lobbys.find(item->lobby_id) ;
if(it == _chat_lobbys.end())
{
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << "Chatlobby for id " << std::hex << item->lobby_id << " has no record. Dropping the msg." << std::dec << std::endl;
#endif
return ;
}
fl = it->second.lobby_flags ;
}
@ -625,6 +661,17 @@ void DistributedChatService::handleRecvChatLobbyEventItem(RsChatLobbyEventItem *
return ;
}
if(IS_PGP_SIGNED_LOBBY(fl))
{
RsIdentityDetails details;
if(!rsIdentity->getIdDetails(item->signature.keyId,details) || !details.mPgpKnown)
{
std::cerr << "(WW) Received a lobby msg/item that is not PGP-authed (ID=" << item->signature.keyId << "), whereas the lobby flags require it. Rejecting!" << std::endl;
return ;
}
}
addTimeShiftStatistics((int)now - (int)item->sendTime) ;
if(now+100 > (time_t) item->sendTime + MAX_KEEP_MSG_RECORD) // the message is older than the max cache keep minus 100 seconds ! It's too old, and is going to make an echo!
@ -912,10 +959,8 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
// now sign the object, if the lobby expects it
if(!IS_ANONYMOUS_LOBBY(lobby.lobby_flags))
{
uint32_t size = item.signed_serial_size() ;
unsigned char *memory = (unsigned char *)malloc(size) ;
RsTemporaryMemory memory(size) ;
if(!item.serialise_signed_part(memory,size))
{
@ -934,12 +979,9 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
default: std::cerr << "(EE) Cannot sign item: unknown error" << std::endl;
break ;
}
free(memory) ;
return false ;
}
#ifdef DEBUG_CHAT_LOBBIES
std::cerr << " signature done." << std::endl;
@ -953,8 +995,6 @@ bool DistributedChatService::locked_initLobbyBouncableObject(const ChatLobbyId&
std::cerr << " Item dump:" << std::endl;
item.print(std::cerr,2) ;
#endif
free(memory) ;
}
return true ;
}

View File

@ -28,6 +28,7 @@ template<int n> class t_RsFlags32
inline t_RsFlags32<n> operator| (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits | f._bits) ; }
inline t_RsFlags32<n> operator^ (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits ^ f._bits) ; }
inline t_RsFlags32<n> operator* (const t_RsFlags32<n>& f) const { return t_RsFlags32<n>(_bits & f._bits) ; }
inline bool operator!=(const t_RsFlags32<n>& f) const { return _bits != f._bits ; }
inline bool operator==(const t_RsFlags32<n>& f) const { return _bits == f._bits ; }

View File

@ -90,7 +90,7 @@
#define RS_CHAT_TYPE_DISTANT 4
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_AUTO_SUBSCRIBE( 0x00000001 ) ;
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_ANONYMOUS ( 0x00000002 ) ;
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ( 0x00000002 ) ; // requires the signing ID to be PGP-linked. Avoids anonymous crap.
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_PUBLIC ( 0x00000004 ) ;
const ChatLobbyFlags RS_CHAT_LOBBY_FLAGS_CHALLENGE ( 0x00000008 ) ;

View File

@ -128,6 +128,7 @@ void CreateLobbyDialog::createLobby()
case GxsIdChooser::NoId:
case GxsIdChooser::None:
return ;
default: break ;
}
// add to group
@ -136,6 +137,9 @@ void CreateLobbyDialog::createLobby()
if(ui->security_CB->currentIndex() == 0)
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PUBLIC ;
if(ui->pgp_signed_CB->isChecked())
lobby_flags |= RS_CHAT_LOBBY_FLAGS_PGP_SIGNED ;
ChatLobbyId id = rsMsgs->createChatLobby(lobby_name,gxs_id, lobby_topic, shareList, lobby_flags);
std::cerr << "gui: Created chat lobby " << std::hex << id << std::dec << std::endl ;

View File

@ -6,7 +6,7 @@
<rect>
<x>0</x>
<y>0</y>
<width>787</width>
<width>1315</width>
<height>486</height>
</rect>
</property>
@ -86,7 +86,7 @@
<item row="3" column="0">
<widget class="QLabel" name="label_6">
<property name="text">
<string>Security policy:</string>
<string>Visibility:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
@ -110,6 +110,29 @@
<item row="2" column="2">
<widget class="GxsIdChooser" name="idChooser_CB"/>
</item>
<item row="4" column="2">
<widget class="QCheckBox" name="pgp_signed_CB">
<property name="toolTip">
<string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;If you check this, only PGP-signed ids can be used to join and talk in this lobby. This limitation prevents anonymous spamming as it becomes possible for at least some people in the lobby to locate the spammer's node.&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
</property>
<property name="text">
<string>require PGP-signed identities</string>
</property>
</widget>
</item>
<item row="4" column="0">
<widget class="QLabel" name="label">
<property name="layoutDirection">
<enum>Qt::LeftToRight</enum>
</property>
<property name="text">
<string>Security:</string>
</property>
<property name="alignment">
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
</property>
</widget>
</item>
</layout>
</item>
<item>