Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Convert FireFox Password Exporter CSV files to KeePass XML

  • Loading branch information...
commit a0ac6d87d1e00367dd10b50212040fc196ede82c 0 parents
@leto authored
88 lib/App/FFPasswordExporter2Keepass.pm
@@ -0,0 +1,88 @@
+package App::FFPasswordExporter2Keepass;
+use Moose;
+with 'MooseX::Runnable';
+with 'MooseX::Getopt';
+use Text::CSV;
+use autodie qw/:all/;
+use Data::Dumper;
+use English;
+use 5.010;
+
+has input => (
+ isa => 'Str',
+ is => 'ro',
+ required => 1,
+);
+
+has output => (
+ isa => 'Str',
+ is => 'ro',
+ required => 0,
+);
+
+has parser => (
+ isa => 'Text::CSV',
+ is => 'ro',
+ default => sub { Text::CSV->new },
+ metaclass => 'NoGetopt',
+);
+has keepass_start => (
+ isa => 'Str',
+ is => 'ro',
+ default => "<!DOCTYPE KEEPASSX_DATABASE><database><group><title>Imported FF passwords at " . localtime . "</title><icon>1</icon>",
+ metaclass => 'NoGetopt',
+);
+has keepass_end => (
+ isa => 'Str',
+ is => 'ro',
+ default => "</group></database>",
+ metaclass => 'NoGetopt',
+);
+
+sub run {
+ my ($self) = @_;
+
+ open my $fh, '<', $self->input;
+ my $entries = '';
+ my $got_header;
+
+
+ while( my $line = $self->parser->getline($fh) ) {
+ next if $line->[0] =~ m/^\s*#/;
+
+ # skip header line
+ unless ( $got_header ) {
+ $got_header = 1;
+ next;
+ }
+
+ $entries .= $self->make_keepass_entry($line);
+ }
+
+ say $self->keepass_start . $entries . $self->keepass_end;
+}
+
+sub make_keepass_entry {
+ my ($self, $line) = @_;
+
+ my ($hostname,$username,$password,$formSubmitURL,$httpRealm,$usernameField,$passwordField) = @$line;
+
+ my $entry = <<KEEPASS_ENTRY;
+ <entry>
+ <title>$username @ $hostname</title>
+ <username>$username</username>
+ <password>$password</password>
+ <url>$formSubmitURL</url>
+ <comment>Realm: $httpRealm, usernameField:$usernameField, passwordField:$passwordField</comment>
+ <icon>1</icon>
+ <expire>Never</expire>
+ </entry>
+KEEPASS_ENTRY
+# <creation>$BASETIME</creation>
+# <lastaccess>$BASETIME</lastaccess>
+# <lastmod>$BASETIME</lastmod>
+
+ return $entry;
+}
+
+1;
19 t/data/keepass.xml
@@ -0,0 +1,19 @@
+<!DOCTYPE KEEPASSX_DATABASE>
+<database>
+ <group>
+ <title>Internet</title>
+ <icon>1</icon>
+ <entry>
+ <title>GPG</title>
+ <username></username>
+ <password>stuff</password>
+ <url></url>
+ <comment></comment>
+ <icon>1</icon>
+ <creation>2010-11-19T15:09:59</creation>
+ <lastaccess>2010-11-19T15:11:48</lastaccess>
+ <lastmod>2010-11-19T15:11:48</lastmod>
+ <expire>Never</expire>
+ </entry>
+ </group>
+</database>
3  t/data/password_exporter.txt
@@ -0,0 +1,3 @@
+# Generated by Password Exporter; Export format 1.1; Encrypted: false
+"hostname","username","password","formSubmitURL","httpRealm","usernameField","passwordField"
+"https://www.google.com","user","foo","https://www.google.com","","Email","Passwd"
Please sign in to comment.
Something went wrong with that request. Please try again.