Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
Add support for md5 checksums (needed for old format)
Baptiste Daroussin committed 13 years ago
commit 193ccd41911c19aa6fdfd65c46d129e69a0a069e
parent 145f2275b8bd6456406667abfcc29a6d993fd78b
3 files changed +48 -0
modified libpkg/private/pkg.h
@@ -36,6 +36,7 @@
#include <archive.h>
#include <sqlite3.h>
#include <openssl/sha.h>
+
#include <openssl/md5.h>
#include <stdbool.h>
#include <uthash.h>

modified libpkg/private/utils.h
@@ -34,6 +34,7 @@

#include <openssl/pem.h>
#include <openssl/sha.h>
+
#include <openssl/md5.h>

#define STARTS_WITH(string, needle) (strncasecmp(string, needle, strlen(needle)) == 0)

@@ -70,6 +71,7 @@ int is_dir(const char *);
int is_conf_file(const char *path, char *newpath, size_t len);

int sha256_file(const char *, char[SHA256_DIGEST_LENGTH * 2 +1]);
+
int md5_file(const char *, char[MD5_DIGEST_LENGTH * 2 +1]);

int rsa_sign(char *path, pem_password_cb *password_cb, char *rsa_key_path,
		 unsigned char **sigret, unsigned int *siglen);
modified libpkg/utils.c
@@ -278,6 +278,51 @@ is_dir(const char *path)
}

static void
+
md5_hash(unsigned char hash[MD5_DIGEST_LENGTH],
+
    char out[MD5_DIGEST_LENGTH * 2 + 1])
+
{
+
	int i;
+
	for (i = 0; i < MD5_DIGEST_LENGTH; i++)
+
		sprintf(out + (i *2), "%02x", hash[i]);
+

+
	out[MD5_DIGEST_LENGTH * 2] = '\0';
+
}
+

+
int
+
md5_file(const char *path, char out[MD5_DIGEST_LENGTH * 2 + 1])
+
{
+
	FILE *fp;
+
	char buffer[BUFSIZ];
+
	unsigned char hash[SHA256_DIGEST_LENGTH];
+
	size_t r = 0;
+
	MD5_CTX md5;
+

+
	if ((fp = fopen(path, "rb")) == NULL) {
+
		pkg_emit_errno("fopen", path);
+
		return EPKG_FATAL;
+
	}
+

+
	MD5_Init(&md5);
+

+
	while ((r = fread(buffer, 1, BUFSIZ, fp)) > 0)
+
		MD5_Update(&md5, buffer, r);
+

+
	if (ferror(fp) != 0) {
+
		fclose(fp);
+
		out[0] = '\0';
+
		pkg_emit_errno("fread", path);
+
		return EPKG_FATAL;
+
	}
+

+
	fclose(fp);
+

+
	MD5_Final(hash, &md5);
+
	md5_hash(hash, out);
+

+
	return (EPKG_OK);
+
}
+

+
static void
sha256_hash(unsigned char hash[SHA256_DIGEST_LENGTH],
    char out[SHA256_DIGEST_LENGTH * 2 + 1])
{