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.

135 lines
5.6 KiB

  1. From 645c30f76bce250772ce4e0b878e7228bd104277 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] Switch get_*Update APIs to get0
  5. Deprecated in 1.1
  6. ---
  7. src/_cffi_src/openssl/x509.py | 34 ++++++++++++++++---
  8. .../hazmat/backends/openssl/backend.py | 4 +--
  9. .../hazmat/backends/openssl/x509.py | 8 ++---
  10. 3 files changed, 36 insertions(+), 10 deletions(-)
  11. diff --git a/src/_cffi_src/openssl/x509.py b/src/_cffi_src/openssl/x509.py
  12. index b88daa1f..54cd66c9 100644
  13. --- a/src/_cffi_src/openssl/x509.py
  14. +++ b/src/_cffi_src/openssl/x509.py
  15. @@ -202,8 +202,10 @@ long X509_get_version(X509 *);
  16. ASN1_TIME *X509_get_notBefore(X509 *);
  17. ASN1_TIME *X509_get_notAfter(X509 *);
  18. -ASN1_TIME *X509_getm_notBefore(X509 *);
  19. -ASN1_TIME *X509_getm_notAfter(X509 *);
  20. +ASN1_TIME *X509_getm_notBefore(const X509 *);
  21. +ASN1_TIME *X509_getm_notAfter(const X509 *);
  22. +const ASN1_TIME *X509_get0_notBefore(const X509 *);
  23. +const ASN1_TIME *X509_get0_notAfter(const X509 *);
  24. long X509_REQ_get_version(X509_REQ *);
  25. X509_NAME *X509_REQ_get_subject_name(X509_REQ *);
  26. @@ -235,6 +237,8 @@ X509_CRL *sk_X509_CRL_value(Cryptography_STACK_OF_X509_CRL *, int);
  27. long X509_CRL_get_version(X509_CRL *);
  28. ASN1_TIME *X509_CRL_get_lastUpdate(X509_CRL *);
  29. ASN1_TIME *X509_CRL_get_nextUpdate(X509_CRL *);
  30. +const ASN1_TIME *X509_CRL_get0_lastUpdate(const X509_CRL *);
  31. +const ASN1_TIME *X509_CRL_get0_nextUpdate(const X509_CRL *);
  32. X509_NAME *X509_CRL_get_issuer(X509_CRL *);
  33. Cryptography_STACK_OF_X509_REVOKED *X509_CRL_get_REVOKED(X509_CRL *);
  34. @@ -243,8 +247,11 @@ int X509_CRL_set_lastUpdate(X509_CRL *, ASN1_TIME *);
  35. int X509_CRL_set_nextUpdate(X509_CRL *, ASN1_TIME *);
  36. int X509_set_notBefore(X509 *, ASN1_TIME *);
  37. int X509_set_notAfter(X509 *, ASN1_TIME *);
  38. -int X509_set1_notBefore(X509 *, ASN1_TIME *);
  39. -int X509_set1_notAfter(X509 *, ASN1_TIME *);
  40. +
  41. +int X509_CRL_set1_lastUpdate(X509_CRL *, const ASN1_TIME *);
  42. +int X509_CRL_set1_nextUpdate(X509_CRL *, const ASN1_TIME *);
  43. +int X509_set1_notBefore(X509 *, const ASN1_TIME *);
  44. +int X509_set1_notAfter(X509 *, const ASN1_TIME *);
  45. EC_KEY *d2i_EC_PUBKEY_bio(BIO *, EC_KEY **);
  46. int i2d_EC_PUBKEY_bio(BIO *, EC_KEY *);
  47. @@ -339,6 +346,25 @@ const ASN1_INTEGER *X509_REVOKED_get0_serialNumber(const X509_REVOKED *x)
  48. #define X509_set1_notAfter X509_set_notAfter
  49. #define X509_getm_notAfter X509_get_notAfter
  50. #define X509_getm_notBefore X509_get_notBefore
  51. +#define X509_get0_notAfter X509_get_notAfter
  52. +#define X509_get0_notBefore X509_get_notBefore
  53. +
  54. +#define X509_CRL_set1_lastUpdate X509_CRL_set_lastUpdate
  55. +#define X509_CRL_set1_nextUpdate X509_CRL_set_nextUpdate
  56. +#define X509_CRL_get0_lastUpdate X509_CRL_get_lastUpdate
  57. +#define X509_CRL_get0_nextUpdate X509_CRL_get_nextUpdate
  58. +#endif
  59. #endif
  60. +
  61. +#if (OPENSSL_API_COMPAT >= 0x10100000L) && !CRYPTOGRAPHY_IS_LIBRESSL
  62. +#define X509_set_notBefore X509_set1_notBefore
  63. +#define X509_set_notAfter X509_set1_notAfter
  64. +#define X509_get_notAfter X509_get0_notAfter
  65. +#define X509_get_notBefore X509_get0_notBefore
  66. +
  67. +#define X509_CRL_get_lastUpdate X509_CRL_get0_lastUpdate
  68. +#define X509_CRL_get_nextUpdate X509_CRL_get0_nextUpdate
  69. +#define X509_CRL_set_lastUpdate X509_CRL_set1_lastUpdate
  70. +#define X509_CRL_set_nextUpdate X509_CRL_set1_nextUpdate
  71. #endif
  72. """
  73. diff --git a/src/cryptography/hazmat/backends/openssl/backend.py b/src/cryptography/hazmat/backends/openssl/backend.py
  74. index 97c7fd05..891d6309 100644
  75. --- a/src/cryptography/hazmat/backends/openssl/backend.py
  76. +++ b/src/cryptography/hazmat/backends/openssl/backend.py
  77. @@ -1129,12 +1129,12 @@ class Backend(object):
  78. # Set the last update time.
  79. last_update = self._create_asn1_time(builder._last_update)
  80. - res = self._lib.X509_CRL_set_lastUpdate(x509_crl, last_update)
  81. + res = self._lib.X509_CRL_set1_lastUpdate(x509_crl, last_update)
  82. self.openssl_assert(res == 1)
  83. # Set the next update time.
  84. next_update = self._create_asn1_time(builder._next_update)
  85. - res = self._lib.X509_CRL_set_nextUpdate(x509_crl, next_update)
  86. + res = self._lib.X509_CRL_set1_nextUpdate(x509_crl, next_update)
  87. self.openssl_assert(res == 1)
  88. # Add extensions.
  89. diff --git a/src/cryptography/hazmat/backends/openssl/x509.py b/src/cryptography/hazmat/backends/openssl/x509.py
  90. index 4d0dac76..074211e6 100644
  91. --- a/src/cryptography/hazmat/backends/openssl/x509.py
  92. +++ b/src/cryptography/hazmat/backends/openssl/x509.py
  93. @@ -86,12 +86,12 @@ class _Certificate(object):
  94. @property
  95. def not_valid_before(self):
  96. - asn1_time = self._backend._lib.X509_getm_notBefore(self._x509)
  97. + asn1_time = self._backend._lib.X509_get0_notBefore(self._x509)
  98. return _parse_asn1_time(self._backend, asn1_time)
  99. @property
  100. def not_valid_after(self):
  101. - asn1_time = self._backend._lib.X509_getm_notAfter(self._x509)
  102. + asn1_time = self._backend._lib.X509_get0_notAfter(self._x509)
  103. return _parse_asn1_time(self._backend, asn1_time)
  104. @property
  105. @@ -277,13 +277,13 @@ class _CertificateRevocationList(object):
  106. @property
  107. def next_update(self):
  108. - nu = self._backend._lib.X509_CRL_get_nextUpdate(self._x509_crl)
  109. + nu = self._backend._lib.X509_CRL_get0_nextUpdate(self._x509_crl)
  110. self._backend.openssl_assert(nu != self._backend._ffi.NULL)
  111. return _parse_asn1_time(self._backend, nu)
  112. @property
  113. def last_update(self):
  114. - lu = self._backend._lib.X509_CRL_get_lastUpdate(self._x509_crl)
  115. + lu = self._backend._lib.X509_CRL_get0_lastUpdate(self._x509_crl)
  116. self._backend.openssl_assert(lu != self._backend._ffi.NULL)
  117. return _parse_asn1_time(self._backend, lu)
  118. --
  119. 2.26.2