tobiasvl / 1password2pass

Script for importing 1Password passwords to pass
http://www.zx2c4.com/projects/password-store/
GNU General Public License v2.0
6 stars 4 forks source link

Script Failing with Error #1

Closed arkag closed 7 years ago

arkag commented 8 years ago

I'm using your script to import my 1password keychain into a pass store... I'm getting a

/usr/lib/ruby/2.3.0/json/common.rb:156:in `parse': 419: unexpected token at '{

error and I don't really know enough about ruby to know why it's doing this. I've exported only my logins to a .1pif file and it's doing this. Is it something to do with my ruby version?

First 2 entries of my .1pif, because it fails at the first entry.

{"uuid":"04E537E284F64A84A610E258AFD6D8B1","updatedAt":1444870365,"locationKey":"domain.com","securityLevel":"SL5","contentsHash":"b256a379","title":"titleThing","location":"insert.url","txTimestamp":1444870365,"createdAt":1444527911,"typeName":"webforms.WebForm","secureContents":{"fields":[{"value":"username","id":"username;opid=__0","name":"username","type":"T","designation":"username"},{"value":"thepassword","id":"password;opid=__1","name":"password","type":"P","designation":"password"},{"value":"","id":"warn;opid=__2","name":"warn","type":"C"},{"value":"LOGIN","id":";opid=__5","name":"submit","type":"I"}],"passwordHistory":[{"value":"password1","time":1444750159},{"value":"password2","time":1444870365}],"sections":[{"fields":[{"k":"string","n":"FF643A063E0A47A99429ED494E785844","v":"(none)","t":"grouping"}],"title":"Other Fields","name":"15f51806-69c2-3b74-f6f2-cab57d27229a"}],"URLs":[{"url":"the.url"}]}}
***5642bee8-a5ff-11dc-8314-0800200c9a66***
{"keyID":"90A0C50DB57F4ED58181E8203999C1F1","locationKey":"","typeName":"webforms.WebForm","location":"","uuid":"059D127620334B0EA70A17E596519D97","createdAt":1445480466,"securityLevel":"SL5","openContents":{"autosubmit":"default","usernameHash":"a683c5c5349f6f7fb903ba8a9e7e55d0ba1b8f03579f95be83f4954c33e81098"},"title":"the wifi","updatedAt":1445480491,"txTimestamp":1445480491,"contentsHash":"8c267141","secureContents":{"fields":[{"type":"T","name":"username","value":"n/a","designation":"username"},{"type":"P","name":"password","value":"thepassword","designation":"password"}]}}
***5642bee8-a5ff-11dc-8314-0800200c9a66***
tobiasvl commented 8 years ago

@cwre Thanks! Found the issue, and it has been fixed in this repo.

I've submitted the patch to pass as well, but not sure when it will be merged. The following patch will apply to the version of my script there (with git am or just patch), from the root of the pass repository. Or you could just apply it manually, it's just one added line of code.

Cheers!

diff --git a/contrib/importers/1password2pass.rb b/contrib/importers/1password2pass.rb
index 79318ee..5ea4523 100755
--- a/contrib/importers/1password2pass.rb
+++ b/contrib/importers/1password2pass.rb
@@ -95,8 +95,10 @@ if File.extname(filename) =~ /.txt/i
 elsif File.extname(filename) =~ /.1pif/i
   require "json"

-  # 1PIF is almost JSON, but not quite
   pif = "[#{File.open(filename).read}]"
+  # Normalize line endings, explicitly preserving encoding just to be sure
+  pif.encode!(pif.encoding, universal_newline: true)
+  # 1PIF is almost JSON, but not quite:
   pif.gsub!(/^\*\*\*.*\*\*\*$/, ",")
   pif = JSON.parse(pif, {symbolize_names: true})
arkag commented 8 years ago

It seems like I'm still having trouble...

/usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `parse': 419: unexpected token at ']' (JSON::ParserError)
    from /usr/local/Cellar/ruby/2.3.0/lib/ruby/2.3.0/json/common.rb:156:in `parse'
    from ./1password2pass.rb:104:in `<main>'
tobiasvl commented 8 years ago

@cwre Gods almighty. Try now.

arkag commented 8 years ago
⇒  ./1password2pass.rb -d Logins ../logins.1pif/data.1pif
./1password2pass.rb:116:in `block in <main>': undefined method `[]' for nil:NilClass (NoMethodError)
    from ./1password2pass.rb:111:in `each'
    from ./1password2pass.rb:111:in `<main>'
arkag commented 8 years ago

Sorry 1password sucks, lol.

tobiasvl commented 8 years ago

@cwre No worries, sorry for the trouble. This issue so far contains three different bugs, the last two apparently due to the 1PIF format being undocumented. Apparently your file has a lot more edge cases than I had tested for. So this is pretty useful actually.

This last error is apparently because one of the entries in your file doesn't have a "secureContents" key in it. Can you confirm that? If you find such an entry, how does it look (with a censored password)?

tobiasvl commented 8 years ago

Might be related to #2.

arkag commented 8 years ago

The field is in every line of my data... Is there some way it needs to be formatted?

arkag commented 8 years ago

This format looks a little weird...

{"uuid":"D26E912EFBB04C4A99A51B62245CE83E","updatedAt":1446947608,"locationKey":"domain.com","securityLevel":"SL5","contentsHash":"d049e692","title":"title","location":"url.domain.com","secureContents":{"fields":[{"id":"email;opid=__3","value":"user@email.com","name":"email","designation":"username","type":"E"},{"id":"password;opid=__4","value":"password","name":"password","designation":"password","type":"P"},{"id":";opid=__5","value":"✓","name":"remember","type":"C"}],"passwordHistory":[{"value":"password1","time":1446947608}],"sections":[{"fields":[{"k":"string","n":"2C70DB01658A491388A24AD8012071E4","v":"(none)","t":"grouping"}],"title":"Other Fields","name":"5e93f226-dc79-94d1-5b9e-a788c9f3ce35"}],"URLs":[{"url":"domain.url"}]},"txTimestamp":1456083029,"createdAt":1444527911,"typeName":"webforms.WebForm"}
***5642bee8-a5ff-11dc-8314-0800200c9a66***
tobiasvl commented 8 years ago

Aaaaah, indeed. I've used the value of name to decide whether something is a username or a password or whatnot. However, that one you just commented with has an email instead which 1Password knows to use as username by having "designation": "username".

Try, try again…

arkag commented 8 years ago

What are standards, anyway?

On Thu, May 26, 2016 at 6:45 AM Tobias V. Langhoff notifications@github.com wrote:

Aaaaah, indeed. I've used the value of name to decide whether something is a username or a password or whatnot. However, that one you just commented with has an email instead which 1Password knows to use as username by having "designation": "username".

Try, try again…

— You are receiving this because you were mentioned. Reply to this email directly or view it on GitHub https://github.com/tobiasvl/1password2pass/issues/1#issuecomment-221849083

tobiasvl commented 7 years ago

Hope this was resolved way back when, please reopen if not.