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

Bug 572366 verify product's public key on hc-fls interaction #696

Merged
merged 1 commit into from
Mar 30, 2021
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -21,25 +21,28 @@
import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationExpression;
import org.eclipse.passage.lic.floating.model.net.ServerAuthenticationType;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.base.NamedData;
import org.eclipse.passage.lic.internal.base.ProductIdentifier;
import org.eclipse.passage.lic.internal.base.ProductVersion;
import org.eclipse.passage.lic.internal.hc.i18n.AccessMessages;
import org.eclipse.passage.lic.internal.hc.remote.QueryParameters;
import org.eclipse.passage.lic.internal.net.EncodingAlgorithm;
import org.eclipse.passage.lic.internal.net.LicenseUser;
import org.eclipse.passage.lic.internal.net.LicensingAction;

public abstract class RequestParameters implements QueryParameters {

private final LicensedProduct product;
private final FloatingLicenseAccess access;
private final String hash;

protected RequestParameters(LicensedProduct product, FloatingLicenseAccess access) {
protected RequestParameters(LicensedProduct product, FloatingLicenseAccess access, String hash) {
this.product = product;
this.access = access;
this.hash = hash;
}

@Override
Expand Down Expand Up @@ -67,6 +70,8 @@ private List<NamedData> generalParameters() throws LicensingException {
new ProductVersion(encode(product.version())), //
new LicensingAction(action()), //
new LicenseUser(access.getUser()), //
new LicenseUser(access.getUser()), //
new EncodingAlgorithm(hash), //
new ServerAuthenticationType(access.getServer().getAuthentication().getType()), //
new ServerAuthenticationExpression(encode(access.getServer().getAuthentication().getExpression())));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import java.util.List;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.base.FeatureIdentifier;
import org.eclipse.passage.lic.internal.base.NamedData;
import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters;
Expand All @@ -27,8 +27,8 @@ final class AcquireRequestParameters extends RequestParameters {

private final String feature;

AcquireRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access) {
super(product, access);
AcquireRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access, String hash) {
super(product, access, hash);
this.feature = feature;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@
import java.util.List;

import org.eclipse.passage.lic.floating.model.api.FloatingLicenseAccess;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.api.LicensedProduct;
import org.eclipse.passage.lic.internal.api.LicensingException;
import org.eclipse.passage.lic.internal.api.PassageAction;
import org.eclipse.passage.lic.internal.base.FeatureIdentifier;
import org.eclipse.passage.lic.internal.base.NamedData;
import org.eclipse.passage.lic.internal.hc.remote.impl.RequestParameters;
Expand All @@ -27,8 +27,8 @@ final class ReleaseRequestParameters extends RequestParameters {

private final String feature;

ReleaseRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access) {
super(product, access);
ReleaseRequestParameters(LicensedProduct product, String feature, FloatingLicenseAccess access, String hash) {
super(product, access, hash);
this.feature = feature;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ private final class Request extends RemoteRequest<C> {

@Override
public RequestParameters parameters() {
return new AcquireRequestParameters(data.product(), data.feature(), access);
return new AcquireRequestParameters(data.product(), data.feature(), access, hash);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public Configuration<C> config() throws LicensingException {

@Override
public RequestParameters parameters() {
return new ReleaseRequestParameters(product, data.payload().feature(), access);
return new ReleaseRequestParameters(product, data.payload().feature(), access, hash);
}

private byte[] payload() throws LicensingException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@

final class MineRequestParameters extends RequestParameters {

MineRequestParameters(LicensedProduct product, FloatingLicenseAccess access) {
super(product, access);
MineRequestParameters(LicensedProduct product, FloatingLicenseAccess access, String hash) {
super(product, access, hash);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public RemoteConditionsRequest(LicensedProduct product, FloatingLicenseAccess ac

@Override
public RequestParameters parameters() {
return new MineRequestParameters(product, access);
return new MineRequestParameters(product, access, hash);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*******************************************************************************
* Copyright (c) 2020 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.net;

import java.util.function.Function;

import org.eclipse.passage.lic.internal.base.StringNamedData;

public final class EncodingAlgorithm extends StringNamedData {

public EncodingAlgorithm(String value) {
super(value);
}

public EncodingAlgorithm(Function<String, String> retrieve) {
super(retrieve);
}

@Override
public String key() {
return "algo"; //$NON-NLS-1$
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.eclipse.passage.lic.internal.base.BaseLicensedProduct;
import org.eclipse.passage.lic.internal.base.ProductIdentifier;
import org.eclipse.passage.lic.internal.base.ProductVersion;
import org.eclipse.passage.lic.internal.net.EncodingAlgorithm;
import org.eclipse.passage.lic.internal.net.LicenseUser;
import org.eclipse.passage.lic.internal.net.api.handle.NetRequest;

Expand All @@ -27,11 +28,13 @@ public final class ProductUserRequest<R extends NetRequest> {
private final R raw;
private final Optional<LicensedProduct> product;
private final Optional<String> user;
private final Optional<String> algorithm;

public ProductUserRequest(R raw) throws LicensingException {
this.raw = raw;
this.product = extractProduct();
this.user = extractUser();
this.algorithm = extractAlgorithm();
}

private Optional<LicensedProduct> extractProduct() throws LicensingException {
Expand All @@ -49,6 +52,10 @@ private Optional<String> extractUser() {
return new LicenseUser(raw::parameter).get();
}

private Optional<String> extractAlgorithm() {
return new EncodingAlgorithm(raw::parameter).get();
}

public R raw() {
return raw;
}
Expand All @@ -61,4 +68,7 @@ public Optional<String> user() {
return user;
}

public Optional<String> algorithm() {
return algorithm;
}
}