Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions OpenSSL/crypto.py
Original file line number Diff line number Diff line change
Expand Up @@ -1340,6 +1340,19 @@ def get_extension(self, index):
extension = _lib.X509_EXTENSION_dup(ext._extension)
ext._extension = _ffi.gc(extension, _lib.X509_EXTENSION_free)
return ext

def del_extension(self, index):
"""
Delete a specific extension of the certificate by index.

:param index: The index of the extension to delete.
:return: The X509Extension object deleted at the specified index.
"""
ext = X509Extension.__new__(X509Extension)
ext._extension = _lib.X509_delete_ext(self._x509, index)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will leak memory. It needs to use X509_EXTENSION_free in conjunction with ffi.gc. Take a look at the method right above this for an example.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, really! Thanks for pointing that out.

if ext._extension == _ffi.NULL:
raise IndexError("extension index out of bounds")
return ext

X509Type = X509

Expand Down