From 142c0a0bef3fd0a4fb7d5091b3df37821073904b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ronald=20Tschal=C3=A4r?= Date: Fri, 4 Aug 2017 19:48:59 -0700 Subject: [PATCH] Fix formatting of IPv6 addresses. They now correctly show as 1234:abcd:... instead of 18::52::171::205::... --- .../java/org/jruby/ext/openssl/X509Extension.java | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/main/java/org/jruby/ext/openssl/X509Extension.java b/src/main/java/org/jruby/ext/openssl/X509Extension.java index 3c9c3fa2..5f8bf8c8 100644 --- a/src/main/java/org/jruby/ext/openssl/X509Extension.java +++ b/src/main/java/org/jruby/ext/openssl/X509Extension.java @@ -661,11 +661,16 @@ private static boolean formatGeneralName(final GeneralName name, final ByteList append(':'); final byte[] ip = ((ASN1OctetString) name.getName()).getOctets(); int len = ip.length; boolean ip4 = len == 4; - for ( int i = 0; i < ip.length; i++ ) { - out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) ); - if ( i != len - 1 ) { - if ( ip4 ) out.append('.'); - else out.append(':').append(':'); + if ( ip4 ) { + for ( int i = 0; i < ip.length; i++ ) { + out.append( ConvertBytes.intToCharBytes( ((int) ip[i]) & 0xff ) ); + if ( i != len - 1 ) out.append('.'); + } + } + else { + for ( int i = 0; i < ip.length; i += 2 ) { + out.append( ConvertBytes.intToHexBytes( ((ip[i] & 0xff) << 8 | (ip[i+1] & 0xff)) ) ); + if ( i != len - 2 ) out.append(':'); } } break;