Explorar el Código

fix deprecated mbedtls functions

StalderT hace 7 años
padre
commit
5b141655a1
Se han modificado 2 ficheros con 21 adiciones y 0 borrados
  1. 11 0
      plugins/ua_securitypolicy_basic256sha256.c
  2. 10 0
      plugins/ua_securitypolicy_common.c

+ 11 - 0
plugins/ua_securitypolicy_basic256sha256.c

@@ -14,6 +14,7 @@
 #include <mbedtls/entropy.h>
 #include <mbedtls/entropy_poll.h>
 #include <mbedtls/error.h>
+#include <mbedtls/version.h>
 
 #include "ua_plugin_pki.h"
 #include "ua_plugin_securitypolicy.h"
@@ -94,7 +95,12 @@ asym_verify_sp_basic256sha256(const UA_SecurityPolicy *securityPolicy,
         return UA_STATUSCODE_BADINTERNALERROR;
 
     unsigned char hash[UA_SHA256_LENGTH];
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    // TODO check return status
+    mbedtls_sha256_ret(message->data, message->length, hash, 0);
+#else
     mbedtls_sha256(message->data, message->length, hash, 0);
+#endif
 
     /* Set the RSA settings */
     mbedtls_rsa_context *rsaContext = mbedtls_pk_rsa(cc->remoteCertificate.pk);
@@ -125,7 +131,12 @@ asym_sign_sp_basic256sha256(const UA_SecurityPolicy *securityPolicy,
         return UA_STATUSCODE_BADINTERNALERROR;
 
     unsigned char hash[UA_SHA256_LENGTH];
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    // TODO check return status
+    mbedtls_sha256_ret(message->data, message->length, hash, 0);
+#else
     mbedtls_sha256(message->data, message->length, hash, 0);
+#endif
 
     Basic256Sha256_PolicyContext *pc = cc->policyContext;
     mbedtls_rsa_context *rsaContext = mbedtls_pk_rsa(pc->localPrivateKey);

+ 10 - 0
plugins/ua_securitypolicy_common.c

@@ -4,6 +4,7 @@
  */
 
 #include <mbedtls/sha1.h>
+#include <mbedtls/version.h>
 
 #include "ua_securitypolicy_common.h"
 
@@ -12,8 +13,17 @@ void
 sha1(const unsigned char *input, size_t ilen, unsigned char output[20]) {
     mbedtls_sha1_context sha1Context;
     mbedtls_sha1_init(&sha1Context);
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    // TODO check return status / actually only/always return 0
+    mbedtls_sha1_starts_ret(&sha1Context);
+    // TODO check return status / actually only/always return 0
+    mbedtls_sha1_update_ret(&sha1Context, input, ilen);
+    // TODO check return status / actually only/always return 0
+    mbedtls_sha1_finish_ret(&sha1Context, output);
+#else
     mbedtls_sha1_starts(&sha1Context);
     mbedtls_sha1_update(&sha1Context, input, ilen);
     mbedtls_sha1_finish(&sha1Context, output);
+#endif
     mbedtls_sha1_free(&sha1Context);
 }