Commit 55d50dac authored by jan.koester's avatar jan.koester
Browse files

fixed secure issue

parent 2aec1096
Loading
Loading
Loading
Loading
Loading
+7 −1
Changes for client/CMakeLists.txt: 7 added lines, 1 removed line.
Original line number Diff line number Diff line
add_library(client SHARED client.cpp ../src/uuid.cpp ../src/session.cpp ../src/hash.cpp ../src/hash/sha512.cpp)

target_link_libraries(client PUBLIC netplus::netplus)
add_library(client-static STATIC client.cpp ../src/uuid.cpp ../src/session.cpp ../src/hash.cpp ../src/hash/sha512.cpp)

target_link_libraries(client PUBLIC netplus::netplus json-c::json-c httppp::httppp uuid)

target_link_libraries(client-static PUBLIC netplus::netplus json-c::json-c httppp::httppp uuid)

add_subdirectory(examples)
+34 −0
Changes for client/client.cpp: 34 added lines, 0 removed lines.
Original line number Diff line number Diff line
@@ -25,6 +25,12 @@
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include <vector>

#include <json.h>
#include <json_object.h>
#include <json_types.h>

#include "client.h"

authdb::ClientConnection::ClientConnection(){
@@ -68,5 +74,33 @@ bool authdb::Client::ClientAuth(){
}

bool authdb::Client::UserAuth(){
    json_object *jresponse = json_object_new_object();
    json_object *cmd=json_object_new_array();
    json_object *login=json_object_new_object();
    json_object *userauth=json_object_new_object();

    json_object_set_string(userauth,"login");
    json_object_object_add(userauth,"type",json_object_new_string("user"));
    json_object_object_add(userauth,"name",json_object_new_string(_Con._UserName.c_str()));
    json_object_object_add(userauth,"key",json_object_new_string(_Con._UserPassword.c_str()));

    json_object_array_add(cmd,userauth);
    json_object_object_add(login,"login",userauth);
    json_object_object_add(jresponse,"commands",login);

    size_t outsize=0;

    std::vector<char> out;

    const char *tmp=json_object_to_json_string_length(jresponse,0,&outsize);

    std::copy(tmp,tmp+outsize,std::back_inserter(out));

    std::vector<char> resp(_Con._Client->Post(_Con._Url.getPath(),"text/json",out));

    while(json_object_put(jresponse)!=0);

    std::cout.write(resp.data(),resp.size())<<std::endl;

    return false;
}
+1 −1
Changes for client/client.h: 1 added line, 1 removed line.
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ namespace authdb {
        void setUsername(const char *username);
        void setUserPassword(const char *password);
    private:
        std::string _Url;
        libhttppp::HttpUrl _Url;
        std::string _CltName;
        std::string _CltSecret;
        std::string _UserName;
+3 −0
Changes for client/examples/CMakeLists.txt: 3 added lines, 0 removed lines.
Original line number Diff line number Diff line
add_executable(userlogin userlogin.cpp)

target_link_libraries(userlogin PRIVATE client-static)
+43 −0
Changes for client/examples/userlogin.cpp: 43 added lines, 0 removed lines.
Original line number Diff line number Diff line
/*******************************************************************************
 * Copyright (c) 2025, Jan Koester jan.koester@gmx.net
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 * Redistributions of source code must retain the above copyright
 *      notice, this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 *      notice, this list of conditions and the following disclaimer in the
 *      documentation and/or other materials provided with the distribution.
 * Neither the name of the <organization> nor the
 *      names of its contributors may be used to endorse or promote products
 *      derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *******************************************************************************/

#include "../client.h"

int main(int argc, char *argv[]){
    authdb::ClientConnection con;
    con.setUrl(argv[1]);
    con.setUsername(argv[2]);
    con.setUserPassword(argv[3]);

    authdb::Client clt(con);
    if(clt.UserAuth()){
        std::cout << "Sucessfully login !" << std::endl;
        return 0;
    }
    std::cout << "Failed login !" << std::endl;
    return -1;
}
Loading