Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
O
our_own_cloud_project
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
die_coolen_jungs
our_own_cloud_project
Commits
80180bea
Commit
80180bea
authored
11 years ago
by
Vincent Petry
Browse files
Options
Downloads
Patches
Plain Diff
Added IV for ext storage password encryption
parent
40a70ecf
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/files_external/lib/config.php
+33
-10
33 additions, 10 deletions
apps/files_external/lib/config.php
lib/public/util.php
+9
-0
9 additions, 0 deletions
lib/public/util.php
with
42 additions
and
10 deletions
apps/files_external/lib/config.php
+
33
−
10
View file @
80180bea
...
...
@@ -39,9 +39,6 @@ class OC_Mount_Config {
// whether to skip backend test (for unit tests, as this static class is not mockable)
public
static
$skipTest
=
false
;
// password encryption cipher
private
static
$cipher
;
/**
* Get details on each of the external storage backends, used for the mount config UI
* If a custom UI is needed, add the key 'custom' and a javascript file with that name will be loaded
...
...
@@ -555,7 +552,7 @@ class OC_Mount_Config {
*/
private
static
function
encryptPasswords
(
$options
)
{
if
(
isset
(
$options
[
'password'
]))
{
$options
[
'password_encrypted'
]
=
base64_encode
(
self
::
getCipher
()
->
encrypt
(
$options
[
'password'
])
)
;
$options
[
'password_encrypted'
]
=
self
::
encryptPassword
(
$options
[
'password'
]);
unset
(
$options
[
'password'
]);
}
return
$options
;
...
...
@@ -569,20 +566,46 @@ class OC_Mount_Config {
private
static
function
decryptPasswords
(
$options
)
{
// note: legacy options might still have the unencrypted password in the "password" field
if
(
isset
(
$options
[
'password_encrypted'
]))
{
$options
[
'password'
]
=
self
::
getCipher
()
->
decrypt
(
base64_decode
(
$options
[
'password_encrypted'
])
)
;
$options
[
'password'
]
=
self
::
decryptPassword
(
$options
[
'password_encrypted'
]);
unset
(
$options
[
'password_encrypted'
]);
}
return
$options
;
}
/**
* Encrypt a single password
* @param string $password plain text password
* @return encrypted password
*/
private
static
function
encryptPassword
(
$password
)
{
$cipher
=
self
::
getCipher
();
$iv
=
\OCP\Util
::
generateRandomBytes
(
16
);
$cipher
->
setIV
(
$iv
);
return
base64_encode
(
$iv
.
$cipher
->
encrypt
(
$password
));
}
/**
* Decrypts a single password
* @param string $encryptedPassword encrypted password
* @return plain text password
*/
private
static
function
decryptPassword
(
$encryptedPassword
)
{
$cipher
=
self
::
getCipher
();
$binaryPassword
=
base64_decode
(
$encryptedPassword
);
$iv
=
substr
(
$binaryPassword
,
0
,
16
);
$cipher
->
setIV
(
$iv
);
$binaryPassword
=
substr
(
$binaryPassword
,
16
);
return
$cipher
->
decrypt
(
$binaryPassword
);
}
/**
* Returns the encryption cipher
*/
private
static
function
getCipher
()
{
if
(
!
isset
(
self
::
$cipher
))
{
self
::
$cipher
=
new
Crypt_AES
(
CRYPT_AES_MODE_CBC
);
self
::
$cipher
->
setKey
(
\OCP\Config
::
getSystemValue
(
'passwordsalt'
)
);
}
return
self
::
$cipher
;
// note: not caching this to make it thread safe as we'll use
// a different IV for each password
$cipher
=
new
Crypt_AES
(
CRYPT_AES_MODE_CBC
);
$cipher
->
setKey
(
\OCP\Config
::
getSystemValue
(
'passwordsalt'
));
return
$cipher
;
}
}
This diff is collapsed.
Click to expand it.
lib/public/util.php
+
9
−
0
View file @
80180bea
...
...
@@ -495,4 +495,13 @@ class Util {
public
static
function
isValidFileName
(
$file
)
{
return
\OC_Util
::
isValidFileName
(
$file
);
}
/**
* @brief Generates a cryptographic secure pseudo-random string
* @param Int $length of the random string
* @return String
*/
public
static
function
generateRandomBytes
(
$length
=
30
)
{
return
\OC_Util
::
generateRandomBytes
(
$length
);
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment