forked from AuthorizeNet/sdk-php
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANetSensitiveFields.php
86 lines (69 loc) · 3.38 KB
/
ANetSensitiveFields.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<?php
namespace net\authorize\util;
use JMS\Serializer\SerializerBuilder;
define("ANET_SENSITIVE_XMLTAGS_JSON_FILE","AuthorizedNetSensitiveTagsConfig.json");
define("ANET_SENSITIVE_DATE_CONFIG_CLASS",'net\authorize\util\SensitiveDataConfigType');
class ANetSensitiveFields
{
private static $applySensitiveTags = NULL;
private static $sensitiveStringRegexes = NULL;
private static function fetchFromConfigFiles(){
if(!class_exists(ANET_SENSITIVE_DATE_CONFIG_CLASS))
exit("Class (".ANET_SENSITIVE_DATE_CONFIG_CLASS.") doesn't exist; can't deserialize json; can't log. Exiting.");
$serializer = SerializerBuilder::create()->build();
$userConfigFilePath = ANET_SENSITIVE_XMLTAGS_JSON_FILE;
$presentUserConfigFile = file_exists($userConfigFilePath);
$configFilePath = dirname(__FILE__) . "/" . ANET_SENSITIVE_XMLTAGS_JSON_FILE;
$useDefaultConfigFile = !$presentUserConfigFile;
if ($presentUserConfigFile) { //client config for tags
//read list of tags (and associated regex-patterns and replacements) from .json file
try{
$jsonFileData=file_get_contents($userConfigFilePath);
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
}
catch(Exception $e){
echo "ERROR deserializing json from : " . $userConfigFilePath . "; Exception : " . $e->getMessage();
$useDefaultConfigFile = true;
}
}
if ($useDefaultConfigFile) { //default sdk config for tags
if(!file_exists($configFilePath)){
exit("ERROR: No config file: " . $configFilePath);
}
//read list of tags (and associated regex-patterns and replacements) from .json file
try{
$jsonFileData=file_get_contents($configFilePath);
$sensitiveDataConfig = $serializer->deserialize($jsonFileData, ANET_SENSITIVE_DATE_CONFIG_CLASS, 'json');
$sensitiveTags = $sensitiveDataConfig->sensitiveTags;
self::$sensitiveStringRegexes = $sensitiveDataConfig->sensitiveStringRegexes;
}
catch(Exception $e){
exit( "ERROR deserializing json from : " . $configFilePath . "; Exception : " . $e->getMessage());
}
}
//Check for disableMask flag in case of client json.
self::$applySensitiveTags = array();
foreach($sensitiveTags as $sensitiveTag){
if($sensitiveTag->disableMask){
//skip masking continue;
}
else{
array_push(self::$applySensitiveTags,$sensitiveTag);
}
}
}
public static function getSensitiveStringRegexes(){
if(NULL == self::$sensitiveStringRegexes) {
self::fetchFromConfigFiles();
}
return self::$sensitiveStringRegexes;
}
public static function getSensitiveXmlTags(){
if(NULL == self::$applySensitiveTags) {
self::fetchFromConfigFiles();
}
return self::$applySensitiveTags;
}
}