Browse Source

remove sha1 function

StalderT 7 years ago
parent
commit
bc8ca555b0

+ 0 - 2
CMakeLists.txt

@@ -441,8 +441,6 @@ if(UA_ENABLE_ENCRYPTION)
             ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic128rsa15.h)
     set(default_plugin_headers ${default_plugin_headers}
             ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic256sha256.h)
-    set(default_plugin_sources ${default_plugin_sources}
-            ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_common.c)
     set(default_plugin_sources ${default_plugin_sources}
             ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic128rsa15.c)
     set(default_plugin_sources ${default_plugin_sources}

+ 17 - 4
plugins/ua_securitypolicy_basic128rsa15.c

@@ -12,10 +12,11 @@
 #include <mbedtls/entropy.h>
 #include <mbedtls/entropy_poll.h>
 #include <mbedtls/error.h>
+#include <mbedtls/version.h>
+#include <mbedtls/sha1.h>
 
 #include "ua_plugin_pki.h"
 #include "ua_plugin_securitypolicy.h"
-#include "ua_securitypolicy_common.h"
 #include "ua_securitypolicy_basic128rsa15.h"
 #include "ua_types.h"
 #include "ua_types_generated_handling.h"
@@ -92,7 +93,11 @@ asym_verify_sp_basic128rsa15(const UA_SecurityPolicy *securityPolicy,
 
     /* Compute the sha1 hash */
     unsigned char hash[UA_SHA1_LENGTH];
-    sha1(message->data, message->length, hash);
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    mbedtls_sha1_ret(message->data, message->length, hash);
+#else
+    mbedtls_sha1(message->data, message->length, hash);
+#endif
 
     /* Set the RSA settings */
     mbedtls_rsa_context *rsaContext = mbedtls_pk_rsa(cc->remoteCertificate.pk);
@@ -115,7 +120,11 @@ asym_sign_sp_basic128rsa15(const UA_SecurityPolicy *securityPolicy,
         return UA_STATUSCODE_BADINTERNALERROR;
 
     unsigned char hash[UA_SHA1_LENGTH];
-    sha1(message->data, message->length, hash);
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    mbedtls_sha1_ret(message->data, message->length, hash);
+#else
+    mbedtls_sha1(message->data, message->length, hash);
+#endif
 
     Basic128Rsa15_PolicyContext *pc = cc->policyContext;
     mbedtls_rsa_context *rsaContext = mbedtls_pk_rsa(pc->localPrivateKey);
@@ -281,7 +290,11 @@ asym_makeThumbprint_sp_basic128rsa15(const UA_SecurityPolicy *securityPolicy,
     if(thumbprint->length != UA_SHA1_LENGTH)
         return UA_STATUSCODE_BADINTERNALERROR;
 
-    sha1(certificate->data, certificate->length, thumbprint->data);
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    mbedtls_sha1_ret(certificate->data, certificate->length, thumbprint->data);
+#else
+    mbedtls_sha1(certificate->data, certificate->length, thumbprint->data);
+#endif
     return UA_STATUSCODE_GOOD;
 }
 

+ 6 - 2
plugins/ua_securitypolicy_basic256sha256.c

@@ -15,10 +15,10 @@
 #include <mbedtls/entropy_poll.h>
 #include <mbedtls/error.h>
 #include <mbedtls/version.h>
+#include <mbedtls/sha1.h>
 
 #include "ua_plugin_pki.h"
 #include "ua_plugin_securitypolicy.h"
-#include "ua_securitypolicy_common.h"
 #include "ua_securitypolicy_basic256sha256.h"
 #include "ua_types.h"
 #include "ua_types_generated_handling.h"
@@ -316,7 +316,11 @@ asym_makeThumbprint_sp_basic256sha256(const UA_SecurityPolicy *securityPolicy,
         return UA_STATUSCODE_BADINTERNALERROR;
 
     /* The certificate thumbprint is always a 20 bit sha1 hash, see Part 4 of the Specification. */
-    sha1(certificate->data, certificate->length, thumbprint->data);
+#if MBEDTLS_VERSION_NUMBER >= 0x02070000
+    mbedtls_sha1_ret(certificate->data, certificate->length, thumbprint->data);
+#else
+    mbedtls_sha1(certificate->data, certificate->length, thumbprint->data);
+#endif
     return UA_STATUSCODE_GOOD;
 }
 

+ 0 - 29
plugins/ua_securitypolicy_common.c

@@ -1,29 +0,0 @@
-/* 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 <mbedtls/sha1.h>
-#include <mbedtls/version.h>
-
-#include "ua_securitypolicy_common.h"
-
-
-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);
-}

+ 0 - 12
plugins/ua_securitypolicy_common.h

@@ -1,12 +0,0 @@
-/* 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/.
- */
- 
-#ifndef UA_SECURITYPOLICY_COMMON_H_
-#define UA_SECURITYPOLICY_COMMON_H_
-
-void
-sha1(const unsigned char *input, size_t ilen, unsigned char output[20]);
-
-#endif // UA_SECURITYPOLICY_COMMON_H_

+ 0 - 2
tests/CMakeLists.txt

@@ -42,8 +42,6 @@ set(test_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
 )
 
 if(UA_ENABLE_ENCRYPTION)
-    set(test_plugin_sources ${test_plugin_sources}
-        ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_common.c)
     set(test_plugin_sources ${test_plugin_sources}
         ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic128rsa15.c)
     set(test_plugin_sources ${test_plugin_sources}

+ 0 - 2
tests/fuzz/CMakeLists.txt

@@ -64,8 +64,6 @@ set(fuzzing_plugin_sources ${PROJECT_SOURCE_DIR}/plugins/ua_network_tcp.c
 )
 
 if(UA_ENABLE_ENCRYPTION)
-    set(fuzzing_plugin_sources ${fuzzing_plugin_sources}
-        ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_common.c)
     set(fuzzing_plugin_sources ${fuzzing_plugin_sources}
         ${PROJECT_SOURCE_DIR}/plugins/ua_securitypolicy_basic128rsa15.c)
     set(fuzzing_plugin_sources ${fuzzing_plugin_sources}