You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@geode.apache.org by jb...@apache.org on 2018/03/29 04:57:51 UTC

[geode-native] 05/09: dhimpl warning free

This is an automated email from the ASF dual-hosted git repository.

jbarrett pushed a commit to branch feature/GEODE-4946-msvc-warn
in repository https://gitbox.apache.org/repos/asf/geode-native.git

commit 0d94941c2dd555b49104256dcbf80d03c1ae34bf
Author: Jacob Barrett <jb...@pivotal.io>
AuthorDate: Wed Mar 28 19:20:36 2018 +0000

    dhimpl warning free
---
 cppcache/src/DiffieHellman.cpp |  8 ++++----
 cppcache/src/DiffieHellman.hpp |  8 ++++----
 cppcache/src/TcrConnection.cpp |  3 ++-
 dhimpl/CMakeLists.txt          |  7 +++++++
 dhimpl/DHImpl.cpp              | 37 +++++++++++++++++--------------------
 dhimpl/DHImpl.hpp              |  2 +-
 6 files changed, 35 insertions(+), 30 deletions(-)

diff --git a/cppcache/src/DiffieHellman.cpp b/cppcache/src/DiffieHellman.cpp
index be2ccb8..454482a 100644
--- a/cppcache/src/DiffieHellman.cpp
+++ b/cppcache/src/DiffieHellman.cpp
@@ -148,8 +148,8 @@ std::shared_ptr<CacheableBytes> DiffieHellman::encrypt(
                  cleartext->length());
 }
 std::shared_ptr<CacheableBytes> DiffieHellman::encrypt(const uint8_t* cleartext,
-                                                       size_t len) {
-  size_t cipherLen = 0;
+                                                       int len) {
+  int cipherLen = 0;
   auto ciphertextPtr = gf_encryptDH_Ptr(m_dhCtx, cleartext, len, &cipherLen);
   return CacheableBytes::create(
       std::vector<int8_t>(ciphertextPtr, ciphertextPtr + cipherLen));
@@ -160,8 +160,8 @@ std::shared_ptr<CacheableBytes> DiffieHellman::decrypt(
                  cleartext->length());
 }
 std::shared_ptr<CacheableBytes> DiffieHellman::decrypt(const uint8_t* cleartext,
-                                                       size_t len) {
-  size_t cipherLen = 0;
+                                                       int len) {
+  int cipherLen = 0;
   auto ciphertextPtr = gf_decryptDH_Ptr(m_dhCtx, cleartext, len, &cipherLen);
   return CacheableBytes::create(
       std::vector<int8_t>(ciphertextPtr, ciphertextPtr + cipherLen));
diff --git a/cppcache/src/DiffieHellman.hpp b/cppcache/src/DiffieHellman.hpp
index 245a745..9813c39 100644
--- a/cppcache/src/DiffieHellman.hpp
+++ b/cppcache/src/DiffieHellman.hpp
@@ -49,10 +49,10 @@ class DiffieHellman {
   void computeSharedSecret(void);
   std::shared_ptr<CacheableBytes> encrypt(
       const std::shared_ptr<CacheableBytes>& cleartext);
-  std::shared_ptr<CacheableBytes> encrypt(const uint8_t* cleartext, size_t len);
+  std::shared_ptr<CacheableBytes> encrypt(const uint8_t* cleartext, int len);
   std::shared_ptr<CacheableBytes> decrypt(
       const std::shared_ptr<CacheableBytes>& cleartext);
-  std::shared_ptr<CacheableBytes> decrypt(const uint8_t* cleartext, size_t len);
+  std::shared_ptr<CacheableBytes> decrypt(const uint8_t* cleartext, int len);
   bool verify(const std::shared_ptr<CacheableString>& subject,
               const std::shared_ptr<CacheableBytes>& challenge,
               const std::shared_ptr<CacheableBytes>& response);
@@ -78,10 +78,10 @@ class DiffieHellman {
   typedef void (*gf_computeSharedSecret_Type)(void* dhCtx);
   typedef unsigned char* (*gf_encryptDH_Type)(void* dhCtx,
                                               const unsigned char* cleartext,
-                                              size_t len, size_t* retLen);
+                                              int len, int* retLen);
   typedef unsigned char* (*gf_decryptDH_Type)(void* dhCtx,
                                               const unsigned char* cleartext,
-                                              size_t len, size_t* retLen);
+                                              int len, int* retLen);
   typedef bool (*gf_verifyDH_Type)(void* dhCtx, const char* subject,
                                    const unsigned char* challenge,
                                    int challengeLen,
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index f590d36..78e9729 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -356,7 +356,8 @@ bool TcrConnection::InitTcrConnection(
       }
       challengeBytes->toData(*cleartext);
       auto ciphertext =
-          m_dh->encrypt(cleartext->getBuffer(), cleartext->getBufferLength());
+          m_dh->encrypt(cleartext->getBuffer(),
+                        static_cast<int>(cleartext->getBufferLength()));
 
       auto sendCreds = cacheImpl->createDataOutput();
       ciphertext->toData(*sendCreds);
diff --git a/dhimpl/CMakeLists.txt b/dhimpl/CMakeLists.txt
index 41d2f83..5d459de 100644
--- a/dhimpl/CMakeLists.txt
+++ b/dhimpl/CMakeLists.txt
@@ -19,9 +19,16 @@ project(dhimpl LANGUAGES CXX)
 file(GLOB_RECURSE SOURCES "*.cpp")
 
 add_library(DHImpl SHARED ${SOURCES})
+
+target_compile_definitions(DHImpl
+  PRIVATE
+    BUILD_CPPCACHE)
+
 target_link_libraries(DHImpl
   PUBLIC 
     apache-geode
     crypto
     c++11
+  PRIVATE
+    _WarningsAsError
 )
diff --git a/dhimpl/DHImpl.cpp b/dhimpl/DHImpl.cpp
index db10507..0b9b85b 100644
--- a/dhimpl/DHImpl.cpp
+++ b/dhimpl/DHImpl.cpp
@@ -59,16 +59,16 @@ static EVP_PKEY *DH_PUBKEY_get(DH_PUBKEY *key);
 static const EVP_CIPHER *getCipherFunc();
 static int setSkAlgo(const char *skalgo);
 
-ASN1_SEQUENCE(
-    DH_PUBKEY) = {ASN1_SIMPLE(DH_PUBKEY, algor, X509_ALGOR),
-                  ASN1_SIMPLE(DH_PUBKEY, public_key,
-                              ASN1_BIT_STRING)} ASN1_SEQUENCE_END(DH_PUBKEY)
+ASN1_SEQUENCE(DH_PUBKEY) = {
+    ASN1_SIMPLE(DH_PUBKEY, algor, X509_ALGOR),
+    ASN1_SIMPLE(DH_PUBKEY, public_key, ASN1_BIT_STRING)};
+ASN1_SEQUENCE_END(DH_PUBKEY);
 
-    // This gives us the i2d/d2i x.509 (ASN1 DER) encode/decode functions
-    IMPLEMENT_ASN1_FUNCTIONS(DH_PUBKEY)
+// This gives us the i2d/d2i x.509 (ASN1 DER) encode/decode functions
+IMPLEMENT_ASN1_FUNCTIONS(DH_PUBKEY);
 
-    // Returns Error code
-    int gf_initDhKeys(const char *dhAlgo, const char *ksPath) {
+// Returns Error code
+int gf_initDhKeys(const char *dhAlgo, const char *ksPath) {
   int errorCode = DH_ERR_NO_ERROR;  // No error;
 
   // ksPath can be null
@@ -209,9 +209,9 @@ unsigned char *gf_getPublicKey(int *pLen) {
   //
   //  Note, this temp pointer is needed because OpenSSL increments the pointer
   //  passed in
-  // so that following encoding can be done at the current output location, this
-  // will cause a
-  // problem if we try to free the pointer which has been moved by OpenSSL.
+  // so that following encoding can be done at the current output location,
+  // this will cause a problem if we try to free the pointer which has been
+  // moved by OpenSSL.
   //
   i2d_DH_PUBKEY(dhpubkey, &temp);
 
@@ -253,7 +253,7 @@ void gf_setPublicKeyOther(const unsigned char *pubkey, int length) {
 #endif
 }
 
-void gf_computeSharedSecret(void) {
+void gf_computeSharedSecret() {
   LOGDH("COMPUTE: DH ptr %p, pubkeyOther ptr %p", m_dh, m_pubKeyOther);
 
   LOGDH("DHcomputeKey DHSize is %d", DH_size(m_dh));
@@ -334,8 +334,8 @@ const EVP_CIPHER *getCipherFunc() {
   }
 }
 
-unsigned char *gf_encryptDH(const unsigned char *cleartext, size_t len,
-                            size_t *retLen) {
+unsigned char *gf_encryptDH(const unsigned char *cleartext, int len,
+                            int *retLen) {
   // Validation
   if (cleartext == NULL || len < 1 || retLen == NULL) {
     return NULL;
@@ -391,13 +391,14 @@ unsigned char *gf_encryptDH(const unsigned char *cleartext, size_t len,
 
   ret = EVP_CIPHER_CTX_cleanup(ctx);
 
-  LOGDH("DHencrypt: in len is %zd, out len is %d", len, outlen);
+  LOGDH("DHencrypt: in len is %d, out len is %d", len, outlen);
 
   *retLen = outlen;
   return ciphertext;
 }
 
-// std::shared_ptr<CacheableBytes> decrypt(const uint8_t * ciphertext, int len)
+// std::shared_ptr<CacheableBytes> decrypt(const uint8_t * ciphertext, int
+// len)
 // {
 //  LOGDH("DH: Used unimplemented decrypt!");
 //  return NULL;
@@ -639,8 +640,4 @@ EVP_PKEY *DH_PUBKEY_get(DH_PUBKEY *key) {
 
   if (asn1int != NULL) ASN1_INTEGER_free(asn1int);
   return (ret);
-err:
-  if (asn1int != NULL) ASN1_INTEGER_free(asn1int);
-  if (ret != NULL) EVP_PKEY_free(ret);
-  return (NULL);
 }
diff --git a/dhimpl/DHImpl.hpp b/dhimpl/DHImpl.hpp
index d66b158..3eb3860 100644
--- a/dhimpl/DHImpl.hpp
+++ b/dhimpl/DHImpl.hpp
@@ -58,7 +58,7 @@ _GEODE_EXPORT void gf_setPublicKeyOther(const unsigned char* pubkey,
                                         int length);
 _GEODE_EXPORT void gf_computeSharedSecret(void);
 _GEODE_EXPORT unsigned char* gf_encryptDH(const unsigned char* cleartext,
-                                          size_t len, size_t* retLen);
+                                          int len, int* retLen);
 _GEODE_EXPORT bool gf_verifyDH(const char* subject,
                                const unsigned char* challenge, int challengeLen,
                                const unsigned char* response, int responseLen,

-- 
To stop receiving notification emails like this one, please contact
jbarrett@apache.org.