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.

117 lines
4.8 KiB

  1. From 339e0ab364ca931435c0ad134dc6047eb6974540 Mon Sep 17 00:00:00 2001
  2. From: Rosen Penev <rosenp@gmail.com>
  3. Date: Sat, 15 Jun 2019 18:47:46 -0700
  4. Subject: [PATCH 5/7] Switch get_*Update APIs to get0
  5. Deprecated in 1.1
  6. ---
  7. src/_cffi_src/openssl/x509.py | 27 ++++++++++++++++---
  8. .../hazmat/backends/openssl/backend.py | 4 +--
  9. .../hazmat/backends/openssl/x509.py | 8 +++---
  10. 3 files changed, 29 insertions(+), 10 deletions(-)
  11. --- a/src/_cffi_src/openssl/x509.py
  12. +++ b/src/_cffi_src/openssl/x509.py
  13. @@ -202,8 +202,10 @@ long X509_get_version(X509 *);
  14. ASN1_TIME *X509_get_notBefore(X509 *);
  15. ASN1_TIME *X509_get_notAfter(X509 *);
  16. -ASN1_TIME *X509_getm_notBefore(X509 *);
  17. -ASN1_TIME *X509_getm_notAfter(X509 *);
  18. +ASN1_TIME *X509_getm_notBefore(const X509 *);
  19. +ASN1_TIME *X509_getm_notAfter(const X509 *);
  20. +const ASN1_TIME *X509_get0_notBefore(const X509 *);
  21. +const ASN1_TIME *X509_get0_notAfter(const X509 *);
  22. long X509_REQ_get_version(X509_REQ *);
  23. X509_NAME *X509_REQ_get_subject_name(X509_REQ *);
  24. @@ -235,6 +237,8 @@ X509_CRL *sk_X509_CRL_value(Cryptography
  25. long X509_CRL_get_version(X509_CRL *);
  26. ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *);
  27. ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *);
  28. +const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *);
  29. +const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *);
  30. X509_NAME *X509_CRL_get_issuer(X509_CRL *);
  31. Cryptography_STACK_OF_X509_REVOKED *X509_CRL_get_REVOKED(X509_CRL *);
  32. @@ -243,8 +247,11 @@ int X509_CRL_set_lastUpdate(X509_CRL *,
  33. int X509_CRL_set_nextUpdate(X509_CRL *, ASN1_TIME *);
  34. int X509_set_notBefore(X509 *, ASN1_TIME *);
  35. int X509_set_notAfter(X509 *, ASN1_TIME *);
  36. -int X509_set1_notBefore(X509 *, ASN1_TIME *);
  37. -int X509_set1_notAfter(X509 *, ASN1_TIME *);
  38. +
  39. +int X509_CRL_set1_lastUpdate(X509_CRL *, const ASN1_TIME *);
  40. +int X509_CRL_set1_nextUpdate(X509_CRL *, const ASN1_TIME *);
  41. +int X509_set1_notBefore(X509 *, const ASN1_TIME *);
  42. +int X509_set1_notAfter(X509 *, const ASN1_TIME *);
  43. EC_KEY *d2i_EC_PUBKEY_bio(BIO *, EC_KEY **);
  44. int i2d_EC_PUBKEY_bio(BIO *, EC_KEY *);
  45. @@ -299,4 +306,16 @@ int i2d_re_X509_CRL_tbs(X509_CRL *crl, u
  46. return i2d_X509_CRL_INFO(crl->crl, pp);
  47. }
  48. #endif
  49. +
  50. +#if (OPENSSL_API_COMPAT >= 0x10100000L) && !CRYPTOGRAPHY_IS_LIBRESSL
  51. +#define X509_get_notBefore X509_get0_notBefore
  52. +#define X509_get_notAfter X509_get0_notAfter
  53. +#define X509_set_notBefore X509_set1_notBefore
  54. +#define X509_set_notAfter X509_set1_notAfter
  55. +
  56. +#define X509_CRL_get_lastUpdate X509_CRL_get0_lastUpdate
  57. +#define X509_CRL_get_nextUpdate X509_CRL_get0_nextUpdate
  58. +#define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate
  59. +#define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate
  60. +#endif
  61. """
  62. --- a/src/cryptography/hazmat/backends/openssl/backend.py
  63. +++ b/src/cryptography/hazmat/backends/openssl/backend.py
  64. @@ -1128,12 +1128,12 @@ class Backend(object):
  65. # Set the last update time.
  66. last_update = self._create_asn1_time(builder._last_update)
  67. - res = self._lib.X509_CRL_set_lastUpdate(x509_crl, last_update)
  68. + res = self._lib.X509_CRL_set1_lastUpdate(x509_crl, last_update)
  69. self.openssl_assert(res == 1)
  70. # Set the next update time.
  71. next_update = self._create_asn1_time(builder._next_update)
  72. - res = self._lib.X509_CRL_set_nextUpdate(x509_crl, next_update)
  73. + res = self._lib.X509_CRL_set1_nextUpdate(x509_crl, next_update)
  74. self.openssl_assert(res == 1)
  75. # Add extensions.
  76. --- a/src/cryptography/hazmat/backends/openssl/x509.py
  77. +++ b/src/cryptography/hazmat/backends/openssl/x509.py
  78. @@ -86,12 +86,12 @@ class _Certificate(object):
  79. @property
  80. def not_valid_before(self):
  81. - asn1_time = self._backend._lib.X509_getm_notBefore(self._x509)
  82. + asn1_time = self._backend._lib.X509_get0_notBefore(self._x509)
  83. return _parse_asn1_time(self._backend, asn1_time)
  84. @property
  85. def not_valid_after(self):
  86. - asn1_time = self._backend._lib.X509_getm_notAfter(self._x509)
  87. + asn1_time = self._backend._lib.X509_get0_notAfter(self._x509)
  88. return _parse_asn1_time(self._backend, asn1_time)
  89. @property
  90. @@ -277,13 +277,13 @@ class _CertificateRevocationList(object)
  91. @property
  92. def next_update(self):
  93. - nu = self._backend._lib.X509_CRL_get_nextUpdate(self._x509_crl)
  94. + nu = self._backend._lib.X509_CRL_get0_nextUpdate(self._x509_crl)
  95. self._backend.openssl_assert(nu != self._backend._ffi.NULL)
  96. return _parse_asn1_time(self._backend, nu)
  97. @property
  98. def last_update(self):
  99. - lu = self._backend._lib.X509_CRL_get_lastUpdate(self._x509_crl)
  100. + lu = self._backend._lib.X509_CRL_get0_lastUpdate(self._x509_crl)
  101. self._backend.openssl_assert(lu != self._backend._ffi.NULL)
  102. return _parse_asn1_time(self._backend, lu)