From 2c6a3daedb8cbe4cdcbb98418cd068562ec45e00 Mon Sep 17 00:00:00 2001 From: cfu Date: Tue, 16 Sep 2008 19:53:28 +0000 Subject: 462488 - IPAddress in SubjAltNameExt incorrectly padded with extra bytes in cert git-svn-id: svn+ssh://svn.fedorahosted.org/svn/pki/trunk@111 c9f7a03b-bd48-0410-a16d-cbbf54688b0b --- .../src/netscape/security/x509/IPAddressName.java | 27 +++++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) (limited to 'pki/base/util') diff --git a/pki/base/util/src/netscape/security/x509/IPAddressName.java b/pki/base/util/src/netscape/security/x509/IPAddressName.java index caa5bcafd..4fe58145c 100644 --- a/pki/base/util/src/netscape/security/x509/IPAddressName.java +++ b/pki/base/util/src/netscape/security/x509/IPAddressName.java @@ -107,10 +107,10 @@ public class IPAddressName implements GeneralNameInterface { IPAddr ipAddr = null; if (s.indexOf(':') != -1) { ipAddr = IPv6; - address = new byte[IPv6_LEN*2]; + address = new byte[IPv6_LEN]; } else { ipAddr = IPv4; - address = new byte[IPv4_LEN*2]; + address = new byte[IPv4_LEN]; } ipAddr.getIPAddr(s, address, 0); } @@ -136,10 +136,31 @@ public class IPAddressName implements GeneralNameInterface { * Return a printable string of IPaddress */ public String toString() { - return ("IPAddress: " + (address[0] & 0xff) + "." + if (address.length == 4) { + return ("IPAddress: " + (address[0] & 0xff) + "." + (address[1] & 0xff) + "." + (address[2] & 0xff) + "." + (address[3] & 0xff)); + } else { + String r= "IPAddress: " + Integer.toHexString(address[0] & 0xff); + String hexString = Integer.toHexString(address[1] & 0xff); + if (hexString.length() ==1) { + r = r+ "0" + hexString; + } else { + r += hexString; + } + for (int i=2; i < address.length; ) { + r+= ":" + Integer.toHexString(address[i] & 0xff); + hexString = Integer.toHexString(address[i+1] & 0xff); + if (hexString.length() ==1) { + r = r +"0" + hexString; + } else { + r += hexString; + } + i+=2; + } + return r; + } } } -- cgit