Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Blake2b hash #5089

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ private byte[] applyRegexReplacements(byte[] value, List<FieldMaskingExpression.
}

private byte[] blake2bHash(byte[] in) {
// Salt is passed incorrectly but order of parameters is retained at present to ensure full backwards compatibility
// Tracking with https://github.com/opensearch-project/security/issues/4274
final Blake2b hash = new Blake2b(null, 32, null, saltBytes);
final Blake2b hash = new Blake2b(null, 32, saltBytes, null);
hash.update(in, 0, in.length);
final byte[] out = new byte[hash.getDigestSize()];
hash.digest(out, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@ public void testComplexMappingSearch() throws Exception {
"88783587fef740690c4fa39476fb86314d034fa3370e1a1fa186f6d9d4644a18ad85063c1e3161f8929f7ca019bb8740611eaf337709113901e7c3a6b59f4166"
)
);
Assert.assertFalse(res.getBody().contains("e90a2fdf7b1939ec06e294321fd7d23e1a70d8fc080a3f85d0f3bf08c205b53"));
Assert.assertFalse(res.getBody().contains("9fe023e13d5179157b2023c21c60bc98340a12470538affd306281619d2477c3"));
Assert.assertFalse(res.getBody().contains("*.*.*.*"));
Assert.assertFalse(res.getBody().contains("430a65d4b9c51de7192e048b2639db0de5c56f1901afccc2a01ef97f6a769a38"));
Assert.assertFalse(res.getBody().contains("7f48bb3636edf546a75968ca7cd0bdfe63e9ce7af04ef7cb642931fa15d2d7a3"));
Assert.assertFalse(res.getBody().contains("5115e9707d1a18772af2a1274e2d3450284754a921692d6b1aef922c33cda8fa"));
Assert.assertFalse(res.getBody().contains("8915d31ba2e0ac9eea0c8af1beb058dfa3d01147c233ede320d441cc1b65fa33"));
Assert.assertFalse(res.getBody().contains("https://www.static.co/downloads/beats/metricbeat"));
Assert.assertFalse(
res.getBody()
Expand Down Expand Up @@ -207,10 +207,10 @@ public void testComplexMappingSearch() throws Exception {
"88783587fef740690c4fa39476fb86314d034fa3370e1a1fa186f6d9d4644a18ad85063c1e3161f8929f7ca019bb8740611eaf337709113901e7c3a6b59f4166"
)
);
Assert.assertTrue(res.getBody().contains("e90a2fdf7b1939ec06e294321fd7d23e1a70d8fc080a3f85d0f3bf08c205b53"));
Assert.assertTrue(res.getBody().contains("9fe023e13d5179157b2023c21c60bc98340a12470538affd306281619d2477c3"));
Assert.assertTrue(res.getBody().contains("*.*.*.*"));
Assert.assertTrue(res.getBody().contains("430a65d4b9c51de7192e048b2639db0de5c56f1901afccc2a01ef97f6a769a38"));
Assert.assertTrue(res.getBody().contains("7f48bb3636edf546a75968ca7cd0bdfe63e9ce7af04ef7cb642931fa15d2d7a3"));
Assert.assertTrue(res.getBody().contains("5115e9707d1a18772af2a1274e2d3450284754a921692d6b1aef922c33cda8fa"));
Assert.assertTrue(res.getBody().contains("8915d31ba2e0ac9eea0c8af1beb058dfa3d01147c233ede320d441cc1b65fa33"));
Assert.assertTrue(res.getBody().contains("https://www.static.co/downloads/beats/metricbeat"));
Assert.assertTrue(
res.getBody()
Expand All @@ -236,9 +236,9 @@ public void testComplexMappingSearch() throws Exception {
"88783587fef740690c4fa39476fb86314d034fa3370e1a1fa186f6d9d4644a18ad85063c1e3161f8929f7ca019bb8740611eaf337709113901e7c3a6b59f4166"
)
);
Assert.assertFalse(res.getBody().contains("e90a2fdf7b1939ec06e294321fd7d23e1a70d8fc080a3f85d0f3bf08c205b53"));
Assert.assertFalse(res.getBody().contains("9fe023e13d5179157b2023c21c60bc98340a12470538affd306281619d2477c3"));
Assert.assertFalse(res.getBody().contains("*.*.*.*"));
Assert.assertFalse(res.getBody().contains("430a65d4b9c51de7192e048b2639db0de5c56f1901afccc2a01ef97f6a769a38"));
Assert.assertFalse(res.getBody().contains("8915d31ba2e0ac9eea0c8af1beb058dfa3d01147c233ede320d441cc1b65fa33"));
Assert.assertFalse(res.getBody().contains("7f48bb3636edf546a75968ca7cd0bdfe63e9ce7af04ef7cb642931fa15d2d7a3"));
Assert.assertFalse(res.getBody().contains("https://www.static.co/downloads/beats/metricbeat"));
Assert.assertFalse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,8 +161,8 @@ public void testDFMRestrictedUser() throws Exception {
Assert.assertFalse(response.getBody().contains("value-2-4"));

// field2 - check also some masked values
Assert.assertTrue(response.getBody().contains("514b27191e2322b0f7cd6afc3a5d657ff438fd0cc8dc229bd1a589804fdffd99"));
Assert.assertTrue(response.getBody().contains("3090f7e867f390fb96b20ba30ee518b09a927b857393ebd1262f31191a385efa"));
Assert.assertTrue(response.getBody().contains("b83363be1efc9a30269963686915db175630744f7b9b53eaf012275c10028ed8"));
Assert.assertTrue(response.getBody().contains("1036e0c7154ead29670a4d0a609727aeec7e6f39a97b72053d49255b5865e341"));
}

/**
Expand Down Expand Up @@ -271,7 +271,7 @@ public void testDFMRestrictedAndUnrestrictedOneIndex() throws Exception {
Assert.assertTrue(response.getBody().contains("value-2-4"));

// but we still have masked values for index1-2 and index1-3
Assert.assertTrue(response.getBody().contains("514b27191e2322b0f7cd6afc3a5d657ff438fd0cc8dc229bd1a589804fdffd99"));
Assert.assertTrue(response.getBody().contains("3090f7e867f390fb96b20ba30ee518b09a927b857393ebd1262f31191a385efa"));
Assert.assertTrue(response.getBody().contains("b83363be1efc9a30269963686915db175630744f7b9b53eaf012275c10028ed8"));
Assert.assertTrue(response.getBody().contains("1036e0c7154ead29670a4d0a609727aeec7e6f39a97b72053d49255b5865e341"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,9 @@ public void testMaskedAggregationsRace() throws Exception {
Assert.assertTrue(res.getBody().contains("200.100"));
Assert.assertTrue(res.getBody().contains("\"doc_count\" : 30"));
Assert.assertTrue(res.getBody().contains("\"doc_count\" : 1"));
Assert.assertFalse(res.getBody().contains("e1623afebfa505884e249a478640ec98094d19a72ac7a89dd0097e28955bb5ae"));
Assert.assertFalse(res.getBody().contains("26a8671e57fefc13504f8c61ced67ac98338261ace1e5bf462038b2f2caae16e"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("4805f3596e68104d71b922124a61c701798180d5511a21586d9d8d58a1fc593f"));
Assert.assertFalse(res.getBody().contains("cf2061910587994e02f446d59d61d2dbabc5a3a8aea2fa05d08ffe2a12ee8bc8"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));

assertThat(
HttpStatus.SC_OK,
Expand All @@ -178,9 +178,9 @@ public void testMaskedAggregationsRace() throws Exception {
Assert.assertTrue(res.getBody().contains("\"doc_count\" : 1"));
Assert.assertFalse(res.getBody().contains("100.100"));
Assert.assertFalse(res.getBody().contains("200.100"));
Assert.assertTrue(res.getBody().contains("e1623afebfa505884e249a478640ec98094d19a72ac7a89dd0097e28955bb5ae"));
Assert.assertTrue(res.getBody().contains("26a8671e57fefc13504f8c61ced67ac98338261ace1e5bf462038b2f2caae16e"));
Assert.assertTrue(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertTrue(res.getBody().contains("4805f3596e68104d71b922124a61c701798180d5511a21586d9d8d58a1fc593f"));
Assert.assertTrue(res.getBody().contains("cf2061910587994e02f446d59d61d2dbabc5a3a8aea2fa05d08ffe2a12ee8bc8"));
Assert.assertTrue(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));

for (int i = 0; i < 10; i++) {
assertThat(
Expand All @@ -194,9 +194,9 @@ public void testMaskedAggregationsRace() throws Exception {
Assert.assertTrue(res.getBody().contains("200.100"));
Assert.assertTrue(res.getBody().contains("\"doc_count\" : 30"));
Assert.assertTrue(res.getBody().contains("\"doc_count\" : 1"));
Assert.assertFalse(res.getBody().contains("e1623afebfa505884e249a478640ec98094d19a72ac7a89dd0097e28955bb5ae"));
Assert.assertFalse(res.getBody().contains("26a8671e57fefc13504f8c61ced67ac98338261ace1e5bf462038b2f2caae16e"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("4805f3596e68104d71b922124a61c701798180d5511a21586d9d8d58a1fc593f"));
Assert.assertFalse(res.getBody().contains("cf2061910587994e02f446d59d61d2dbabc5a3a8aea2fa05d08ffe2a12ee8bc8"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
}

}
Expand All @@ -218,7 +218,7 @@ public void testMaskedSearch() throws Exception {
Assert.assertTrue(res.getBody().contains("cust2"));
Assert.assertTrue(res.getBody().contains("100.100.1.1"));
Assert.assertTrue(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));

assertThat(
HttpStatus.SC_OK,
Expand All @@ -230,7 +230,7 @@ public void testMaskedSearch() throws Exception {
Assert.assertTrue(res.getBody().contains("cust2"));
Assert.assertFalse(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertTrue(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertTrue(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));

}

Expand All @@ -252,7 +252,7 @@ public void testMaskedSearchWithClusterDefaultSHA512() throws Exception {
Assert.assertTrue(res.getBody().contains("cust2"));
Assert.assertTrue(res.getBody().contains("100.100.1.1"));
Assert.assertTrue(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));

assertThat(
Expand All @@ -265,7 +265,7 @@ public void testMaskedSearchWithClusterDefaultSHA512() throws Exception {
Assert.assertTrue(res.getBody().contains("cust2"));
Assert.assertFalse(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertTrue(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));

}
Expand All @@ -286,7 +286,7 @@ public void testMaskedGet() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertTrue(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));

assertThat(
HttpStatus.SC_OK,
Expand All @@ -297,7 +297,7 @@ public void testMaskedGet() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertFalse(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertTrue(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertTrue(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
}

@Test
Expand All @@ -317,7 +317,7 @@ public void testMaskedGetWithClusterDefaultSHA512() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertTrue(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha3_224Hex("100.100.1.1")));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));

Expand All @@ -331,7 +331,7 @@ public void testMaskedGetWithClusterDefaultSHA512() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertFalse(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha3_224Hex("100.100.1.1")));
Assert.assertTrue(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));
}
Expand All @@ -353,7 +353,7 @@ public void testMaskedGetWithClusterDefaultSHA3() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertTrue(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha3_224Hex("100.100.1.1")));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));

Expand All @@ -367,7 +367,7 @@ public void testMaskedGetWithClusterDefaultSHA3() throws Exception {
Assert.assertFalse(res.getBody().contains("cust2"));
Assert.assertFalse(res.getBody().contains("100.100.1.1"));
Assert.assertFalse(res.getBody().contains("100.100.2.2"));
Assert.assertFalse(res.getBody().contains("87873bdb698e5f0f60e0b02b76dad1ec11b2787c628edbc95b7ff0e82274b140"));
Assert.assertFalse(res.getBody().contains("0e3f99018654fda6757601e88d4317f1649efae79126eb62c3f8c15105ba47ac"));
Assert.assertTrue(res.getBody().contains(DigestUtils.sha3_224Hex("100.100.1.1")));
Assert.assertFalse(res.getBody().contains(DigestUtils.sha512Hex("100.100.1.1")));
}
Expand Down
Loading