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

8 bytes Subject Key identifier. #131

Closed
MmKolodziej opened this issue Apr 27, 2017 · 0 comments
Closed

8 bytes Subject Key identifier. #131

MmKolodziej opened this issue Apr 27, 2017 · 0 comments

Comments

@MmKolodziej
Copy link

MmKolodziej commented Apr 27, 2017

Hey,

I'm having problems using SSL with JRuby when connecting to services which certificates use 8 bytes SKI. As defined in RFC#3280:

Two common
methods for generating key identifiers from the public key are:
(1) The keyIdentifier is composed of the 160-bit SHA-1 hash of the
value of the BIT STRING subjectPublicKey (excluding the tag,
length, and number of unused bits).
(2) The keyIdentifier is composed of a four bit type field with
the value 0100 followed by the least significant 60 bits of the
SHA-1 hash of the value of the BIT STRING subjectPublicKey
(excluding the tag, length, and number of unused bit string bits).

I've looked through multiple (100+ probably) publicly available certificates to find any using 8 bytes SKI, but each certificate I found used the first version from RFC, 20 bytes. The certificates I'm having problems with are self-signed and used behind a VPN, so I cannot prepare a good example.
Using JRuby 1.7.26 and jruby-openssl 0.9.20, the problem seems to be within X509Utils.java. The only debugging I have been able to do was rebuilding the gem with added System.out.printlns and comparing the OctetStrings.

The problem, in my opinion, lies within this if:

if ( der.getOctets().length > 20 ) {
  der = (DEROctetString) get(der.getOctets());
}

For certificates using 20-bytes SKI, the length here is 22 (tag, length and 20 bytes of actual key).
For certificates using 8-bytes SKI, the length here is 10, therefore the assignment of Octets only does not happen. This results in this comparison:
Arrays.equals( sakid.getKeyIdentifier(), iskid.getKeyIdentifier() )
failing because sakid.getKeyIdentifier() is calculated correctly, without tag and length ([67, 108, 30, 22, -44, 61, 5, 14] in my case), but iskid.getKeyIdentifier() contains tag and length ([4, 8, 67, 108, 30, 22, -44, 61, 5, 14]), so the check results in V_ERR_AKID_SKID_MISMATCH.

Removing the if mentioned (leaving the assignment untouched), results in SSL connection working for both type of certificates and all tests in jruby-openssl passing. I'm not sure why the if was introduced, since the tag and length should be stripped in all cases in my opinion.
If my assumptions are correct, the fix seems pretty easy, but I wouldn't know where to start in order to write a proper test for it.

Note: I can connect properly using any other HTTP client I could have thought of (MRI included).

@kares kares closed this as completed in 45ee02a Jul 26, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant