Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
A script to turn a Palm Keyring file into a PasswordSafe v3 file. http://gnukeyring.sourceforge.net/ http://passwordsafe.sourceforge.net/
#!/usr/bin/perl
########################################################################
# Copyright (c) 2013 Andrew Fresh <andrew@afresh1.com>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
########################################################################
use strict;
use warnings;
use 5.010;
use Palm::Keyring;
use Crypt::PWSafe3;
use Time::Local;
my ( $in, $out ) = @ARGV;
$in ||= 'Keys-Gtkr.pdb';
unless ($out) {
$out = $in;
$out =~ s/\.pdb$/\.pwsafe3/i;
}
die "In and out must have different names!" if $in eq $out;
say "Loading $in";
my $pdb = Palm::Keyring->new;
$pdb->Load($in) || die "Unable to load";
print "Enter: ";
my $Pass = <STDIN>;
chomp $Pass;
my $vault = Crypt::PWSafe3->new( file => $out, password => $Pass );
foreach my $rec ( @{ $pdb->{'records'} } ) {
next unless $rec->{'encrypted'};
my $category
= $pdb->{'appinfo'}->{'categories'}->[ $rec->{'category'} ]->{'name'};
my $acct = $pdb->Decrypt( $rec, $Pass ) || die "Couldn't decrypt!";
my %acct = map { $_->{label} => $_->{data} } values %{$acct};
if ( $acct{lastchange} ) {
if ( $acct{lastchange}{month} < 0 ) {
delete $acct{lastchange};
}
else {
$acct{lastchange} = timelocal(
0, 0, 0,
$acct{lastchange}{day},
$acct{lastchange}{month},
$acct{lastchange}{year} + 1900,
);
}
}
$acct{group} = $category;
$acct{title} = delete $acct{name};
$acct{user} = delete $acct{account};
$acct{passwd} = delete $acct{password};
if ( my $last = delete $acct{lastchange} ) {
$acct{mtime} = $acct{ctime} = $last;
}
if ( $acct{notes} =~ m{^\w+://\S+$} ) {
$acct{url} = delete $acct{notes};
}
delete $acct{notes} unless length $acct{notes};
$vault->newrecord(%acct);
say join ':', $acct{group}, $acct{title}, $acct{user};
}
$vault->save;
say "Saved " . $vault->file;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment