Skip to content

Commit fb15b01

Browse files
committed
more correctr names
1 parent b367e6d commit fb15b01

File tree

2 files changed

+32
-71
lines changed

2 files changed

+32
-71
lines changed

java/src/main/java/com/ibm/plugin/rules/detection/bc/asymmetricblockcipher/BcAsymCipherEngine.java

Lines changed: 25 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@
2424
import com.ibm.engine.model.factory.ValueActionFactory;
2525
import com.ibm.engine.rule.IDetectionRule;
2626
import com.ibm.engine.rule.builder.DetectionRuleBuilder;
27-
import java.util.Arrays;
27+
import com.ibm.plugin.rules.detection.bc.BouncyCastleInfoMap;
2828
import java.util.LinkedList;
2929
import java.util.List;
30+
import java.util.Map;
3031
import javax.annotation.Nonnull;
3132
import javax.annotation.Nullable;
3233
import org.jetbrains.annotations.NotNull;
@@ -39,14 +40,16 @@ private BcAsymCipherEngine() {
3940
// nothing
4041
}
4142

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+
}
5053

5154
private static @NotNull List<IDetectionRule<Tree>> constructors(
5255
@Nullable IDetectionContext detectionValueContext) {
@@ -56,65 +59,19 @@ private BcAsymCipherEngine() {
5659
? detectionValueContext
5760
: new CipherContext(CipherContext.Kind.ASYMMETRIC_CIPHER_ENGINE);
5861

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()));
11875
}
11976
return constructorsList;
12077
}

java/src/main/java/com/ibm/plugin/rules/detection/bc/messagesigner/BcMessageSigner.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,13 @@ private BcMessageSigner() {
5555
infoMap.putKey("HSSSigner").putType("org.bouncycastle.pqc.crypto.lms.");
5656
infoMap.putKey("LMSSigner").putType("org.bouncycastle.pqc.crypto.lms.");
5757
infoMap.putKey("PicnicSigner").putType("org.bouncycastle.pqc.crypto.picnic.");
58-
infoMap.putKey("QTESLASigner").putType("org.bouncycastle.pqc.legacy.crypto.qtesla.");
58+
infoMap.putKey("QTESLASigner")
59+
.putName("qTESLA")
60+
.putType("org.bouncycastle.pqc.legacy.crypto.qtesla.");
5961
infoMap.putKey("RainbowSigner").putType("org.bouncycastle.pqc.crypto.rainbow.");
60-
infoMap.putKey("SPHINCSPlusSigner").putType("org.bouncycastle.pqc.crypto.sphincsplus.");
62+
infoMap.putKey("SPHINCSPlusSigner")
63+
.putName("SPHINCS+")
64+
.putType("org.bouncycastle.pqc.crypto.sphincsplus.");
6165
}
6266

6367
private static @NotNull List<IDetectionRule<Tree>> simpleConstructors() {
@@ -91,7 +95,7 @@ private BcMessageSigner() {
9195
.createDetectionRule()
9296
.forObjectTypes("org.bouncycastle.pqc.crypto.sphincs.SPHINCS256Signer")
9397
.forConstructor()
94-
.shouldBeDetectedAs(new ValueActionFactory<>("SPHINCS256"))
98+
.shouldBeDetectedAs(new ValueActionFactory<>("SPHINCS-256"))
9599
.withMethodParameter("org.bouncycastle.crypto.Digest")
96100
.addDependingDetectionRules(BcDigests.rules())
97101
.withMethodParameter("org.bouncycastle.crypto.Digest")

0 commit comments

Comments
 (0)