-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3 from thoth-pub/stable-3_4_0
Adapt to OMP 3.4
- Loading branch information
Showing
43 changed files
with
526 additions
and
321 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace APP\plugins\generic\thoth\classes; | ||
|
||
use Exception; | ||
use Firebase\JWT\JWT; | ||
use PKP\config\Config; | ||
|
||
class APIKeyEncryption | ||
{ | ||
public static function secretConfigExists(): bool | ||
{ | ||
try { | ||
self::getSecretFromConfig(); | ||
} catch (Exception $e) { | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
private static function getSecretFromConfig(): string | ||
{ | ||
$secret = Config::getVar('security', 'api_key_secret'); | ||
if ($secret === '') { | ||
throw new Exception("A secret must be set in the config file ('api_key_secret') so that keys can be encrypted and decrypted"); | ||
} | ||
return $secret; | ||
} | ||
|
||
public static function encryptString(string $plainText): string | ||
{ | ||
$secret = self::getSecretFromConfig(); | ||
return JWT::encode($plainText, $secret, 'HS256'); | ||
} | ||
|
||
public static function decryptString(string $encryptedText): string | ||
{ | ||
$secret = self::getSecretFromConfig(); | ||
try { | ||
return JWT::decode($encryptedText, $secret, ['HS256']); | ||
} catch (Firebase\JWT\SignatureInvalidException $e) { | ||
throw new Exception( | ||
'The `api_key_secret` configuration is not the same as the one used to encrypt the key.', | ||
1 | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.