Skip to content

Commit

Permalink
update feault keysize in enricher, add bit as command to size values …
Browse files Browse the repository at this point in the history
…in model

Signed-off-by: Nicklas Körtge <nicklas.koertge1@ibm.com>
  • Loading branch information
n1ckl0sk0rtge committed Aug 13, 2024
1 parent 95b6c4a commit 0fa5c40
Show file tree
Hide file tree
Showing 10 changed files with 24 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public INode enrich(@NotNull INode node) {
private INode enrich(@NotNull AES aes) {
@Nullable KeyLength keyLength = aes.getKeyLength().orElse(null);
@Nullable final Mode mode = aes.getMode().orElse(null);
this.applyDefaultKeySize(aes, 128);
this.applyDefaultKeySizeForJca(aes, 128);
// add oid
final Oid oid = new Oid(buildOid(keyLength, mode), aes.getDetectionContext());
aes.append(oid);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DESEnricher implements IEnricher, IEnrichWithDefaultKeySize {
@Override
public @NotNull INode enrich(@NotNull INode node) {
if (node instanceof DES des) {
this.applyDefaultKeySize(des, 56);
this.applyDefaultKeySizeForJca(des, 56);
return des;
}
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@
import com.ibm.enricher.IEnricher;
import com.ibm.mapper.model.INode;
import com.ibm.mapper.model.algorithms.DH;
import javax.annotation.Nonnull;
import org.jetbrains.annotations.NotNull;

import javax.annotation.Nonnull;

public class DHEnricher implements IEnricher, IEnrichWithDefaultKeySize {

@Override
Expand All @@ -37,7 +38,7 @@ public class DHEnricher implements IEnricher, IEnrichWithDefaultKeySize {

@Nonnull
private DH enrich(@Nonnull DH dh) {
this.applyDefaultKeySize(dh, 3072);
this.applyDefaultKeySizeForJca(dh, 3072);
return dh;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class DSAEnricher implements IEnricher, IEnrichWithDefaultKeySize {
@Override
public @NotNull INode enrich(@NotNull INode node) {
if (node instanceof DSA dsa) {
this.applyDefaultKeySize(dsa, 2048);
this.applyDefaultKeySizeForJca(dsa, 2048);
return dsa;
}
return node;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,17 +27,13 @@

public interface IEnrichWithDefaultKeySize {

default void applyDefaultKeySize(@Nonnull IAsset asset, int defaultKeySize) {
default void applyDefaultKeySizeForJca(@Nonnull IAsset asset, int defaultKeySize) {
@Nullable INode keyLength = asset.hasChildOfType(KeyLength.class).orElse(null);
// default key length
if (keyLength == null) {
switch (asset.getDetectionContext().bundle().getIdentifier()) {
case "Jca":
{
keyLength = new KeyLength(defaultKeySize, asset.getDetectionContext());
asset.append(keyLength);
}
if (keyLength == null && asset.getDetectionContext().bundle().getIdentifier().equals("Jca")) {
keyLength = new KeyLength(defaultKeySize, asset.getDetectionContext());
asset.append(keyLength);
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public INode enrich(@NotNull INode node) {
}

@NotNull private RSA enrich(@NotNull RSA rsa) {
this.applyDefaultKeySize(rsa, 2048);
this.applyDefaultKeySizeForJca(rsa, 2048);
return rsa;
}

Expand Down
5 changes: 3 additions & 2 deletions mapper/src/main/java/com/ibm/mapper/model/BlockSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
package com.ibm.mapper.model;

import com.ibm.mapper.utils.DetectionLocation;
import java.util.Objects;

import javax.annotation.Nonnull;
import java.util.Objects;

public final class BlockSize extends Property {
@Nonnull private final Integer value;
@Nonnull private final Integer value; // bit

public BlockSize(@Nonnull Integer value, @Nonnull DetectionLocation detectionLocation) {
super(BlockSize.class, detectionLocation);
Expand Down
5 changes: 3 additions & 2 deletions mapper/src/main/java/com/ibm/mapper/model/DigestSize.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
package com.ibm.mapper.model;

import com.ibm.mapper.utils.DetectionLocation;
import java.util.Objects;

import javax.annotation.Nonnull;
import java.util.Objects;

public final class DigestSize extends Property {
@Nonnull private final Integer value;
@Nonnull private final Integer value; // bit

public DigestSize(@Nonnull Integer value, @Nonnull DetectionLocation detectionLocation) {
super(DigestSize.class, detectionLocation);
Expand Down
5 changes: 3 additions & 2 deletions mapper/src/main/java/com/ibm/mapper/model/Seed.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
package com.ibm.mapper.model;

import com.ibm.mapper.utils.DetectionLocation;
import java.util.Objects;

import javax.annotation.Nonnull;
import java.util.Objects;

public final class Seed extends Property {
@Nonnull private final Integer value; // in bit
@Nonnull private final Integer value; // bit

public Seed(@Nonnull Integer value, @Nonnull DetectionLocation detectionLocation) {
super(Seed.class, detectionLocation);
Expand Down
5 changes: 3 additions & 2 deletions mapper/src/main/java/com/ibm/mapper/model/TagLength.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@
package com.ibm.mapper.model;

import com.ibm.mapper.utils.DetectionLocation;
import java.util.Objects;

import javax.annotation.Nonnull;
import java.util.Objects;

public final class TagLength extends Property {
@Nonnull private final Integer value; // in bit
@Nonnull private final Integer value; // bit

public TagLength(@Nonnull Integer value, @Nonnull DetectionLocation detectionLocation) {
super(TagLength.class, detectionLocation);
Expand Down

0 comments on commit 0fa5c40

Please sign in to comment.