diff options
Diffstat (limited to 'Swiften/Crypto')
-rw-r--r-- | Swiften/Crypto/CommonCryptoCryptoProvider.cpp | 39 | ||||
-rw-r--r-- | Swiften/Crypto/CommonCryptoCryptoProvider.h | 15 | ||||
-rw-r--r-- | Swiften/Crypto/OpenSSLCryptoProvider.cpp | 25 | ||||
-rw-r--r-- | Swiften/Crypto/OpenSSLCryptoProvider.h | 15 | ||||
-rw-r--r-- | Swiften/Crypto/WindowsCryptoProvider.cpp | 10 | ||||
-rw-r--r-- | Swiften/Crypto/WindowsCryptoProvider.h | 13 |
6 files changed, 67 insertions, 50 deletions
diff --git a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp index 9fbdb2a..3cc69b0 100644 --- a/Swiften/Crypto/CommonCryptoCryptoProvider.cpp +++ b/Swiften/Crypto/CommonCryptoCryptoProvider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -27,18 +27,18 @@ namespace { } } - ~SHA1Hash() { + virtual ~SHA1Hash() override { } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } - virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE { + virtual std::vector<unsigned char> getHash() override { assert(!finalized); std::vector<unsigned char> result(CC_SHA1_DIGEST_LENGTH); CC_SHA1_Final(vecptr(result), &context); @@ -49,7 +49,12 @@ namespace { template<typename ContainerType> Hash& updateInternal(const ContainerType& data) { assert(!finalized); - if (!CC_SHA1_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) { + try { + if (!CC_SHA1_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) { + assert(false); + } + } + catch (const boost::numeric::bad_numeric_cast&) { assert(false); } return *this; @@ -68,18 +73,18 @@ namespace { } } - ~MD5Hash() { + virtual ~MD5Hash() override { } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } - virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE { + virtual std::vector<unsigned char> getHash() override { assert(!finalized); std::vector<unsigned char> result(CC_MD5_DIGEST_LENGTH); CC_MD5_Final(vecptr(result), &context); @@ -90,7 +95,12 @@ namespace { template<typename ContainerType> Hash& updateInternal(const ContainerType& data) { assert(!finalized); - if (!CC_MD5_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) { + try { + if (!CC_MD5_Update(&context, vecptr(data), boost::numeric_cast<CC_LONG>(data.size()))) { + assert(false); + } + } + catch (const boost::numeric::bad_numeric_cast&) { assert(false); } return *this; @@ -104,7 +114,12 @@ namespace { template<typename T> ByteArray getHMACSHA1Internal(const T& key, const ByteArray& data) { std::vector<unsigned char> result(CC_SHA1_DIGEST_LENGTH); - CCHmac(kCCHmacAlgSHA1, vecptr(key), key.size(), vecptr(data), boost::numeric_cast<CC_LONG>(data.size()), vecptr(result)); + try { + CCHmac(kCCHmacAlgSHA1, vecptr(key), key.size(), vecptr(data), boost::numeric_cast<CC_LONG>(data.size()), vecptr(result)); + } + catch (const boost::numeric::bad_numeric_cast&) { + assert(false); + } return result; } } diff --git a/Swiften/Crypto/CommonCryptoCryptoProvider.h b/Swiften/Crypto/CommonCryptoCryptoProvider.h index 8fa7fa6..7d1675f 100644 --- a/Swiften/Crypto/CommonCryptoCryptoProvider.h +++ b/Swiften/Crypto/CommonCryptoCryptoProvider.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -7,19 +7,18 @@ #pragma once #include <Swiften/Base/API.h> -#include <Swiften/Base/Override.h> #include <Swiften/Crypto/CryptoProvider.h> namespace Swift { class SWIFTEN_API CommonCryptoCryptoProvider : public CryptoProvider { public: CommonCryptoCryptoProvider(); - ~CommonCryptoCryptoProvider(); + virtual ~CommonCryptoCryptoProvider() override; - virtual Hash* createSHA1() SWIFTEN_OVERRIDE; - virtual Hash* createMD5() SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual bool isMD5AllowedForCrypto() const SWIFTEN_OVERRIDE; + virtual Hash* createSHA1() override; + virtual Hash* createMD5() override; + virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) override; + virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) override; + virtual bool isMD5AllowedForCrypto() const override; }; } diff --git a/Swiften/Crypto/OpenSSLCryptoProvider.cpp b/Swiften/Crypto/OpenSSLCryptoProvider.cpp index c785041..5245bd8 100644 --- a/Swiften/Crypto/OpenSSLCryptoProvider.cpp +++ b/Swiften/Crypto/OpenSSLCryptoProvider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Isode Limited. + * Copyright (c) 2013-2018 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -28,18 +28,18 @@ namespace { } } - ~SHA1Hash() { + ~SHA1Hash() override { } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } - virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE { + virtual std::vector<unsigned char> getHash() override { assert(!finalized); std::vector<unsigned char> result(SHA_DIGEST_LENGTH); SHA1_Final(vecptr(result), &context); @@ -69,18 +69,18 @@ namespace { } } - ~MD5Hash() { + ~MD5Hash() override { } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } - virtual std::vector<unsigned char> getHash() SWIFTEN_OVERRIDE { + virtual std::vector<unsigned char> getHash() override { assert(!finalized); std::vector<unsigned char> result(MD5_DIGEST_LENGTH); MD5_Final(vecptr(result), &context); @@ -107,7 +107,12 @@ namespace { ByteArray getHMACSHA1Internal(const T& key, const ByteArray& data) { unsigned int len = SHA_DIGEST_LENGTH; std::vector<unsigned char> result(len); - HMAC(EVP_sha1(), vecptr(key), boost::numeric_cast<int>(key.size()), vecptr(data), data.size(), vecptr(result), &len); + try { + HMAC(EVP_sha1(), vecptr(key), boost::numeric_cast<int>(key.size()), vecptr(data), data.size(), vecptr(result), &len); + } + catch (const boost::numeric::bad_numeric_cast&) { + assert(false); + } return result; } } diff --git a/Swiften/Crypto/OpenSSLCryptoProvider.h b/Swiften/Crypto/OpenSSLCryptoProvider.h index 6e0c01b..e4ee97d 100644 --- a/Swiften/Crypto/OpenSSLCryptoProvider.h +++ b/Swiften/Crypto/OpenSSLCryptoProvider.h @@ -1,24 +1,23 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ #pragma once -#include <Swiften/Base/Override.h> #include <Swiften/Crypto/CryptoProvider.h> namespace Swift { class OpenSSLCryptoProvider : public CryptoProvider { public: OpenSSLCryptoProvider(); - ~OpenSSLCryptoProvider(); + virtual ~OpenSSLCryptoProvider() override; - virtual Hash* createSHA1() SWIFTEN_OVERRIDE; - virtual Hash* createMD5() SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual bool isMD5AllowedForCrypto() const SWIFTEN_OVERRIDE; + virtual Hash* createSHA1() override; + virtual Hash* createMD5() override; + virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) override; + virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) override; + virtual bool isMD5AllowedForCrypto() const override; }; } diff --git a/Swiften/Crypto/WindowsCryptoProvider.cpp b/Swiften/Crypto/WindowsCryptoProvider.cpp index 513941f..c784283 100644 --- a/Swiften/Crypto/WindowsCryptoProvider.cpp +++ b/Swiften/Crypto/WindowsCryptoProvider.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2012-2016 Isode Limited. + * Copyright (c) 2012-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -43,11 +43,11 @@ namespace { CryptDestroyHash(hash); } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } @@ -123,11 +123,11 @@ namespace { CryptDestroyHash(hash); } - virtual Hash& update(const ByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const ByteArray& data) override { return updateInternal(data); } - virtual Hash& update(const SafeByteArray& data) SWIFTEN_OVERRIDE { + virtual Hash& update(const SafeByteArray& data) override { return updateInternal(data); } diff --git a/Swiften/Crypto/WindowsCryptoProvider.h b/Swiften/Crypto/WindowsCryptoProvider.h index f446027..d0c982e 100644 --- a/Swiften/Crypto/WindowsCryptoProvider.h +++ b/Swiften/Crypto/WindowsCryptoProvider.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013-2016 Isode Limited. + * Copyright (c) 2013-2017 Isode Limited. * All rights reserved. * See the COPYING file for more information. */ @@ -10,7 +10,6 @@ #include <boost/noncopyable.hpp> -#include <Swiften/Base/Override.h> #include <Swiften/Crypto/CryptoProvider.h> namespace Swift { @@ -19,11 +18,11 @@ namespace Swift { WindowsCryptoProvider(); virtual ~WindowsCryptoProvider(); - virtual Hash* createSHA1() SWIFTEN_OVERRIDE; - virtual Hash* createMD5() SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) SWIFTEN_OVERRIDE; - virtual bool isMD5AllowedForCrypto() const SWIFTEN_OVERRIDE; + virtual Hash* createSHA1() override; + virtual Hash* createMD5() override; + virtual ByteArray getHMACSHA1(const SafeByteArray& key, const ByteArray& data) override; + virtual ByteArray getHMACSHA1(const ByteArray& key, const ByteArray& data) override; + virtual bool isMD5AllowedForCrypto() const override; private: struct Private; |