]> granicus.if.org Git - pdns/commitdiff
this commit enters verbose debugging output into our packages. This is because it...
authorbert hubert <bert.hubert@powerdns.com>
Tue, 2 Feb 2016 14:25:31 +0000 (15:25 +0100)
committerbert hubert <bert.hubert@powerdns.com>
Tue, 2 Feb 2016 14:25:31 +0000 (15:25 +0100)
pdns/opensslsigners.cc
pdns/opensslsigners.hh

index b722d1cdeab37d30e72daaea5854e76a0ea7ddbc..a9d5e8eae6aa49d410f298d07a7fe4cb8ff117cb 100644 (file)
@@ -6,9 +6,76 @@
 #include <openssl/sha.h>
 #include <openssl/rand.h>
 #include <openssl/rsa.h>
-
+#include "opensslsigners.hh"
 #include "dnssecinfra.hh"
 
+
+static pthread_mutex_t *openssllocks;
+
+extern "C" {
+void openssl_pthreads_locking_callback(int mode, int type, const char *file, int line)
+{
+  if (mode & CRYPTO_LOCK) {
+    if(type != 19 && type !=18)
+    cout<<"Lock of "<<type<<" from "<<file<<" " <<line<<": r/w -> " << ((type&CRYPTO_READ)?"r":"w")<<endl;
+
+    pthread_mutex_lock(&(openssllocks[type]));
+
+  }else {
+    if(type != 19 && type !=18)
+    cout<<"Unlock of "<<type<<" from "<<file<<" " <<line<<" -> "<<((type&CRYPTO_READ)?"r":"w")<<endl;
+    pthread_mutex_unlock(&(openssllocks[type]));
+  }
+}
+
+unsigned long openssl_pthreads_id_callback()
+{
+  return (unsigned long)pthread_self();
+}
+}
+
+void openssl_thread_setup()
+{
+  cout<<"Thread setup!"<<endl;
+  openssllocks = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
+
+  for (int i = 0; i < CRYPTO_num_locks(); i++)
+    pthread_mutex_init(&(openssllocks[i++]), NULL);
+
+  CRYPTO_set_id_callback(openssl_pthreads_id_callback);
+  CRYPTO_set_locking_callback(openssl_pthreads_locking_callback);
+}
+
+void openssl_thread_cleanup()
+{
+  cout<<"Thread cleanup!"<<endl;
+  CRYPTO_set_locking_callback(NULL);
+
+  for (int i=0; i<CRYPTO_num_locks(); i++) {
+    pthread_mutex_destroy(&(openssllocks[i]));
+  }
+
+  OPENSSL_free(openssllocks);
+}
+
+
+/* seeding PRNG */
+
+void openssl_seed()
+{
+  std::string entropy;
+  entropy.reserve(1024);
+
+  unsigned int r;
+  for(int i=0; i<1024; i+=4) {
+    r=dns_random(0xffffffff);
+    entropy.append((const char*)&r, 4);
+  }
+
+  RAND_seed((const unsigned char*)entropy.c_str(), 1024);
+}
+
+
 class OpenSSLRSADNSCryptoKeyEngine : public DNSCryptoKeyEngine
 {
 public:
index 92ce2c074d84ad3f95c390a0c68cadc397bbe785..5f474b6c9388bc73d3990e5cf1a2b200187c965e 100644 (file)
@@ -6,56 +6,6 @@
 #include "dns_random.hh"
 
 /* pthread locking */
-
-static pthread_mutex_t *locks;
-
-void openssl_pthreads_locking_callback(int mode, int type, char *file, int line)
-{
-  if (mode & CRYPTO_LOCK)
-    pthread_mutex_lock(&(locks[type]));
-  else
-    pthread_mutex_unlock(&(locks[type]));
-}
-
-unsigned long openssl_pthreads_id_callback()
-{
-  return (unsigned long)pthread_self();
-}
-
-void openssl_thread_setup()
-{
-  locks = (pthread_mutex_t*)OPENSSL_malloc(CRYPTO_num_locks() * sizeof(pthread_mutex_t));
-
-  for (int i = 0; i < CRYPTO_num_locks(); i++)
-    pthread_mutex_init(&(locks[i++]), NULL);
-
-  CRYPTO_set_id_callback((unsigned long (*)())openssl_pthreads_id_callback);
-  CRYPTO_set_locking_callback((void (*)(int, int, const char*, int))openssl_pthreads_locking_callback);
-}
-
-void openssl_thread_cleanup()
-{
-  CRYPTO_set_locking_callback(NULL);
-
-  for (int i=0; i<CRYPTO_num_locks(); i++)
-    pthread_mutex_destroy(&(locks[i]));
-
-  OPENSSL_free(locks);
-}
-
-
-/* seeding PRNG */
-
-void openssl_seed()
-{
-  std::string entropy;
-  entropy.reserve(1024);
-
-  unsigned int r;
-  for(int i=0; i<1024; i+=4) {
-    r=dns_random(0xffffffff);
-    entropy.append((const char*)&r, 4);
-  }
-
-  RAND_seed((const unsigned char*)entropy.c_str(), 1024);
-}
+void openssl_thread_setup();
+void openssl_thread_cleanup();
+void openssl_seed();