Blame SOURCES/libgcrypt-1.6.2-use-fipscheck.patch

9fde57
diff -up libgcrypt-1.6.2/src/fips.c.use-fipscheck libgcrypt-1.6.2/src/fips.c
9fde57
--- libgcrypt-1.6.2/src/fips.c.use-fipscheck	2014-08-21 14:50:39.000000000 +0200
9fde57
+++ libgcrypt-1.6.2/src/fips.c	2014-09-26 11:42:20.999588282 +0200
9fde57
@@ -578,23 +578,50 @@ run_random_selftests (void)
9fde57
   return !!err;
9fde57
 }
9fde57
 
9fde57
+#ifdef ENABLE_HMAC_BINARY_CHECK
9fde57
+static int
9fde57
+get_library_path(const char *libname, const char *symbolname, char *path, size_t pathlen)
9fde57
+{
9fde57
+    Dl_info info;
9fde57
+    void *dl, *sym;
9fde57
+    int rv = -1;
9fde57
+
9fde57
+        dl = dlopen(libname, RTLD_LAZY);
9fde57
+        if (dl == NULL) {
9fde57
+            return -1;
9fde57
+        }       
9fde57
+
9fde57
+    sym = dlsym(dl, symbolname);
9fde57
+
9fde57
+    if (sym != NULL && dladdr(sym, &info)) {
9fde57
+	strncpy(path, info.dli_fname, pathlen-1);
9fde57
+	path[pathlen-1] = '\0';
9fde57
+	rv = 0;
9fde57
+    }
9fde57
+
9fde57
+    dlclose(dl);	
9fde57
+    
9fde57
+    return rv;
9fde57
+}
9fde57
+#endif
9fde57
+
9fde57
 /* Run an integrity check on the binary.  Returns 0 on success.  */
9fde57
 static int
9fde57
 check_binary_integrity (void)
9fde57
 {
9fde57
 #ifdef ENABLE_HMAC_BINARY_CHECK
9fde57
   gpg_error_t err;
9fde57
-  Dl_info info;
9fde57
+  char libpath[4096];
9fde57
   unsigned char digest[32];
9fde57
   int dlen;
9fde57
   char *fname = NULL;
9fde57
-  const char key[] = "What am I, a doctor or a moonshuttle conductor?";
9fde57
-
9fde57
-  if (!dladdr ("gcry_check_version", &info))
9fde57
+  const char key[] = "orboDeJITITejsirpADONivirpUkvarP";
9fde57
+  
9fde57
+  if (get_library_path ("libgcrypt.so.20", "gcry_check_version", libpath, sizeof(libpath)))
9fde57
     err = gpg_error_from_syserror ();
9fde57
   else
9fde57
     {
9fde57
-      dlen = _gcry_hmac256_file (digest, sizeof digest, info.dli_fname,
9fde57
+      dlen = _gcry_hmac256_file (digest, sizeof digest, libpath,
9fde57
                                  key, strlen (key));
9fde57
       if (dlen < 0)
9fde57
         err = gpg_error_from_syserror ();
9fde57
@@ -602,7 +629,7 @@ check_binary_integrity (void)
9fde57
         err = gpg_error (GPG_ERR_INTERNAL);
9fde57
       else
9fde57
         {
9fde57
-          fname = xtrymalloc (strlen (info.dli_fname) + 1 + 5 + 1 );
9fde57
+          fname = xtrymalloc (strlen (libpath) + 1 + 5 + 1 );
9fde57
           if (!fname)
9fde57
             err = gpg_error_from_syserror ();
9fde57
           else
9fde57
@@ -611,7 +638,7 @@ check_binary_integrity (void)
9fde57
               char *p;
9fde57
 
9fde57
               /* Prefix the basename with a dot.  */
9fde57
-              strcpy (fname, info.dli_fname);
9fde57
+              strcpy (fname, libpath);
9fde57
               p = strrchr (fname, '/');
9fde57
               if (p)
9fde57
                 p++;
9fde57
diff -up libgcrypt-1.6.2/src/Makefile.in.use-fipscheck libgcrypt-1.6.2/src/Makefile.in
9fde57
--- libgcrypt-1.6.2/src/Makefile.in.use-fipscheck	2014-08-21 15:14:08.000000000 +0200
9fde57
+++ libgcrypt-1.6.2/src/Makefile.in	2014-09-26 11:41:13.271059281 +0200
9fde57
@@ -449,7 +449,7 @@ libgcrypt_la_LIBADD = $(gcrypt_res) \
9fde57
 	../cipher/libcipher.la \
9fde57
 	../random/librandom.la \
9fde57
 	../mpi/libmpi.la \
9fde57
-	../compat/libcompat.la  $(GPG_ERROR_LIBS)
9fde57
+	../compat/libcompat.la  $(GPG_ERROR_LIBS) -ldl
9fde57
 
9fde57
 dumpsexp_SOURCES = dumpsexp.c
9fde57
 dumpsexp_CFLAGS = $(arch_gpg_error_cflags)