diff --git a/BUILD.md b/BUILD.md index 32c35a4c2b..43c3ca7a09 100644 --- a/BUILD.md +++ b/BUILD.md @@ -5,8 +5,8 @@ Dependencies * [zLib](http://www.zlib.net/) ~> 1.2.8 * [glm](http://glm.g-truc.net/0.9.5/index.html) ~> 0.9.5.2 * [qxmpp](https://github.com/qxmpp-project/qxmpp/) ~> 0.7.6 -* [GnuTLS](http://gnutls.org/download.html) ~> 3.2.12 - * IMPORTANT: GnuTLS 3.2.12 is critical to avoid a security vulnerability. +* [OpenSSL](https://www.openssl.org/related/binaries.html) ~> 1.0.1g + * IMPORTANT: OpenSSL 1.0.1g is critical to avoid a security vulnerability. #####Linux only * [freeglut](http://freeglut.sourceforge.net/) ~> 2.8.0 @@ -30,7 +30,6 @@ The path it needs to be set to will depend on where and how Qt5 was installed. e export QT_CMAKE_PREFIX_PATH=/usr/local/Cellar/qt5/5.2.1/lib/cmake export QT_CMAKE_PREFIX_PATH=/usr/local/opt/qt5/lib/cmake - ####Generating build files Create a build directory in the root of your checkout and then run the CMake build from there. This will keep the rest of the directory clean. @@ -43,8 +42,16 @@ Any variables that need to be set for CMake to find dependencies can be set as E For example, to pass the QT_CMAKE_PREFIX_PATH variable during build file generation: - cmake .. -DQT_CMAKE_PREFIX_PATH=/usr/local/qt/5.2.0/lib/cmake + cmake .. -DQT_CMAKE_PREFIX_PATH=/usr/local/qt/5.2.1/lib/cmake +####Finding Dependencies +You can point our [Cmake find modules](cmake/modules/) to the correct version of dependencies by setting one of the three following variables to the location of the correct version of the dependency. + +In the examples below the variable $NAME would be replaced by the name of the dependency in uppercase, and $name would be replaced by the name of the dependency in lowercase (ex: OPENSSL_ROOT_DIR, openssl). + +* $NAME_ROOT_DIR - pass this variable to Cmake with the -DNAME_ROOT_DIR= flag when running Cmake to generate build files +* $NAME_ROOT_DIR - set this variable in your ENV +* HIFI_LIB_DIR - set this variable in your ENV to your High Fidelity lib folder, should contain a folder '$name' UNIX === @@ -55,18 +62,12 @@ Should you choose not to install Qt5 via a package manager that handles dependen libasound2 libxmu-dev libxi-dev freeglut3-dev libasound2-dev libjack-dev -#####GnuTLS - -If `libgnutls28-dev` 3.2.12 or higher is available via your package manager, it would be easiest to grab it from there. At the time of this writing that is not the case for any version of Ubuntu, so it will need to be built from source. - -`gmplib` is a dependency for GnuTLS. On Ubuntu, we were unable to build `hogweed` (part of `libnettle`) with `gmpib` 6.x.x. If nettle is not built with `hogweed`, GnuTLS will fail to build. If you run into this problem, try version 4.2.1 of `gmplib`. - ####OS X #####Package Managers [Homebrew](http://brew.sh/) is an excellent package manager for OS X. It makes install of all hifi dependencies very simple. brew tap highfidelity/homebrew-formulas - brew install cmake glm gnutls + brew install cmake glm openssl brew install highfidelity/formulas/qt5 brew link qt5 --force brew install highfidelity/formulas/qxmpp @@ -217,20 +218,6 @@ This package contains only headers, so there's nothing to add to the PATH. Be careful with glm. For the folder other libraries would normally call 'include', the folder containing the headers, glm opts to use 'glm'. You will have a glm folder nested inside the top-level glm folder. -#### GnuTLS - -You can get a precompiled version of GnuTLS for Windows [here](http://gnutls.org/download.html). - -To use GnuTLS with Visual Studio, you will need to create `libgnutls-28.lib`, the import library for Visual Studio projects. This is done using the `lib` command in the `bin` folder of your GnuTLS download. Start a Visual Studio Command Prompt, and then run: - - cd %HIFI_LIB_DIR%\gnutls\bin - lib /def:libgnutls-28.def - copy libgnutls-28.lib ..\lib - -The Cmake FindGnuTLS module will now find libgnutls-28.lib during the Cmake run. - -Add to the PATH: `%HIFI_LIB_DIR%\gnutls\bin` - #### qxmpp Download a source-code release from the [qxmpp GitHub page](https://github.com/qxmpp-project/qxmpp/releases). diff --git a/cmake/modules/FindOpenSSL.cmake b/cmake/modules/FindOpenSSL.cmake new file mode 100644 index 0000000000..1dbac311da --- /dev/null +++ b/cmake/modules/FindOpenSSL.cmake @@ -0,0 +1,319 @@ +# - Try to find the OpenSSL encryption library +# Once done this will define +# +# OPENSSL_ROOT_DIR - Set this variable to the root installation of OpenSSL +# +# Read-Only variables: +# OPENSSL_FOUND - system has the OpenSSL library +# OPENSSL_INCLUDE_DIR - the OpenSSL include directory +# OPENSSL_LIBRARIES - The libraries needed to use OpenSSL +# OPENSSL_VERSION - This is set to $major.$minor.$revision$path (eg. 0.9.8s) +# +# Modified on 7/16/2014 by Stephen Birarda +# This is an adapted version of the FindOpenSSL.cmake module distributed with Cmake 2.8.12.2 +# The original license for that file is displayed below. +# +#============================================================================= +# Copyright 2006-2009 Kitware, Inc. +# Copyright 2006 Alexander Neundorf +# Copyright 2009-2011 Mathieu Malaterre +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= +# (To distribute this file outside of CMake, substitute the full +# License text for the above reference.) + +if (UNIX) + find_package(PkgConfig QUIET) + pkg_check_modules(_OPENSSL QUIET openssl) +endif () + +if (WIN32) + # http://www.slproweb.com/products/Win32OpenSSL.html + set(_OPENSSL_ROOT_HINTS + ${OPENSSL_ROOT_DIR} + $ENV{OPENSSL_ROOT_DIR} + $ENV{HIFI_LIB_DIR}/openssl + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (32-bit)_is1;Inno Setup: App Path]" + "[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\OpenSSL (64-bit)_is1;Inno Setup: App Path]" + ) + file(TO_CMAKE_PATH "$ENV{PROGRAMFILES}" _programfiles) + set(_OPENSSL_ROOT_PATHS + "${_programfiles}/OpenSSL" + "${_programfiles}/OpenSSL-Win32" + "${_programfiles}/OpenSSL-Win64" + "C:/OpenSSL/" + "C:/OpenSSL-Win32/" + "C:/OpenSSL-Win64/" + ) + unset(_programfiles) + set(_OPENSSL_ROOT_HINTS_AND_PATHS + HINTS ${_OPENSSL_ROOT_HINTS} + PATHS ${_OPENSSL_ROOT_PATHS} + ) +else () + set(_OPENSSL_ROOT_HINTS_AND_PATHS ${OPENSSL_ROOT_DIR} $ENV{OPENSSL_ROOT_DIR} $ENV{HIFI_LIB_DIR}/openssl) +endif () + +find_path(OPENSSL_INCLUDE_DIR + NAMES + openssl/ssl.h + HINTS + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + ${_OPENSSL_INCLUDEDIR} + PATH_SUFFIXES + include +) + +if(WIN32 AND NOT CYGWIN) + if(MSVC) + # /MD and /MDd are the standard values - if someone wants to use + # others, the libnames have to change here too + # use also ssl and ssleay32 in debug as fallback for openssl < 0.9.8b + # TODO: handle /MT and static lib + # In Visual C++ naming convention each of these four kinds of Windows libraries has it's standard suffix: + # * MD for dynamic-release + # * MDd for dynamic-debug + # * MT for static-release + # * MTd for static-debug + + # Implementation details: + # We are using the libraries located in the VC subdir instead of the parent directory eventhough : + # libeay32MD.lib is identical to ../libeay32.lib, and + # ssleay32MD.lib is identical to ../ssleay32.lib + find_library(LIB_EAY_DEBUG + NAMES + libeay32MDd + libeay32d + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "VC" + "lib/VC" + ) + + find_library(LIB_EAY_RELEASE + NAMES + libeay32MD + libeay32 + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "VC" + "lib/VC" + ) + + find_library(SSL_EAY_DEBUG + NAMES + ssleay32MDd + ssleay32d + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "VC" + "lib/VC" + ) + + find_library(SSL_EAY_RELEASE + NAMES + ssleay32MD + ssleay32 + ssl + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "VC" + "lib/VC" + ) + + set(LIB_EAY_LIBRARY_DEBUG "${LIB_EAY_DEBUG}") + set(LIB_EAY_LIBRARY_RELEASE "${LIB_EAY_RELEASE}") + set(SSL_EAY_LIBRARY_DEBUG "${SSL_EAY_DEBUG}") + set(SSL_EAY_LIBRARY_RELEASE "${SSL_EAY_RELEASE}") + + include(SelectLibraryConfigurations) + select_library_configurations(LIB_EAY) + select_library_configurations(SSL_EAY) + + set( OPENSSL_LIBRARIES ${SSL_EAY_LIBRARY} ${LIB_EAY_LIBRARY} ) + elseif(MINGW) + # same player, for MinGW + set(LIB_EAY_NAMES libeay32) + set(SSL_EAY_NAMES ssleay32) + if(CMAKE_CROSSCOMPILING) + list(APPEND LIB_EAY_NAMES crypto) + list(APPEND SSL_EAY_NAMES ssl) + endif() + find_library(LIB_EAY + NAMES + ${LIB_EAY_NAMES} + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "lib/MinGW" + ) + + find_library(SSL_EAY + NAMES + ${SSL_EAY_NAMES} + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + PATH_SUFFIXES + "lib" + "lib/MinGW" + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} ) + unset(LIB_EAY_NAMES) + unset(SSL_EAY_NAMES) + else() + # Not sure what to pick for -say- intel, let's use the toplevel ones and hope someone report issues: + find_library(LIB_EAY + NAMES + libeay32 + HINTS + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + find_library(SSL_EAY + NAMES + ssleay32 + HINTS + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + mark_as_advanced(SSL_EAY LIB_EAY) + set( OPENSSL_LIBRARIES ${SSL_EAY} ${LIB_EAY} ) + endif() +else() + + find_library(OPENSSL_SSL_LIBRARY + NAMES + ssl + ssleay32 + ssleay32MD + HINTS + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + find_library(OPENSSL_CRYPTO_LIBRARY + NAMES + crypto + HINTS + ${_OPENSSL_ROOT_HINTS_AND_PATHS} + ${_OPENSSL_LIBDIR} + PATH_SUFFIXES + lib + ) + + mark_as_advanced(OPENSSL_CRYPTO_LIBRARY OPENSSL_SSL_LIBRARY) + + # compat defines + set(OPENSSL_SSL_LIBRARIES ${OPENSSL_SSL_LIBRARY}) + set(OPENSSL_CRYPTO_LIBRARIES ${OPENSSL_CRYPTO_LIBRARY}) + + set(OPENSSL_LIBRARIES ${OPENSSL_SSL_LIBRARY} ${OPENSSL_CRYPTO_LIBRARY}) + +endif() + +function(from_hex HEX DEC) + string(TOUPPER "${HEX}" HEX) + set(_res 0) + string(LENGTH "${HEX}" _strlen) + + while (_strlen GREATER 0) + math(EXPR _res "${_res} * 16") + string(SUBSTRING "${HEX}" 0 1 NIBBLE) + string(SUBSTRING "${HEX}" 1 -1 HEX) + if (NIBBLE STREQUAL "A") + math(EXPR _res "${_res} + 10") + elseif (NIBBLE STREQUAL "B") + math(EXPR _res "${_res} + 11") + elseif (NIBBLE STREQUAL "C") + math(EXPR _res "${_res} + 12") + elseif (NIBBLE STREQUAL "D") + math(EXPR _res "${_res} + 13") + elseif (NIBBLE STREQUAL "E") + math(EXPR _res "${_res} + 14") + elseif (NIBBLE STREQUAL "F") + math(EXPR _res "${_res} + 15") + else() + math(EXPR _res "${_res} + ${NIBBLE}") + endif() + + string(LENGTH "${HEX}" _strlen) + endwhile() + + set(${DEC} ${_res} PARENT_SCOPE) +endfunction() + +if (OPENSSL_INCLUDE_DIR) + if(OPENSSL_INCLUDE_DIR AND EXISTS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h") + file(STRINGS "${OPENSSL_INCLUDE_DIR}/openssl/opensslv.h" openssl_version_str + REGEX "^#define[\t ]+OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])+.*") + + # The version number is encoded as 0xMNNFFPPS: major minor fix patch status + # The status gives if this is a developer or prerelease and is ignored here. + # Major, minor, and fix directly translate into the version numbers shown in + # the string. The patch field translates to the single character suffix that + # indicates the bug fix state, which 00 -> nothing, 01 -> a, 02 -> b and so + # on. + + string(REGEX REPLACE "^.*OPENSSL_VERSION_NUMBER[\t ]+0x([0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F][0-9a-fA-F])([0-9a-fA-F]).*$" + "\\1;\\2;\\3;\\4;\\5" OPENSSL_VERSION_LIST "${openssl_version_str}") + list(GET OPENSSL_VERSION_LIST 0 OPENSSL_VERSION_MAJOR) + list(GET OPENSSL_VERSION_LIST 1 OPENSSL_VERSION_MINOR) + from_hex("${OPENSSL_VERSION_MINOR}" OPENSSL_VERSION_MINOR) + list(GET OPENSSL_VERSION_LIST 2 OPENSSL_VERSION_FIX) + from_hex("${OPENSSL_VERSION_FIX}" OPENSSL_VERSION_FIX) + list(GET OPENSSL_VERSION_LIST 3 OPENSSL_VERSION_PATCH) + + if (NOT OPENSSL_VERSION_PATCH STREQUAL "00") + from_hex("${OPENSSL_VERSION_PATCH}" _tmp) + # 96 is the ASCII code of 'a' minus 1 + math(EXPR OPENSSL_VERSION_PATCH_ASCII "${_tmp} + 96") + unset(_tmp) + # Once anyone knows how OpenSSL would call the patch versions beyond 'z' + # this should be updated to handle that, too. This has not happened yet + # so it is simply ignored here for now. + string(ASCII "${OPENSSL_VERSION_PATCH_ASCII}" OPENSSL_VERSION_PATCH_STRING) + endif () + + set(OPENSSL_VERSION "${OPENSSL_VERSION_MAJOR}.${OPENSSL_VERSION_MINOR}.${OPENSSL_VERSION_FIX}${OPENSSL_VERSION_PATCH_STRING}") + endif () +endif () + +include(FindPackageHandleStandardArgs) + +if (OPENSSL_VERSION) + find_package_handle_standard_args(OpenSSL + REQUIRED_VARS + OPENSSL_LIBRARIES + OPENSSL_INCLUDE_DIR + VERSION_VAR + OPENSSL_VERSION + FAIL_MESSAGE + "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR" + ) +else () + find_package_handle_standard_args(OpenSSL "Could NOT find OpenSSL, try to set the path to OpenSSL root folder in the system variable OPENSSL_ROOT_DIR" + OPENSSL_LIBRARIES + OPENSSL_INCLUDE_DIR + ) +endif () + +mark_as_advanced(OPENSSL_INCLUDE_DIR OPENSSL_LIBRARIES) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index a5d1b0193e..324fd6ee1d 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -133,7 +133,7 @@ link_hifi_library(audio ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(animation ${TARGET_NAME} "${ROOT_DIR}") link_hifi_library(script-engine ${TARGET_NAME} "${ROOT_DIR}") -# find any optional libraries +# find any optional and required libraries find_package(Faceplus) find_package(Faceshift) find_package(LibOVR) @@ -145,6 +145,7 @@ find_package(LeapMotion) find_package(ZLIB) find_package(Qxmpp) find_package(RtMidi) +find_package(OpenSSL REQUIRED) # include the Sixense library for Razer Hydra if available if (SIXENSE_FOUND AND NOT DISABLE_SIXENSE) @@ -247,12 +248,13 @@ include_directories("${PROJECT_SOURCE_DIR}/src" "${PROJECT_BINARY_DIR}/includes" # include external library headers # use system flag so warnings are supressed -include_directories(SYSTEM "${FACESHIFT_INCLUDE_DIRS}") +include_directories(SYSTEM "${FACESHIFT_INCLUDE_DIRS}" "${OPENSSL_INCLUDE_DIR}") target_link_libraries( ${TARGET_NAME} "${FACESHIFT_LIBRARIES}" "${ZLIB_LIBRARIES}" + ${OPENSSL_LIBRARIES} Qt5::Core Qt5::Gui Qt5::Multimedia Qt5::Network Qt5::OpenGL Qt5::Script Qt5::Svg Qt5::WebKit Qt5::WebKitWidgets Qt5::Xml Qt5::UiTools ) diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index 1c3d0f25b8..38af5d4659 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -112,7 +112,8 @@ Menu::Menu() : _preferencesDialog(NULL), _loginDialog(NULL), _snapshotsLocation(), - _scriptsLocation() + _scriptsLocation(), + _walletPrivateKey() { Application *appInstance = Application::getInstance(); @@ -442,6 +443,8 @@ Menu::Menu() : false, &UserActivityLogger::getInstance(), SLOT(disable(bool))); + + addActionToQMenuAndActionHash(developerMenu, MenuOption::WalletPrivateKey, 0, this, SLOT(changePrivateKey())); addDisabledActionAndSeparator(developerMenu, "Testing"); @@ -639,6 +642,8 @@ void Menu::loadSettings(QSettings* settings) { _viewFrustumOffset.distance = loadSetting(settings, "viewFrustumOffsetDistance", 0.0f); _viewFrustumOffset.up = loadSetting(settings, "viewFrustumOffsetUp", 0.0f); settings->endGroup(); + + _walletPrivateKey = settings->value("privateKey").toByteArray(); scanMenuBar(&loadAction, settings); Application::getInstance()->getAvatar()->loadData(settings); @@ -682,6 +687,7 @@ void Menu::saveSettings(QSettings* settings) { settings->setValue("viewFrustumOffsetDistance", _viewFrustumOffset.distance); settings->setValue("viewFrustumOffsetUp", _viewFrustumOffset.up); settings->endGroup(); + settings->setValue("privateKey", _walletPrivateKey); scanMenuBar(&saveAction, settings); Application::getInstance()->getAvatar()->saveData(settings); @@ -996,6 +1002,25 @@ void Menu::editAnimations() { } } +void Menu::changePrivateKey() { + // setup the dialog + QInputDialog privateKeyDialog(Application::getInstance()->getWindow()); + privateKeyDialog.setWindowTitle("Change Private Key"); + privateKeyDialog.setLabelText("RSA 2048-bit Private Key:"); + privateKeyDialog.setWindowFlags(Qt::Sheet); + privateKeyDialog.setTextValue(QString(_walletPrivateKey)); + privateKeyDialog.resize(privateKeyDialog.parentWidget()->size().width() * DIALOG_RATIO_OF_WINDOW, + privateKeyDialog.size().height()); + + int dialogReturn = privateKeyDialog.exec(); + if (dialogReturn == QDialog::Accepted) { + // pull the private key from the dialog + _walletPrivateKey = privateKeyDialog.textValue().toUtf8(); + } + + sendFakeEnterEvent(); +} + void Menu::goToDomain(const QString newDomain) { if (NodeList::getInstance()->getDomainHandler().getHostname() != newDomain) { // send a node kill request, indicating to other clients that they should play the "disappeared" effect diff --git a/interface/src/Menu.h b/interface/src/Menu.h index afe34c09d9..006f6dafc9 100644 --- a/interface/src/Menu.h +++ b/interface/src/Menu.h @@ -159,6 +159,8 @@ public: void static goToOrientation(QString orientation); void static goToDomain(const QString newDomain); void static goTo(QString destination); + + const QByteArray& getWalletPrivateKey() const { return _walletPrivateKey; } signals: void scriptLocationChanged(const QString& newPath); @@ -197,6 +199,7 @@ private slots: void editPreferences(); void editAttachments(); void editAnimations(); + void changePrivateKey(); void goToDomainDialog(); void goToLocation(); void nameLocation(); @@ -293,6 +296,8 @@ private: QAction* _chatAction; QString _snapshotsLocation; QString _scriptsLocation; + QByteArray _walletPrivateKey; + }; namespace MenuOption { @@ -444,6 +449,7 @@ namespace MenuOption { const QString VoxelMode = "Cycle Voxel Mode"; const QString Voxels = "Voxels"; const QString VoxelTextures = "Voxel Textures"; + const QString WalletPrivateKey = "Wallet Private Key"; } void sendFakeEnterEvent(); diff --git a/interface/src/SignedWalletTransaction.cpp b/interface/src/SignedWalletTransaction.cpp new file mode 100644 index 0000000000..d29207e4f5 --- /dev/null +++ b/interface/src/SignedWalletTransaction.cpp @@ -0,0 +1,82 @@ +// +// SignedWalletTransaction.cpp +// interface/src +// +// Created by Stephen Birarda on 2014-07-11. +// 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 +#include + +#include + +#include "Menu.h" + +#include "SignedWalletTransaction.h" + +SignedWalletTransaction::SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, + qint64 messageTimestamp, qint64 expiryDelta) : + WalletTransaction(destinationUUID, amount), + _messageTimestamp(messageTimestamp), + _expiryDelta(expiryDelta) +{ + +} + +QByteArray SignedWalletTransaction::hexMessage() { + // build the message using the components of this transaction + + // UUID, source UUID, destination UUID, message timestamp, expiry delta, amount + QByteArray messageBinary; + + messageBinary.append(_uuid.toRfc4122()); + + messageBinary.append(reinterpret_cast(&_messageTimestamp), sizeof(_messageTimestamp)); + messageBinary.append(reinterpret_cast(&_expiryDelta), sizeof(_expiryDelta)); + + messageBinary.append(AccountManager::getInstance().getAccountInfo().getWalletID().toRfc4122()); + + messageBinary.append(_destinationUUID.toRfc4122()); + + messageBinary.append(reinterpret_cast(&_amount), sizeof(_amount)); + + return messageBinary.toHex(); +} + +QByteArray SignedWalletTransaction::messageDigest() { + return QCryptographicHash::hash(hexMessage(), QCryptographicHash::Sha256).toHex(); +} + +QByteArray SignedWalletTransaction::signedMessageDigest() { + // pull the current private key from menu into RSA structure in memory + QByteArray privateKeyByteArray = Menu::getInstance()->getWalletPrivateKey(); + + BIO* privateKeyBIO = NULL; + RSA* rsaPrivateKey = NULL; + + privateKeyBIO = BIO_new_mem_buf(privateKeyByteArray.data(), privateKeyByteArray.size()); + PEM_read_bio_RSAPrivateKey(privateKeyBIO, &rsaPrivateKey, NULL, NULL); + + QByteArray digestToEncrypt = messageDigest(); + QByteArray encryptedDigest(RSA_size(rsaPrivateKey), 0); + + int encryptReturn = RSA_private_encrypt(digestToEncrypt.size(), + reinterpret_cast(digestToEncrypt.constData()), + reinterpret_cast(encryptedDigest.data()), + rsaPrivateKey, RSA_PKCS1_PADDING); + + // free the two structures used + BIO_free(privateKeyBIO); + RSA_free(rsaPrivateKey); + + return (encryptReturn != -1) ? encryptedDigest : QByteArray(); +} \ No newline at end of file diff --git a/interface/src/SignedWalletTransaction.h b/interface/src/SignedWalletTransaction.h new file mode 100644 index 0000000000..3b13f73335 --- /dev/null +++ b/interface/src/SignedWalletTransaction.h @@ -0,0 +1,31 @@ +// +// SignedWalletTransaction.h +// interfac/src +// +// Created by Stephen Birarda on 2014-07-11. +// 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_SignedWalletTransaction_h +#define hifi_SignedWalletTransaction_h + +#include + +class SignedWalletTransaction : public WalletTransaction { + Q_OBJECT +public: + SignedWalletTransaction(const QUuid& destinationUUID, qint64 amount, qint64 messageTimestamp, qint64 expiryDelta); + + QByteArray hexMessage(); + QByteArray messageDigest(); + QByteArray signedMessageDigest(); + +private: + qint64 _messageTimestamp; + qint64 _expiryDelta; +}; + +#endif // hifi_SignedWalletTransaction_h \ No newline at end of file diff --git a/libraries/networking/src/DataServerAccountInfo.cpp b/libraries/networking/src/DataServerAccountInfo.cpp index 507c085d26..9bdb012f70 100644 --- a/libraries/networking/src/DataServerAccountInfo.cpp +++ b/libraries/networking/src/DataServerAccountInfo.cpp @@ -18,6 +18,7 @@ DataServerAccountInfo::DataServerAccountInfo() : _username(), _xmppPassword(), _discourseApiKey(), + _walletID(), _balance(0), _hasBalance(false) { @@ -29,6 +30,7 @@ DataServerAccountInfo::DataServerAccountInfo(const DataServerAccountInfo& otherI _username = otherInfo._username; _xmppPassword = otherInfo._xmppPassword; _discourseApiKey = otherInfo._discourseApiKey; + _walletID = otherInfo._walletID; _balance = otherInfo._balance; _hasBalance = otherInfo._hasBalance; } @@ -46,6 +48,7 @@ void DataServerAccountInfo::swap(DataServerAccountInfo& otherInfo) { swap(_username, otherInfo._username); swap(_xmppPassword, otherInfo._xmppPassword); swap(_discourseApiKey, otherInfo._discourseApiKey); + swap(_walletID, otherInfo._walletID); swap(_balance, otherInfo._balance); swap(_hasBalance, otherInfo._hasBalance); } @@ -74,6 +77,12 @@ void DataServerAccountInfo::setDiscourseApiKey(const QString& discourseApiKey) { } } +void DataServerAccountInfo::setWalletID(const QUuid& walletID) { + if (_walletID != walletID) { + _walletID = walletID; + } +} + void DataServerAccountInfo::setBalance(qint64 balance) { if (!_hasBalance || _balance != balance) { _balance = balance; @@ -99,14 +108,15 @@ void DataServerAccountInfo::setProfileInfoFromJSON(const QJsonObject& jsonObject setUsername(user["username"].toString()); setXMPPPassword(user["xmpp_password"].toString()); setDiscourseApiKey(user["discourse_api_key"].toString()); + setWalletID(QUuid(user["wallet_id"].toString())); } QDataStream& operator<<(QDataStream &out, const DataServerAccountInfo& info) { - out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey; + out << info._accessToken << info._username << info._xmppPassword << info._discourseApiKey << info._walletID; return out; } QDataStream& operator>>(QDataStream &in, DataServerAccountInfo& info) { - in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey; + in >> info._accessToken >> info._username >> info._xmppPassword >> info._discourseApiKey >> info._walletID; return in; } diff --git a/libraries/networking/src/DataServerAccountInfo.h b/libraries/networking/src/DataServerAccountInfo.h index 27b776e3ff..dd9540718e 100644 --- a/libraries/networking/src/DataServerAccountInfo.h +++ b/libraries/networking/src/DataServerAccountInfo.h @@ -13,6 +13,7 @@ #define hifi_DataServerAccountInfo_h #include +#include #include "OAuthAccessToken.h" @@ -36,6 +37,9 @@ public: const QString& getDiscourseApiKey() const { return _discourseApiKey; } void setDiscourseApiKey(const QString& discourseApiKey); + + const QUuid& getWalletID() const { return _walletID; } + void setWalletID(const QUuid& walletID); qint64 getBalance() const { return _balance; } float getBalanceInSatoshis() const { return _balance / SATOSHIS_PER_CREDIT; } @@ -59,6 +63,7 @@ private: QString _username; QString _xmppPassword; QString _discourseApiKey; + QUuid _walletID; qint64 _balance; bool _hasBalance; }; diff --git a/domain-server/src/WalletTransaction.cpp b/libraries/networking/src/WalletTransaction.cpp similarity index 100% rename from domain-server/src/WalletTransaction.cpp rename to libraries/networking/src/WalletTransaction.cpp diff --git a/domain-server/src/WalletTransaction.h b/libraries/networking/src/WalletTransaction.h similarity index 99% rename from domain-server/src/WalletTransaction.h rename to libraries/networking/src/WalletTransaction.h index 5e05f9f549..7728eb0f1b 100644 --- a/domain-server/src/WalletTransaction.h +++ b/libraries/networking/src/WalletTransaction.h @@ -36,7 +36,7 @@ public: QJsonDocument postJson(); QJsonObject toJson(); void loadFromJson(const QJsonObject& jsonObject); -private: +protected: QUuid _uuid; QUuid _destinationUUID; qint64 _amount;