0001-java-jni-client.c-add-support-for-OpenSSL-1.1.patch 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. From 8f152a6e47484056968973a71a16e4f2142213a9 Mon Sep 17 00:00:00 2001
  2. From: Aleksandr Makarov <aleksandr.o.makarov@gmail.com>
  3. Date: Mon, 13 Jul 2020 23:05:26 +0000
  4. Subject: [PATCH] java/jni/client.c: add support for OpenSSL 1.1
  5. This shall allow the java/jni to build with and link against OpenSSL 1.1.
  6. Additionally, the configuration program will not attempt to process the
  7. java/jni/ subdirectory if no --enable-jni has been specified.
  8. Upstream: https://github.com/cisco/libest/pull/81/. It was merged
  9. upstream in commit 4fd7e74dc556519132b9ea4c8a0f022bd1254a31, but this
  10. commit mixes multiple patches in one.
  11. Signed-off-by: Aleksandr Makarov <aleksandr.o.makarov@gmail.com>
  12. ---
  13. Makefile.am | 8 ++++++--
  14. configure.ac | 10 ++++++----
  15. java/jni/client.c | 21 ++++++++++++++++-----
  16. 3 files changed, 28 insertions(+), 11 deletions(-)
  17. diff --git a/Makefile.am b/Makefile.am
  18. index 10e38fd..9601de6 100644
  19. --- a/Makefile.am
  20. +++ b/Makefile.am
  21. @@ -1,9 +1,13 @@
  22. ACLOCAL_AMFLAGS = -I m4
  23. +if ENABLE_JNI
  24. +libest_jni = java/jni
  25. +endif
  26. +
  27. if ENABLE_CLIENT_ONLY
  28. -SUBDIRS = safe_c_stub src java/jni example/client example/client-simple example/client-brski
  29. +SUBDIRS = safe_c_stub src $(libest_jni) example/client example/client-simple example/client-brski
  30. else
  31. -SUBDIRS = safe_c_stub src java/jni example/client example/client-simple example/server example/proxy example/client-brski
  32. +SUBDIRS = safe_c_stub src $(libest_jni) example/client example/client-simple example/server example/proxy example/client-brski
  33. endif
  34. EXTRA_DIST = autogen.sh example/util LICENSE README.brski $(srcdir)/build.gradle $(srcdir)/example/build_examples.gradle
  35. diff --git a/configure.ac b/configure.ac
  36. index e02a54d..d648030 100644
  37. --- a/configure.ac
  38. +++ b/configure.ac
  39. @@ -35,9 +35,9 @@ AM_COND_IF([FREEBSD], AC_MSG_RESULT([Skipping libdl check]),
  40. AC_ARG_ENABLE([jni],
  41. [AS_HELP_STRING([--enable-jni],
  42. [Enable support for JNI library])],
  43. - [jni_on=1],
  44. - [jni_on=0])
  45. -AM_CONDITIONAL([ENABLE_JNI], [test x$jni_on = x1])
  46. + [],
  47. + [enable_jni="no"])
  48. +AM_CONDITIONAL([ENABLE_JNI], [test "$enable_jni" = "yes"])
  49. AM_COND_IF([ENABLE_JNI],
  50. AC_MSG_RESULT([JNI support enabled])
  51. AC_DEFINE([ENABLE_JNI]),
  52. @@ -198,5 +198,7 @@ AC_PREFIX_DEFAULT([/usr/local/est])
  53. cp confdefs.h est_config.h
  54. -AC_CONFIG_FILES([Makefile version safe_c_stub/Makefile safe_c_stub/lib/Makefile java/jni/Makefile src/Makefile src/est/Makefile example/client/Makefile example/client-simple/Makefile example/client-brski/Makefile example/server/Makefile example/proxy/Makefile])
  55. +AC_CONFIG_FILES([Makefile version safe_c_stub/Makefile safe_c_stub/lib/Makefile src/Makefile src/est/Makefile example/client/Makefile example/client-simple/Makefile example/client-brski/Makefile example/server/Makefile example/proxy/Makefile])
  56. +AM_COND_IF([ENABLE_JNI],
  57. + [AC_CONFIG_FILES([java/jni/Makefile])])
  58. AC_OUTPUT
  59. diff --git a/java/jni/client.c b/java/jni/client.c
  60. index 9a8a34e..f7aeefc 100644
  61. --- a/java/jni/client.c
  62. +++ b/java/jni/client.c
  63. @@ -130,11 +130,18 @@ static int jni_est_client_X509_REQ_sign (X509_REQ *x, EVP_PKEY *pkey, const EVP_
  64. {
  65. int rv;
  66. EVP_PKEY_CTX *pkctx = NULL;
  67. - EVP_MD_CTX mctx;
  68. + EVP_MD_CTX *mctx;
  69. - EVP_MD_CTX_init(&mctx);
  70. +#ifdef HAVE_OLD_OPENSSL
  71. + EVP_MD_CTX md_ctx;
  72. + mctx = &md_ctx;
  73. - if (!EVP_DigestSignInit(&mctx, &pkctx, md, NULL, pkey)) {
  74. + EVP_MD_CTX_init(mctx);
  75. +#else
  76. + mctx = EVP_MD_CTX_new();
  77. +#endif
  78. +
  79. + if (!EVP_DigestSignInit(mctx, &pkctx, md, NULL, pkey)) {
  80. return 0;
  81. }
  82. @@ -150,9 +157,13 @@ static int jni_est_client_X509_REQ_sign (X509_REQ *x, EVP_PKEY *pkey, const EVP_
  83. x->req_info->enc.modified = 1;
  84. #endif
  85. - rv = X509_REQ_sign_ctx(x, &mctx);
  86. + rv = X509_REQ_sign_ctx(x, mctx);
  87. - EVP_MD_CTX_cleanup(&mctx);
  88. +#ifdef HAVE_OLD_OPENSSL
  89. + EVP_MD_CTX_cleanup(mctx);
  90. +#else
  91. + EVP_MD_CTX_free(mctx);
  92. +#endif
  93. return (rv);
  94. }
  95. --
  96. 2.17.1