Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Nextcloud
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Monitor
Service Desk
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
TeDomum
Nextcloud
Commits
d25b8dac
Commit
d25b8dac
authored
9 years ago
by
Lukas Reschke
Browse files
Options
Downloads
Patches
Plain Diff
Use AES-256-CTR as default
CTR is recommended over CFB mode.
parent
29f6f451
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
apps/encryption/lib/crypto/crypt.php
+38
-22
38 additions, 22 deletions
apps/encryption/lib/crypto/crypt.php
apps/encryption/tests/lib/crypto/cryptTest.php
+30
-4
30 additions, 4 deletions
apps/encryption/tests/lib/crypto/cryptTest.php
with
68 additions
and
26 deletions
apps/encryption/lib/crypto/crypt.php
+
38
−
22
View file @
d25b8dac
...
...
@@ -36,9 +36,21 @@ use OCP\IConfig;
use
OCP\ILogger
;
use
OCP\IUserSession
;
/**
* Class Crypt provides the encryption implementation of the default ownCloud
* encryption module. As default AES-256-CTR is used, it does however offer support
* for the following modes:
*
* - AES-256-CTR
* - AES-128-CTR
* - AES-256-CFB
* - AES-128-CFB
*
* @package OCA\Encryption\Crypto
*/
class
Crypt
{
const
DEFAULT_CIPHER
=
'AES-256-C
FB
'
;
const
DEFAULT_CIPHER
=
'AES-256-C
TR
'
;
// default cipher from old ownCloud versions
const
LEGACY_CIPHER
=
'AES-128-CFB'
;
...
...
@@ -48,23 +60,21 @@ class Crypt {
const
HEADER_START
=
'HBEGIN'
;
const
HEADER_END
=
'HEND'
;
/**
* @var ILogger
*/
/** @var ILogger */
private
$logger
;
/**
* @var string
*/
/** @var string */
private
$user
;
/**
* @var IConfig
*/
/** @var IConfig */
private
$config
;
/**
* @var array
*/
/** @var array */
private
$supportedKeyFormats
;
/** @var array */
private
$supportedCiphersAndKeySize
=
[
'AES-256-CTR'
=>
32
,
'AES-128-CTR'
=>
16
,
'AES-256-CFB'
=>
32
,
'AES-128-CFB'
=>
16
,
];
/**
* @param ILogger $logger
...
...
@@ -225,8 +235,13 @@ class Crypt {
*/
public
function
getCipher
()
{
$cipher
=
$this
->
config
->
getSystemValue
(
'cipher'
,
self
::
DEFAULT_CIPHER
);
if
(
$cipher
!==
'AES-256-CFB'
&&
$cipher
!==
'AES-128-CFB'
)
{
$this
->
logger
->
warning
(
'Wrong cipher defined in config.php only AES-128-CFB and AES-256-CFB are supported. Fall back'
.
self
::
DEFAULT_CIPHER
,
if
(
!
isset
(
$this
->
supportedCiphersAndKeySize
[
$cipher
]))
{
$this
->
logger
->
warning
(
sprintf
(
'Unsupported cipher (%s) defined in config.php supported. Falling back to %s'
,
$cipher
,
self
::
DEFAULT_CIPHER
),
[
'app'
=>
'encryption'
]);
$cipher
=
self
::
DEFAULT_CIPHER
;
}
...
...
@@ -237,19 +252,20 @@ class Crypt {
/**
* get key size depending on the cipher
*
* @param string $cipher
supported ('AES-256-CFB' and 'AES-128-CFB')
* @param string $cipher
* @return int
* @throws \InvalidArgumentException
*/
protected
function
getKeySize
(
$cipher
)
{
if
(
$cipher
===
'AES-256-CFB'
)
{
return
32
;
}
else
if
(
$cipher
===
'AES-128-CFB'
)
{
return
16
;
if
(
isset
(
$this
->
supportedCiphersAndKeySize
[
$cipher
]))
{
return
$this
->
supportedCiphersAndKeySize
[
$cipher
];
}
throw
new
\InvalidArgumentException
(
'Wrong cipher defined only AES-128-CFB and AES-256-CFB are supported.'
sprintf
(
'Unsupported cipher (%s) defined.'
,
$cipher
)
);
}
...
...
This diff is collapsed.
Click to expand it.
apps/encryption/tests/lib/crypto/cryptTest.php
+
30
−
4
View file @
d25b8dac
...
...
@@ -105,7 +105,7 @@ class cryptTest extends TestCase {
$this
->
config
->
expects
(
$this
->
once
())
->
method
(
'getSystemValue'
)
->
with
(
$this
->
equalTo
(
'cipher'
),
$this
->
equalTo
(
'AES-256-C
FB
'
))
->
with
(
$this
->
equalTo
(
'cipher'
),
$this
->
equalTo
(
'AES-256-C
TR
'
))
->
willReturn
(
'AES-128-CFB'
);
if
(
$keyFormat
)
{
...
...
@@ -126,6 +126,9 @@ class cryptTest extends TestCase {
$this
->
crypt
->
generateHeader
(
'unknown'
);
}
/**
* @return array
*/
public
function
dataTestGenerateHeader
()
{
return
[
[
null
,
'HBEGIN:cipher:AES-128-CFB:keyFormat:hash:HEND'
],
...
...
@@ -134,16 +137,28 @@ class cryptTest extends TestCase {
];
}
public
function
testGetCipherWithInvalidCipher
()
{
$this
->
config
->
expects
(
$this
->
once
())
->
method
(
'getSystemValue'
)
->
with
(
$this
->
equalTo
(
'cipher'
),
$this
->
equalTo
(
'AES-256-CTR'
))
->
willReturn
(
'Not-Existing-Cipher'
);
$this
->
logger
->
expects
(
$this
->
once
())
->
method
(
'warning'
)
->
with
(
'Unsupported cipher (Not-Existing-Cipher) defined in config.php supported. Falling back to AES-256-CTR'
);
$this
->
assertSame
(
'AES-256-CTR'
,
$this
->
crypt
->
getCipher
());
}
/**
* @dataProvider dataProviderGetCipher
* @param string $configValue
* @param string $expected
*/
public
function
testGetCipher
(
$configValue
,
$expected
)
{
$this
->
config
->
expects
(
$this
->
once
())
->
method
(
'getSystemValue'
)
->
with
(
$this
->
equalTo
(
'cipher'
),
$this
->
equalTo
(
'AES-256-C
FB
'
))
->
with
(
$this
->
equalTo
(
'cipher'
),
$this
->
equalTo
(
'AES-256-C
TR
'
))
->
willReturn
(
$configValue
);
$this
->
assertSame
(
$expected
,
...
...
@@ -161,7 +176,10 @@ class cryptTest extends TestCase {
return
array
(
array
(
'AES-128-CFB'
,
'AES-128-CFB'
),
array
(
'AES-256-CFB'
,
'AES-256-CFB'
),
array
(
'unknown'
,
'AES-256-CFB'
)
array
(
'AES-128-CTR'
,
'AES-128-CTR'
),
array
(
'AES-256-CTR'
,
'AES-256-CTR'
),
array
(
'unknown'
,
'AES-256-CTR'
)
);
}
...
...
@@ -303,10 +321,15 @@ class cryptTest extends TestCase {
$this
->
invokePrivate
(
$this
->
crypt
,
'getKeySize'
,
[
'foo'
]);
}
/**
* @return array
*/
public
function
dataTestGetKeySize
()
{
return
[
[
'AES-256-CFB'
,
32
],
[
'AES-128-CFB'
,
16
],
[
'AES-256-CTR'
,
32
],
[
'AES-128-CTR'
,
16
],
];
}
...
...
@@ -351,6 +374,9 @@ class cryptTest extends TestCase {
$this
->
assertSame
(
$expected
,
$result
);
}
/**
* @return array
*/
public
function
dataTestDecryptPrivateKey
()
{
return
[
[[
'cipher'
=>
'AES-128-CFB'
,
'keyFormat'
=>
'password'
],
'HBEGIN:HENDprivateKey'
,
'AES-128-CFB'
,
true
,
'key'
],
...
...
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