code: public static X500Principal getSubjectDNFromChain(List<X509Certificate> chain)
  	{
  		if (chain == null || chain.isEmpty())
  			throw new IllegalArgumentException("Must provide a chain that is non-null and non-empty");
  
  		X509Certificate cert = chain.get(chain.size() - 1);
  
  		return cert.getSubjectX500Principal();
  	}
docs: Extracts the Subject: the final certificate in a chain
  
  @param chain
  a normalised chain
  
  @return the subject (the final certificate in the chain)
  
  @throws IllegalArgumentException
  if the chain is null or empty