Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sni) stricter detection and handling of duplicate snis #2285

Merged
merged 3 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
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
36 changes: 33 additions & 3 deletions kong/api/routes/certificates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,49 @@ return {
self.params.snis = nil
end

if snis then
-- dont add the certificate or any snis if we have an SNI conflict
-- its fairly inefficient that we have to loop twice over the datastore
-- but no support for OR queries means we gotsta!
local seen = {}

for _, sni in ipairs(snis) do
if seen[sni] then
return helpers.responses.send_HTTP_CONFLICT(
"duplicate requested sni name " .. sni
)
end

local cnt, err = dao_factory.ssl_servers_names:count({
name = sni,
})
if err then
return helpers.yield_error(err)
end

if cnt > 0 then
return helpers.responses.send_HTTP_CONFLICT(
"entry already exists with name " .. sni
)
end

seen[sni] = true
end
end

local ssl_cert, err = dao_factory.ssl_certificates:insert(self.params)
if err then
return helpers.yield_error(err)
end

-- insert SNIs if given

if type(snis) == "table" then
if snis then
ssl_cert.snis = {}

for i = 1, #snis do
for _, sni in ipairs(snis) do
local ssl_server_name = {
name = snis[i],
name = sni,
ssl_certificate_id = ssl_cert.id,
}

Expand Down
2 changes: 1 addition & 1 deletion kong/dao/schemas/ssl_servers_names.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ return {
table = "ssl_servers_names",
primary_key = { "name" },
fields = {
name = { type = "text", required = true },
name = { type = "text", required = true, unique = true },
ssl_certificate_id = { type = "id", foreign = "ssl_certificates:id" },
created_at = {
type = "timestamp",
Expand Down
Loading