[Pkg-ocaml-maint-commits] [nss-passwords] 03/09: Add support for JSON-based password store (Firefox >= 32)

Stéphane Glondu glondu at moszumanska.debian.org
Sat Sep 6 11:50:54 UTC 2014


This is an automated email from the git hooks/post-receive script.

glondu pushed a commit to branch master
in repository nss-passwords.

commit ad9dc17cd299a3c06bc4f990018c0911ed80a409
Author: Stephane Glondu <steph at glondu.net>
Date:   Fri Sep 5 17:16:28 2014 +0200

    Add support for JSON-based password store (Firefox >= 32)
---
 .gitignore     |  1 +
 Makefile       | 20 +++++++++++++++++---
 README         |  5 ++++-
 json_types.atd |  9 +++++++++
 main.ml        | 26 +++++++++++++++++++++++++-
 5 files changed, 56 insertions(+), 5 deletions(-)

diff --git a/.gitignore b/.gitignore
index e6388f5..4b8af13 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 *~
 *.o
 *.cm[iox]
+*_[jt].ml*
 nss-passwords
diff --git a/Makefile b/Makefile
index 8a9f249..74cebb4 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,6 @@
-OCAMLC = ocamlfind ocamlc -g -package fileutils.str,sqlite3
-OCAMLOPT = ocamlfind ocamlopt -g -package fileutils.str,sqlite3
+OCAMLC = ocamlfind ocamlc -g -package fileutils.str,sqlite3,atdgen
+OCAMLOPT = ocamlfind ocamlopt -g -package fileutils.str,sqlite3,atdgen
+
 ML_CFLAGS = $(foreach u,$(shell pkg-config --cflags nss),-ccopt $(u))
 ML_LFLAGS = $(foreach u,$(shell pkg-config --libs nss),-cclib $(u))
 
@@ -10,7 +11,7 @@ all: nss-passwords
 clean:
 	rm -f *~ *.cm[oxi] *.o nss-passwords
 
-nss-passwords: main.cmo nss_stubs.o main_stubs.o
+nss-passwords: json_types_t.cmo json_types_j.cmo main.cmo nss_stubs.o main_stubs.o
 	$(OCAMLC) -o $@ $^ $(ML_LFLAGS) -custom -linkpkg
 
 %.cmx: %.ml
@@ -19,5 +20,18 @@ nss-passwords: main.cmo nss_stubs.o main_stubs.o
 %.cmo: %.ml
 	$(OCAMLC) -c $<
 
+%.cmi: %.mli
+	$(OCAMLC) -c $<
+
 %.o: %.c
 	$(OCAMLC) $(ML_CFLAGS) -c $<
+
+%_j.ml %_j.mli: %.atd
+	atdgen -j -j-std $<
+
+%_t.ml %_t.mli: %.atd
+	atdgen -t $<
+
+json_types_t.cmo: json_types_t.cmi
+json_types_j.ml: json_types_t.ml
+json_types_j.cmo: json_types_j.cmi
diff --git a/README b/README
index ce08fd7..f40bb46 100644
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ nss-passwords
 This program reads passwords from a Mozilla keyring. It can run
 entirely in text mode. It is merely a higher level version of
 pwdecrypt, which is no longer convenient for direct use with
-SQLite-based keyrings of recent versions of Firefox.
+SQLite-based and JSON-based keyrings of recent versions of Firefox.
 
 Requirements (versions known to work are between brackets):
  - Mozilla's Network Security Services (NSS) [3.12.6]
@@ -15,6 +15,8 @@ Requirements (versions known to work are between brackets):
      (http://ocaml-fileutils.forge.ocamlcore.org/)
  - ocaml-sqlite3 [1.5.6]
      (http://ocaml.info/home/ocaml_sources.html#ocaml-sqlite3)
+ - atdgen [1.3.1]
+     (http://mjambon.com/atdgen)
  - some pinentry obeying the Assuan protocol
      (e.g. pinentry-curses [0.8.0] from http://www.gnupg.org/aegypten/)
 
@@ -22,6 +24,7 @@ Usage: run with --help option
 
 Tested with:
  - Iceweasel 3.5.11 (should be OK with Firefox of same version)
+ - Iceweasel 32.0 (should be OK with Firefox of same version)
  - Icedove 3.0.6 (should be OK with Thunderbird of same version)
 
  -- Stéphane Glondu <steph at glondu.net>  Tue, 31 Aug 2010 17:58:11 +0200
diff --git a/json_types.atd b/json_types.atd
new file mode 100644
index 0000000..f76a601
--- /dev/null
+++ b/json_types.atd
@@ -0,0 +1,9 @@
+type login = {
+  hostname : string;
+  encryptedUsername : string;
+  encryptedPassword : string;
+}
+
+type logins = {
+  logins : login list;
+}
diff --git a/main.ml b/main.ml
index 7dd3ba8..8736f02 100644
--- a/main.ml
+++ b/main.ml
@@ -168,9 +168,33 @@ let exec_sqlite () =
   let r = Sqlite3.db_close db in
   assert (r = true)
 
+open Json_types_j
+
+let json_process logins query =
+  let rex = Str.regexp (".*" ^ Str.quote query ^ ".*") in
+  List.iter
+    (fun l ->
+     if Str.string_match rex l.hostname 0 then (
+       let username = do_decrypt ~callback ~data:l.encryptedUsername in
+       let password = do_decrypt ~callback ~data:l.encryptedPassword in
+       results := (l.hostname, username, password) :: !results
+     )
+    ) logins
+
+let exec_json () =
+  let ic = open_in (FilePath.concat !dir "logins.json") in
+  let ls = Yojson.init_lexer () in
+  let lb = Lexing.from_channel ic in
+  let logins = read_logins ls lb in
+  close_in ic;
+  List.iter (json_process logins.logins) !queries
+
 let () =
   try
-    exec_sqlite ();
+    (if Sys.file_exists (FilePath.concat !dir "logins.json")
+     then exec_json ()
+     else exec_sqlite ()
+    );
     let results = List.sort compare !results in
     let (a, b, c) = List.fold_left
       (fun (a, b, c) (x, y, z) ->

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-ocaml-maint/packages/nss-passwords.git



More information about the Pkg-ocaml-maint-commits mailing list