Bladeren bron

[FIX] Security certificate validation for CA certificate

 - Check if the certificate used to establish connection is
   CA or User certificate
 - This fix resolves Security/Security Certificate Validation/029.js

Change-Id: I9e7d1e3ba43c13e4eec830368da4a94b0ce7aaf7
Signed-off-by: Asish Ganesh <asish.g@kalycito.com>
Asish Ganesh 5 jaren geleden
bovenliggende
commit
d85d929592
1 gewijzigde bestanden met toevoegingen van 13 en 0 verwijderingen
  1. 13 0
      plugins/ua_pki_default.c

+ 13 - 0
plugins/ua_pki_default.c

@@ -2,6 +2,7 @@
  * See http://creativecommons.org/publicdomain/zero/1.0/ for more information.
  *
  *    Copyright 2018 (c) Mark Giraud, Fraunhofer IOSB
+ *    Copyright 2019 (c) Kalycito Infotech Private Limited
  */
 
 #include <open62541/plugin/pki_default.h>
@@ -79,6 +80,18 @@ certificateVerification_verify(void *verificationContext,
                                                    &crtProfile, NULL, &flags, NULL, NULL);
 
     // TODO: Extend verification
+
+    /* This condition will check whether the certificate is a User certificate
+     * or a CA certificate. If the MBEDTLS_X509_KU_KEY_CERT_SIGN and
+     * MBEDTLS_X509_KU_CRL_SIGN of key_usage are set, then the certificate
+     * shall be condidered as CA Certificate and cannot be used to establish a
+     * connection. Refer the test case CTT/Security/Security Certificate Validation/029.js
+     * for more details */
+    if((remoteCertificate.key_usage & MBEDTLS_X509_KU_KEY_CERT_SIGN) &&
+       (remoteCertificate.key_usage & MBEDTLS_X509_KU_CRL_SIGN)) {
+        return UA_STATUSCODE_BADCERTIFICATEUSENOTALLOWED;
+    }
+
     UA_StatusCode retval = UA_STATUSCODE_GOOD;
     if(mbedErr) {
         /* char buff[100]; */