]> git.ipfire.org Git - thirdparty/gnutls.git/commitdiff
use the same flags in all verification functions
authorNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 2 Jun 2015 14:31:49 +0000 (16:31 +0200)
committerNikos Mavrogiannopoulos <nmav@gnutls.org>
Tue, 2 Jun 2015 14:33:57 +0000 (16:33 +0200)
lib/gnutls_errors.c
lib/gnutls_pubkey.c
lib/includes/gnutls/abstract.h
lib/includes/gnutls/gnutls.h.in
lib/includes/gnutls/x509.h
lib/x509/pkcs7.c
lib/x509/x509.c

index ce5aaf796e69e37bc316af83fe8f27c8bed6bfa1..6e3fe0cc9982eb0823b9b3f16c0313dc51e3cbef 100644 (file)
@@ -387,6 +387,8 @@ static const gnutls_error_entry non_fatal_error_entries[] = {
        ERROR_ENTRY(N_("Function was interrupted."), GNUTLS_E_INTERRUPTED),
        ERROR_ENTRY(N_("Rehandshake was requested by the peer."),
                    GNUTLS_E_REHANDSHAKE),
+       ERROR_ENTRY(N_("One of the involved algorithms has insufficient security level."),
+                   GNUTLS_E_INSUFFICIENT_SECURITY),
        {NULL, NULL, 0}
 };
 
index 6c7a3905fe1e6c62c2e36536fa0cf59a09da6a3b..74a9802b157fb677b8cf1096735e5dcefc4e727f 100644 (file)
@@ -1581,11 +1581,13 @@ gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key,
 
 }
 
+#define OLD_PUBKEY_VERIFY_FLAG_TLS1_RSA 1
+
 /**
  * gnutls_pubkey_verify_data2:
  * @pubkey: Holds the public key
  * @algo: The signature algorithm used
- * @flags: Zero or one of %gnutls_pubkey_flags_t
+ * @flags: Zero or an OR list of #gnutls_certificate_verify_flags
  * @data: holds the signed data
  * @signature: contains the signature
  *
@@ -1593,7 +1595,9 @@ gnutls_pubkey_import_dsa_raw(gnutls_pubkey_t key,
  * parameters from the certificate.
  *
  * Returns: In case of a verification failure %GNUTLS_E_PK_SIG_VERIFY_FAILED 
- * is returned, and zero or positive code on success.
+ * is returned, and zero or positive code on success. For known to be insecure
+ * signatures this function will return %GNUTLS_E_INSUFFICIENT_SECURITY unless
+ * the flag %GNUTLS_VERIFY_ALLOW_BROKEN is specified.
  *
  * Since: 3.0
  **/
@@ -1612,7 +1616,7 @@ gnutls_pubkey_verify_data2(gnutls_pubkey_t pubkey,
                return GNUTLS_E_INVALID_REQUEST;
        }
 
-       if (flags & GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA)
+       if (flags & OLD_PUBKEY_VERIFY_FLAG_TLS1_RSA || flags & GNUTLS_VERIFY_USE_TLS1_RSA)
                return gnutls_assert_val(GNUTLS_E_INVALID_REQUEST);
 
        me = hash_to_entry(gnutls_sign_get_hash_algorithm(algo));
@@ -1623,6 +1627,13 @@ gnutls_pubkey_verify_data2(gnutls_pubkey_t pubkey,
                                 data, signature, &pubkey->params);
        if (ret < 0) {
                gnutls_assert();
+               return ret;
+       }
+
+       if (!(flags & GNUTLS_VERIFY_ALLOW_BROKEN)) {
+               if (gnutls_sign_is_secure(algo) == 0) {
+                       return gnutls_assert_val(GNUTLS_E_INSUFFICIENT_SECURITY);
+               }
        }
 
        return ret;
@@ -1632,7 +1643,7 @@ gnutls_pubkey_verify_data2(gnutls_pubkey_t pubkey,
  * gnutls_pubkey_verify_hash2:
  * @key: Holds the public key
  * @algo: The signature algorithm used
- * @flags: Zero or one of %gnutls_pubkey_flags_t
+ * @flags: Zero or an OR list of #gnutls_certificate_verify_flags
  * @hash: holds the hash digest to be verified
  * @signature: contains the signature
  *
@@ -1660,7 +1671,7 @@ gnutls_pubkey_verify_hash2(gnutls_pubkey_t key,
                return GNUTLS_E_INVALID_REQUEST;
        }
 
-       if (flags & GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA) {
+       if (flags & OLD_PUBKEY_VERIFY_FLAG_TLS1_RSA || flags & GNUTLS_VERIFY_USE_TLS1_RSA) {
                return _gnutls_pk_verify(GNUTLS_PK_RSA, hash, signature,
                                         &key->params);
        } else {
index 44123ec2ab1aed3fa75c7d507b3f3fb2fe545ce7..c915d7a03574b23856bcd96baf7d031eddf5a277 100644 (file)
@@ -40,8 +40,6 @@ extern "C" {
 #define GNUTLS_PUBKEY_VERIFY_FLAG_TLS_RSA GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA
 /**
  * gnutls_pubkey_flags:
- * @GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA: This indicates that a (raw) RSA signature is provided
- *   as in the TLS 1.0 protocol.
  * @GNUTLS_PUBKEY_DISABLE_CALLBACKS: The following flag disables call to PIN callbacks. Only
  *   relevant to TPM keys.
  * @GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT: request an OPENPGP fingerprint instead of the default.
@@ -49,11 +47,12 @@ extern "C" {
  * Enumeration of different certificate import flags.
  */
 typedef enum gnutls_pubkey_flags {
-       GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA = 1,
        GNUTLS_PUBKEY_DISABLE_CALLBACKS = 1 << 2,
        GNUTLS_PUBKEY_GET_OPENPGP_FINGERPRINT = 1 << 3
 } gnutls_pubkey_flags_t;
 
+#define GNUTLS_PUBKEY_VERIFY_FLAG_TLS1_RSA GNUTLS_VERIFY_USE_TLS1_RSA
+
 typedef int (*gnutls_privkey_sign_func) (gnutls_privkey_t key,
                                         void *userdata,
                                         const gnutls_datum_t *
index 49c4805adde90713e6f3d7352a178184e46b246c..4dd54eeff98f56557bcb90184db83e0851ac099f 100644 (file)
@@ -2452,6 +2452,7 @@ int gnutls_fips140_mode_enabled(void);
 #define GNUTLS_E_BAD_COOKIE -214
 #define GNUTLS_E_OPENPGP_PREFERRED_KEY_ERROR -215
 #define GNUTLS_E_INCOMPAT_DSA_KEY_WITH_TLS_PROTOCOL -216
+#define GNUTLS_E_INSUFFICIENT_SECURITY -217
 
 #define GNUTLS_E_HEARTBEAT_PONG_RECEIVED -292
 #define GNUTLS_E_HEARTBEAT_PING_RECEIVED -293
index 84d3601ca6fc8ca17cd61c33998ed3e620bf6f55..73b98e85a9aaf45623b4a3b9a14b0dbdac433c5f 100644 (file)
@@ -802,6 +802,8 @@ int gnutls_x509_crl_set_number(gnutls_x509_crl_t crl,
  *   using the broken MD2 algorithm.
  * @GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5: Allow certificates to be signed
  *   using the broken MD5 algorithm.
+ * @GNUTLS_VERIFY_ALLOW_BROKEN: Allow certificates to be signed
+ *   using any broken algorithm.
  * @GNUTLS_VERIFY_DISABLE_TIME_CHECKS: Disable checking of activation
  *   and expiration validity periods of certificate chains. Don't set
  *   this unless you understand the security implications.
@@ -809,6 +811,8 @@ int gnutls_x509_crl_set_number(gnutls_x509_crl_t crl,
  *   using certificate revocation lists or the available OCSP data.
  * @GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS: When including a hostname
  *   check in the verification, do not consider any wildcards.
+ * @GNUTLS_VERIFY_USE_TLS1_RSA: This indicates that a (raw) RSA signature is provided
+ *   as in the TLS 1.0 protocol. Not all functions accept this flag.
  *
  * Enumeration of different certificate verify flags. Additional
  * verification profiles can be set using GNUTLS_PROFILE_TO_VFLAGS()
@@ -827,9 +831,12 @@ typedef enum gnutls_certificate_verify_flags {
        GNUTLS_VERIFY_ALLOW_UNSORTED_CHAIN = 1 << 10,
        GNUTLS_VERIFY_DO_NOT_ALLOW_UNSORTED_CHAIN = 1 << 11,
        GNUTLS_VERIFY_DO_NOT_ALLOW_WILDCARDS = 1 << 12,
+       GNUTLS_VERIFY_USE_TLS1_RSA = 1 << 13
        /* cannot exceed 2^24 due to GNUTLS_PROFILE_TO_VFLAGS() */
 } gnutls_certificate_verify_flags;
 
+#define GNUTLS_VERIFY_ALLOW_BROKEN (GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD2|GNUTLS_VERIFY_ALLOW_SIGN_RSA_MD5)
+
 /**
  * gnutls_certificate_verification_profiles_t:
  * @GNUTLS_PROFILE_VERY_WEAK: A verification profile that
index 55cd7bd79970499e671b2656fb7cc4543d69cf78..be4f3b8a2ecdc6042858167558e32007a570e814 100644 (file)
@@ -768,7 +768,7 @@ static int figure_pkcs7_sigdata(gnutls_pkcs7_t pkcs7, const char *root,
  * @signer: the certificate believe to have signed the structure
  * @idx: the index of the signature info to check
  * @data: The data to be verified or %NULL
- * @flags: Should be zero
+ * @flags: Zero or an OR list of #gnutls_certificate_verify_flags
  *
  * This function will verify the provided data against the signature
  * present in the SignedData of the PKCS #7 structure. If the data
@@ -817,7 +817,7 @@ int gnutls_pkcs7_verify_direct(gnutls_pkcs7_t pkcs7,
                return gnutls_assert_val(ret);
        }
 
-       ret = gnutls_x509_crt_verify_data2(signer, info.algo, 0, &sigdata, &info.sig);
+       ret = gnutls_x509_crt_verify_data2(signer, info.algo, flags, &sigdata, &info.sig);
        if (ret < 0) {
                gnutls_assert();
        }
@@ -970,7 +970,7 @@ gnutls_x509_crt_t find_signer(gnutls_pkcs7_t pkcs7, gnutls_x509_trust_list_t tl,
  * @vdata_size: the number of data elements
  * @idx: the index of the signature info to check
  * @data: The data to be verified or %NULL
- * @flags: Should be zero
+ * @flags: Zero or an OR list of #gnutls_certificate_verify_flags
  *
  * This function will verify the provided data against the signature
  * present in the SignedData of the PKCS #7 structure. If the data
@@ -1025,7 +1025,7 @@ int gnutls_pkcs7_verify(gnutls_pkcs7_t pkcs7,
 
        signer = find_signer(pkcs7, tl, vdata, vdata_size, &info);
        if (signer) {
-               ret = gnutls_x509_crt_verify_data2(signer, info.algo, 0, &sigdata, &info.sig);
+               ret = gnutls_x509_crt_verify_data2(signer, info.algo, flags, &sigdata, &info.sig);
                if (ret < 0) {
                        gnutls_assert();
                }
index b16f56cad70d76bc89884a0fe1a8471a6060ce0a..aac2b2630cbf36625fd933a5317dcec05e16f943 100644 (file)
@@ -3815,7 +3815,7 @@ gnutls_x509_crt_import_url(gnutls_x509_crt_t crt,
  * gnutls_x509_crt_verify_data2:
  * @crt: Holds the certificate to verify with
  * @algo: The signature algorithm used
- * @flags: Must be zero
+ * @flags: Zero or an OR list of #gnutls_certificate_verify_flags
  * @data: holds the signed data
  * @signature: contains the signature
  *