Skip to content

Instantly share code, notes, and snippets.

@xee5ch
Created December 5, 2013 17:52
Show Gist options
  • Save xee5ch/7810078 to your computer and use it in GitHub Desktop.
Save xee5ch/7810078 to your computer and use it in GitHub Desktop.
Convert Firefox passwords to KeePass XML for import into KeePassX.
#!/bin/env ruby
require 'rexml/document'
require 'digest/md5'
xml = File.read('ff-passwords-export.xml')
doc = REXML::Document.new(xml)
head = ""
foot = ""
head += "<!DOCTYPE KEEPASSX_DATABASE>\n"
head += "<database>\n"
head += " <group>\n"
head += " <title>Imported from Firefox</title>\n"
head += " <icon>1</icon>\n"
puts head
doc.elements.each("xml/entries/entry") do |e|
entry = ""
if e.attributes['httpRealm'] != ""
title = e.attributes['httpRealm']
else
title = e.attributes['formSubmitURL']
end
url = e.attributes['host']
username = e.attributes['user']
password = e.attributes['password']
notes = "Form Submit URL: " + e.attributes['formSubmitURL'] + " HTTP Realm: " + e.attributes['httpRealm'] + " User Field Name: " + e.attributes['userFieldName'] + " Pass Field Name: "+ e.attributes['passFieldName']
import_time = Time.new.utc.strftime("%Y-%m-%dT%H:%M:%S")
uuid = Digest::MD5.hexdigest(import_time+username+url+notes)
entry += " <entry>\n"
entry += " <title>#{title}</title>\n"
entry += " <username>#{username}</username>\n"
entry += " <url>#{url}</url>\n"
entry += " <password>#{password}</password>\n"
entry += " <comment>#{notes}</comment>\n"
entry += " <icon>0</icon>\n"
entry += " <creation>#{import_time}</creation>\n"
entry += " <lastmod>#{import_time}</lastmod>\n"
entry += " <lastaccess>#{import_time}</lastaccess>\n"
entry += " <expire>never</expire>\n"
entry += " </entry>\n"
puts entry
end
foot += " </group>\n"
foot += "</database>\n"
puts foot
@gnuletik
Copy link

Works flawlessly thanks !
To use with this plugin: https://addons.mozilla.org/en-US/firefox/addon/password-exporter/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment