Skip to content

Commit 0e68cf7

Browse files
committed
(maint) Simply to_utf8 monkey patch
Ruby 2.5.0 supports OpenSSL::X509::Name#to_utf8, but jruby-openssl does not. So simplify the monkey patch for JRuby and continue to only use RFC2253 format, because masking off ~ASN1_STRFLGS_ESC_MSB produces the wrong output: dn = OpenSSL::X509::Name.parse('/DC=com').to_s(OpenSSL::X509::Name::RFC2253 & ~4) => "/DC=com" dn = OpenSSL::X509::Name.parse('/DC=com').to_s(OpenSSL::X509::Name::RFC2253) => "DC=com"
1 parent 8ac279d commit 0e68cf7

File tree

1 file changed

+2
-10
lines changed

1 file changed

+2
-10
lines changed

lib/puppet/util/monkey_patches.rb

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,20 +87,12 @@ def set_default_paths
8787
OpenSSL::X509.const_set(:V_ERR_HOSTNAME_MISMATCH, 62)
8888
end
8989

90+
# jruby-openssl doesn't support this
9091
unless OpenSSL::X509::Name.instance_methods.include?(:to_utf8)
9192
class OpenSSL::X509::Name
92-
# https://github.com/openssl/openssl/blob/OpenSSL_1_1_0j/include/openssl/asn1.h#L362
93-
ASN1_STRFLGS_ESC_MSB = 4
94-
95-
FLAGS = if RUBY_PLATFORM == 'java'
96-
OpenSSL::X509::Name::RFC2253
97-
else
98-
OpenSSL::X509::Name::RFC2253 & ~ASN1_STRFLGS_ESC_MSB
99-
end
100-
10193
def to_utf8
10294
# https://github.com/ruby/ruby/blob/v2_5_5/ext/openssl/ossl_x509name.c#L317
103-
str = to_s(FLAGS)
95+
str = to_s(OpenSSL::X509::Name::RFC2253)
10496
str.force_encoding(Encoding::UTF_8)
10597
end
10698
end

0 commit comments

Comments
 (0)