[Libreoffice-commits] online.git: test/Makefile.am test/WopiProofTests.cpp wsd/ProofKey.cpp wsd/ProofKey.hpp
Michael Meeks (via logerrit)
logerrit at kemper.freedesktop.org
Wed Apr 8 20:20:11 UTC 2020
test/Makefile.am | 3 ++-
test/WopiProofTests.cpp | 16 ++++++++++++++++
wsd/ProofKey.cpp | 15 ++++++++++++++-
wsd/ProofKey.hpp | 6 ++++++
4 files changed, 38 insertions(+), 2 deletions(-)
New commits:
commit f4f7b08d44aa8af50b18061f7c4ac84855aa1399
Author: Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Wed Apr 8 18:25:44 2020 +0100
Commit: Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed Apr 8 22:19:51 2020 +0200
Proof: implement CAPI blob test.
Change-Id: Ifa4ddc3c5fa375606eedd932af029e4b30a740de
Reviewed-on: https://gerrit.libreoffice.org/c/online/+/91936
Tested-by: Michael Meeks <michael.meeks at collabora.com>
Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
diff --git a/test/Makefile.am b/test/Makefile.am
index 629b52c19..0e63ab5ab 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -65,7 +65,8 @@ wsd_sources = \
../common/Authorization.cpp \
../kit/Kit.cpp \
../kit/TestStubs.cpp \
- ../wsd/TileCache.cpp
+ ../wsd/TileCache.cpp \
+ ../wsd/ProofKey.cpp
test_base_source = \
TileQueueTests.cpp \
diff --git a/test/WopiProofTests.cpp b/test/WopiProofTests.cpp
index 1d2b1d5cb..74a9c1df3 100644
--- a/test/WopiProofTests.cpp
+++ b/test/WopiProofTests.cpp
@@ -19,13 +19,29 @@ class WopiProofTests : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(WopiProofTests);
+ CPPUNIT_TEST(testCapiBlob);
CPPUNIT_TEST(testProof);
CPPUNIT_TEST_SUITE_END();
+ void testCapiBlob();
+
void testProof();
};
+
+void WopiProofTests::testCapiBlob()
+{
+ // Known-good sample strings from https://github.com/microsoft/Office-Online-Test-Tools-and-Documentation
+ std::vector<unsigned char> modulus = Proof::Base64ToBytes("0HOWUPFFgmSYHbLZZzdWO/HUOr8YNfx5NAl7GUytooHZ7B9QxQKTJpj0NIJ4XEskQW8e4dLzRrPbNOOJ+KpWHttXz8HoQXkkZV/gYNxaNHJ8/pRXGMZzfVM5vchhx/2C7ULPTrpBsSpmfWQ6ShaVoQzfThFUd0MsBvIN7HVtqzPx9jbSV04wAqyNjcro7F3iu9w7AEsMejHbFlWoN+J05dP5ixryF7+2U5RVmjMt7/dYUdCoiXvCMt2CaVr0XEG6udHU4iDKVKZjmUBc7cTWRzhqEL7lZ1yQfylp38Nd2xxVJ0sSU7OkC1bBDlePcYGaF3JjJgsmp/H5BNnlW9gSxQ==");
+ std::vector<unsigned char> exponent = Proof::Base64ToBytes("AQAB");
+
+ std::vector<unsigned char> capiBlob = Proof::RSA2CapiBlob(modulus, exponent);
+
+ std::string capiEncoded = Proof::BytesToBase64(capiBlob);
+ LOK_ASSERT_EQUAL(capiEncoded, std::string("BgIAAACkAABSU0ExAAgAAAEAAQDFEthb5dkE+fGnJgsmY3IXmoFxj1cOwVYLpLNTEksnVRzbXcPfaSl/kFxn5b4QajhH1sTtXECZY6ZUyiDi1NG5ukFc9Fppgt0ywnuJqNBRWPfvLTOaVZRTtr8X8hqL+dPldOI3qFUW2zF6DEsAO9y74l3s6MqNjawCME5X0jb28TOrbXXsDfIGLEN3VBFO3wyhlRZKOmR9ZiqxQbpOz0Ltgv3HYci9OVN9c8YYV5T+fHI0Wtxg4F9lJHlB6MHPV9seVqr4ieM027NG89LhHm9BJEtceII09JgmkwLFUB/s2YGirUwZewk0efw1GL861PE7Vjdn2bIdmGSCRfFQlnPQ"));
+}
+
void WopiProofTests::testProof()
{
LOK_ASSERT(1 > 0);
diff --git a/wsd/ProofKey.cpp b/wsd/ProofKey.cpp
index 489ad89b1..b78499da0 100644
--- a/wsd/ProofKey.cpp
+++ b/wsd/ProofKey.cpp
@@ -81,7 +81,9 @@ std::vector<unsigned char> ToNetworkOrderBytes(const T& x)
return getBytesBE(reinterpret_cast<const unsigned char*>(&x), sizeof(x));
}
-std::string BytesToBase64(const std::vector<unsigned char>& bytes)
+} // namespace
+
+std::string Proof::BytesToBase64(const std::vector<unsigned char>& bytes)
{
std::ostringstream oss;
// The signature generated contains CRLF line endings.
@@ -93,6 +95,17 @@ std::string BytesToBase64(const std::vector<unsigned char>& bytes)
return oss.str();
}
+std::vector<unsigned char> Proof::Base64ToBytes(const std::string &str)
+{
+ std::istringstream oss(str);
+ Poco::Base64Decoder decoder(oss);
+
+ char c = 0;
+ std::vector<unsigned char> vec;
+ while (decoder.get(c))
+ vec.push_back(c);
+
+ return vec;
}
Proof::Proof()
diff --git a/wsd/ProofKey.hpp b/wsd/ProofKey.hpp
index e74942e70..8e9f5c885 100644
--- a/wsd/ProofKey.hpp
+++ b/wsd/ProofKey.hpp
@@ -25,7 +25,10 @@ namespace Poco {
}
}
+class WopiProofTests;
+
class Proof {
+ friend class WopiProofTests;
public:
Proof();
VecOfStringPairs GetProofHeaders(const std::string& access_token, const std::string& uri) const;
@@ -33,6 +36,9 @@ public:
private:
static std::string ProofKeyPath();
+ static std::string BytesToBase64(const std::vector<unsigned char>& bytes);
+ static std::vector<unsigned char> Base64ToBytes(const std::string &str);
+
// 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);
More information about the Libreoffice-commits
mailing list