From 39588638b6c959175a003a8e350ab2787305c1aa Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Tue, 30 Mar 2021 18:03:45 +0300 Subject: [PATCH 1/2] Bug 572366 verify product's public key on hc-fls interaction - promote Gear notion to lic.api - extract GearAware functionality for reuse Signed-off-by: eparovyshnaya --- .../passage/lic/internal/api/Gear.java | 21 ++++++++ .../lic/internal/api/GearSupplier.java | 19 +++++++ .../META-INF/MANIFEST.MF | 4 +- .../lic/internal/equinox/GearAware.java | 50 +++++++++++++++++++ .../META-INF/MANIFEST.MF | 2 +- .../loc/internal/api/OperatorGear.java | 3 +- .../internal/api/OperatorGearSupplier.java | 4 +- .../internal/equinox/OperatorGearAware.java | 32 ++---------- 8 files changed, 103 insertions(+), 32 deletions(-) create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/Gear.java create mode 100644 bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/GearSupplier.java create mode 100644 bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/Gear.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/Gear.java new file mode 100644 index 000000000..018a5105a --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/Gear.java @@ -0,0 +1,21 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.api; + +/** + * Marker interface for a product based on Passage infrastructure to supply all + * necessary services + */ +public interface Gear { + +} diff --git a/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/GearSupplier.java b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/GearSupplier.java new file mode 100644 index 000000000..149d10ac8 --- /dev/null +++ b/bundles/org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/GearSupplier.java @@ -0,0 +1,19 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.api; + +public interface GearSupplier { + + G gear(); + +} diff --git a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF index ac38ef218..a822ab2e5 100644 --- a/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.lic.equinox/META-INF/MANIFEST.MF @@ -18,7 +18,9 @@ Export-Package: org.eclipse.passage.lic.internal.equinox; org.eclipse.passage.lic.jface, org.eclipse.passage.lic.net, org.eclipse.passage.seal.demo, - org.eclipse.passage.lic.jetty", + org.eclipse.passage.lic.jetty, + org.eclipse.passage.loc.api, + org.eclipse.passage.lbc.base", org.eclipse.passage.lic.internal.equinox.acquire;x-internal:=true, org.eclipse.passage.lic.internal.equinox.conditions;x-internal:=true, org.eclipse.passage.lic.internal.equinox.events; diff --git a/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java new file mode 100644 index 000000000..aa02bf2ec --- /dev/null +++ b/bundles/org.eclipse.passage.lic.equinox/src/org/eclipse/passage/lic/internal/equinox/GearAware.java @@ -0,0 +1,50 @@ +/******************************************************************************* + * Copyright (c) 2021 ArSysOp + * + * This program and the accompanying materials are made available under the + * terms of the Eclipse Public License 2.0 which is available at + * https://www.eclipse.org/legal/epl-2.0/. + * + * SPDX-License-Identifier: EPL-2.0 + * + * Contributors: + * ArSysOp - initial API and implementation + *******************************************************************************/ +package org.eclipse.passage.lic.internal.equinox; + +import java.util.Collection; +import java.util.Collections; +import java.util.Optional; +import java.util.function.Function; + +import org.eclipse.passage.lic.internal.api.Gear; +import org.eclipse.passage.lic.internal.api.GearSupplier; +import org.osgi.framework.BundleContext; +import org.osgi.framework.FrameworkUtil; +import org.osgi.framework.InvalidSyntaxException; +import org.osgi.framework.ServiceReference; + +public abstract class GearAware> { + + public final Optional withGear(Function> with) { + BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); + Collection> references = Collections.emptyList(); + try { + references = context.getServiceReferences(supplier(), null); + } catch (InvalidSyntaxException e) { + return Optional.empty(); + } + if (references.isEmpty()) { + return Optional.empty(); + } + ServiceReference any = references.iterator().next(); + try { + return with.apply(context.getService(any).gear()); + } finally { + context.ungetService(any); + } + } + + protected abstract Class supplier(); + +} diff --git a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF index c8541e309..aa15f8cae 100644 --- a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF @@ -34,7 +34,7 @@ Require-Bundle: org.eclipse.e4.core.services;bundle-version="0.0.0", org.eclipse.osgi;bundle-version="0.0.0", org.eclipse.passage.lic.base;bundle-version="1.0.0", org.eclipse.passage.lic.emf;bundle-version="1.0.0", - org.eclipse.passage.lic.equinox;bundle-version="1.0.0", + org.eclipse.passage.lic.equinox;bundle-version="1.0.0";visibility:=reexport, org.eclipse.passage.lic.floating.model;bundle-version="0.1.0", org.eclipse.passage.lic.licenses;bundle-version="1.0.0";visibility:=reexport, org.eclipse.passage.lic.products;bundle-version="1.0.0";visibility:=reexport, diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGear.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGear.java index 43d7be065..78a40a298 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGear.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGear.java @@ -14,11 +14,12 @@ import java.util.Optional; +import org.eclipse.passage.lic.internal.api.Gear; import org.eclipse.passage.lic.internal.api.LicensedProduct; import org.eclipse.passage.lic.internal.api.inspection.RuntimeEnvironmentRegistry; import org.eclipse.passage.lic.internal.api.io.StreamCodec; -public interface OperatorGear { +public interface OperatorGear extends Gear { Optional codec(LicensedProduct product); diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGearSupplier.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGearSupplier.java index 0941e7fdd..33c8c6d7d 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGearSupplier.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/api/OperatorGearSupplier.java @@ -12,8 +12,8 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.api; -public interface OperatorGearSupplier { +import org.eclipse.passage.lic.internal.api.GearSupplier; - OperatorGear gear(); +public interface OperatorGearSupplier extends GearSupplier { } diff --git a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/equinox/OperatorGearAware.java b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/equinox/OperatorGearAware.java index 887c83cb4..1f0d13775 100644 --- a/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/equinox/OperatorGearAware.java +++ b/bundles/org.eclipse.passage.loc.api/src/org/eclipse/passage/loc/internal/equinox/OperatorGearAware.java @@ -12,37 +12,15 @@ *******************************************************************************/ package org.eclipse.passage.loc.internal.equinox; -import java.util.Collection; -import java.util.Collections; -import java.util.Optional; -import java.util.function.Function; - +import org.eclipse.passage.lic.internal.equinox.GearAware; import org.eclipse.passage.loc.internal.api.OperatorGear; import org.eclipse.passage.loc.internal.api.OperatorGearSupplier; -import org.osgi.framework.BundleContext; -import org.osgi.framework.FrameworkUtil; -import org.osgi.framework.InvalidSyntaxException; -import org.osgi.framework.ServiceReference; -public final class OperatorGearAware { +public final class OperatorGearAware extends GearAware { - public Optional withGear(Function> with) { - BundleContext context = FrameworkUtil.getBundle(getClass()).getBundleContext(); - Collection> references = Collections.emptyList(); - try { - references = context.getServiceReferences(OperatorGearSupplier.class, null); - } catch (InvalidSyntaxException e) { - return Optional.empty(); - } - if (references.isEmpty()) { - return Optional.empty(); - } - ServiceReference any = references.iterator().next(); - try { - return with.apply(context.getService(any).gear()); - } finally { - context.ungetService(any); - } + @Override + protected Class supplier() { + return OperatorGearSupplier.class; } } From 08e7b72590144501fc9f567a389897b16092cdf1 Mon Sep 17 00:00:00 2001 From: Elena Parovyshnaia Date: Tue, 30 Mar 2021 18:36:58 +0300 Subject: [PATCH 2/2] Bug 572366 verify product's public key on hc-fls interaction bump service version of touched bundle Signed-off-by: eparovyshnaya --- bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF index aa15f8cae..f18260292 100644 --- a/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF +++ b/bundles/org.eclipse.passage.loc.api/META-INF/MANIFEST.MF @@ -2,7 +2,7 @@ Manifest-Version: 1.0 Automatic-Module-Name: org.eclipse.passage.loc.api Bundle-ManifestVersion: 2 Bundle-SymbolicName: org.eclipse.passage.loc.api -Bundle-Version: 1.0.102.qualifier +Bundle-Version: 1.0.103.qualifier Bundle-Name: %Bundle-Name Bundle-Vendor: %Bundle-Vendor Bundle-Copyright: %Bundle-Copyright