You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

66 lines
1.6 KiB

# usage: onetimekey path/to/mycert.pem
# onetimekey -certonly path/to/mycert.pem
# Takes an openssl cert+key pem file and turns into a long string
# for the x11vnc SSL VNC Java Viewer.
# The Java applet URL parameter can be oneTimeKey=<str> where str is
# the output of this program, or can be oneTimeKey=PROMPT in which
# case the applet will ask you to paste in the string.
# The problem trying to be solved here is it is difficult to get
# the Java applet to have or use a keystore with the key saved
# in it. Also, as the name implies, an HTTPS server can create
# a one time key to send to the applet (the user has already
# logged in via password to the HTTPS server).
# Note oneTimeKey is to provide a CLIENT Certificate for the viewer
# to authenticate itself to the VNC Server.
# There is also the serverCert=<str> Applet parameter. This is
# a cert to authenticate the VNC server against. To create that
# string with this tool specify -certonly as the first argument.
if [ "X$1" = "X-certonly" ]; then
touch $der
chmod 600 $der
openssl pkcs8 -topk8 -nocrypt -in "$in" -out "$der" -outform der
cat > $pbinhex <<END
\$str = '';
while (1) {
\$c = getc(STDIN);
last if \$c eq '';
\$str .= sprintf("%02x", unpack("C", \$c));
print "\$str\n";
chmod 700 $pbinhex
str1=`$pbinhex < "$der"`
rm -f "$der"
n=`grep -n 'BEGIN CERTIFICATE' $in | awk -F: '{print $1}' | head -1`
str2=`tail +$n $in | $pbinhex`
if [ "X$certonly" = "X1" ]; then
echo "$str2"
echo "$str1,$str2"
rm -f $pbinhex