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
a43ad7bd
Commit
a43ad7bd
authored
Jul 25, 2019
by
Gary Allan
Browse files
Options
Downloads
Patches
Plain Diff
Feature: Hook up PR #2667
parent
1395dc70
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/index.php
+3
-8
3 additions, 8 deletions
api/index.php
config.dist.php
+5
-2
5 additions, 2 deletions
config.dist.php
functions/classes/class.Crypto.php
+51
-16
51 additions, 16 deletions
functions/classes/class.Crypto.php
with
59 additions
and
26 deletions
api/index.php
+
3
−
8
View file @
a43ad7bd
...
@@ -66,16 +66,11 @@ try {
...
@@ -66,16 +66,11 @@ try {
// crypt check
// crypt check
if
(
$app
->
app_security
==
"crypt"
)
{
if
(
$app
->
app_security
==
"crypt"
)
{
$api_crypt_encryption_library
=
Config
::
get
(
'api_crypt_encryption_library'
)
===
"mcrypt"
?
'mcrypt'
:
'openssl'
;
$encryption_method
=
Config
::
get
(
'api_crypt_encryption_library'
,
'openssl-128-cbc'
);
// verify php extensions
if
(
!
in_array
(
$api_crypt_encryption_library
,
get_loaded_extensions
()))
{
$Response
->
throw_exception
(
500
,
'php extension '
.
$api_crypt_encryption_library
.
' missing'
);
}
// decrypt request - form_encoded
// decrypt request - form_encoded
if
(
strpos
(
$_SERVER
[
'CONTENT_TYPE'
],
"application/x-www-form-urlencoded"
)
!==
false
)
{
if
(
strpos
(
$_SERVER
[
'CONTENT_TYPE'
],
"application/x-www-form-urlencoded"
)
!==
false
)
{
$decoded
=
$User
->
Crypto
->
decrypt
(
$_GET
[
'enc_request'
],
$app
->
app_code
,
$
api_crypt_
encryption_
library
);
$decoded
=
$User
->
Crypto
->
decrypt
(
$_GET
[
'enc_request'
],
$app
->
app_code
,
$encryption_
method
);
if
(
$decoded
===
false
)
$Response
->
throw_exception
(
503
,
'Invalid enc_request'
);
if
(
$decoded
===
false
)
$Response
->
throw_exception
(
503
,
'Invalid enc_request'
);
$decoded
=
$decoded
[
0
]
==
"?"
?
substr
(
$decoded
,
1
)
:
$decoded
;
$decoded
=
$decoded
[
0
]
==
"?"
?
substr
(
$decoded
,
1
)
:
$decoded
;
parse_str
(
$decoded
,
$encrypted_params
);
parse_str
(
$decoded
,
$encrypted_params
);
...
@@ -84,7 +79,7 @@ try {
...
@@ -84,7 +79,7 @@ try {
}
}
// json_encoded
// json_encoded
else
{
else
{
$encrypted_params
=
$User
->
Crypto
->
decrypt
(
$_GET
[
'enc_request'
],
$app
->
app_code
,
$
api_crypt_
encryption_
library
);
$encrypted_params
=
$User
->
Crypto
->
decrypt
(
$_GET
[
'enc_request'
],
$app
->
app_code
,
$encryption_
method
);
if
(
$encrypted_params
===
false
)
$Response
->
throw_exception
(
503
,
'Invalid enc_request'
);
if
(
$encrypted_params
===
false
)
$Response
->
throw_exception
(
503
,
'Invalid enc_request'
);
$encrypted_params
=
json_decode
(
$encrypted_params
,
true
);
$encrypted_params
=
json_decode
(
$encrypted_params
,
true
);
$encrypted_params
[
'app_id'
]
=
$_GET
[
'app_id'
];
$encrypted_params
[
'app_id'
]
=
$_GET
[
'app_id'
];
...
...
This diff is collapsed.
Click to expand it.
config.dist.php
+
5
−
2
View file @
a43ad7bd
...
@@ -75,9 +75,12 @@ $config['resolve_verbose'] = true; // verbose response - print
...
@@ -75,9 +75,12 @@ $config['resolve_verbose'] = true; // verbose response - print
$debugging
=
false
;
$debugging
=
false
;
/*
/*
* API Crypt security provider. "mcrypt" or "openssl"
* API Crypt security provider. "mcrypt" or "openssl*"
* Supported methods:
* openssl-128-cbc (alias openssl, openssl-128) *default
* openssl-256-cbc (alias openssl-256)
*
*
* default as of 1.3.2 "openssl"
* default as of 1.3.2 "openssl
-128-cbc
"
******************************/
******************************/
// $api_crypt_encryption_library = "mcrypt";
// $api_crypt_encryption_library = "mcrypt";
...
...
This diff is collapsed.
Click to expand it.
functions/classes/class.Crypto.php
+
51
−
16
View file @
a43ad7bd
...
@@ -71,28 +71,65 @@ class Crypto {
...
@@ -71,28 +71,65 @@ class Crypto {
* encrypt data and base64 encode results
* encrypt data and base64 encode results
* @param string $rawdata
* @param string $rawdata
* @param string $password
* @param string $password
* @param string
$encryption_library
(default value: "openssl")
* @param string
method
(default value: "openssl
-128-cbc
")
* @return string|false
* @return string|false
*/
*/
public
function
encrypt
(
$rawdata
,
$password
,
$encryption_library
=
"openssl"
)
{
public
function
encrypt
(
$rawdata
,
$password
,
$method
=
"openssl-128-cbc"
)
{
if
(
$encryption_library
===
"mcrypt"
)
$method
=
$this
->
supported_methods
(
$method
);
if
(
$method
===
'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
,
$
encryption_library
);
return
$this
->
encrypt_using_openssl
(
$rawdata
,
$password
,
$
method
);
}
}
/**
/**
* decrypt base64 encoded data
* decrypt base64 encoded data
* @param string $base64data
* @param string $base64data
* @param string $password
* @param string $password
* @param string $
encryption_library
(default value: "openssl")
* @param string $
method
(default value: "openssl
-128-cbc
")
* @return string|false
* @return string|false
*/
*/
public
function
decrypt
(
$base64data
,
$password
,
$encryption_library
=
"openssl"
)
{
public
function
decrypt
(
$base64data
,
$password
,
$method
=
"openssl-128-cbc"
)
{
if
(
$encryption_library
===
"mcrypt"
)
$method
=
$this
->
supported_methods
(
$method
);
if
(
$method
===
"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
,
$encryption_library
);
return
$this
->
decrypt_using_openssl
(
$base64data
,
$password
,
$method
);
}
/**
* Return a supported encryption method
* @param string $method
* @return string
*/
private
function
supported_methods
(
$method
)
{
switch
(
$method
)
{
case
'mcrypt'
:
$retval
=
'mcrypt'
;
break
;
case
'openssl'
:
case
'openssl-128'
:
case
'openssl-128-cbc'
:
$retval
=
'AES-128-CBC'
;
break
;
case
'openssl-256'
:
case
'openssl-256-cbc'
:
$retval
=
'AES-256-CBC'
;
break
;
default
:
$this
->
Result
->
show
(
"danger"
,
_
(
"Error: "
)
.
_
(
'Unsupported $api_crypt_encryption_library method: '
)
.
escape_input
(
$method
),
true
);
}
$required_ext
=
(
$retval
===
'mcrypt'
)
?
'mcrypt'
:
'openssl'
;
if
(
!
in_array
(
$required_ext
,
get_loaded_extensions
()))
$this
->
Result
->
show
(
"danger"
,
_
(
"Error: "
)
.
_
(
'php extension not installed: '
)
.
$required_ext
,
true
);
return
$retval
;
}
}
// OpenSSL
// OpenSSL
...
@@ -101,12 +138,11 @@ class Crypto {
...
@@ -101,12 +138,11 @@ class Crypto {
* encrypt data and base64 encode results
* encrypt data and base64 encode results
* @param string $rawdata
* @param string $rawdata
* @param string $password
* @param string $password
* @param string $method
* @return string|false
* @return string|false
*/
*/
private
function
encrypt_using_openssl
(
$rawdata
,
$password
,
$key_size
)
{
private
function
encrypt_using_openssl
(
$rawdata
,
$password
,
$method
)
{
$method
=
(
$key_size
==
"openssl-256"
)
?
'AES-256-CBC'
:
'AES-128-CBC'
;
// Binary key derived from password (32 bytes)
// 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
(
$method
);
$ivlen
=
openssl_cipher_iv_length
(
$method
);
...
@@ -124,12 +160,11 @@ class Crypto {
...
@@ -124,12 +160,11 @@ class Crypto {
* decrypt base64 encoded data
* decrypt base64 encoded data
* @param string $base64data
* @param string $base64data
* @param string $password
* @param string $password
* @param string $method
* @return string|false
* @return string|false
*/
*/
private
function
decrypt_using_openssl
(
$base64data
,
$password
,
$key_size
)
{
private
function
decrypt_using_openssl
(
$base64data
,
$password
,
$method
)
{
$method
=
(
$key_size
==
"openssl-256"
)
?
'AES-256-CBC'
:
'AES-128-CBC'
;
// Binary key derived from password (32 bytes)
// 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
);
...
...
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