-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
crypto/x509: AKI (Authority Key Id) exclusion logic is broken #62060
Comments
CC @golang/security. |
This comes up from time to time. My understanding of the specifications is that a certificate with Issuer equal to the Subject is, by definition, a self-signed certificate. Path building will or at least should stop at such a certificate. If you make a certificate with Issuer equal to Subject but signed by a different public key, it's just a self-signed certificate with a broken signature, it doesn't stop being a self-signed certificate. AKI makes no sense in a self-signed certificate because, well, it's supposed to be signed by itself. |
(Disclaimer: I do not have enough knowledge to talk about actual "correct" way things should be) Better expression of our case;
In above scenario, by the mentioned change;
So in that case; KeyId's are different. but accidentally CNs are same. but it is not self-signed (by the same key). It could be said that "it is self-signed" in the sense of actually same organization is signing it, yes. but it is definitely not self-signed by its own key. Key Id, in my literal reading, refers to identity of the key, not the identity of the signing authority. Reading the RFC (5280) also gives me that implication, it says, the AKI will have same content when it is self-signed. Furthermore, it suggests two ways for deriving a key id;
Which, in my reading, also defines "what is self-signed", which is a certificate signed by the same exact key, or again the same exact key (of same subject with same serial). -- For another reference; all other tooling, including openssl, browsers, https clients, works just fine with the way it was (CA, and the signed cert, having the same CN). In our case, initial CN overlap problem was descended from following "Kubernetes the hard way", where it build the PKI stack using a CN "kubernetes" for CA, and then it uses the same CN again in one of the signed certificates (API certificate) later on. (link) Which might sound like a problem, but it was not, so far. |
"Self-signed" is a technical term of art, not just a statement about it being signed by the same key. You could have the same key in two certificates with different Subjects and if you sign one with the other it will not be "self-signed". In X.509, what's dispositive for chaining is the Subject and the Issuer. SKI and AKI are hints to the chain building process, but they don't override Subject/Issuer chaining. The api certificate is technically a self-signed certificate because it is a certificate for Other tooling might be tolerant of this because this is a common point of confusion, but crypto/x509 tries to stay simple by targeting the WebPKI and well-formed PKIs that follow the same profile. I remember another issue where we looked into the definition of self-signed certificate, but I can't find it. I did find a duplicate though #20002. |
whoops, sorry. I did look for a duplicate but apparently oversaw that one. Looks like an exact duplicate. |
I looked around to find any information about what defines self-signed, but there is almost zero information on it. One hint I could found was on NIST;
It kinda matches with the RFC's (my-own-reading) intentions, to omit AKI, because the subject key id and authority key id would be exactly same, only in that case.
It goes on to say;
Above two paragraphs says, "self-signed" here, means the certificate is signed by it's own private key, thus it can be verified with the public key it contains.
Would mean this case is also "self-signed", because it can be verified with the public key it contains, also SKI and AKI would be identical, so AKI information can be omitted. On the other hand; allowing omittance of AKI, would only make sense if it is same with SKI, regardless of what "self-signed" actually means. (AFAIU) I intend to test what openssl produces as well soon. I can share results when I do. I think that's my limit on what I could understand so far from the situation. I hope a nicer and compatible solution could be implemented in golang. |
I'm not particularly opposed to making this change, it seems unlikely to really break anything, and perhaps would fix this for a handful of people. That said it seems like we've only heard this is an issue twice since the initial change was made, so I'm not sure how worthwhile the additional complexity is. In the described use case above, is there any particular reason that you cannot just use a different CN? (I don't think the definition of self-signed is a particularly useful discussion to have here, it's been incredibly vaguely defined since the beginnings of X509, and various technical forums tend to define it differently or use the term to refer to different things. Trying to find a concrete, well accepted definition in any of the multitude of specifications is a rabbit hole with no end.) |
No. That's what I did at the end. But two things along the way were difficult; First, understanding that this was the cause was very difficult;
Second, being able to make the change; The original guide instructed such setup, and we have been running stuff that way for years. So even after lucky random change I made made things work, I couldn't be confident that it is not going to break things in unexpected ways.
That is feels interesting for me as well, but my guess is that, for any related problem people might be having, it is extremely hard to escalate and finally link to here. |
Hiya! A few points for those who care:
HTH |
For what it's worth, the CA/Browser Forum has AKI presence as RECOMMENDED instead of MUST (so, probably not worth much): https://cabforum.org/working-groups/server/baseline-requirements/requirements/#71212-root-ca-extensions |
it is RECOMMENDED for "Root CA" situtations (which almost always is self-signed, hence "Root") it is a MUST for almost all other cases in the page you have linked. |
While the RFC has no useful text about it, almost all supportive information around implies that self-signed means that it has been signed with the key, which the public key in the certificate belongs to. Therefore, naturally no need to explicitly state the IMO, Good understanding about what self-signed means;
One incorrect assumption about self-signed could be;
I mean, besides above behavior&understanding being incorrect IMO, Let's put aside my understanding. It's a WHOLE new invention only freshly invented here, to the best of my limited knowledge so far. And now we're discussing interpretations and vagueness of spec and such. If some things are vague, how about doing what all other tooling is doing, and not break things? I don't understand the resistance/reluctance/staleness about not fixing this. Checklist:
|
Fix for a previous issue #15194, in 2016, introduces a breaking change,
where AKIs suddenly stops appearing in created certificates after the
golang upgrade.
The main case for the original issue is probably not an issue for
actually self-signed certificates. But; the logic for excluding AKI
from output, instead of comparing KeyIds, it compares
Subject
(CN)s.So if you use same CNs for a CA and a certificate to sign, the
signed certificate will not have AKI included, even though it is not
self-signed at all.
This change caused us quite a deal of confusion, and months of delay
for upgrading our tooling. Workaround wasn't obvious, we just tried
changing CN fields after so many things. And it just worked, which
confused us even more.
go version
1.7+
Does this issue reproduce with the latest release?
I believe so, but did not do a through testing.
What did you do?
The problem was observed when upgrading CFSSL from 1.2 to 1.6.
Which indicates this change in the README:158.
What did you expect to see?
AKI omission decision to be made by checking if KeyIds are actually same or not.
What did you see instead?
to decide KeyId is same, comparison is done on
Subject
fields :(The text was updated successfully, but these errors were encountered: