#!/usr/bin/env perl # Small script to extract pkcs12 data from TDC digital signature backups # contained in a html file. # Michael Legart (michael@legart.dk) May 2007 use MIME::Base64; my $filename = shift; my $destination_filename = shift; unless ($filename && $destination_filename) { die "usage: ./get_pkcs12_signature.pl pathtohtmlfile.html mysignature.pkcs12"; } die "unknown file $filenam" unless -e $filename; open (FILE, "<", $filename) or die "unable to open $filename"; my $contents = ""; while () { $contents .= $_; } if ($contents =~ m/pkcs12\=\"(.*?)\"\;/s) { my $encoded_signature = $1; my $decoded_signature = decode_base64($encoded_signature); open (SIGNATURE, ">", $destination_filename) or die "unable to open $destination_filename for writing"; print SIGNATURE $decoded_signature; close (SIGNATURE); } else { die "pkcs12 section not found in html"; } close (FILE);