Shell Script to retrieve Certificate

Here is a helpful script I received from a friend-collegue to retrieve a SSL certificate and store it in a file in Linux.



#!/bin/sh

#
# usage: retrieve-cert.sh remote.host.name [port]
#

REMHOST=$1

REMPORT=${2:-443}

echo |\
/usr/local/ssl/bin/openssl s_client -connect ${REMHOST}:${REMPORT} 2>&1 |\

sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p'

# Use the below command to show certficates, dont use this with sed or you will only get the same output as the command above

#/usr/local/ssl/bin/openssl s_client -showcerts -connect ${REMHOST}:${REMPORT} 2>&1 |\

Mehotd to read Jar versions

I have a test JSP that is used for testing the installation of the applicaiton. 
I that I needed to find the versions of the Jar files that are loaded by the server. I wrote a small method in a JSP to read the Versions from the JAR files. 


String readManifest(String jar) {
try {
JarFile jarfile = new JarFile(jar);
Manifest manifest = jarfile.getManifest();
java.util.Map map = manifest.getEntries();
java.util.Iterator iter = map.keySet().iterator();
String ver = "unknown";
while(iter.hasNext()){
String key = (String)iter.next();
String str = null;
java.util.jar.Attributes attr = (Attributes)map.get(key);
str = attr.getValue(Attributes.Name.IMPLEMENTATION_VERSION);
if(str == null) {
str = attr.getValue(Attributes.Name.SPECIFICATION_VERSION);
}
if(str != null) { ver = str; }
else {
ver = "unknown";
}
}
return ver;
} catch (Exception ex) {
return "Error:"+ex.getMessage();
}
}