Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo

Close

Commit [48dbf7] Maximize Restore History

Fixed some errors in the format descriptions, moved stuff to Misc directory, removed unused files.

git-svn-id: svn://svn.code.sf.net/p/passwordsafe/code/trunk/pwsafe/pwsafe@534 1f79f812-37fb-46fe-a122-30589dd2bf55

Rony Shapiro Rony Shapiro 2005-04-07

added Misc
removed pwsafe-decode.pl
changed formatV2.txt
changed notes.txt
copied Makefile.linux.w32 -> Misc/pwsafe-decode2.pl
copied Makefile.w32 -> Misc/pwsafe-decode.pl
Misc
Directory.
pwsafe-decode.pl
File was removed.
formatV2.txt Diff Switch to side-by-side view
Loading...
notes.txt Diff Switch to side-by-side view
Loading...
Makefile.linux.w32 to Misc/pwsafe-decode2.pl
--- a/Makefile.linux.w32
+++ b/Misc/pwsafe-decode2.pl
@@ -1,157 +1,139 @@
-# Makefile for pwsafe, building win32 target under Linux via WINE
-#------------------------------------------------------------------------
+#!/usr/bin/perl
 
-PLATFORM=win32
-#MAKEDEBUG=y
+# Updated April 5, 2005 by Jason Diamond.
 
-### The Microsoft toolset, living on Wine
-VCPATH=c:\\local\\vc7\\bin
-HTMLHELPPATH=c:\\local\\htmlhelp
+# This is an updated version of the original script written by Paul Pluzhnikov.
+# This version knows how to parse the different record types introduced in the
+# Version 2 File Format.  It doesn't do any checking to see if the specified
+# file actually is a Version 2 file--it just assumes that it is.
 
-WINE=wine
-CC=$(WINE) $(VCPATH)\\cl.exe
-CXX=$(WINE) $(VCPATH)\\cl.exe
-LINK=$(WINE) $(VCPATH)\\link.exe
-AR=$(WINE) $(VCPATH)\\link.exe -lib
-RC=$(WINE) $(VCPATH)\\rc.exe
-# note - use the normal Linux rm
-RM=rm
+use Crypt::Blowfish;
+use Digest::SHA1;
+use Getopt::Std;
 
-CXXFLAGS=$(DEBUG) $(DEFINES) $(OPTIONS) $(TEST) $(INCLUDES)
-CFLAGS=$(DEBUG) $(DEFINES) $(OPTIONS) $(TEST) $(INCLUDES)
+$verify = 0;
 
-ifndef TEMP
-TEMP=c:\\temp
-endif
+getopts("c"); # '-c' => produce CSV file
 
-.SUFFIXES:
-.SUFFIXES: .cpp .c .o
+if ($#ARGV < 1) {
+	die "usage: $0 [-c] password file.dat\n";
+}
 
-%.obj : %.c
-	$(CC) /c $(CFLAGS) $< /Fo$@
+$pass = $ARGV[0];
+open(IN, $ARGV[1]) || die "unable to open $AGV[1]: $!";
 
-%.obj : %.cpp
-	$(CXX) /c $(CXXFLAGS) $< /Fo$@
+sysread(IN, $rnd, 8);
+sysread(IN, $rndhash, 20);
 
-THE_APP=pwsafe.exe
+if ($verify) {
+	# verify password is correct; doesn't work: see below
+	$sha = new Digest::SHA1;
+	$sha->add($rnd, pack("xx"), $pass);
 
-TARGETS=$(THE_APP)
+	$salt = $sha->digest();
 
-SOURCE_FILES=
-#SOURCE_FILES+=AddBackupDlg.cpp
-SOURCE_FILES+=AddDlg.cpp
-#SOURCE_FILES+=BackupDlg.cpp
-SOURCE_FILES+=BlowFish.cpp
-SOURCE_FILES+=ClearQuestionDlg.cpp
-SOURCE_FILES+=ConfirmDeleteDlg.cpp
-#SOURCE_FILES+=CryptKeyEntry.cpp
-SOURCE_FILES+=EditDlg.cpp
-#SOURCE_FILES+=FileDialogExt.cpp
-SOURCE_FILES+=ItemData.cpp
-SOURCE_FILES+=MyString.cpp
-SOURCE_FILES+=OptionsDlg.cpp
-SOURCE_FILES+=PasskeyChangeDlg.cpp
-SOURCE_FILES+=PasskeyEntry.cpp
-SOURCE_FILES+=PasskeySetup.cpp
-#SOURCE_FILES+=PasswordSafe.cpp
-SOURCE_FILES+=DboxMain.cpp
-SOURCE_FILES+=QueryAddName.cpp
-SOURCE_FILES+=QuerySetDef.cpp
-SOURCE_FILES+=RemindSaveDlg.cpp
-SOURCE_FILES+=sha1.cpp
-#SOURCE_FILES+=StdAfx.cpp
-SOURCE_FILES+=SysColStatic.cpp
-SOURCE_FILES+=ThisMfcApp.cpp
-SOURCE_FILES+=TryAgainDlg.cpp
-SOURCE_FILES+=UsernameEntry.cpp
-SOURCE_FILES+=Util.cpp
-#SOURCE_FILES+=variables.cpp
+	# perl does Blowfish in Network byte order, but pwsafe does it in Host
+	# hence conversion back and forth
+	$rnd = pack("N2", unpack("L2", $rnd));
 
-OBJECT_FILES = ${SOURCE_FILES:.cpp=.obj}
+	$cypher = new Crypt::Blowfish $salt;
+	for (0 .. 999) {
+		$rnd = $cypher->encrypt($rnd);
+	}
+	$rnd = pack("L2", unpack("N2", $rnd));
 
-### Build Parameters
-INCLUDES= 
-INCLUDES+=/I"c:\\local\\vc7\\include"
-INCLUDES+=/I"c:\\local\\vc7\\atlmfc\\include"
+	$sha->add($rnd, pack("xx"));
 
-OPTIONS=
-# OPTIONS+=/ML # create single-threaded exe, using LIBC.LIB
-# OPTIONS+=/MT # create multi-threaded exe, using LIBCMT.LIB
-ifeq ($(MAKEDEBUG),y)
-OPTIONS+=/MTd # create debug multithreaded exe, using LIBCMT.LIB
-OPTIONS+=/ZI # debug info in program database (Edit and Continue)
-OPTIONS+=/Od # disable optimization
-OPTIONS+=/Gm # enable minimal rebuild
-else
-OPTIONS+=/MT # multithread
-#OPTIONS+=/MD # multithread DLL
-OPTIONS+=/O2 # optimize for speed
-endif
-OPTIONS+=/W3 # warning level
-OPTIONS+=/GX # synchronous exception handling
-# OPTIONS+=/FD # generate dependencies
-# OPTIONS+=/GZ # catch release-build errors in debug build
+	# $sha->digest() ought to match $rndhash, but doesn't
+	# due to the fact that SHA1Final() doesn't reset to the same state as SHA1Init().
+	# print $sha->hexdigest(), "\n";
+}
 
-DEFINES+=/DWIN32
-ifeq ($(MAKEDEBUG),y)
-DEFINES+=/DDEBUG
-DEFINES+=/D_DEBUG
-else
-DEFINES+=/DNDEBUG
-endif
-# so far, I'm always defining JPRDEBUG - eventually I won't
-DEFINES+=/DJPRDEBUG
-#DEFINES+=/D_CONSOLE
-DEFINES+=/D_MBCS
-DEFINES+=/D_WINDOWS
-#DEFINES+=/D_AFXDLL
+sysread(IN, $salt, 20);
+sysread(IN, $ip, 8);
 
-#debug
-LDSPECS=
-LDSPECS += ws2_32.lib
-LDSPECS += kernel32.lib
-LDSPECS += user32.lib
-LDSPECS += gdi32.lib
-LDSPECS += winspool.lib
-LDSPECS += comdlg32.lib
-LDSPECS += advapi32.lib
-LDSPECS += shell32.lib
-LDSPECS += ole32.lib
-LDSPECS += oleaut32.lib
-LDSPECS += uuid.lib
-LDSPECS += odbc32.lib
-LDSPECS += odbccp32.lib
-LDSPECS += htmlhelp.lib
+$sha = new Digest::SHA1;
+$sha->add($pass, $salt);
+$cypher = new Crypt::Blowfish($sha->digest());
 
-#LDOPTIONS+=/subsystem:console 
-LDOPTIONS+=/subsystem:windows
-LDOPTIONS+=/incremental:yes 
-#LDOPTIONS+=/incremental:no
-ifeq ($(MAKEDEBUG),y)
-LDOPTIONS+=/debug 
-endif
-LDOPTIONS+=/machine:I386 
-LDOPTIONS+=/out:$(THE_APP)
+# This hash is here for debugging purposes.
+%recordTypes = (
+	0 => "None",
+	1 => "UUID",
+	2 => "Group",
+	3 => "Title",
+	4 => "Username",
+	5 => "Notes",
+	6 => "Password",
+	7 => "Creation Time",
+	8 => "Password Modification Time",
+	9 => "Last Access Time",
+	10 => "Password Lifetime",
+	11 => "Password Policy",
+	12 => "Last Mod. Time",
+	255 => "End of Entry"
+);
 
-LDPATHS+=/libpath:"c:\\local\\vc7\\lib"
-LDPATHS+=/libpath:"c:\\local\\vc7\\atlmfc\\lib"
-LDPATHS+=/libpath:"c:\\local\\htmlhelp\\lib"
+while (sysread(IN, $len, 8)) {
+	$ipNext = $len;
+	$len = pack("N2", unpack("L2", $len));
+	$len = $cypher->decrypt($len);
+	$len = pack("N2", unpack("L2", $len));
+	($len, $rt) = unpack("L2", $len ^ $ip);
+	$ip = $ipNext;
 
-LDFLAGS = $(LDOPTIONS) $(LDPATHS) $(LDSPECS)
+	#print "length of record is $len\n";
+	#print "record type is $recordTypes{$rt}\n";
 
-RESFILE = PasswordSafe.res
+	if ($len > 1000) {
+		die "the password was probably incorrect";
+	}
 
-all: $(TARGETS)
+	if ($len == 0) { $len = 8; }
+	$str = "";
+	while (0 < $len)
+	{
+		sysread(IN, $d, 8); $ipNext = $d;
+		$d = pack("N2", unpack("L2", $d));
+		$d = $cypher->decrypt($d);
+		$d = pack("N2", unpack("L2", $d));
+		$d ^= $ip;
+		$str .= unpack("A*", $d);
+		$ip = $ipNext;
+		$len -= 8;
+	}
 
-$(THE_APP): $(RESFILE) $(OBJECT_FILES)
-	$(LINK) /out:$@ $(LDFLAGS) $(OBJECT_FILES) $(RESFILE)
+	# Skip the first three records.
+	$rc += 1;
+	if ($rc < 4) { next; }
 
-PasswordSafe.res: PasswordSafe.rc
-	$(RC) /fo$@ $(DEFINES) $(INCLUDES) $<
+	# Format the data based on the record type.
+	if ($rt == 1) {
+		@uuid = unpack("C16", $str);
+		$str = sprintf "%02X" x 4 . "-" . ("%02X" x 2 . "-") x 3 . "%02X" x 6, @uuid;
+	} elsif ($rt > 6) {
+		$str = "<not supported>";
+	}
 
-install: all
+	if ($opt_c) {
+		# Output the CSV data. This depends on all entries having the
+		# same records in the same order.
+		if ($rt != 255) {
+			$str =~ s/,/\\,/g;
+			$str =~ s/\r*\n/\\n/g;
+			print "$str,";
+		} else {
+			print "\n";
+		}
+	} else {
+		# Output the non-CSV data. One record per line.
+		if ($rt != 255) {
+			print "$recordTypes{$rt}: $str\n";
+		} else {
+			print "=" x 60, "\n";
+		}
+	}
+}
 
-clean:
-	-$(RM) *.obj
-	-$(RM) $(THE_APP)
-	-$(RM) *.res
+exit(0);
+
Makefile.w32 to Misc/pwsafe-decode.pl
--- a/Makefile.w32
+++ b/Misc/pwsafe-decode.pl
@@ -1,148 +1,89 @@
-# Makefile for pwsafe under win32
-#------------------------------------------------------------------------
+#!/usr/bin/perl
 
-PLATFORM=win32
-#MAKEDEBUG=y
+use Crypt::Blowfish;
+use Digest::SHA1;
+use Getopt::Std;
 
-### The Microsoft toolset
-CC=cl.exe
-CXX=cl.exe
-LINK=link.exe
-AR=link.exe -lib
-RC=rc.exe
-# note - this is not usually around, but you should be able to find one
-RM=rm.exe
+$verify = 0;
 
-CXXFLAGS=$(DEBUG) $(DEFINES) $(OPTIONS) $(TEST) $(INCLUDES)
-CFLAGS=$(DEBUG) $(DEFINES) $(OPTIONS) $(TEST) $(INCLUDES)
+getopts("c"); # '-c' => produce CSV file
 
-ifndef TEMP
-TEMP=c:\\temp
-endif
+if ($#ARGV < 1) {
+    die "usage: $0 [-c] password file.dat\n"; 
+}
+$pass = $ARGV[0];
+open(IN, $ARGV[1]) || die "unable to open $AGV[1]: $!";
 
-.SUFFIXES:
-.SUFFIXES: .cpp .c .o
+sysread(IN, $rnd, 8);
+sysread(IN, $rndhash, 20);
 
-%.obj : %.c
-	$(CC) /c $(CFLAGS) $< /Fo$@
+if ($verify) {
+    # verify password is correct; doesn't work: see below
+    $sha = new Digest::SHA1;
+    $sha->add($rnd, pack("xx"), $pass);
 
-%.obj : %.cpp
-	$(CXX) /c $(CXXFLAGS) $< /Fo$@
+    $salt = $sha->digest();
 
-THE_APP=pwsafe.exe
+# perl does Blowfish in Network byte order, but pwsafe does it in Host
+# hence conversion back and forth
+    $rnd = pack("N2", unpack("L2", $rnd)); 
 
-TARGETS=$(THE_APP)
+    $cypher = new Crypt::Blowfish $salt;
+    for (0 .. 999) {
+	$rnd = $cypher->encrypt($rnd);
+    }
+    $rnd = pack("L2", unpack("N2", $rnd));
+    
+    $sha->add($rnd, pack("xx"));
+    
+    # $sha->digest() ought to match $rndhash, but doesn't
+    # due to the fact that SHA1Final() doesn't reset to the same state as SHA1Init().
+    # print $sha->hexdigest(), "\n";
+}
 
-SOURCE_FILES=
-#SOURCE_FILES+=AddBackupDlg.cpp
-SOURCE_FILES+=AddDlg.cpp
-#SOURCE_FILES+=BackupDlg.cpp
-SOURCE_FILES+=BlowFish.cpp
-SOURCE_FILES+=ClearQuestionDlg.cpp
-SOURCE_FILES+=ConfirmDeleteDlg.cpp
-#SOURCE_FILES+=CryptKeyEntry.cpp
-SOURCE_FILES+=EditDlg.cpp
-#SOURCE_FILES+=FileDialogExt.cpp
-SOURCE_FILES+=ItemData.cpp
-SOURCE_FILES+=MyString.cpp
-SOURCE_FILES+=OptionsDlg.cpp
-SOURCE_FILES+=PasskeyChangeDlg.cpp
-SOURCE_FILES+=PasskeyEntry.cpp
-SOURCE_FILES+=PasskeySetup.cpp
-#SOURCE_FILES+=PasswordSafe.cpp
-SOURCE_FILES+=DboxMain.cpp
-SOURCE_FILES+=QueryAddName.cpp
-SOURCE_FILES+=QuerySetDef.cpp
-SOURCE_FILES+=RemindSaveDlg.cpp
-SOURCE_FILES+=sha1.cpp
-#SOURCE_FILES+=StdAfx.cpp
-SOURCE_FILES+=SysColStatic.cpp
-SOURCE_FILES+=ThisMfcApp.cpp
-SOURCE_FILES+=TryAgainDlg.cpp
-SOURCE_FILES+=UsernameEntry.cpp
-SOURCE_FILES+=Util.cpp
-#SOURCE_FILES+=variables.cpp
+sysread(IN, $salt, 20);
+sysread(IN, $ip, 8);
 
-OBJECT_FILES = ${SOURCE_FILES:.cpp=.obj}
+$sha = new Digest::SHA1;
+$sha->add($pass, $salt);
+$cypher = new Crypt::Blowfish($sha->digest());
 
-### Build Parameters
-INCLUDES= 
+while (sysread(IN, $len, 8)) {
+    if ($rc % 3 == 0 && ! $opt_c) {
+	print "=" x 60, "\n";
+    }
+    $rc += 1; # record counter
+    $ipNext = $len;
+    $len = pack("N2", unpack("L2", $len));
+    $len = $cypher->decrypt($len);
+    $len = pack("N2", unpack("L2", $len));
+    $len = unpack("L2", $len ^ $ip);
+    $ip = $ipNext;
 
-OPTIONS=
-# OPTIONS+=/ML # create single-threaded exe, using LIBC.LIB
-# OPTIONS+=/MT # create multi-threaded exe, using LIBCMT.LIB
-ifeq ($(MAKEDEBUG),y)
-OPTIONS+=/MTd # create debug multithreaded exe, using LIBCMT.LIB
-OPTIONS+=/ZI # debug info in program database (Edit and Continue)
-OPTIONS+=/Od # disable optimization
-OPTIONS+=/Gm # enable minimal rebuild
-else
-OPTIONS+=/MT # multithread
-#OPTIONS+=/MD # multithread DLL
-OPTIONS+=/O2 # optimize for speed
-endif
-OPTIONS+=/W3 # warning level
-OPTIONS+=/GX # synchronous exception handling
-# OPTIONS+=/FD # generate dependencies
-# OPTIONS+=/GZ # catch release-build errors in debug build
-
-DEFINES+=/DWIN32
-ifeq ($(MAKEDEBUG),y)
-DEFINES+=/DDEBUG
-DEFINES+=/D_DEBUG
-else
-DEFINES+=/DNDEBUG
-endif
-DEFINES+=/DJPRDEBUG
-#DEFINES+=/D_CONSOLE
-DEFINES+=/D_MBCS
-DEFINES+=/D_WINDOWS
-#DEFINES+=/D_AFXDLL
-
-#debug
-LDSPECS=
-LDSPECS += ws2_32.lib
-LDSPECS += kernel32.lib
-LDSPECS += user32.lib
-LDSPECS += gdi32.lib
-LDSPECS += winspool.lib
-LDSPECS += comdlg32.lib
-LDSPECS += advapi32.lib
-LDSPECS += shell32.lib
-LDSPECS += ole32.lib
-LDSPECS += oleaut32.lib
-LDSPECS += uuid.lib
-LDSPECS += odbc32.lib
-LDSPECS += odbccp32.lib
-LDSPECS += htmlhelp.lib
-
-#LDOPTIONS+=/subsystem:console 
-LDOPTIONS+=/subsystem:windows
-LDOPTIONS+=/incremental:yes 
-#LDOPTIONS+=/incremental:no
-ifeq ($(MAKEDEBUG),y)
-LDOPTIONS+=/debug 
-endif
-LDOPTIONS+=/machine:I386 
-LDOPTIONS+=/out:$(THE_APP)
-
-#LDPATHS+=/libpath:"/some/lib/path"
-
-LDFLAGS = $(LDOPTIONS) $(LDPATHS) $(LDSPECS)
-
-RESFILE = PasswordSafe.res
-
-all: $(TARGETS)
-
-$(THE_APP): $(RESFILE) $(OBJECT_FILES)
-	$(LINK) /out:$@ $(LDFLAGS) $(OBJECT_FILES) $(RESFILE)
-
-PasswordSafe.res: PasswordSafe.rc
-	$(RC) /fo$@ $(DEFINES) $<
-
-install: all
-
-clean:
-	-@erase *.obj
-	-@erase $(THE_APP)
-	-@erase *.res
+    if ($len > 1000) {
+	die "the password was probably incorrect";
+    }
+    
+    if ($len == 0) { $len = 8; }
+    $str = "";
+    while (0 < $len)
+    {
+	sysread(IN, $d, 8); $ipNext = $d;
+	$d = pack("N2", unpack("L2", $d));
+	$d = $cypher->decrypt($d);
+	$d = pack("N2", unpack("L2", $d));
+	$d ^= $ip; 
+	$str .= unpack("A*", $d);
+	$ip = $ipNext;
+	$len -= 8;
+    }
+    if ($opt_c) {
+	$str =~ s/,/\\,/g;
+	$str =~ s/\r*\n/\\n/g;
+	print $str;
+	print $rc % 3 ? "," : "\n";
+    } else {
+	print $str, "\n";
+    }
+}
+exit(0);