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

There's no way to replace an OpenSSL::X509::Name entry. #94

Closed
evilsocket opened this issue Dec 23, 2016 · 3 comments
Closed

There's no way to replace an OpenSSL::X509::Name entry. #94

evilsocket opened this issue Dec 23, 2016 · 3 comments

Comments

@evilsocket
Copy link

Given a OpenSSL::X509::Name object, there's only an add_entry method to manipulate its entries, but this method will always append due to the -1 argument specified here.

If the object already contains an entry with the specified name, the method should instead find its index and replace it, otherwise the new appended entry won't be visible from browsers for instance, as they only get the first entry with a given name.

Ideally, a new set_entry or replace_entry method would be needed.

Ref. to the issue where this behaviour was highlighted this.

@evilsocket evilsocket changed the title There's no way to replace a OpenSSL::X509::Name entry. There's no way to replace an OpenSSL::X509::Name entry. Dec 23, 2016
@rhenium
Copy link
Member

rhenium commented Dec 25, 2016

I'm afraid a method like #replace_entry wouldn't be useful, because a distinguished name can contain multiple attributes with the same type. E.g.

dn = OpenSSL::X509::Certificate.new(File.read("/etc/ssl/certs/VeriSign_Class_3_Public_Primary_Certification_Authority_-_G5.pem")).subject
pp dn.to_a #=>
[["C", "US", 19],
 ["O", "VeriSign, Inc.", 19],
 ["OU", "VeriSign Trust Network", 19],
 ["OU", "(c) 2006 VeriSign, Inc. - For authorized use only", 19],
 ["CN", "VeriSign Class 3 Public Primary Certification Authority - G5", 19]]

dn.replace_entry("OU", "Test Unit") # which existing OU attribute will be replaced?

If you don't care about multi-valued RDN, you can convert into an array by OpenSSL::X509::Name#to_a and modify it, and re-construct by passing the modified array to OpenSSL::X509::Name.new.

@evilsocket
Copy link
Author

what about an optional "index" parameter (default to -1 as in the current implementation) for the add_entry method?

@rhenium
Copy link
Member

rhenium commented Jul 25, 2017

The ability to specify the position to insert would be a good addition for completeness. I'll do this for the next version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants