Skip to content

Commit 719c456

Browse files
cwperksRyanL1997
andauthored
Signed-off-by: Craig Perkins <[email protected]> Co-authored-by: Jialiang Liang <[email protected]>
1 parent ac718cc commit 719c456

File tree

11 files changed

+99
-57
lines changed

11 files changed

+99
-57
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ jobs:
430430
- id: build-previous
431431
uses: ./.github/actions/run-bwc-suite
432432
with:
433-
plugin-previous-branch: "2.x"
433+
plugin-previous-branch: "2.19"
434434
plugin-next-branch: "current_branch"
435435
report-artifact-name: bwc-${{ matrix.platform }}-jdk${{ matrix.jdk }}
436436
username: admin

build.gradle

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ buildscript {
2424
version_tokens = opensearch_version.tokenize('-')
2525
opensearch_build = version_tokens[0] + '.0'
2626

27-
common_utils_version = System.getProperty("common_utils.version", '3.1.0.0-SNAPSHOT')
27+
common_utils_version = System.getProperty("common_utils.version", '3.2.0.0-SNAPSHOT')
2828

2929
kafka_version = '4.0.0'
3030
open_saml_version = '5.1.5'
@@ -49,7 +49,6 @@ buildscript {
4949
mavenCentral()
5050
maven { url "https://plugins.gradle.org/m2/" }
5151
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
52-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
5352
maven { url "https://artifacts.opensearch.org/snapshots/lucene/" }
5453
maven { url "https://build.shibboleth.net/nexus/content/groups/public" }
5554
}
@@ -508,7 +507,6 @@ allprojects {
508507
mavenCentral()
509508
maven { url "https://plugins.gradle.org/m2/" }
510509
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
511-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
512510
maven { url "https://artifacts.opensearch.org/snapshots/lucene/" }
513511
maven { url "https://build.shibboleth.net/nexus/content/repositories/releases" }
514512
maven { url "build.shibboleth.net/maven/releases"}

bwc-test/build.gradle

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ buildscript {
4646
repositories {
4747
mavenLocal()
4848
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
49-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
5049
mavenCentral()
5150
maven { url "https://plugins.gradle.org/m2/" }
5251
}
@@ -59,7 +58,6 @@ buildscript {
5958
repositories {
6059
mavenLocal()
6160
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
62-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
6361
mavenCentral()
6462
maven { url "https://plugins.gradle.org/m2/" }
6563
}

bwc-test/src/test/java/org/opensearch/security/bwc/SecurityBackwardsCompatibilityIT.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@ public void testSslCertsInfoEndpoint() throws IOException {
226226
@SuppressWarnings("unchecked")
227227
Map<String, Object> nodeCerts = (Map<String, Object>) nodeInfo.get("certificates");
228228
for (String expectCertKey : expectCertificates) {
229-
assertTrue(nodeCerts.containsKey(expectCertKey));
229+
// required cert types
230+
if (Set.of("http", "transport").contains(expectCertKey)) {
231+
assertTrue(nodeCerts.containsKey(expectCertKey));
232+
}
230233
@SuppressWarnings("unchecked")
231-
List<Map<String, Object>> certList = (List<Map<String, Object>>) nodeCerts.get(expectCertKey);
234+
List<Map<String, Object>> certList = (List<Map<String, Object>>) nodeCerts.getOrDefault(expectCertKey, List.of());
232235
for (Map<String, Object> singleCert : certList) {
233236
verifyCertificateInfo(singleCert);
234237
}

libs/opensaml/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ buildscript {
1414
mavenLocal()
1515
mavenCentral()
1616
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
17-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
1817
}
1918

2019
dependencies {

sample-resource-plugin/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ repositories {
4545
mavenLocal()
4646
mavenCentral()
4747
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
48-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
4948
}
5049

5150
configurations.all {

spi/build.gradle

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ repositories {
1313
mavenLocal()
1414
mavenCentral()
1515
maven { url "https://central.sonatype.com/repository/maven-snapshots/" }
16-
maven { url "https://aws.oss.sonatype.org/content/repositories/snapshots" }
1716
}
1817

1918
dependencies {

src/main/java/org/opensearch/security/dlic/rest/api/ssl/CertificateInfo.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.util.Objects;
1616

17+
import org.opensearch.Version;
1718
import org.opensearch.core.common.io.stream.StreamInput;
1819
import org.opensearch.core.common.io.stream.StreamOutput;
1920
import org.opensearch.core.common.io.stream.Writeable;
@@ -68,10 +69,17 @@ public CertificateInfo(final StreamInput in) throws IOException {
6869
this.issuer = in.readOptionalString();
6970
this.notAfter = in.readOptionalString();
7071
this.notBefore = in.readOptionalString();
71-
this.format = in.readOptionalString();
72-
this.alias = in.readOptionalString();
73-
this.serialNumber = in.readOptionalString();
74-
this.hasPrivateKey = in.readBoolean();
72+
if (in.getVersion().onOrAfter(Version.V_3_0_0)) {
73+
this.format = in.readOptionalString();
74+
this.alias = in.readOptionalString();
75+
this.serialNumber = in.readOptionalString();
76+
this.hasPrivateKey = in.readBoolean();
77+
} else {
78+
this.format = null;
79+
this.alias = null;
80+
this.serialNumber = null;
81+
this.hasPrivateKey = false;
82+
}
7583
}
7684

7785
@Override
@@ -81,10 +89,12 @@ public void writeTo(final StreamOutput out) throws IOException {
8189
out.writeOptionalString(issuer);
8290
out.writeOptionalString(notAfter);
8391
out.writeOptionalString(notBefore);
84-
out.writeOptionalString(format);
85-
out.writeOptionalString(alias);
86-
out.writeOptionalString(serialNumber);
87-
out.writeBoolean(hasPrivateKey);
92+
if (out.getVersion().onOrAfter(Version.V_3_0_0)) {
93+
out.writeOptionalString(format);
94+
out.writeOptionalString(alias);
95+
out.writeOptionalString(serialNumber);
96+
out.writeBoolean(hasPrivateKey);
97+
}
8898
}
8999

90100
@Override

src/main/java/org/opensearch/security/dlic/rest/api/ssl/CertificatesInfo.java

Lines changed: 54 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@
1212
package org.opensearch.security.dlic.rest.api.ssl;
1313

1414
import java.io.IOException;
15+
import java.util.HashMap;
1516
import java.util.List;
17+
import java.util.Locale;
1618
import java.util.Map;
1719
import java.util.Set;
1820

@@ -22,7 +24,6 @@
2224
import org.opensearch.core.common.io.stream.Writeable;
2325
import org.opensearch.core.xcontent.ToXContent;
2426
import org.opensearch.core.xcontent.XContentBuilder;
25-
import org.opensearch.security.ssl.config.CertType;
2627

2728
public class CertificatesInfo implements Writeable, ToXContent {
2829
private final Map<String, List<CertificateInfo>> certificates;
@@ -32,45 +33,32 @@ public CertificatesInfo(final Map<String, List<CertificateInfo>> certificates) {
3233
}
3334

3435
public CertificatesInfo(final StreamInput in) throws IOException {
35-
if (in.getVersion().onOrAfter(Version.V_3_2_0)) {
36-
certificates = in.readMap(StreamInput::readString, listIn -> listIn.readList(CertificateInfo::new));
36+
if (in.getVersion().before(Version.V_3_0_0)) {
37+
Map<CertificateType_2_19, List<CertificateInfo>> compatMap = in.readMap(
38+
keyIn -> keyIn.readEnum(CertificateType_2_19.class),
39+
listIn -> listIn.readList(CertificateInfo::new)
40+
);
41+
certificates = new HashMap<>();
42+
for (Map.Entry<CertificateType_2_19, List<CertificateInfo>> entry : compatMap.entrySet()) {
43+
certificates.put(entry.getKey().value(), entry.getValue());
44+
}
3745
} else {
38-
/*
39-
Previous versions represent cert types with an enum and serialize based on
40-
enum ordinal. To maintain backwards compatibility we fall back to mapping these
41-
enum ordinals to the appropriate native certificate type.
42-
*/
43-
certificates = in.readMap((StreamInput streamIn) -> switch (streamIn.readEnum(CertType.LegacyCertType.class)) {
44-
case CertType.LegacyCertType.HTTP -> CertType.HTTP.id();
45-
case CertType.LegacyCertType.TRANSPORT -> CertType.TRANSPORT.id();
46-
case CertType.LegacyCertType.TRANSPORT_CLIENT -> CertType.TRANSPORT_CLIENT.id();
47-
}, listIn -> listIn.readList(CertificateInfo::new));
46+
certificates = in.readMap(StreamInput::readString, listIn -> listIn.readList(CertificateInfo::new));
4847
}
4948
}
5049

5150
@Override
5251
public void writeTo(StreamOutput out) throws IOException {
53-
if (out.getVersion().onOrAfter(Version.V_3_2_0)) {
54-
out.writeMap(certificates, StreamOutput::writeString, StreamOutput::writeList);
55-
} else {
56-
/*
57-
We need to write only map elements which previous versions will understand.
58-
CertTypes are strictly bound to LegacyCertType enum in these versions and only has knowledge of
59-
HTTP, TRANSPORT, TRANSPORT_CLIENT.
60-
*/
61-
Set<String> legacyCerts = certificates.keySet();
62-
legacyCerts.retainAll(List.of(CertType.HTTP.id(), CertType.TRANSPORT.id(), CertType.TRANSPORT_CLIENT.id()));
63-
out.writeVInt(legacyCerts.size());
64-
for (String certId : legacyCerts) {
65-
if (CertType.HTTP.id().equals(certId)) {
66-
out.writeEnum(CertType.LegacyCertType.HTTP);
67-
} else if (CertType.TRANSPORT.id().equals(certId)) {
68-
out.writeEnum(CertType.LegacyCertType.TRANSPORT);
69-
} else if (CertType.TRANSPORT_CLIENT.id().equals(certId)) {
70-
out.writeEnum(CertType.LegacyCertType.TRANSPORT_CLIENT);
52+
if (out.getVersion().before(Version.V_3_0_0)) {
53+
Map<CertificateType_2_19, List<CertificateInfo>> compatMap = new HashMap<>();
54+
for (Map.Entry<String, List<CertificateInfo>> entry : certificates.entrySet()) {
55+
if (Set.of("http", "transport").contains(entry.getKey().toLowerCase(Locale.ROOT))) {
56+
compatMap.put(CertificateType_2_19.from(entry.getKey()), entry.getValue());
7157
}
72-
out.writeList(certificates.get(certId));
7358
}
59+
out.writeMap(compatMap, StreamOutput::writeEnum, StreamOutput::writeList);
60+
} else {
61+
out.writeMap(certificates, StreamOutput::writeString, StreamOutput::writeList);
7462
}
7563
}
7664

@@ -82,4 +70,38 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
8270
}
8371
return builder.endObject();
8472
}
73+
74+
public enum CertificateType_2_19 {
75+
HTTP("http"),
76+
TRANSPORT("transport"),
77+
ALL("all");
78+
79+
private final String value;
80+
81+
private CertificateType_2_19(String value) {
82+
this.value = value;
83+
}
84+
85+
public static boolean isHttp(final CertificateType_2_19 certificateType) {
86+
return certificateType == HTTP || certificateType == ALL;
87+
}
88+
89+
public static boolean isTransport(final CertificateType_2_19 certificateType) {
90+
return certificateType == TRANSPORT || certificateType == ALL;
91+
}
92+
93+
public String value() {
94+
return value.toLowerCase(Locale.ROOT);
95+
}
96+
97+
public static CertificateType_2_19 from(final String certType) {
98+
if (certType == null) {
99+
return ALL;
100+
}
101+
for (final var t : values())
102+
if (t.value.equalsIgnoreCase(certType)) return t;
103+
throw new IllegalArgumentException("Invalid certificate type: " + certType);
104+
}
105+
106+
}
85107
}

src/main/java/org/opensearch/security/dlic/rest/api/ssl/CertificatesInfoNodesRequest.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import java.io.IOException;
1515
import java.util.Optional;
1616

17+
import org.opensearch.Version;
1718
import org.opensearch.action.ActionRequestValidationException;
1819
import org.opensearch.action.support.nodes.BaseNodesRequest;
1920
import org.opensearch.core.common.Strings;
@@ -33,7 +34,11 @@ public CertificatesInfoNodesRequest(String certTypeID, boolean inMemory, String.
3334

3435
public CertificatesInfoNodesRequest(final StreamInput in) throws IOException {
3536
super(in);
36-
certTypeID = in.readOptionalString();
37+
if (in.getVersion().before(Version.V_3_0_0)) {
38+
certTypeID = in.readEnum(CertificatesInfo.CertificateType_2_19.class).value();
39+
} else {
40+
certTypeID = in.readOptionalString();
41+
}
3742
inMemory = in.readBoolean();
3843
}
3944

@@ -48,7 +53,15 @@ public boolean inMemory() {
4853
@Override
4954
public void writeTo(final StreamOutput out) throws IOException {
5055
super.writeTo(out);
51-
out.writeOptionalString(certTypeID);
56+
if (out.getVersion().before(Version.V_3_0_0)) {
57+
if (certTypeID == null) {
58+
out.writeEnum(CertificatesInfo.CertificateType_2_19.ALL);
59+
} else {
60+
out.writeEnum(CertificatesInfo.CertificateType_2_19.valueOf(certTypeID));
61+
}
62+
} else {
63+
out.writeOptionalString(certTypeID);
64+
}
5265
out.writeBoolean(inMemory);
5366
}
5467

0 commit comments

Comments
 (0)