pwman-tools

Check-in [e97152f612]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Handle single and double quotes. Update README with assumptions

Quite a hacky mess to handle single and double quotes but seems to work. This was the test file used:

```
<?xml version="1.0"?>
<PWMan_PasswordList version="3"><PwList name="Main"><PwList name="SECURE-NOTES"><PwItem><name>test 1</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff '</launch></PwItem><PwItem><name>test 2</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff "</launch></PwItem><PwItem><name>test 3</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff ;</launch></PwItem></PwList></PwList></PWMan_PasswordList>
```

Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | master | trunk
Files: files | file ages | folders
SHA3-256: e97152f6128e014d23e024125e4eb9d21596b759cc4aa7da890f2f16524a9cd6
User & Date: atomicules 2019-08-09 13:36:13
Context
2019-08-09
15:48
Much more sensible escaping of quotes

I'd tried unicode before, but couldn't get it to work, I think because I was
missing an extra backslash that is required for some reason. check-in: 2165591f67 user: atomicules tags: master, trunk

13:36
Handle single and double quotes. Update README with assumptions

Quite a hacky mess to handle single and double quotes but seems to work. This was the test file used:

```
<?xml version="1.0"?>
<PWMan_PasswordList version="3"><PwList name="Main"><PwList name="SECURE-NOTES"><PwItem><name>test 1</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff '</launch></PwItem><PwItem><name>test 2</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff "</launch></PwItem><PwItem><name>test 3</name><host>http://sn</host><user>me</user><passwd/><launch>Stuff ;</launch></PwItem></PwList></PwList></PWMan_PasswordList>
``` check-in: e97152f612 user: atomicules tags: master, trunk

2019-06-29
11:05
Some spaces to tabs check-in: c039cd9bd1 user: atomicules tags: master, trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to README.markdown.

36
37
38
39
40
41
42



43
44
45
46
47
48
49
..
51
52
53
54
55
56
57
58
59
60
61
62
63

- Assumes two-level hierarchy of data in pwman
- Only uses Login and Secure Note op templates
- Secure Notes have to be in a "SECURE-NOTES" category/heading in PWman
- Ignores stuff in a "INACTIVE" category/heading in PWman
- Assumes an existing authenticated op session
- pwman.db file needs to be decrypted up front to `~/.pwman.db.decrypt`



- Mappings from PWman to 1password are as follows:
	- For Logins
		- name -> title
		- host -> url
		- user -> username
		- passwd -> password
		- launch -> notesPlain
................................................................................
	- For Secure Notes
		- name -> title
		- host -> notesPlain
		- user -> notesPlain
		- passwd -> notesPlain
		- launch -> notesPlain
		- category -> tag
- Doesn't escape quotes, etc. In practice when I used this to migrate ~270 items I only had 5 failures due to things like:
	- Quote marks (`"`) in Secure notes
	- Single quote marks (`'`) in Secure notes
	- Login items with quotes in the launch field

	Since I've already migrated I might not fix. But basically issue is due to trying to populate notesPlain and not properly escaping things that break json







>
>
>







 







<
<
<
<
<
<
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
..
54
55
56
57
58
59
60







- Assumes two-level hierarchy of data in pwman
- Only uses Login and Secure Note op templates
- Secure Notes have to be in a "SECURE-NOTES" category/heading in PWman
- Ignores stuff in a "INACTIVE" category/heading in PWman
- Assumes an existing authenticated op session
- pwman.db file needs to be decrypted up front to `~/.pwman.db.decrypt`
- Assumes untampered with XML. Note that newlines and spaces will add
  additional "nodes" that breaks the assumption of this code. By default PWman
  includes no spaces or newlines, etc.
- Mappings from PWman to 1password are as follows:
	- For Logins
		- name -> title
		- host -> url
		- user -> username
		- passwd -> password
		- launch -> notesPlain
................................................................................
	- For Secure Notes
		- name -> title
		- host -> notesPlain
		- user -> notesPlain
		- passwd -> notesPlain
		- launch -> notesPlain
		- category -> tag






Changes to pwman2op.lisp.

3
4
5
6
7
8
9






10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35


36

37
38
39
40
41
42
43
; See README for usage instructions

; Load quicklisp
(load "~/.sbclrc")
; Load libraries
; Had parsing errors with xmls so use cxml instead
(ql:quickload "cxml")







; Just assume two template types
; Obtained from `op get template <category>`
(defun template-secure-note
	(content)
	(concatenate 'string "{\"notesPlain\":\"" content "\",\"sections\":[]}"))

(defun template-login
	(username password content)
	(concatenate 'string "{\"notesPlain\":\"" content "\",\"sections\":[],\"passwordHistory\":[],\"fields\":[{\"value\":\"" username "\",\"name\":\"username\",\"type\":\"T\",\"designation\":\"username\"},{\"value\":\"" password "\",\"name\":\"password\",\"type\":\"P\",\"designation\":\"password\"}]}"))

(defun send-to-op
	(op-category pwman-category name host username passwd launch)
	(progn
		; Case would be better if I can figure that out
		(defparameter template
			(if (string= op-category "Login")
				(template-login username passwd launch)
				; Need to do this and not multiple ifs in progn as otherwise template picks up NIL from progmn
				; Need to combine fields for Secure notes
				(template-secure-note (concatenate 'string "host: " host "; user: " username "; password: " passwd "; launch: " launch))))
		; Encode first and get return
		; Probably many better ways to do this...
		; Maybe base64 encode directly here? Subtle differences though it seems with op
		; Need to single quote encode the json
		(defparameter extproc (sb-ext:run-program "sh" (list "-c" (concatenate 'string "echo '" template "' | op encode")) :search :environment :output :stream))


		(defparameter encoded-item (read-line (sb-ext:process-output extproc)))

		; Create item
		; Just going to send blanks, etc if that's what some fields are. It doesn't seem to matter.
		; Need to only send url if it's a Login item
		(defparameter defaultargs (list  "create" "item" op-category encoded-item (concatenate 'string "--title=" name) (concatenate 'string "--tags=" pwman-category)))
		(defparameter args
			(if (string= op-category "Login")
				; Append, because need at end







>
>
>
>
>
>





|



|











|
|
|
|
|
>
>

>







3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
; See README for usage instructions

; Load quicklisp
(load "~/.sbclrc")
; Load libraries
; Had parsing errors with xmls so use cxml instead
(ql:quickload "cxml")
(ql:quickload "cl-ppcre")

; "Escape" certain characters. Will replace back on cli call
(defun escape-quotes
	(text)
	(cl-ppcre:regex-replace-all "\"" (cl-ppcre:regex-replace-all "'" text "SINGLEQUOTE" :preserve-case t) "DOUBLEQUOTE" :preserve-case t))

; Just assume two template types
; Obtained from `op get template <category>`
(defun template-secure-note
	(content)
	(concatenate 'string "{\"notesPlain\":\"" (escape-quotes content) "\",\"sections\":[]}"))

(defun template-login
	(username password content)
	(concatenate 'string "{\"notesPlain\":\"" (escape-quotes content) "\",\"sections\":[],\"passwordHistory\":[],\"fields\":[{\"value\":\"" username "\",\"name\":\"username\",\"type\":\"T\",\"designation\":\"username\"},{\"value\":\"" password "\",\"name\":\"password\",\"type\":\"P\",\"designation\":\"password\"}]}"))

(defun send-to-op
	(op-category pwman-category name host username passwd launch)
	(progn
		; Case would be better if I can figure that out
		(defparameter template
			(if (string= op-category "Login")
				(template-login username passwd launch)
				; Need to do this and not multiple ifs in progn as otherwise template picks up NIL from progmn
				; Need to combine fields for Secure notes
				(template-secure-note (concatenate 'string "host: " host "; user: " username "; password: " passwd "; launch: " launch))))
		; Command line notes, because multiple levels of escaping are confusing
		; echo | sed 's#DOUBLEQUOTE#\\"#'
		; echo | sed s#SINGLEQUOTE#\\\'#
		; should work
		(defparameter extproc (sb-ext:run-program "sh" (list "-c" (concatenate 'string "echo '" template "' | sed 's#DOUBLEQUOTE#\\\\\"#g' | sed s#SINGLEQUOTE#\\\'#g | op encode")) :search :environment :output :stream))
		(print template)
		(print (concatenate 'string "echo '" template "' | sed 's#DOUBLEQUOTE#\\\"#g' | sed s#SINGLEQUOTE#\\\'#g | op encode"))
		(defparameter encoded-item (read-line (sb-ext:process-output extproc)))
		(print encoded-item)
		; Create item
		; Just going to send blanks, etc if that's what some fields are. It doesn't seem to matter.
		; Need to only send url if it's a Login item
		(defparameter defaultargs (list  "create" "item" op-category encoded-item (concatenate 'string "--title=" name) (concatenate 'string "--tags=" pwman-category)))
		(defparameter args
			(if (string= op-category "Login")
				; Append, because need at end