Blame SOURCES/fapolicyd-openssl.patch

abc874
diff -up ./BUILD.md.openssl ./BUILD.md
abc874
--- ./BUILD.md.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./BUILD.md	2022-08-02 14:10:48.092466542 +0200
abc874
@@ -16,7 +16,8 @@ BUILD-TIME DEPENDENCIES (fedora and RHEL
abc874
 * libudev-devel
abc874
 * kernel-headers
abc874
 * systemd-devel
abc874
-* libgcrypt-devel
abc874
+* libgcrypt-devel ( <= fapolicyd-1.1.3)
abc874
+* openssl         ( >= fapolicyd-1.1.4)
abc874
 * rpm-devel (optional)
abc874
 * file
abc874
 * file-devel
abc874
diff -U0 ./ChangeLog.openssl ./ChangeLog
abc874
diff -up ./configure.ac.openssl ./configure.ac
abc874
--- ./configure.ac.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./configure.ac	2022-08-02 14:10:48.092466542 +0200
abc874
@@ -87,7 +87,7 @@ AC_CHECK_HEADER(uthash.h, , [AC_MSG_ERRO
abc874
 echo .
abc874
 echo Checking for required libraries
abc874
 AC_CHECK_LIB(udev, udev_device_get_devnode, , [AC_MSG_ERROR([libudev not found])], -ludev)
abc874
-AC_CHECK_LIB(gcrypt, gcry_md_open, , [AC_MSG_ERROR([libgcrypt not found])], -lgcrypt)
abc874
+AC_CHECK_LIB(crypto, SHA256, , [AC_MSG_ERROR([openssl libcrypto not found])], -lcrypto)
abc874
 AC_CHECK_LIB(magic, magic_descriptor, , [AC_MSG_ERROR([libmagic not found])], -lmagic)
abc874
 AC_CHECK_LIB(cap-ng, capng_change_id, , [AC_MSG_ERROR([libcap-ng not found])], -lcap-ng)
abc874
 AC_CHECK_LIB(seccomp, seccomp_rule_add, , [AC_MSG_ERROR([libseccomp not found])], -lseccomp)
abc874
diff -up ./fapolicyd.spec.openssl ./fapolicyd.spec
abc874
--- ./fapolicyd.spec.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./fapolicyd.spec	2022-08-02 14:10:48.092466542 +0200
abc874
@@ -8,7 +8,7 @@ Source0: https://people.redhat.com/sgrub
abc874
 BuildRequires: gcc
abc874
 BuildRequires: kernel-headers
abc874
 BuildRequires: autoconf automake make gcc libtool
abc874
-BuildRequires: systemd-devel libgcrypt-devel rpm-devel file-devel file
abc874
+BuildRequires: systemd-devel openssl-devel rpm-devel file-devel file
abc874
 BuildRequires: libcap-ng-devel libseccomp-devel lmdb-devel
abc874
 BuildRequires: python3-devel
abc874
 BuildRequires: uthash-devel
abc874
diff -up ./src/cli/fapolicyd-cli.c.openssl ./src/cli/fapolicyd-cli.c
abc874
--- ./src/cli/fapolicyd-cli.c.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./src/cli/fapolicyd-cli.c	2022-08-02 14:10:48.093466520 +0200
abc874
@@ -39,7 +39,6 @@
abc874
 #include <stdatomic.h>
abc874
 #include <lmdb.h>
abc874
 #include <limits.h>
abc874
-#include <gcrypt.h>
abc874
 #include "policy.h"
abc874
 #include "database.h"
abc874
 #include "file-cli.h"
abc874
@@ -670,11 +669,6 @@ static int check_trustdb(void)
abc874
 	if (rc)
abc874
 		return 1;
abc874
 
abc874
-	// Initialize libgcrypt
abc874
-	gcry_check_version(NULL);
abc874
-	gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
abc874
-	gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
abc874
-
abc874
 	do {
abc874
 		unsigned int tsource; // unused
abc874
 		off_t size;
abc874
diff -up ./src/library/database.c.openssl ./src/library/database.c
abc874
--- ./src/library/database.c.openssl	2022-08-02 14:10:48.090466587 +0200
abc874
+++ ./src/library/database.c	2022-08-02 14:13:11.995236110 +0200
abc874
@@ -35,7 +35,7 @@
abc874
 #include <unistd.h>
abc874
 #include <fcntl.h>
abc874
 #include <ctype.h>
abc874
-#include <gcrypt.h>
abc874
+#include <openssl/sha.h>
abc874
 #include <signal.h>
abc874
 #include <sys/stat.h>
abc874
 #include <sys/types.h>
abc874
@@ -244,26 +244,18 @@ static void abort_transaction(MDB_txn *t
abc874
 static char *path_to_hash(const char *path, const size_t path_len) MALLOCLIKE;
abc874
 static char *path_to_hash(const char *path, const size_t path_len)
abc874
 {
abc874
-	gcry_md_hd_t h;
abc874
-	unsigned int len;
abc874
-	unsigned char *hptr;
abc874
+	unsigned char hptr[80];
abc874
 	char *digest;
abc874
 
abc874
-	if (gcry_md_open(&h, GCRY_MD_SHA512, GCRY_MD_FLAG_SECURE))
abc874
+	if (path_len == 0)
abc874
 		return NULL;
abc874
 
abc874
-	gcry_md_write(h, path, path_len);
abc874
-	hptr = gcry_md_read(h, GCRY_MD_SHA512);
abc874
-
abc874
-	len = gcry_md_get_algo_dlen(GCRY_MD_SHA512) * sizeof(char);
abc874
-	digest = malloc((2 * len) + 1);
abc874
-	if (digest == NULL) {
abc874
-		gcry_md_close(h);
abc874
+	SHA512((unsigned char *)path, path_len, (unsigned char *)&hptr);
abc874
+	digest = malloc((SHA512_LEN * 2) + 1);
abc874
+	if (digest == NULL)
abc874
 		return digest;
abc874
-	}
abc874
 
abc874
-	bytes2hex(digest, hptr, len);
abc874
-	gcry_md_close(h);
abc874
+	bytes2hex(digest, hptr, SHA512_LEN);
abc874
 
abc874
 	return digest;
abc874
 }
abc874
@@ -296,7 +288,7 @@ static int write_db(const char *idx, con
abc874
 		if (hash == NULL)
abc874
 			return 5;
abc874
 		key.mv_data = (void *)hash;
abc874
-		key.mv_size = gcry_md_get_algo_dlen(GCRY_MD_SHA512) * 2 + 1;
abc874
+		key.mv_size = (SHA512_LEN * 2) + 1;
abc874
 	} else {
abc874
 		key.mv_data = (void *)idx;
abc874
 		key.mv_size = len;
abc874
@@ -416,7 +408,7 @@ static char *lt_read_db(const char *inde
abc874
 		if (hash == NULL)
abc874
 			return NULL;
abc874
 		key.mv_data = (void *)hash;
abc874
-		key.mv_size = gcry_md_get_algo_dlen(GCRY_MD_SHA512) * 2 + 1;
abc874
+		key.mv_size = (SHA512_LEN * 2) + 1;
abc874
 	} else {
abc874
 		key.mv_data = (void *)index;
abc874
 		key.mv_size = len;
abc874
diff -up ./src/library/file.c.openssl ./src/library/file.c
abc874
--- ./src/library/file.c.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./src/library/file.c	2022-08-02 14:10:48.094466497 +0200
abc874
@@ -31,7 +31,7 @@
abc874
 #include <sys/stat.h>
abc874
 #include <string.h>
abc874
 #include <stdlib.h>
abc874
-#include <gcrypt.h>
abc874
+#include <openssl/sha.h>
abc874
 #include <magic.h>
abc874
 #include <libudev.h>
abc874
 #include <elf.h>
abc874
@@ -51,7 +51,6 @@ static struct udev *udev;
abc874
 magic_t magic_cookie;
abc874
 struct cache { dev_t device; const char *devname; };
abc874
 static struct cache c = { 0, NULL };
abc874
-static size_t hash_size = 32;	// init so cli doesn't need to call file_init
abc874
 
abc874
 // readelf -l path-to-app | grep 'Requesting' | cut -d':' -f2 | tr -d ' ]';
abc874
 static const char *interpreters[] = {
abc874
@@ -96,12 +95,6 @@ void file_init(void)
abc874
 		msg(LOG_ERR, "Unable to load magic database");
abc874
 		exit(1);
abc874
 	}
abc874
-
abc874
-	// Initialize libgcrypt
abc874
-	gcry_check_version(NULL);
abc874
-	gcry_control(GCRYCTL_DISABLE_SECMEM, 0);
abc874
-	gcry_control(GCRYCTL_INITIALIZATION_FINISHED, 0);
abc874
-	hash_size = gcry_md_get_algo_dlen(GCRY_MD_SHA256) * sizeof(char);
abc874
 }
abc874
 
abc874
 
abc874
@@ -445,12 +438,12 @@ char *get_hash_from_fd2(int fd, size_t s
abc874
 	if (mapped != MAP_FAILED) {
abc874
 		unsigned char hptr[40];
abc874
 
abc874
-		gcry_md_hash_buffer(GCRY_MD_SHA256, &hptr, mapped, size);
abc874
+		SHA256(mapped, size, (unsigned char *)&hptr);
abc874
 		munmap(mapped, size);
abc874
-		digest = malloc(65);
abc874
+		digest = malloc((SHA256_LEN * 2) + 1);
abc874
 
abc874
 		// Convert to ASCII string
abc874
-		bytes2hex(digest, hptr, hash_size);
abc874
+		bytes2hex(digest, hptr, SHA256_LEN);
abc874
 	}
abc874
 	return digest;
abc874
 }
abc874
@@ -476,7 +469,7 @@ int get_ima_hash(int fd, char *sha)
abc874
 	}
abc874
 
abc874
 	// Looks like it what we want...
abc874
-	bytes2hex(sha, &tmp[2], 32);
abc874
+	bytes2hex(sha, &tmp[2], SHA256_LEN);
abc874
 	return 1;
abc874
 }
abc874
 
abc874
diff -up ./src/library/file.h.openssl ./src/library/file.h
abc874
--- ./src/library/file.h.openssl	2022-06-21 16:55:47.000000000 +0200
abc874
+++ ./src/library/file.h	2022-08-02 14:10:48.094466497 +0200
abc874
@@ -40,6 +40,9 @@ struct file_info
abc874
 	struct timespec time;
abc874
 };
abc874
 
abc874
+#define SHA256_LEN	32
abc874
+#define SHA512_LEN	64
abc874
+
abc874
 void file_init(void);
abc874
 void file_close(void);
abc874
 struct file_info *stat_file_entry(int fd) MALLOCLIKE;