Blog‎ > ‎

Import Passwords from Passpack to F-Secure Key

posted Jan 9, 2014, 10:59 AM by Pasi Orovuo   [ updated Jan 9, 2014, 1:05 PM ]
I've been a long time user of Passpack. After F-Secure released it's Key password manager (http://www.f-secure.com/en/web/home_global/key) I decided to give it a shot, and found it very appealing due to it's simplicity.

And after using it for a while I decided give up Passpack - there was a problem though... F-Secure Key did not support import of CSV or such formats. Fortunately, it supports few other formats, so it is possible to convert from Passpack's CSV to one of the other formats. Below is the script I wrote for the task. Basically, you can format just about any export format to the simple CSV format:
  • UTF-8 encoding
  • No header line
  • Comma as the separator
  • Double quote " as the quoting character
  • Fields should be in the following order
    1. title
    2. username
    3. password
    4. url
    5. tags (ignored!)
    6. note
    7. email (will be concatenated with note in the output xml)

Usage: fskey.py input.csv > output.xml

And output.xml is ready to be imported in F-Secure Key.
 

#!/usr/bin/python
# -*- coding: utf-8 -*-

import lxml.etree
import sys
import csv

if len( sys.argv ) != 2:
    print '%s csv.txt' % sys.argv[0]
    sys.exit()

def utf8_csv_reader( utf8_data, dialect = csv.excel, **kwargs ):
    csv_reader = csv.reader( utf8_data, dialect = dialect, **kwargs )
    for row in csv_reader:
        yield [ unicode( cell, 'utf-8' ) for cell in row ]

root = lxml.etree.Element( 'passwordsafe' )
with open( sys.argv[1], 'rb' ) as csvfile:
    lines = utf8_csv_reader( csvfile, delimiter = ',', quotechar = '"' )
    
    for line in lines:
        ( name, uid, pwd, link, tags, note, email ) = line
        
        notes = []
        if len( email ) > 0:
            notes.append( 'Email: %s' % ( email ) )
        if len( note ) > 0:
            notes.append( note )
        
        entry = lxml.etree.SubElement( root, 'entry' )
        lxml.etree.SubElement( entry, 'title' ).text    = name
        lxml.etree.SubElement( entry, 'url' ).text      = link
        lxml.etree.SubElement( entry, 'username' ).text = uid
        lxml.etree.SubElement( entry, 'password' ).text = pwd
        lxml.etree.SubElement( entry, 'notes' ).text    = '\n\n'.join( notes )

print lxml.etree.tostring( root, pretty_print = True, xml_declaration = True, encoding = 'utf-8' )






ċ
Pasi Orovuo,
Jan 9, 2014, 1:07 PM
Comments