You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

151 lines
5.5 KiB

  1. From 6c825349e1994a991f287e398cf0ead5f790a01b Mon Sep 17 00:00:00 2001
  2. From: Eneas U de Queiroz <cote2004-github@yahoo.com>
  3. Date: Wed, 6 Jun 2018 18:05:33 -0300
  4. Subject: [PATCH] Remove API deprecated in openssl 1.1
  5. With openssl 1.1, we do not call OpenSSL_add_all_algorithms(), as
  6. library initialization is done automatically.
  7. Functions RAND_pseudo_bytes and RSA_generate_key were deprecated as
  8. well.
  9. Also, we need to #include <openssl/bn.h> for BN_num_bytes().
  10. Signed-off-by: Eneas U de Queiroz <cote2004-github@yahoo.com>
  11. ---
  12. lib/rsa.c | 15 ++++++++++++---
  13. net/common/processors/keepalive-proc.c | 4 ++--
  14. net/common/processors/keepalive2-proc.c | 2 +-
  15. net/common/processors/sendsessionkey-proc.c | 2 +-
  16. net/common/processors/sendsessionkey-v2-proc.c | 2 +-
  17. net/server/user-mgr.c | 4 ++++
  18. tools/ccnet-init.c | 2 ++
  19. 7 files changed, 23 insertions(+), 8 deletions(-)
  20. diff --git a/lib/rsa.c b/lib/rsa.c
  21. index 7cca150..d969a62 100644
  22. --- a/lib/rsa.c
  23. +++ b/lib/rsa.c
  24. @@ -4,6 +4,7 @@
  25. #include <openssl/rand.h>
  26. #include <openssl/rsa.h>
  27. #include <openssl/err.h>
  28. +#include <openssl/bn.h>
  29. #include <string.h>
  30. #include <glib.h>
  31. @@ -207,9 +208,17 @@ RSA *
  32. generate_private_key(u_int bits)
  33. {
  34. RSA *private = NULL;
  35. -
  36. - private = RSA_generate_key(bits, 35, NULL, NULL);
  37. - if (private == NULL)
  38. + BIGNUM *e = NULL;
  39. +
  40. + private = RSA_new();
  41. + e = BN_new();
  42. + if (private == NULL || e == NULL || !BN_set_word(e, 35) ||
  43. + !RSA_generate_key_ex(private, bits, e, NULL)) {
  44. + RSA_free(private);
  45. + BN_free(e);
  46. g_error ("rsa_generate_private_key: key generation failed.");
  47. + return NULL;
  48. + }
  49. + BN_free(e);
  50. return private;
  51. }
  52. diff --git a/net/common/processors/keepalive-proc.c b/net/common/processors/keepalive-proc.c
  53. index 609d102..42a0c23 100644
  54. --- a/net/common/processors/keepalive-proc.c
  55. +++ b/net/common/processors/keepalive-proc.c
  56. @@ -401,7 +401,7 @@ static void send_challenge(CcnetProcessor *processor)
  57. unsigned char *buf;
  58. int len;
  59. - RAND_pseudo_bytes (priv->random_buf, 40);
  60. + RAND_bytes (priv->random_buf, 40);
  61. buf = public_key_encrypt (peer->pubkey, priv->random_buf, 40, &len);
  62. ccnet_processor_send_update (processor, "311", NULL, (char *)buf, len);
  63. @@ -434,7 +434,7 @@ static void send_challenge_user(CcnetProcessor *processor, CcnetUser *user)
  64. ccnet_debug ("[Keepalive] Send user challenge to %.8s\n",
  65. processor->peer->id);
  66. - RAND_pseudo_bytes (priv->random_buf, 40);
  67. + RAND_bytes (priv->random_buf, 40);
  68. buf = public_key_encrypt (user->pubkey, priv->random_buf, 40, &len);
  69. ccnet_processor_send_update (processor, "321", NULL, (char *)buf, len);
  70. diff --git a/net/common/processors/keepalive2-proc.c b/net/common/processors/keepalive2-proc.c
  71. index d3e799e..d81c266 100644
  72. --- a/net/common/processors/keepalive2-proc.c
  73. +++ b/net/common/processors/keepalive2-proc.c
  74. @@ -306,7 +306,7 @@ static void send_challenge(CcnetProcessor *processor)
  75. unsigned char *buf;
  76. int len;
  77. - RAND_pseudo_bytes (priv->random_buf, 40);
  78. + RAND_bytes (priv->random_buf, 40);
  79. buf = public_key_encrypt (peer->pubkey, priv->random_buf, 40, &len);
  80. if (len < 0) {
  81. ccnet_debug ("[Keepalive] Failed to encrypt challenge "
  82. diff --git a/net/common/processors/sendsessionkey-proc.c b/net/common/processors/sendsessionkey-proc.c
  83. index 3ec2757..10c3340 100644
  84. --- a/net/common/processors/sendsessionkey-proc.c
  85. +++ b/net/common/processors/sendsessionkey-proc.c
  86. @@ -124,7 +124,7 @@ generate_session_key (CcnetProcessor *processor, int *len_p)
  87. unsigned char random_buf[40];
  88. SHA_CTX s;
  89. - RAND_pseudo_bytes (random_buf, sizeof(random_buf));
  90. + RAND_bytes (random_buf, sizeof(random_buf));
  91. SHA1_Init (&s);
  92. SHA1_Update (&s, random_buf, sizeof(random_buf));
  93. diff --git a/net/common/processors/sendsessionkey-v2-proc.c b/net/common/processors/sendsessionkey-v2-proc.c
  94. index c1c6924..4805ba6 100644
  95. --- a/net/common/processors/sendsessionkey-v2-proc.c
  96. +++ b/net/common/processors/sendsessionkey-v2-proc.c
  97. @@ -125,7 +125,7 @@ generate_session_key (CcnetProcessor *processor, int *len_p)
  98. unsigned char random_buf[40];
  99. SHA_CTX s;
  100. - RAND_pseudo_bytes (random_buf, sizeof(random_buf));
  101. + RAND_bytes (random_buf, sizeof(random_buf));
  102. SHA1_Init (&s);
  103. SHA1_Update (&s, random_buf, sizeof(random_buf));
  104. diff --git a/net/server/user-mgr.c b/net/server/user-mgr.c
  105. index 8a356f0..7a3f5cb 100644
  106. --- a/net/server/user-mgr.c
  107. +++ b/net/server/user-mgr.c
  108. @@ -816,9 +816,13 @@ hash_password_pbkdf2_sha256 (const char *passwd,
  109. char salt_str[SHA256_DIGEST_LENGTH*2+1];
  110. if (!RAND_bytes (salt, sizeof(salt))) {
  111. +#if OPENSSL_VERSION_NUMBER < 0x10100000L || OPENSSL_API_COMPAT < 0x10100000L
  112. ccnet_warning ("Failed to generate salt "
  113. "with RAND_bytes(), use RAND_pseudo_bytes().\n");
  114. RAND_pseudo_bytes (salt, sizeof(salt));
  115. +#else
  116. + ccnet_warning ("Failed to generate salt with RAND_bytes().\n");
  117. +#endif
  118. }
  119. PKCS5_PBKDF2_HMAC (passwd, strlen(passwd),
  120. diff --git a/tools/ccnet-init.c b/tools/ccnet-init.c
  121. index 4748962..28c9995 100644
  122. --- a/tools/ccnet-init.c
  123. +++ b/tools/ccnet-init.c
  124. @@ -162,7 +162,9 @@ main(int argc, char **argv)
  125. config_dir = ccnet_expand_path (config_dir);
  126. /* printf("[conf_dir=%s\n]", config_dir); */
  127. +#if OPENSSL_VERSION_NUMBER < 0x10100000L
  128. OpenSSL_add_all_algorithms();
  129. +#endif
  130. if (RAND_status() != 1) { /* it should be seeded automatically */
  131. fprintf(stderr, "PRNG is not seeded\n");
  132. --
  133. 2.19.1