Blame SOURCES/aide-0.16-crypto-disable-haval-and-others.patch

1e4393
diff -up ./include/md.h.crypto ./include/md.h
1e4393
--- ./include/md.h.crypto	2016-07-25 22:56:55.000000000 +0200
1e4393
+++ ./include/md.h	2018-08-29 15:00:30.827491299 +0200
1e4393
@@ -149,6 +149,7 @@ int init_md(struct md_container*);
1e4393
 int update_md(struct md_container*,void*,ssize_t);
1e4393
 int close_md(struct md_container*);
1e4393
 void md2line(struct md_container*,struct db_line*);
1e4393
+DB_ATTR_TYPE get_available_crypto();
1e4393
 
1e4393
 
1e4393
 #endif /*_MD_H_INCLUDED*/
1e4393
diff -up ./src/aide.c.crypto ./src/aide.c
1e4393
--- ./src/aide.c.crypto	2018-08-29 15:00:30.825491309 +0200
1e4393
+++ ./src/aide.c	2018-08-29 15:00:30.827491299 +0200
1e4393
@@ -349,7 +349,7 @@ static void setdefaults_before_config()
1e4393
 
1e4393
   conf->db_attrs = 0;
1e4393
 #if defined(WITH_MHASH) || defined(WITH_GCRYPT)
1e4393
-  conf->db_attrs |= DB_MD5|DB_TIGER|DB_HAVAL|DB_CRC32|DB_SHA1|DB_RMD160|DB_SHA256|DB_SHA512;
1e4393
+  conf->db_attrs |= get_available_crypto();
1e4393
 #ifdef WITH_MHASH
1e4393
   conf->db_attrs |= DB_GOST;
1e4393
 #ifdef HAVE_MHASH_WHIRLPOOL
1e4393
diff -up ./src/md.c.crypto ./src/md.c
1e4393
--- ./src/md.c.crypto	2018-08-29 15:00:30.823491319 +0200
1e4393
+++ ./src/md.c	2018-08-29 15:02:28.013903479 +0200
1e4393
@@ -78,6 +78,49 @@ DB_ATTR_TYPE hash_gcrypt2attr(int i) {
1e4393
   return r;
1e4393
 }
1e4393
 
1e4393
+const char * hash_gcrypt2str(int i) {
1e4393
+  char * r = "?";
1e4393
+#ifdef WITH_GCRYPT
1e4393
+  switch (i) {
1e4393
+  case GCRY_MD_MD5: {
1e4393
+    r = "MD5";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_SHA1: {
1e4393
+    r = "SHA1";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_RMD160: {
1e4393
+    r = "RMD160";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_TIGER: {
1e4393
+    r = "TIGER";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_HAVAL: {
1e4393
+    r = "HAVAL";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_SHA256: {
1e4393
+    r = "SHA256";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_SHA512: {
1e4393
+    r = "SHA512";
1e4393
+    break;
1e4393
+  }
1e4393
+  case GCRY_MD_CRC32: {
1e4393
+    r = "CRC32";
1e4393
+    break;
1e4393
+  }
1e4393
+  default:
1e4393
+    break;
1e4393
+  }
1e4393
+#endif
1e4393
+  return r;
1e4393
+}
1e4393
+
1e4393
 DB_ATTR_TYPE hash_mhash2attr(int i) {
1e4393
   DB_ATTR_TYPE r=0;
1e4393
 #ifdef WITH_MHASH
1e4393
@@ -163,6 +206,44 @@ DB_ATTR_TYPE hash_mhash2attr(int i) {
1e4393
   Initialise md_container according it's todo_attr field
1e4393
  */
1e4393
 
1e4393
+DB_ATTR_TYPE get_available_crypto() {
1e4393
+  
1e4393
+  DB_ATTR_TYPE ret = 0;
1e4393
+
1e4393
+/*
1e4393
+ * This function is usually called before config processing
1e4393
+ * and default verbose level is 5
1e4393
+ */
1e4393
+#define lvl 255
1e4393
+
1e4393
+  error(lvl, "get_available_crypto called\n");
1e4393
+
1e4393
+#ifdef WITH_GCRYPT
1e4393
+
1e4393
+  /*
1e4393
+ * some initialization for FIPS
1e4393
+ */
1e4393
+  gcry_check_version(NULL);
1e4393
+  error(lvl, "Found algos:");
1e4393
+
1e4393
+  for(int i=0;i<=HASH_GCRYPT_COUNT;i++) {
1e4393
+
1e4393
+    if ( (hash_gcrypt2attr(i) & HASH_USE_GCRYPT) == 0 )
1e4393
+      continue;
1e4393
+  
1e4393
+    if (gcry_md_algo_info(i, GCRYCTL_TEST_ALGO, NULL, NULL) == 0) {
1e4393
+      ret |= hash_gcrypt2attr(i);
1e4393
+      error(lvl, " %s", hash_gcrypt2str(i));
1e4393
+    }
1e4393
+  }
1e4393
+  error(lvl, "\n");
1e4393
+
1e4393
+#endif
1e4393
+
1e4393
+  error(lvl, "get_available_crypto_returned with %lld\n", ret);
1e4393
+  return ret;
1e4393
+}
1e4393
+
1e4393
 int init_md(struct md_container* md) {
1e4393
   
1e4393
   int i;
1e4393
@@ -201,18 +282,27 @@ int init_md(struct md_container* md) {
1e4393
   }
1e4393
 #endif 
1e4393
 #ifdef WITH_GCRYPT
1e4393
-        if(gcry_md_open(&md->mdh,0,GCRY_MD_FLAG_SECURE)!=GPG_ERR_NO_ERROR){
1e4393
+  if(gcry_md_open(&md->mdh,0,GCRY_MD_FLAG_SECURE)!=GPG_ERR_NO_ERROR){
1e4393
 		error(0,"gcrypt_md_open failed\n");
1e4393
 		exit(IO_ERROR);
1e4393
 	}
1e4393
   for(i=0;i<=HASH_GCRYPT_COUNT;i++) {
1e4393
+
1e4393
+
1e4393
     if (((hash_gcrypt2attr(i)&HASH_USE_GCRYPT)&md->todo_attr)!=0) {
1e4393
-      DB_ATTR_TYPE h=hash_gcrypt2attr(i);
1e4393
-      error(255,"inserting %llu\n",h);
1e4393
+
1e4393
+        DB_ATTR_TYPE h=hash_gcrypt2attr(i);
1e4393
+
1e4393
+        if (gcry_md_algo_info(i, GCRYCTL_TEST_ALGO, NULL, NULL) != 0) {
1e4393
+            error(0,"Algo %s is not available\n", hash_gcrypt2str(i));
1e4393
+            exit(-1);
1e4393
+        }
1e4393
+
1e4393
+        error(255,"inserting %llu\n",h);
1e4393
 			if(gcry_md_enable(md->mdh,i)==GPG_ERR_NO_ERROR){
1e4393
 				md->calc_attr|=h;
1e4393
 			} else {
1e4393
-				error(0,"gcry_md_enable %i failed",i);
1e4393
+				error(0,"gcry_md_enable %i failed\n",i);
1e4393
 				md->todo_attr&=~h;
1e4393
 			}
1e4393
 		}