Skip to content

Commit

Permalink
fix(x509.*) fix set_extension will fail when a extension with same NI…
Browse files Browse the repository at this point in the history
…D is not exist yet (#75)
  • Loading branch information
fffonion authored Oct 13, 2022
1 parent 363c80d commit b2f57b8
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 9 deletions.
4 changes: 1 addition & 3 deletions lib/resty/openssl/x509/crl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -421,9 +421,7 @@ function _M:set_extension(extension, last_pos)

local nid = extension:get_object().nid
local pos = C.X509_CRL_get_ext_by_NID(self.ctx, nid, last_pos)
if pos == -1 then
return nil
end
-- pos may be -1, which means not found, it's fine, we will add new one instead of replace

local removed = X509_CRL_delete_ext(self.ctx, pos)
C.X509_EXTENSION_free(removed)
Expand Down
4 changes: 1 addition & 3 deletions lib/resty/openssl/x509/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,7 @@ function _M:set_extension(extension, last_pos)

local nid = extension:get_object().nid
local pos = C.X509_get_ext_by_NID(self.ctx, nid, last_pos)
if pos == -1 then
return nil
end
-- pos may be -1, which means not found, it's fine, we will add new one instead of replace

local removed = X509_delete_ext(self.ctx, pos)
C.X509_EXTENSION_free(removed)
Expand Down
4 changes: 1 addition & 3 deletions scripts/templates/x509_functions.j2
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ function _M:set_extension(extension, last_pos)

local nid = extension:get_object().nid
local pos = C.{{ module.type }}_get_ext_by_NID(self.ctx, nid, last_pos)
if pos == -1 then
return nil
end
-- pos may be -1, which means not found, it's fine, we will add new one instead of replace

local removed = {{ module.type }}_delete_ext(self.ctx, pos)
C.X509_EXTENSION_free(removed)
Expand Down

0 comments on commit b2f57b8

Please sign in to comment.