Merge branch 'libresapi_attempt_connection' into qmlapp_pex_alpha

This commit is contained in:
Gioacchino Mazzurco 2017-06-02 10:39:42 +02:00
commit efdfa4666b
4 changed files with 63 additions and 4 deletions

View File

@ -1,3 +1,23 @@
/*
* libresapi
*
* Copyright (C) 2015 electron128 <electron128@yahoo.com>
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "PeersHandler.h" #include "PeersHandler.h"
#include <retroshare/rspeers.h> #include <retroshare/rspeers.h>
@ -194,6 +214,7 @@ PeersHandler::PeersHandler(StateTokenServer* sts, RsNotify* notify, RsPeers *pee
mNotify->registerNotifyClient(this); mNotify->registerNotifyClient(this);
mStateTokenServer->registerTickClient(this); mStateTokenServer->registerTickClient(this);
addResourceHandler("*", this, &PeersHandler::handleWildcard); addResourceHandler("*", this, &PeersHandler::handleWildcard);
addResourceHandler("attempt_connection", this, &PeersHandler::handleAttemptConnection);
addResourceHandler("get_state_string", this, &PeersHandler::handleGetStateString); addResourceHandler("get_state_string", this, &PeersHandler::handleGetStateString);
addResourceHandler("set_state_string", this, &PeersHandler::handleSetStateString); addResourceHandler("set_state_string", this, &PeersHandler::handleSetStateString);
addResourceHandler("get_custom_state_string", this, &PeersHandler::handleGetCustomStateString); addResourceHandler("get_custom_state_string", this, &PeersHandler::handleGetCustomStateString);
@ -203,6 +224,7 @@ PeersHandler::PeersHandler(StateTokenServer* sts, RsNotify* notify, RsPeers *pee
addResourceHandler("get_node_options", this, &PeersHandler::handleGetNodeOptions); addResourceHandler("get_node_options", this, &PeersHandler::handleGetNodeOptions);
addResourceHandler("set_node_options", this, &PeersHandler::handleSetNodeOptions); addResourceHandler("set_node_options", this, &PeersHandler::handleSetNodeOptions);
addResourceHandler("examine_cert", this, &PeersHandler::handleExamineCert); addResourceHandler("examine_cert", this, &PeersHandler::handleExamineCert);
} }
PeersHandler::~PeersHandler() PeersHandler::~PeersHandler()
@ -601,6 +623,19 @@ void PeersHandler::handleWildcard(Request &req, Response &resp)
} }
} }
void PeersHandler::handleAttemptConnection(Request &req, Response &resp)
{
std::string ssl_peer_id;
req.mStream << makeKeyValueReference("peer_id", ssl_peer_id);
RsPeerId peerId(ssl_peer_id);
if(peerId.isNull()) resp.setFail("Invalid peer_id");
else
{
mRsPeers->connectAttempt(peerId);
resp.setOk();
}
}
void PeersHandler::handleExamineCert(Request &req, Response &resp) void PeersHandler::handleExamineCert(Request &req, Response &resp)
{ {
std::string cert_string; std::string cert_string;

View File

@ -1,4 +1,23 @@
#pragma once #pragma once
/*
* libresapi
*
* Copyright (C) 2015 electron128 <electron128@yahoo.com>
* Copyright (C) 2017 Gioacchino Mazzurco <gio@eigenlab.org>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "ResourceRouter.h" #include "ResourceRouter.h"
#include "StateTokenServer.h" #include "StateTokenServer.h"
@ -34,6 +53,9 @@ public:
private: private:
void handleWildcard(Request& req, Response& resp); void handleWildcard(Request& req, Response& resp);
void handleAttemptConnection(Request& req, Response& resp);
void handleExamineCert(Request& req, Response& resp); void handleExamineCert(Request& req, Response& resp);
void handleGetStateString(Request& req, Response& resp); void handleGetStateString(Request& req, Response& resp);

View File

@ -359,7 +359,8 @@ bool GxsSecurity::getSignature(const char *data, uint32_t data_len, const RsTlvP
ok &= EVP_SignUpdate(mdctx, data, data_len) == 1; ok &= EVP_SignUpdate(mdctx, data, data_len) == 1;
unsigned int siglen = EVP_PKEY_size(key_priv); unsigned int siglen = EVP_PKEY_size(key_priv);
unsigned char sigbuf[siglen] = { 0 }; unsigned char sigbuf[siglen] ;
memset(sigbuf,0,siglen) ;
ok &= EVP_SignFinal(mdctx, sigbuf, &siglen, key_priv) == 1; ok &= EVP_SignFinal(mdctx, sigbuf, &siglen, key_priv) == 1;
// clean up // clean up

View File

@ -599,7 +599,8 @@ bool AuthSSLimpl::SignData(const void *data, const uint32_t len, std::string &si
EVP_MD_CTX *mdctx = EVP_MD_CTX_create(); EVP_MD_CTX *mdctx = EVP_MD_CTX_create();
unsigned int signlen = EVP_PKEY_size(mOwnPrivateKey); unsigned int signlen = EVP_PKEY_size(mOwnPrivateKey);
unsigned char signature[signlen] = { 0 }; unsigned char signature[signlen] ;
memset(signature,0,signlen) ;
if (0 == EVP_SignInit(mdctx, EVP_sha1())) if (0 == EVP_SignInit(mdctx, EVP_sha1()))
{ {