teknoraver / rpms / rpm

Forked from rpms/rpm 4 months ago
Clone

Blame rpm-4.4.2.2-cryptoinit.patch

Panu Matilainen 271f69
diff -up rpm-4.4.2.2/rpmio/digest.c.nss-init rpm-4.4.2.2/rpmio/digest.c
Panu Matilainen 77f9b1
--- rpm-4.4.2.2/rpmio/digest.c.nss-init	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 77f9b1
+++ rpm-4.4.2.2/rpmio/digest.c	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 271f69
@@ -78,9 +78,6 @@ rpmDigestInit(pgpHashAlgo hashalgo, rpmD
Panu Matilainen 271f69
     HASH_HashType type;
Panu Matilainen 271f69
     DIGEST_CTX ctx = xcalloc(1, sizeof(*ctx));
Panu Matilainen 271f69
 
Panu Matilainen 271f69
-    if (NSS_NoDB_Init(NULL) != SECSuccess)
Panu Matilainen 271f69
-	return NULL;
Panu Matilainen 271f69
-
Panu Matilainen 271f69
     ctx->flags = flags;
Panu Matilainen 271f69
 
Panu Matilainen 271f69
     type = getHashType(hashalgo);
Panu Matilainen 271f69
diff -up rpm-4.4.2.2/rpmio/rpmpgp.h.nss-init rpm-4.4.2.2/rpmio/rpmpgp.h
Panu Matilainen 77f9b1
--- rpm-4.4.2.2/rpmio/rpmpgp.h.nss-init	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 77f9b1
+++ rpm-4.4.2.2/rpmio/rpmpgp.h	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 271f69
@@ -1380,6 +1380,15 @@ unsigned int pgpCRC(const byte *octets, 
Panu Matilainen 271f69
 }
Panu Matilainen 271f69
 
Panu Matilainen 271f69
 /** \ingroup rpmio
Panu Matilainen 271f69
+ * Perform cryptography initialization.
Panu Matilainen 271f69
+ * It must be called before any cryptography can be used within rpm.
Panu Matilainen 271f69
+ * It's not normally necessary to call it directly as it's called in
Panu Matilainen 271f69
+ * general rpm initialization routines.
Panu Matilainen 271f69
+ * @return		0 on success, -1 on failure
Panu Matilainen 271f69
+ */
Panu Matilainen 271f69
+int rpmInitCrypto(void);
Panu Matilainen 271f69
+
Panu Matilainen 271f69
+/** \ingroup rpmio
Panu Matilainen 271f69
  * Duplicate a digest context.
Panu Matilainen 271f69
  * @param octx		existing digest context
Panu Matilainen 271f69
  * @return		duplicated digest context
Panu Matilainen 271f69
diff -up rpm-4.4.2.2/rpmio/rpmpgp.c.nss-init rpm-4.4.2.2/rpmio/rpmpgp.c
Panu Matilainen 77f9b1
--- rpm-4.4.2.2/rpmio/rpmpgp.c.nss-init	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 77f9b1
+++ rpm-4.4.2.2/rpmio/rpmpgp.c	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 271f69
@@ -17,6 +17,8 @@ static int _debug = 0;
Panu Matilainen 271f69
 /*@unchecked@*/
Panu Matilainen 271f69
 static int _print = 0;
Panu Matilainen 271f69
 
Panu Matilainen 271f69
+static int _crypto_initialized = 0;
Panu Matilainen 271f69
+
Panu Matilainen 271f69
 /*@unchecked@*/ /*@null@*/
Panu Matilainen 271f69
 static pgpDig _dig = NULL;
Panu Matilainen 271f69
 
Panu Matilainen 271f69
@@ -1094,7 +1096,6 @@ int pgpPrtPkt(const byte *pkt, unsigned 
Panu Matilainen 271f69
 pgpDig pgpNewDig(void)
Panu Matilainen 271f69
 {
Panu Matilainen 271f69
     pgpDig dig = xcalloc(1, sizeof(*dig));
Panu Matilainen 271f69
-    NSS_NoDB_Init(NULL);
Panu Matilainen 271f69
 
Panu Matilainen 271f69
     return dig;
Panu Matilainen 271f69
 }
Panu Matilainen 271f69
@@ -1404,5 +1405,18 @@ char * pgpArmorWrap(int atype, const uns
Panu Matilainen 271f69
 
Panu Matilainen 271f69
     return val;
Panu Matilainen 271f69
 }
Panu Matilainen 271f69
-
Panu Matilainen 271f69
 /*@=boundsread@*/
Panu Matilainen 271f69
+
Panu Matilainen 271f69
+int rpmInitCrypto(void) {
Panu Matilainen 271f69
+    int rc = 0;
Panu Matilainen 271f69
+
Panu Matilainen 271f69
+    if (!_crypto_initialized && NSS_NoDB_Init(NULL) != SECSuccess) {
Panu Matilainen 271f69
+        rc = -1;
Panu Matilainen 271f69
+    } else {
Panu Matilainen 271f69
+        _crypto_initialized = 1;
Panu Matilainen 271f69
+    }
Panu Matilainen 271f69
+
Panu Matilainen 271f69
+    return rc;
Panu Matilainen 271f69
+}
Panu Matilainen 271f69
+
Panu Matilainen 271f69
+
Panu Matilainen 77f9b1
diff -up rpm-4.4.2.2/tools/debugedit.c.nss-init rpm-4.4.2.2/tools/debugedit.c
Panu Matilainen 77f9b1
--- rpm-4.4.2.2/tools/debugedit.c.nss-init	2007-11-15 15:01:42.000000000 +0200
Panu Matilainen 77f9b1
+++ rpm-4.4.2.2/tools/debugedit.c	2007-11-15 15:02:23.000000000 +0200
Panu Matilainen 77f9b1
@@ -1318,6 +1318,8 @@ handle_build_id (DSO *dso, Elf_Data *bui
Panu Matilainen 77f9b1
   void *digest = NULL;
Panu Matilainen 77f9b1
   size_t len;
Panu Matilainen 77f9b1
 
Panu Matilainen 77f9b1
+  rpmInitCrypto();
Panu Matilainen 77f9b1
+
Panu Matilainen 77f9b1
   while (i-- > 0)
Panu Matilainen 77f9b1
     {
Panu Matilainen 77f9b1
       algorithm = algorithms[i];
Panu Matilainen 271f69
diff -up rpm-4.4.2.2/lib/rpmrc.c.nss-init rpm-4.4.2.2/lib/rpmrc.c
Panu Matilainen 271f69
--- rpm-4.4.2.2/lib/rpmrc.c.nss-init	2007-09-11 09:28:15.000000000 +0300
Panu Matilainen 77f9b1
+++ rpm-4.4.2.2/lib/rpmrc.c	2007-11-15 15:00:41.000000000 +0200
Panu Matilainen 271f69
@@ -1850,6 +1850,10 @@ static int rpmReadRC(/*@null@*/ const ch
Panu Matilainen 271f69
 
Panu Matilainen 271f69
 int rpmReadConfigFiles(const char * file, const char * target)
Panu Matilainen 271f69
 {
Panu Matilainen 271f69
+    /* Initialize crypto engine as early as possible */
Panu Matilainen 271f69
+    if (rpmInitCrypto() < 0) {
Panu Matilainen 271f69
+	return -1;
Panu Matilainen 271f69
+    }	
Panu Matilainen 271f69
 
Panu Matilainen 271f69
     /* Preset target macros */
Panu Matilainen 271f69
     /*@-nullstate@*/	/* FIX: target can be NULL */