-
Notifications
You must be signed in to change notification settings - Fork 43
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
x509:get_extension("subjectKeyIdentifier"):text() is in weird format #24
Comments
@Evengard Could you share a sample cert you are seeing this error? If not possible could you share output of
|
I might had mistaken and subjectKeyIdentifier gives a line return, and authorityKeyIdentifier gives the "keyid:" prefix. Anyway, I actually noticed kind of similar behaviour (regarding the prefix) when checking the cert in the Windows cert viewer dialog. So that may be an ill-formed certificate... |
Also I couldn't find documentation for the to_der method... |
The output format for authorityKeyIdentifier is decided by openssl and it's not actually an cert issue. By rfc5280, AuthorityKeyIdentifier is a sequence and it's element at position 0 decribes the KeyIdentifier (which is an octect string); while SubjectKeyIdentifier is just a octect string. That makes the
So there're couple of ways to archieve your goal:
local x509 = require("resty.openssl.x509")
local c1 = assert(x509.new(io.open("buggy.crt"):read("*a")))
local function to_hex(str)
return (str:gsub('.', function (c)
return string.format('%02X', string.byte(c))
end))
end
print(to_hex(c1:get_extension("subjectKeyIdentifier"):to_der()))
print(to_hex(c1:get_extension("authorityKeyIdentifier"):to_der()))
gives you
This can be made into a helper function
local store = require("resty.openssl.x509.store")
local x509 = require("resty.openssl.x509")
local c1 = assert(x509.new(io.open("buggy.crt"):read("*a")))
local s1 = store.new()
assert(s1:add(c1))
print(s1:verify(c1)) gives you |
Oh ok. I actually searched a method for binary comparison, but the to_der method wasn't documented, so I haven't found it =). |
@Evengard Per my understanding, usually |
fix #24 Co-authored-by: Callum Loh <cloh@squiz.net>
For some reason, when doing x509:get_extension("subjectKeyIdentifier"):text(), I am getting a "keyid:" prefix, the actual keyid and a line return at the end.
When doing x509:get_extension("authorityKeyIdentifier"):text() I am getting only the keyid without any prefixes and line returns at the end.
I am using it to detect if a certificate is self-signed, so I filter theese weirdnesses out with gsub, but it is still strange that the keyid outputting is different for the similar use case.
The text was updated successfully, but these errors were encountered: