Skip to content

Commit

Permalink
#2288 Prefix hash with algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
To-om committed Dec 14, 2021
1 parent 2e02312 commit e20a231
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ class PublicObservable @Inject() (
Query[Traversal.V[Observable], Traversal.V[Case]]("case", (observableSteps, _) => observableSteps.`case`),
Query[Traversal.V[Observable], Traversal.V[Alert]]("alert", (observableSteps, _) => observableSteps.alert)
)
lazy val hasher: Hasher = Hasher("SHA-256")
override val publicProperties: PublicProperties = PublicPropertyListBuilder[Observable]
.property("status", UMapping.string)(_.select(_.constant("Ok")).readonly)
.property("startDate", UMapping.date)(_.select(_._createdAt).readonly)
Expand Down
5 changes: 2 additions & 3 deletions thehive/app/org/thp/thehive/models/Observable.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.thp.scalligraph.utils.Hasher
import org.thp.scalligraph.{BuildEdgeEntity, BuildVertexEntity, EntityId}

import java.util.Date
import scala.util.Try

@BuildEdgeEntity[Observable, KeyValue]
case class ObservableKeyValue()
Expand Down Expand Up @@ -80,7 +79,7 @@ object UseHashToIndex extends ImmenseTermProcessor with ImmenseStringTermFilter
private val hasher: Hasher = Hasher("SHA-256")

def hashToIndex(value: String): Option[String] =
if (value.length > termSizeLimit) Some(hasher.fromString(value).head.toString)
if (value.length > termSizeLimit) Some("sha256/" + hasher.fromString(value).head.toString)
else None

override def apply[V](vertex: Vertex, property: VertexProperty[V]): Boolean = {
Expand All @@ -95,7 +94,7 @@ object UseHashToIndex extends ImmenseTermProcessor with ImmenseStringTermFilter
| message=${UMapping.string.optional.getProperty(vertex, "message").getOrElse("<not set>")}
| tags=${UMapping.string.sequence.getProperty(vertex, "message").mkString(", ")}""".stripMargin)
strProp.remove()
vertex.property(strProp.key(), hasher.fromString(currentValue).head.toString)
vertex.property(strProp.key(), "sha256/" + hasher.fromString(currentValue).head.toString)
}

case "Data" =>
Expand Down

0 comments on commit e20a231

Please sign in to comment.