test/Makefile.am | 1 + test/WopiProofTests.cpp | 36 ++++++++++++++++++++++++++++++++++++ wsd/ProofKey.cpp | 30 +----------------------------- wsd/ProofKey.hpp | 35 +++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 29 deletions(-)
New commits: commit a2b9fc474a1b250fdaf8510a35089d4513de9585 Author: Michael Meeks <[email protected]> AuthorDate: Tue Apr 7 21:42:30 2020 +0100 Commit: Michael Meeks <[email protected]> CommitDate: Wed Apr 8 10:58:49 2020 +0200 Proof: re-factor - publicise some internals to make testing easier. Also add dummy, run-every-build test to validate wopi like proofs. Change-Id: Ic2dc647a8d61693ae87b6523aaa30632979fd5d6 Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91854 Tested-by: Jenkins CollaboraOffice <[email protected]> Reviewed-by: Michael Meeks <[email protected]> diff --git a/test/Makefile.am b/test/Makefile.am index db5c6fb95..629b52c19 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -71,6 +71,7 @@ test_base_source = \ TileQueueTests.cpp \ WhiteBoxTests.cpp \ DeltaTests.cpp \ + WopiProofTests.cpp \ $(wsd_sources) unittest_CPPFLAGS = -I$(top_srcdir) -DBUILDING_TESTS -DSTANDALONE_CPPUNIT diff --git a/test/WopiProofTests.cpp b/test/WopiProofTests.cpp new file mode 100644 index 000000000..1d2b1d5cb --- /dev/null +++ b/test/WopiProofTests.cpp @@ -0,0 +1,36 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <config.h> + +#include <test/lokassert.hpp> + +#include <ProofKey.hpp> +#include <Util.hpp> + +/// Delta unit-tests. +class WopiProofTests : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(WopiProofTests); + + CPPUNIT_TEST(testProof); + + CPPUNIT_TEST_SUITE_END(); + + void testProof(); +}; + +void WopiProofTests::testProof() +{ + LOK_ASSERT(1 > 0); +} + +CPPUNIT_TEST_SUITE_REGISTRATION(WopiProofTests); + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/wsd/ProofKey.cpp b/wsd/ProofKey.cpp index e0dba1b46..489ad89b1 100644 --- a/wsd/ProofKey.cpp +++ b/wsd/ProofKey.cpp @@ -14,9 +14,7 @@ #include <algorithm> #include <cassert> -#include <chrono> #include <cstdlib> -#include <memory> #include <vector> #include <Poco/Base64Decoder.h> @@ -95,31 +93,7 @@ std::string BytesToBase64(const std::vector<unsigned char>& bytes) return oss.str(); } -class Proof { -public: - Proof(); - VecOfStringPairs GetProofHeaders(const std::string& access_token, const std::string& uri) const; - const VecOfStringPairs& GetProofKeyAttributes() const { return m_aAttribs; } -private: - static std::string ProofKeyPath(); - - // modulus and exponent are big-endian vectors - static std::vector<unsigned char> RSA2CapiBlob(const std::vector<unsigned char>& modulus, - const std::vector<unsigned char>& exponent); - - // Returns .Net tick (=100ns) count since 0001-01-01 00:00:00 Z - // See https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks - static int64_t DotNetTicks(const std::chrono::system_clock::time_point& utc); - // Returns bytes to sign and base64-encode - // See http://www.wictorwilen.se/sharepoint-2013-building-your-own-wopi-client-part-2 - static std::vector<unsigned char> GetProof(const std::string& access_token, - const std::string& uri, int64_t ticks); - // Signs bytes and returns base64-encoded string - std::string SignProof(const std::vector<unsigned char>& proof) const; - - const std::unique_ptr<const Poco::Crypto::RSAKey> m_pKey; - VecOfStringPairs m_aAttribs; -}; +} Proof::Proof() : m_pKey([]() -> Poco::Crypto::RSAKey* { @@ -262,8 +236,6 @@ const Proof& GetProof() return proof; } -} - VecOfStringPairs GetProofHeaders(const std::string& access_token, const std::string& uri) { return GetProof().GetProofHeaders(access_token, uri); diff --git a/wsd/ProofKey.hpp b/wsd/ProofKey.hpp index f02403db1..e74942e70 100644 --- a/wsd/ProofKey.hpp +++ b/wsd/ProofKey.hpp @@ -14,9 +14,44 @@ #include <string> #include <utility> #include <vector> +#include <chrono> +#include <memory> typedef std::vector<std::pair<std::string, std::string>> VecOfStringPairs; +namespace Poco { + namespace Crypto { + class RSAKey; + } +} + +class Proof { +public: + Proof(); + VecOfStringPairs GetProofHeaders(const std::string& access_token, const std::string& uri) const; + const VecOfStringPairs& GetProofKeyAttributes() const { return m_aAttribs; } +private: + static std::string ProofKeyPath(); + + // modulus and exponent are big-endian vectors + static std::vector<unsigned char> RSA2CapiBlob(const std::vector<unsigned char>& modulus, + const std::vector<unsigned char>& exponent); + + // Returns .Net tick (=100ns) count since 0001-01-01 00:00:00 Z + // See https://docs.microsoft.com/en-us/dotnet/api/system.datetime.ticks + static int64_t DotNetTicks(const std::chrono::system_clock::time_point& utc); + // Returns bytes to sign and base64-encode + // See http://www.wictorwilen.se/sharepoint-2013-building-your-own-wopi-client-part-2 + static std::vector<unsigned char> GetProof(const std::string& access_token, + const std::string& uri, int64_t ticks); + // Signs bytes and returns base64-encoded string + std::string SignProof(const std::vector<unsigned char>& proof) const; + + const std::unique_ptr<const Poco::Crypto::RSAKey> m_pKey; + VecOfStringPairs m_aAttribs; +}; + + // Returns pairs <header_name, header_value> to add to request // The headers returned are X-WOPI-TimeStamp, X-WOPI-Proof // If no proof key, returns empty vector _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
