Private GIT
Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
phpipam
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
vlbox
phpipam
Commits
1395dc70
Commit
1395dc70
authored
Jul 25, 2019
by
D10n1x
Committed by
GaryAllan
Jul 25, 2019
Browse files
Options
Downloads
Patches
Plain Diff
Update Crypto (#2667)
Add support for AES-256-CBC
parent
0fed68ea
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
functions/classes/class.Crypto.php
+12
-9
12 additions, 9 deletions
functions/classes/class.Crypto.php
with
12 additions
and
9 deletions
functions/classes/class.Crypto.php
+
12
−
9
View file @
1395dc70
...
@@ -78,7 +78,7 @@ class Crypto {
...
@@ -78,7 +78,7 @@ class Crypto {
if
(
$encryption_library
===
"mcrypt"
)
if
(
$encryption_library
===
"mcrypt"
)
return
$this
->
encrypt_using_legacy_mcrypt
(
$rawdata
,
$password
);
return
$this
->
encrypt_using_legacy_mcrypt
(
$rawdata
,
$password
);
else
else
return
$this
->
encrypt_using_openssl
(
$rawdata
,
$password
);
return
$this
->
encrypt_using_openssl
(
$rawdata
,
$password
,
$encryption_library
);
}
}
/**
/**
...
@@ -92,7 +92,7 @@ class Crypto {
...
@@ -92,7 +92,7 @@ class Crypto {
if
(
$encryption_library
===
"mcrypt"
)
if
(
$encryption_library
===
"mcrypt"
)
return
$this
->
decrypt_using_legacy_mcrypt
(
$base64data
,
$password
);
return
$this
->
decrypt_using_legacy_mcrypt
(
$base64data
,
$password
);
else
else
return
$this
->
decrypt_using_openssl
(
$base64data
,
$password
);
return
$this
->
decrypt_using_openssl
(
$base64data
,
$password
,
$encryption_library
);
}
}
// OpenSSL
// OpenSSL
...
@@ -103,14 +103,15 @@ class Crypto {
...
@@ -103,14 +103,15 @@ class Crypto {
* @param string $password
* @param string $password
* @return string|false
* @return string|false
*/
*/
private
function
encrypt_using_openssl
(
$rawdata
,
$password
)
{
private
function
encrypt_using_openssl
(
$rawdata
,
$password
,
$key_size
)
{
$method
=
(
$key_size
==
"openssl-256"
)
?
'AES-256-CBC'
:
'AES-128-CBC'
;
// Binary key derived from password
// Binary key derived from password
$key
=
openssl_digest
(
$password
,
'sha256'
,
true
);
$key
=
openssl_digest
(
$password
,
'sha256'
,
true
);
// Encrypt using IV
// Encrypt using IV
$ivlen
=
openssl_cipher_iv_length
(
'AES-128-CBC'
);
$ivlen
=
openssl_cipher_iv_length
(
$method
);
$iv
=
$this
->
random_pseudo_bytes
(
$ivlen
);
$iv
=
$this
->
random_pseudo_bytes
(
$ivlen
);
$ciphertext_raw
=
openssl_encrypt
(
$rawdata
,
'AES-128-CBC'
,
$key
,
OPENSSL_RAW_DATA
,
$iv
);
$ciphertext_raw
=
openssl_encrypt
(
$rawdata
,
$method
,
$key
,
OPENSSL_RAW_DATA
,
$iv
);
// Generate HMAC covering IV and ciphertext
// Generate HMAC covering IV and ciphertext
$hmac
=
$this
->
hash_hmac
(
'sha256'
,
$iv
.
$ciphertext_raw
,
$key
,
true
);
$hmac
=
$this
->
hash_hmac
(
'sha256'
,
$iv
.
$ciphertext_raw
,
$key
,
true
);
...
@@ -125,14 +126,16 @@ class Crypto {
...
@@ -125,14 +126,16 @@ class Crypto {
* @param string $password
* @param string $password
* @return string|false
* @return string|false
*/
*/
private
function
decrypt_using_openssl
(
$base64data
,
$password
)
{
private
function
decrypt_using_openssl
(
$base64data
,
$password
,
$key_size
)
{
$method
=
(
$key_size
==
"openssl-256"
)
?
'AES-256-CBC'
:
'AES-128-CBC'
;
// Binary key derived from password
// Binary key derived from password
$key
=
openssl_digest
(
$password
,
'sha256'
,
true
);
$key
=
openssl_digest
(
$password
,
'sha256'
,
true
);
$c
=
base64_decode
(
$base64data
);
$c
=
base64_decode
(
$base64data
);
if
(
$c
===
false
)
return
false
;
if
(
$c
===
false
)
return
false
;
$ivlen
=
openssl_cipher_iv_length
(
'AES-128-CBC'
);
$ivlen
=
openssl_cipher_iv_length
(
$method
);
// Check data > minimum length
// Check data > minimum length
if
(
strlen
(
$c
)
<=
(
32
+
$ivlen
))
if
(
strlen
(
$c
)
<=
(
32
+
$ivlen
))
...
@@ -149,7 +152,7 @@ class Crypto {
...
@@ -149,7 +152,7 @@ class Crypto {
return
false
;
return
false
;
// Finally decrypt
// Finally decrypt
return
openssl_decrypt
(
$ciphertext_raw
,
'AES-128-CBC'
,
$key
,
OPENSSL_RAW_DATA
,
$iv
);
return
openssl_decrypt
(
$ciphertext_raw
,
$method
,
$key
,
OPENSSL_RAW_DATA
,
$iv
);
}
}
// Legacy mcrypt - mcrypt support may be removed in a future release.
// Legacy mcrypt - mcrypt support may be removed in a future release.
...
...
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