code: protected String getHostBasedServiceCN(boolean last) {
          if (hostBasedServiceCN == null) {
              String dn = name.getName();
  
              int cnStart;
  
              if (last) {
                  // use the last instance of CN in the DN
                  cnStart = dn.lastIndexOf("CN=") + 3;
              } else {
                  // use the first instance of CN in the DN
                  cnStart = dn.indexOf("CN=") + 3;
              }
  
              if (cnStart == -1) {
                  return null;
              }
  
              int cnEnd = dn.indexOf(",", cnStart);
  
              if (cnEnd == -1) {
                  int nextAtt = dn.indexOf("=", cnStart);
                  if (nextAtt == -1) {
                      // CN is the last attribute in the DN
                      cnEnd = dn.length();
                  } else {
                      // unexpected DN format (attributes not comma delimited)
                      return null;
                  }
              }
  
              hostBasedServiceCN = name.getName().substring(cnStart, cnEnd);
          }
          return hostBasedServiceCN;
      }
docs: Returns the CN corresponding to the host part of the DN
  @param last true if the CN is assumed to be the last CN attribute
  in the RFC 2253 formatted DN, else false to assume it is the first DN
  attribute
  @return the CN of the host based service