24
24
import com .ibm .engine .model .factory .ValueActionFactory ;
25
25
import com .ibm .engine .rule .IDetectionRule ;
26
26
import com .ibm .engine .rule .builder .DetectionRuleBuilder ;
27
- import java . util . Arrays ;
27
+ import com . ibm . plugin . rules . detection . bc . BouncyCastleInfoMap ;
28
28
import java .util .LinkedList ;
29
29
import java .util .List ;
30
+ import java .util .Map ;
30
31
import javax .annotation .Nonnull ;
31
32
import javax .annotation .Nullable ;
32
33
import org .jetbrains .annotations .NotNull ;
@@ -39,14 +40,16 @@ private BcAsymCipherEngine() {
39
40
// nothing
40
41
}
41
42
42
- private static final List <String > cipherEnginesList =
43
- Arrays .asList (
44
- "ElGamalEngine" ,
45
- "NaccacheSternEngine" ,
46
- "NTRUEngine" ,
47
- "RSABlindedEngine" ,
48
- "RSABlindingEngine" ,
49
- "RSAEngine" );
43
+ private static BouncyCastleInfoMap infoMap = new BouncyCastleInfoMap ();
44
+
45
+ static {
46
+ infoMap .putKey ("ElGamalEngine" );
47
+ infoMap .putKey ("NaccacheSternEngine" ).putName ("Naccache-Stern" );
48
+ infoMap .putKey ("NTRUEngine" );
49
+ infoMap .putKey ("RSABlindedEngine" ).putName ("RSA" );
50
+ infoMap .putKey ("RSABlindingEngine" ).putName ("RSA" );
51
+ infoMap .putKey ("RSAEngine" ).putName ("RSA" );
52
+ }
50
53
51
54
private static @ NotNull List <IDetectionRule <Tree >> constructors (
52
55
@ Nullable IDetectionContext detectionValueContext ) {
@@ -56,65 +59,19 @@ private BcAsymCipherEngine() {
56
59
? detectionValueContext
57
60
: new CipherContext (CipherContext .Kind .ASYMMETRIC_CIPHER_ENGINE );
58
61
59
- for (String cipherEngine : cipherEnginesList ) {
60
- switch (cipherEngine ) {
61
- case "ElGamalEngine" :
62
- constructorsList .add (
63
- new DetectionRuleBuilder <Tree >()
64
- .createDetectionRule ()
65
- .forObjectTypes (
66
- "org.bouncycastle.crypto.engines." + cipherEngine )
67
- .forConstructor ()
68
- .shouldBeDetectedAs (new ValueActionFactory <>("ElGamal" ))
69
- .withoutParameters ()
70
- .buildForContext (context )
71
- .inBundle (() -> "BcAsymCipherEngine" )
72
- .withDependingDetectionRules (BcAsymCipherInit .rules ()));
73
- break ;
74
- case "NaccacheSternEngine" :
75
- constructorsList .add (
76
- new DetectionRuleBuilder <Tree >()
77
- .createDetectionRule ()
78
- .forObjectTypes (
79
- "org.bouncycastle.crypto.engines." + cipherEngine )
80
- .forConstructor ()
81
- .shouldBeDetectedAs (new ValueActionFactory <>("NaccacheStern" ))
82
- .withoutParameters ()
83
- .buildForContext (context )
84
- .inBundle (() -> "BcAsymCipherEngine" )
85
- .withDependingDetectionRules (BcAsymCipherInit .rules ()));
86
- break ;
87
- case "NTRUEngine" :
88
- constructorsList .add (
89
- new DetectionRuleBuilder <Tree >()
90
- .createDetectionRule ()
91
- .forObjectTypes (
92
- "org.bouncycastle.crypto.engines." + cipherEngine )
93
- .forConstructor ()
94
- .shouldBeDetectedAs (new ValueActionFactory <>("NTRU" ))
95
- .withoutParameters ()
96
- .buildForContext (context )
97
- .inBundle (() -> "BcAsymCipherEngine" )
98
- .withDependingDetectionRules (BcAsymCipherInit .rules ()));
99
- break ;
100
- case "RSAEngine" ,
101
- "RSABlindedEngine" ,
102
- "RSABlindingEngine" : // TODO: Should I distinguish these RSA cases?
103
- constructorsList .add (
104
- new DetectionRuleBuilder <Tree >()
105
- .createDetectionRule ()
106
- .forObjectTypes (
107
- "org.bouncycastle.crypto.engines." + cipherEngine )
108
- .forConstructor ()
109
- .shouldBeDetectedAs (new ValueActionFactory <>("RSA" ))
110
- .withoutParameters ()
111
- .buildForContext (context )
112
- .inBundle (() -> "BcAsymCipherEngine" )
113
- .withDependingDetectionRules (BcAsymCipherInit .rules ()));
114
- break ;
115
- default :
116
- break ;
117
- }
62
+ for (Map .Entry <String , BouncyCastleInfoMap .Info > entry : infoMap .entrySet ()) {
63
+ String engine = entry .getKey ();
64
+ String engineName = infoMap .getDisplayName (engine , "Engine" );
65
+ constructorsList .add (
66
+ new DetectionRuleBuilder <Tree >()
67
+ .createDetectionRule ()
68
+ .forObjectTypes ("org.bouncycastle.crypto.engines." + engine )
69
+ .forConstructor ()
70
+ .shouldBeDetectedAs (new ValueActionFactory <>(engineName ))
71
+ .withoutParameters ()
72
+ .buildForContext (context )
73
+ .inBundle (() -> "BcAsymCipherEngine" )
74
+ .withDependingDetectionRules (BcAsymCipherInit .rules ()));
118
75
}
119
76
return constructorsList ;
120
77
}
0 commit comments