Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
O
officejs
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
officejs
Commits
36e09bbc
Commit
36e09bbc
authored
Aug 14, 2012
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update CryptStorage and Jio tests
parent
08c3aa1d
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
152 deletions
+124
-152
OfficeJS/src/jio.storage/cryptstorage.js
OfficeJS/src/jio.storage/cryptstorage.js
+82
-96
OfficeJS/test/jiotests.js
OfficeJS/test/jiotests.js
+42
-56
No files found.
OfficeJS/src/jio.storage/cryptstorage.js
View file @
36e09bbc
...
...
@@ -12,7 +12,7 @@ var newCryptedStorage = function ( spec, my ) {
that
.
serialized
=
function
()
{
var
o
=
super_serialized
();
o
.
username
=
priv
.
username
;
o
.
password
=
priv
.
password
;
o
.
password
=
priv
.
password
;
// TODO : unsecured !!!
o
.
storage
=
priv
.
secondstorage_string
;
return
o
;
};
...
...
@@ -60,8 +60,8 @@ var newCryptedStorage = function ( spec, my ) {
priv
.
password
,
param
);
}
catch
(
e
)
{
callback
({
status
:
0
,
statusText
:
'
Decrypt Fail
'
,
message
:
'
Unable to decrypt.
'
});
callback
({
status
:
403
,
statusText
:
'
Forbidden
'
,
error
:
'
forbidden
'
,
message
:
'
Unable to decrypt.
'
,
reason
:
'
unable to decrypt
'
});
return
;
}
callback
(
undefined
,
tmp
);
...
...
@@ -95,181 +95,167 @@ var newCryptedStorage = function ( spec, my ) {
return
async
;
};
that
.
post
=
function
(
command
)
{
that
.
put
(
command
);
};
/**
* Saves a document.
* @method
saveDocumen
t
* @method
pu
t
*/
that
.
saveDocumen
t
=
function
(
command
)
{
that
.
pu
t
=
function
(
command
)
{
var
new_file_name
,
new_file_content
,
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
.
encryptFilePath
=
function
()
{
priv
.
encrypt
(
command
.
get
Path
(),
function
(
res
)
{
priv
.
encrypt
(
command
.
get
DocId
(),
function
(
res
)
{
new_file_name
=
res
;
am
.
call
(
o
,
'
save
'
);
});
};
o
.
encryptFileContent
=
function
()
{
priv
.
encrypt
(
command
.
getContent
(),
function
(
res
)
{
priv
.
encrypt
(
command
.
get
Doc
Content
(),
function
(
res
)
{
new_file_content
=
res
;
am
.
call
(
o
,
'
save
'
);
});
};
o
.
save
=
function
()
{
var
settings
=
command
.
cloneOption
(),
newcommand
;
settings
.
success
=
function
()
{
that
.
success
();
};
settings
.
error
=
function
(
r
)
{
that
.
error
(
r
);
};
newcommand
=
that
.
newCommand
(
'
saveDocument
'
,
{
path
:
new_file_name
,
content
:
new_file_content
,
option
:
settings
});
that
.
addJob
(
that
.
newStorage
(
priv
.
secondstorage_spec
),
newcommand
);
var
success
=
function
(
val
)
{
val
.
id
=
command
.
getDocId
();
that
.
success
(
val
);
},
error
=
function
(
err
)
{
that
.
error
(
err
);
},
cloned_doc
=
command
.
cloneDoc
();
cloned_doc
.
_id
=
new_file_name
;
cloned_doc
.
content
=
new_file_content
;
that
.
addJob
(
'
put
'
,
priv
.
secondstorage_spec
,
cloned_doc
,
command
.
cloneOption
(),
success
,
error
);
};
am
.
wait
(
o
,
'
save
'
,
1
);
am
.
call
(
o
,
'
encryptFilePath
'
);
am
.
call
(
o
,
'
encryptFileContent
'
);
};
// end
saveDocumen
t
};
// end
pu
t
/**
* Loads a document.
* @method
loadDocumen
t
* @method
ge
t
*/
that
.
loadDocumen
t
=
function
(
command
)
{
that
.
ge
t
=
function
(
command
)
{
var
new_file_name
,
option
,
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
.
encryptFilePath
=
function
()
{
priv
.
encrypt
(
command
.
get
Path
(),
function
(
res
)
{
priv
.
encrypt
(
command
.
get
DocId
(),
function
(
res
)
{
new_file_name
=
res
;
am
.
call
(
o
,
'
loadDocumen
t
'
);
am
.
call
(
o
,
'
ge
t
'
);
});
};
o
.
loadDocument
=
function
()
{
var
settings
=
command
.
cloneOption
(),
newcommand
;
settings
.
error
=
o
.
loadOnError
;
settings
.
success
=
o
.
loadOnSuccess
;
newcommand
=
that
.
newCommand
(
'
loadDocument
'
,
{
path
:
new_file_name
,
option
:
settings
});
that
.
addJob
(
that
.
newStorage
(
priv
.
secondstorage_spec
),
newcommand
);
o
.
get
=
function
()
{
that
.
addJob
(
'
get
'
,
priv
.
secondstorage_spec
,
new_file_name
,
command
.
cloneOption
(),
o
.
success
,
o
.
error
);
};
o
.
loadOnSuccess
=
function
(
result
)
{
result
.
name
=
command
.
getPath
();
o
.
success
=
function
(
val
)
{
val
.
_id
=
command
.
getDocId
();
if
(
command
.
getOption
(
'
metadata_only
'
))
{
that
.
success
(
result
);
that
.
success
(
val
);
}
else
{
priv
.
decrypt
(
result
.
content
,
function
(
err
,
res
){
priv
.
decrypt
(
val
.
content
,
function
(
err
,
res
){
if
(
err
)
{
that
.
error
(
err
);
}
else
{
result
.
content
=
res
;
// content only: the second storage should
// manage content_only option, so it is not
// necessary to manage it.
that
.
success
(
result
);
val
.
content
=
res
;
that
.
success
(
val
);
}
});
}
};
o
.
loadOnError
=
function
(
error
)
{
// NOTE : we can re create an error object instead of
// keep the old ex:status=404,message="document 1y59gyl8g
// not found in localStorage"...
o
.
error
=
function
(
error
)
{
that
.
error
(
error
);
};
am
.
call
(
o
,
'
encryptFilePath
'
);
};
// end
loadDocumen
t
};
// end
ge
t
/**
* Gets a document list.
* @method
getDocumentList
* @method
allDocs
*/
that
.
getDocumentList
=
function
(
command
)
{
that
.
allDocs
=
function
(
command
)
{
var
result_array
=
[],
am
=
priv
.
newAsyncModule
(),
o
=
{};
o
.
getDocumentList
=
function
()
{
var
settings
=
command
.
cloneOption
();
settings
.
success
=
o
.
getListOnSuccess
;
settings
.
error
=
o
.
getListOnError
;
that
.
addJob
(
that
.
newStorage
(
priv
.
secondstorage_spec
),
that
.
newCommand
(
'
getDocumentList
'
,
{
path
:
command
.
getPath
(),
option
:
settings
})
);
o
.
allDocs
=
function
()
{
that
.
addJob
(
'
allDocs
'
,
priv
.
secondstorage_spec
,
null
,
command
.
cloneOption
(),
o
.
onSuccess
,
o
.
error
);
};
o
.
getListOnSuccess
=
function
(
result
)
{
result_array
=
result
;
o
.
onSuccess
=
function
(
val
)
{
if
(
val
.
total_rows
===
0
)
{
return
am
.
call
(
o
,
'
success
'
);
}
result_array
=
val
.
rows
;
var
i
,
decrypt
=
function
(
c
)
{
priv
.
decrypt
(
result_array
[
c
].
name
,
function
(
err
,
res
)
{
priv
.
decrypt
(
result_array
[
c
].
id
,
function
(
err
,
res
)
{
if
(
err
)
{
am
.
call
(
o
,
'
error
'
,[
err
]);
}
else
{
am
.
call
(
o
,
'
pushResult
'
,[
res
,
c
,
'
name
'
]);
result_array
[
c
].
id
=
res
;
result_array
[
c
].
key
=
res
;
am
.
call
(
o
,
'
success
'
);
}
});
if
(
!
command
.
getOption
(
'
metadata_only
'
))
{
priv
.
decrypt
(
result_array
[
c
].
content
,
function
(
err
,
res
)
{
priv
.
decrypt
(
result_array
[
c
].
value
.
content
,
function
(
err
,
res
)
{
if
(
err
)
{
am
.
call
(
o
,
'
error
'
,[
err
]);
}
else
{
am
.
call
(
o
,
'
pushResult
'
,[
res
,
c
,
'
content
'
]);
result_array
[
c
].
value
.
content
=
res
;
am
.
call
(
o
,
'
success
'
);
}
});
}
};
if
(
command
.
getOption
(
'
metadata_only
'
))
{
am
.
wait
(
o
,
'
success
'
,
result
.
length
-
1
);
am
.
wait
(
o
,
'
success
'
,
val
.
total_rows
*
1
-
1
);
}
else
{
am
.
wait
(
o
,
'
success
'
,
result
.
length
*
2
-
1
);
am
.
wait
(
o
,
'
success
'
,
val
.
total_rows
*
2
-
1
);
}
for
(
i
=
0
;
i
<
result_array
.
length
;
i
+=
1
)
{
decrypt
(
i
);
}
};
o
.
getListOnError
=
function
(
error
)
{
am
.
call
(
o
,
'
error
'
,[
error
]);
};
o
.
pushResult
=
function
(
result
,
index
,
key
)
{
result_array
[
index
][
key
]
=
result
;
am
.
call
(
o
,
'
success
'
);
};
o
.
error
=
function
(
error
)
{
am
.
end
();
that
.
error
(
error
);
};
o
.
success
=
function
()
{
am
.
end
();
that
.
success
(
result_array
);
that
.
success
(
{
total_rows
:
result_array
.
length
,
rows
:
result_array
}
);
};
am
.
call
(
o
,
'
getDocumentList
'
);
};
// end
getDocumentList
am
.
call
(
o
,
'
allDocs
'
);
};
// end
allDocs
/**
* Removes a document.
* @method remove
Document
* @method remove
*/
that
.
remove
Document
=
function
(
command
)
{
that
.
remove
=
function
(
command
)
{
var
new_file_name
,
o
=
{};
o
.
encrypt
FilePath
=
function
()
{
priv
.
encrypt
(
command
.
get
Path
(),
function
(
res
)
{
o
.
encrypt
DocId
=
function
()
{
priv
.
encrypt
(
command
.
get
DocId
(),
function
(
res
)
{
new_file_name
=
res
;
o
.
removeDocument
();
});
};
o
.
removeDocument
=
function
()
{
var
cloned_option
=
command
.
cloneOption
();
cloned_option
.
error
=
o
.
removeOnError
;
cloned_option
.
success
=
o
.
removeOnSuccess
;
that
.
addJob
(
that
.
newStorage
(
priv
.
secondstorage_spec
),
that
.
newCommand
(
'
removeDocument
'
,
{
path
:
new_file_name
,
option
:
cloned_option
}));
var
cloned_doc
=
command
.
cloneDoc
();
cloned_doc
.
_id
=
new_file_name
;
that
.
addJob
(
'
remove
'
,
priv
.
secondstorage_spec
,
cloned_doc
,
command
.
cloneOption
(),
o
.
success
,
that
.
error
);
};
o
.
removeOnSuccess
=
function
(
result
)
{
that
.
success
();
};
o
.
removeOnError
=
function
(
error
)
{
that
.
error
(
error
);
};
o
.
encryptFilePath
();
o
.
success
=
function
(
val
)
{
val
.
id
=
command
.
getDocId
();
that
.
success
(
val
);
};
o
.
encryptDocId
();
};
// end remove
return
that
;
};
Jio
.
addStorageType
(
'
crypt
'
,
newCryptedStorage
);
OfficeJS/test/jiotests.js
View file @
36e09bbc
...
...
@@ -1157,29 +1157,27 @@ test ('Document save' , function () {
storage
:{
type
:
'
local
'
,
username
:
'
cryptsavelocal
'
,
applicationname
:
'
jiotests
'
}});
o
.
f
=
function
(
result
)
{
if
(
!
result
)
{
result
=
'
done
'
;
}
else
{
result
=
'
fail
'
;
o
.
f
=
function
(
err
,
val
)
{
if
(
err
)
{
err
=
err
.
status
;
}
deepEqual
(
result
,
'
done
'
,
'
save ok
'
);
deepEqual
(
err
||
val
,{
ok
:
true
,
id
:
'
testsave
'
}
,
'
save ok
'
);
};
this
.
spy
(
o
,
'
f
'
);
o
.
jio
.
saveDocument
(
'
testsave
'
,
'
contentoftest
'
,{
success
:
o
.
f
,
error
:
o
.
f
}
);
o
.
jio
.
put
({
_id
:
'
testsave
'
,
content
:
'
contentoftest
'
},
o
.
f
);
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
}
// encrypt 'testsave' with 'cryptsave:mypwd' password
o
.
tmp
=
LocalOrCookieStorage
.
getItem
(
'
jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER
/
5x354bfX54QFa1
'
);
o
.
tmp
=
LocalOrCookieStorage
.
getItem
(
// '/' = '%2F'
'
jio/local/cryptsavelocal/jiotests/rZx5PJxttlf9QpZER
%2F
5x354bfX54QFa1
'
);
if
(
o
.
tmp
)
{
delete
o
.
tmp
.
last_modified
;
delete
o
.
tmp
.
creation_date
;
delete
o
.
tmp
.
_
last_modified
;
delete
o
.
tmp
.
_
creation_date
;
}
deepEqual
(
o
.
tmp
,
{
name
:
'
rZx5PJxttlf9QpZER/5x354bfX54QFa1
'
,
{
_id
:
'
rZx5PJxttlf9QpZER/5x354bfX54QFa1
'
,
content
:
'
upZkPIpitF3QMT/DU5jM3gP0SEbwo1n81rMOfLE
'
},
'
Check if the document is realy encrypted
'
);
o
.
jio
.
stop
();
...
...
@@ -1194,26 +1192,20 @@ test ('Document load' , function () {
storage
:{
type
:
'
local
'
,
username
:
'
cryptloadlocal
'
,
applicationname
:
'
jiotests
'
}});
o
.
f
=
function
(
result
)
{
if
(
result
&&
!
result
.
status
)
{
deepEqual
(
result
,
{
name
:
'
testload
'
,
content
:
'
contentoftest
'
,
last_modified
:
500
,
creation_date
:
500
},
'
load ok
'
);
}
else
{
ok
(
false
,
'
cannot load
'
);
}
o
.
f
=
function
(
err
,
val
)
{
deepEqual
(
err
||
val
,{
_id
:
'
testload
'
,
content
:
'
contentoftest
'
,
_last_modified
:
500
,
_creation_date
:
500
},
'
load ok
'
);
};
this
.
spy
(
o
,
'
f
'
);
// encrypt 'testload' with 'cryptload:mypwd' password
// and 'contentoftest' with 'cryptload:mypwd'
o
.
doc
=
{
name
:
'
hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX
'
,
o
.
doc
=
{
_id
:
'
hiG4H80pwkXCCrlLl1X0BD0BfWLZwDUX
'
,
content
:
'
kSulH8Qo105dSKHcY2hEBXWXC9b+3PCEFSm1k7k
'
,
last_modified
:
500
,
creation_date
:
500
};
_last_modified
:
500
,
_
creation_date
:
500
};
addFileToLocalStorage
(
'
cryptloadlocal
'
,
'
jiotests
'
,
o
.
doc
);
o
.
jio
.
loadDocument
(
'
testload
'
,{
success
:
o
.
f
,
error
:
o
.
f
}
);
o
.
jio
.
get
(
'
testload
'
,
o
.
f
);
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
)
{
ok
(
false
,
'
no response / too much results
'
);
...
...
@@ -1230,13 +1222,9 @@ test ('Get Document List', function () {
storage
:{
type
:
'
local
'
,
username
:
'
cryptgetlistlocal
'
,
applicationname
:
'
jiotests
'
}});
o
.
f
=
function
(
result
)
{
if
(
result
&&
!
result
.
status
)
{
deepEqual
(
objectifyDocumentArray
(
result
),
o
.
f
=
function
(
err
,
val
)
{
deepEqual
(
err
||
objectifyDocumentArray
(
val
.
rows
),
objectifyDocumentArray
(
o
.
doc_list
),
'
Getting list
'
);
}
else
{
ok
(
false
,
'
Cannot get list
'
);
}
};
o
.
tick
=
function
(
tick
)
{
clock
.
tick
(
tick
||
1000
);
...
...
@@ -1249,29 +1237,32 @@ test ('Get Document List', function () {
}
};
this
.
spy
(
o
,
'
f
'
);
o
.
doc_list
=
[
{
name
:
'
testgetlist1
'
,
last_modified
:
500
,
creation_date
:
200
},
{
name
:
'
testgetlist2
'
,
last_modified
:
300
,
creation_date
:
300
}
];
o
.
doc_list
=
[{
id
:
'
testgetlist1
'
,
key
:
'
testgetlist1
'
,
value
:{
_last_modified
:
500
,
_creation_date
:
200
}
},{
id
:
'
testgetlist2
'
,
key
:
'
testgetlist2
'
,
value
:{
_last_modified
:
300
,
_creation_date
:
300
}
}];
o
.
doc_encrypt_list
=
[
{
name
:
'
541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw
'
,
{
_id
:
'
541eX0WTMDw7rqIP7Ofxd1nXlPOtejxGnwOzMw
'
,
content
:
'
/4dBPUdmLolLfUaDxPPrhjRPdA
'
,
last_modified
:
500
,
creation_date
:
200
},
{
name
:
'
541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw
'
,
_last_modified
:
500
,
_
creation_date
:
200
},
{
_id
:
'
541eX0WTMDw7rqIMyJ5tx4YHWSyxJ5UjYvmtqw
'
,
content
:
'
/4FBALhweuyjxxD53eFQDSm4VA
'
,
last_modified
:
300
,
creation_date
:
300
}
_last_modified
:
300
,
_
creation_date
:
300
}
];
// encrypt with 'cryptgetlist:mypwd' as password
LocalOrCookieStorage
.
setItem
(
'
jio/local_file_name_array/cryptgetlistlocal/jiotests
'
,
[
o
.
doc_encrypt_list
[
0
].
name
,
o
.
doc_encrypt_list
[
1
].
name
]);
[
o
.
doc_encrypt_list
[
0
].
_id
,
o
.
doc_encrypt_list
[
1
].
_id
]);
LocalOrCookieStorage
.
setItem
(
'
jio/local/cryptgetlistlocal/jiotests/
'
+
o
.
doc_encrypt_list
[
0
].
name
,
'
jio/local/cryptgetlistlocal/jiotests/
'
+
o
.
doc_encrypt_list
[
0
].
_id
,
o
.
doc_encrypt_list
[
0
]);
LocalOrCookieStorage
.
setItem
(
'
jio/local/cryptgetlistlocal/jiotests/
'
+
o
.
doc_encrypt_list
[
1
].
name
,
'
jio/local/cryptgetlistlocal/jiotests/
'
+
o
.
doc_encrypt_list
[
1
].
_id
,
o
.
doc_encrypt_list
[
1
]);
o
.
jio
.
getDocumentList
(
'
.
'
,{
success
:
o
.
f
,
error
:
o
.
f
}
);
o
.
jio
.
allDocs
(
o
.
f
);
o
.
tick
(
10000
);
o
.
jio
.
stop
();
...
...
@@ -1286,20 +1277,15 @@ test ('Remove document', function () {
storage
:{
type
:
'
local
'
,
username
:
'
cryptremovelocal
'
,
applicationname
:
'
jiotests
'
}});
o
.
f
=
function
(
result
)
{
if
(
!
result
)
{
result
=
'
done
'
;
}
else
{
result
=
'
fail
'
;
}
deepEqual
(
result
,
'
done
'
,
'
Document remove
'
);
o
.
f
=
function
(
err
,
val
)
{
deepEqual
(
err
||
val
,{
ok
:
true
,
id
:
'
file
'
},
'
Document remove
'
);
};
this
.
spy
(
o
,
'
f
'
);
// encrypt with 'cryptremove:mypwd' as password
o
.
doc
=
{
name
:
'
JqCLTjyxQqO9jwfxD/lyfGIX+qA
'
,
o
.
doc
=
{
_id
:
'
JqCLTjyxQqO9jwfxD/lyfGIX+qA
'
,
content
:
'
LKaLZopWgML6IxERqoJ2mUyyO
'
,
last_modified
:
500
,
creation_date
:
500
};
o
.
jio
.
remove
Document
(
'
file
'
,{
success
:
o
.
f
,
error
:
o
.
f
}
);
_last_modified
:
500
,
_
creation_date
:
500
};
o
.
jio
.
remove
({
_id
:
'
file
'
},
o
.
f
);
clock
.
tick
(
1000
);
if
(
!
o
.
f
.
calledOnce
){
ok
(
false
,
'
no response / too much results
'
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment