Skip to content

Commit 9638aad

Browse files
Matthew HowellMatthew Howell
authored andcommitted
Updated from fork of ClickStudios PasswordState to CSV for 1Password
1 parent c6c3a0c commit 9638aad

File tree

2 files changed

+34
-94
lines changed

2 files changed

+34
-94
lines changed

README.md

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,17 @@
1-
keepass2passwordstate - README
1+
keepass2csv - README
22
=====================
3-
keepass2passwordstate.xsl
3+
keepass2csv.xsl
44

5-
Convert KeePass XML (2.x) format ClickStudios PasswordState Import format
5+
Convert KeePass XML (2.x) format to CSV, columns tailored to 1Password's CSV import
66

77
Usage
88
Either:
99
a) - Export from Keepass 2 to XML
10-
- Apply xsl to exported xml (I use Notepad++. Complements->XML tools->XSL Transformation) and provide parameter values for PasswordListID and AccountType
11-
b) Apply xsl directly from Keepass 2 (File->Export->Transform using XSL Template). Here you cannot pass parameters, so you have to edit keepass2passwordstate.xsl
12-
13-
Notes: * Its mandatory to know the passwordlist ID.
14-
* All passwords are imported into the same password list. Then you can use bulk move to reorder
15-
* The original keepass "folder" is stored into Description.
16-
* !!File Must have .csv extension. If not, passwordstate refuses to import it.!!
17-
18-
19-
Field Mapping
20-
21-
PasswordState Keepass
22-
================= =====================================================
23-
PasswordListID; As set in param PasswordListID in config section
24-
Title; Title
25-
UserName; Username
26-
Description; Folder Hierarchy
27-
AccountType; As set in param AccountType in config section
28-
Notes; Notes
29-
URL; URL
30-
Password; Password
31-
ExpiryDate; Expiration Date
32-
GenericField1;
33-
GenericField2;
34-
GenericField3;
35-
GenericField4;
36-
GenericField5;
37-
GenericField6;
38-
GenericField7;
39-
GenericField8;
40-
GenericField9;
41-
GenericField10
42-
10+
- Apply xsl to exported xml (e.g with Notepad++, Plugins->XML tools->XSL Transformation)
11+
b) Apply xsl directly from Keepass 2 (File->Export->Transform using XSL Template).
4312

13+
Notes: * Notes lists "From KeePass conversion" on all entries
14+
* The original keepass "folder" is stored into Notes, along with the icon that was used.
15+
* Not all icons numbers are translated, you may see the numeric IconID
16+
4417

keepass2passwordstate.xsl renamed to keepass2csv.xsl

Lines changed: 25 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,17 @@
11
<?xml version="1.0" encoding="utf-8"?>
2-
<xsl:stylesheet version="1.0"
3-
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
4-
<!-- Convert KeePass XML (2.x) format ClickStudios PasswordState Import
5-
format
6-
Toni Comerma September 2013
7-
Copyright (c) 2013 Toni Comerma - Televisió de Catalunya.
8-
GNU GENERAL PUBLIC LICENSE - See attached License File
9-
10-
Based on LiosK/keepass2keeper.xsl (https://gist.github.com/LiosK/388889)
11-
-->
12-
13-
<!-- Config Section -->
14-
<xsl:param name="PasswordListID">14</xsl:param>
15-
<xsl:param name="AccountType" />
16-
17-
18-
<!-- Code Section -->
19-
20-
<xsl:variable name="cometa">"</xsl:variable>
21-
2+
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
223
<xsl:output method="text" encoding="utf-8" />
4+
<xsl:variable name="cometa">"</xsl:variable>
235

246
<xsl:template match="/">
257
<!-- Header Row -->
26-
<xsl:text>PasswordListID,Title,UserName,Description,AccountType,Notes,URL,Password,ExpiryDate,GenericField1,GenericField2,GenericField3,GenericField4,GenericField5,GenericField6,GenericField7,GenericField8,GenericField9,GenericField10
27-
</xsl:text>
8+
<xsl:text>Title,UserName,Password,Url,Notes&#10;</xsl:text>
289
<xsl:apply-templates select="/KeePassFile/Root/Group" />
2910
</xsl:template>
3011

12+
<!-- These groups will be ignored -->
13+
<xsl:template match="Group[Name='Recycle Bin']" />
14+
3115
<xsl:template match="Group">
3216
<xsl:param name="parent" select="'/'" />
3317
<xsl:variable name="current" select="concat($parent, Name)" />
@@ -43,7 +27,6 @@
4327
</xsl:apply-templates>
4428
</xsl:template>
4529

46-
4730
<xsl:template match="Entry">
4831
<xsl:param name="group" />
4932

@@ -56,6 +39,12 @@
5639
<xsl:with-param name="by" select="concat($cometa,$cometa)" />
5740
</xsl:call-template>
5841
</xsl:if>
42+
<xsl:text>From KeePass conversion, Group: </xsl:text>
43+
<xsl:value-of select="$group" />
44+
<xsl:text>, Icon: </xsl:text>
45+
<xsl:call-template name="iconName">
46+
<xsl:with-param name="iconId" select="IconID" />
47+
</xsl:call-template>
5948
</xsl:variable>
6049

6150
<!-- Escape Double quotes in password field -->
@@ -69,7 +58,7 @@
6958
</xsl:if>
7059
</xsl:variable>
7160

72-
<!-- Escape Double quotes in password field (yes, someone put quotes in that field too)-->
61+
<!-- Escape Double quotes in URL field (yes, someone put quotes in that field too)-->
7362
<xsl:variable name="url">
7463
<xsl:if test="String[Key='URL']/Value!=''">
7564
<xsl:call-template name="string-replace-all">
@@ -92,33 +81,17 @@
9281
</xsl:choose>
9382
</xsl:variable>
9483

95-
<!-- Fix wrong dates (year 2999) -->
96-
<xsl:variable name="date">
97-
<xsl:call-template name="replaceDate">
98-
<xsl:with-param name="value" select="Times/ExpiryTime" />
99-
</xsl:call-template>
100-
</xsl:variable>
101-
102-
<!-- put tab-separated fields: Title, UserName, Password, Notes, Group,
103-
URL, JSON -->
84+
<!-- put CSV fields: Title, UserName, Password, Group, URL, Notes -->
10485
<xsl:text>"</xsl:text>
105-
<xsl:value-of select="$PasswordListID" />
106-
<xsl:text>","</xsl:text>
10786
<xsl:value-of select="$title" />
10887
<xsl:text>","</xsl:text>
10988
<xsl:value-of select="String[Key='UserName']/Value" />
11089
<xsl:text>","</xsl:text>
111-
<xsl:value-of select="$group" />
112-
<xsl:text>","</xsl:text>
113-
<xsl:value-of select="$AccountType" />
114-
<xsl:text>","</xsl:text>
115-
<xsl:value-of select="$notes" />
90+
<xsl:value-of select="$password" />
11691
<xsl:text>","</xsl:text>
11792
<xsl:value-of select="$url" />
11893
<xsl:text>","</xsl:text>
119-
<xsl:value-of select="$password" />
120-
<xsl:text>","</xsl:text>
121-
<xsl:value-of select="$date" />
94+
<xsl:value-of select="$notes" />
12295
<xsl:text>"&#10;</xsl:text>
12396
</xsl:template>
12497

@@ -165,22 +138,16 @@
165138
</xsl:choose>
166139
</xsl:template>
167140

168-
<xsl:template name="replaceDate">
169-
<xsl:param name="value" />
141+
<xsl:template name="iconName">
142+
<xsl:param name="iconId" />
170143
<xsl:choose>
171-
<xsl:when test="$value!=''">
172-
<xsl:choose>
173-
<xsl:when test="substring($value,1,4) > 2020">
174-
<xsl:text>2020-12-31T23:59:59Z</xsl:text>
175-
</xsl:when>
176-
<xsl:otherwise>
177-
<xsl:value-of select="$value" />
178-
</xsl:otherwise>
179-
</xsl:choose>
180-
</xsl:when>
181-
<xsl:otherwise>
182-
<xsl:value-of select="$value" />
183-
</xsl:otherwise>
144+
<xsl:when test="$iconId=0">Default Key</xsl:when>
145+
<xsl:when test="$iconId=43">Trash Bin</xsl:when>
146+
<xsl:when test="$iconId=45">Red X</xsl:when>
147+
<xsl:otherwise>
148+
<xsl:value-of select="$iconId" />
149+
</xsl:otherwise>
184150
</xsl:choose>
185151
</xsl:template>
152+
186153
</xsl:stylesheet>

0 commit comments

Comments
 (0)