diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index 16ca977bae..e6e49750d1 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -105,7 +105,6 @@ link_hifi_libraries(shared octree voxels fbx metavoxels networking particles ent # find any optional and required libraries find_package(ZLIB REQUIRED) -find_package(OpenSSL REQUIRED) # perform standard include and linking for found externals foreach(EXTERNAL ${OPTIONAL_EXTERNALS}) @@ -169,10 +168,9 @@ endif () # include headers for interface and InterfaceConfig. include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes") -include_directories("${OPENSSL_INCLUDE_DIR}") target_link_libraries( - ${TARGET_NAME} ${ZLIB_LIBRARIES} ${OPENSSL_LIBRARIES} + ${TARGET_NAME} ${ZLIB_LIBRARIES} Qt5::Gui Qt5::Network Qt5::Multimedia Qt5::OpenGL Qt5::Script Qt5::Svg Qt5::WebKitWidgets ) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index f14edec313..af108dc947 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -64,6 +64,7 @@ #include #include #include +#include #include #include diff --git a/libraries/networking/CMakeLists.txt b/libraries/networking/CMakeLists.txt index 501437fab2..b86f53105c 100644 --- a/libraries/networking/CMakeLists.txt +++ b/libraries/networking/CMakeLists.txt @@ -10,5 +10,13 @@ if (WIN32) target_link_libraries(${TARGET_NAME} ws2_32.lib) endif () +# find OpenSSL +find_package(OpenSSL REQUIRED) + +include_directories(SYSTEM "${OPENSSL_INCLUDE_DIR}") + +# append OpenSSL to our list of libraries to link +list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${OPENSSL_LIBRARIES}") + # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() \ No newline at end of file diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 225227d16a..ae7699584b 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -67,7 +67,7 @@ private: QUuid _walletID; qint64 _balance; bool _hasBalance; - QString _privateKey; + QByteArray _privateKey; }; #endif // hifi_DataServerAccountInfo_h diff --git a/libraries/networking/src/RSAKeypairGenerator.cpp b/libraries/networking/src/RSAKeypairGenerator.cpp new file mode 100644 index 0000000000..032bd62f06 --- /dev/null +++ b/libraries/networking/src/RSAKeypairGenerator.cpp @@ -0,0 +1,83 @@ +// +// RSAKeypairGenerator.cpp +// libraries/networking/src +// +// Created by Stephen Birarda on 2014-10-14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#include +#include +#include + +#include + +#include "RSAKeypairGenerator.h" + +void RSAKeypairGenerator::generateKeypair() { + + RSA* keyPair = RSA_new(); + BIGNUM* exponent = BN_new(); + + const unsigned long RSA_KEY_EXPONENT = 65537; + BN_set_word(exponent, RSA_KEY_EXPONENT); + + // seed the random number generator before we call RSA_generate_key_ex + srand(time(NULL)); + + const int RSA_KEY_BITS = 2048; + + if (!RSA_generate_key_ex(keyPair, RSA_KEY_BITS, exponent, NULL)) { + qDebug() << "Error generating 2048-bit RSA Keypair -" << ERR_get_error(); + + emit errorGeneratingKeypair(); + + // we're going to bust out of here but first we cleanup the BIGNUM + BN_free(exponent); + return; + } + + // we don't need the BIGNUM anymore so clean that up + BN_free(exponent); + + // grab the public key and private key from the file + BIO *privateKeyBIO = BIO_new(BIO_s_mem()); + int privateWrite = PEM_write_bio_RSAPrivateKey(privateKeyBIO, keyPair, NULL, NULL, 0, NULL, NULL); + + BIO *publicKeyBIO = BIO_new(BIO_s_mem()); + int publicWrite = PEM_write_bio_RSAPublicKey(publicKeyBIO, keyPair); + + if (privateWrite == 0 || publicWrite == 0) { + // we had a error grabbing either the private or public key from the RSA + + // bubble up our error + emit errorGeneratingKeypair(); + + // cleanup the RSA struct + RSA_free(keyPair); + + // cleanup the BIOs + BIO_free(privateKeyBIO); + BIO_free(publicKeyBIO); + + return; + } + + // we have the public key and private key in memory + // we can cleanup the RSA struct before we continue on + RSA_free(keyPair); + + char* publicKeyData; + int publicKeyLength = BIO_get_mem_data(publicKeyBIO, &publicKeyData); + + char* privateKeyData; + int privateKeyLength = BIO_get_mem_data(privateKeyBIO, &privateKeyData); + + QByteArray publicKeyArray(publicKeyData, publicKeyLength); + QByteArray privateKeyArray(privateKeyData, privateKeyLength); + + emit generatedKeypair(publicKeyArray, privateKeyArray); +} \ No newline at end of file diff --git a/libraries/networking/src/RSAKeypairGenerator.h b/libraries/networking/src/RSAKeypairGenerator.h new file mode 100644 index 0000000000..f98daddb1e --- /dev/null +++ b/libraries/networking/src/RSAKeypairGenerator.h @@ -0,0 +1,26 @@ +// +// RSAKeypairGenerator.h +// libraries/networking/src +// +// Created by Stephen Birarda on 2014-10-14. +// Copyright 2014 High Fidelity, Inc. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +// + +#ifndef hifi_RSAKeypairGenerator_h +#define hifi_RSAKeypairGenerator_h + +#include + +class RSAKeypairGenerator : public QObject { + Q_OBJECT +public slots: + void generateKeypair(); +signals: + void errorGeneratingKeypair(); + void generatedKeypair(const QByteArray& publicKey, const QByteArray& privateKey); +}; + +#endif // hifi_RSAKeypairGenerator_h \ No newline at end of file