-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #275 from eclipse-passage/564819
Bug 564819 - API revision | conditions | stream codecs review
- Loading branch information
Showing
20 changed files
with
571 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
...clipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/io/DigestExpectation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/******************************************************************************* | ||
* 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.api.io; | ||
|
||
public interface DigestExpectation { | ||
|
||
/** | ||
* @return is there is any expectation at all | ||
*/ | ||
boolean expected(); | ||
|
||
/** | ||
* <p> | ||
* In the case we actually expect input digest to be verified, here actual | ||
* digest expectation is supplied. | ||
* </p> | ||
* <p> | ||
* Is not designed to be called if there are no expectations at all. Thus, is | ||
* not designed to ever return {@code null}. | ||
* </p> | ||
*/ | ||
byte[] value(); | ||
|
||
public static final class None implements DigestExpectation { | ||
|
||
@Override | ||
public boolean expected() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public byte[] value() { | ||
throw new UnsupportedOperationException(); | ||
} | ||
|
||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...ipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/io/EncryptionAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/******************************************************************************* | ||
* 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.api.io; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class EncryptionAlgorithm { | ||
|
||
private final String name; | ||
|
||
public EncryptionAlgorithm(String name) { | ||
Objects.requireNonNull(name, "EncryptionAlgorithm::name"); //$NON-NLS-1$ | ||
this.name = name.toUpperCase(); | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!getClass().isInstance(object)) { | ||
return false; | ||
} | ||
return name.equals(((EncryptionAlgorithm) object).name()); | ||
} | ||
|
||
public String name() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return name.hashCode(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return name; | ||
} | ||
|
||
public static final class RSA extends EncryptionAlgorithm { | ||
|
||
public RSA() { | ||
super("RSA"); //$NON-NLS-1$ | ||
} | ||
|
||
} | ||
|
||
public static final class Default extends EncryptionAlgorithm { | ||
|
||
public Default() { | ||
super(new RSA().name()); | ||
} | ||
|
||
} | ||
|
||
public static final class Of extends EncryptionAlgorithm { | ||
|
||
public Of(String name) { | ||
super(name); | ||
} | ||
|
||
} | ||
|
||
} |
66 changes: 66 additions & 0 deletions
66
...clipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/io/EncryptionKeySize.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/******************************************************************************* | ||
* 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.api.io; | ||
|
||
import java.util.Objects; | ||
|
||
public abstract class EncryptionKeySize { | ||
|
||
private final int size; | ||
|
||
public EncryptionKeySize(int size) { | ||
if (size <= 0) { | ||
throw new IllegalArgumentException("EncryptionKeySize::size must be positiv"); //$NON-NLS-1$ | ||
} | ||
this.size = size; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object object) { | ||
if (!getClass().isInstance(object)) { | ||
return false; | ||
} | ||
return size == ((EncryptionKeySize) object).size(); | ||
} | ||
|
||
public int size() { | ||
return size; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hash(size); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return Integer.toString(size); | ||
} | ||
|
||
public static final class Default extends EncryptionKeySize { | ||
|
||
public Default() { | ||
super(1024); | ||
} | ||
|
||
} | ||
|
||
public static final class Of extends EncryptionKeySize { | ||
|
||
public Of(int size) { | ||
super(size); | ||
} | ||
|
||
} | ||
|
||
} |
78 changes: 78 additions & 0 deletions
78
.../org.eclipse.passage.lic.api/src/org/eclipse/passage/lic/internal/api/io/StreamCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/******************************************************************************* | ||
* 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.api.io; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
|
||
import org.eclipse.passage.lic.internal.api.LicensedProduct; | ||
import org.eclipse.passage.lic.internal.api.conditions.mining.MinedConditions; | ||
import org.eclipse.passage.lic.internal.api.registry.Service; | ||
|
||
/** | ||
* Coder and decoder for licensing data, used by {@link MinedConditions} to read | ||
* licensing conditions data from encoded streams (like license text) | ||
*/ | ||
public interface StreamCodec extends Service<LicensedProduct> { | ||
/** | ||
* Identifier of an encoding algorithm used by the codec. | ||
*/ | ||
EncryptionAlgorithm algorithm(); | ||
|
||
/** | ||
* Encoding key size. | ||
*/ | ||
EncryptionKeySize keySize(); | ||
|
||
/** | ||
* Create a public/private keys pair and store them to {@code publicKeyPath} and | ||
* {@code privateKeyPath} respectively. | ||
* | ||
* @param publicKeyPath file system path for <i>public key</i> to be generated | ||
* @param privateKeyPath file system path for <i>private key</i> to be generated | ||
* @param username of the keys owner user | ||
* @param password of the keys owner user | ||
* @throws IOException in case of any i/o misbehavior | ||
*/ | ||
void createKeyPair(String publicKeyPath, String privateKeyPath, String username, String password) | ||
throws IOException; | ||
|
||
/** | ||
* Encode {@code input} stream data with a private key retrieved form the given | ||
* {@code key} stream. Fill {@code output} stream with the encoded data. | ||
* | ||
* @param input source of data to be encoded | ||
* @param output target stream to place encoded data into | ||
* @param key source for a private key | ||
* @param username of the private key owner user | ||
* @param password of the private key owner user | ||
* @throws IOException in case of any i/o misbehavior | ||
*/ | ||
void encode(InputStream input, OutputStream output, InputStream key, String username, String password) | ||
throws IOException; | ||
|
||
/** | ||
* Decode the {@code input} stream with the <i>public key</i> and store decoded | ||
* data to {@code output} stream. | ||
* | ||
* @param input source stream with encoded data | ||
* @param output target stream for decoded data | ||
* @param key stream containing the <i>public key</i> for decoding | ||
* @param digest expected digest for public key source stream {@code key} to be | ||
* validated prior decoding | ||
* @throws IOException in case of any i/o denial or misbehavior | ||
*/ | ||
void decode(InputStream input, OutputStream output, InputStream key, DigestExpectation digest) throws IOException; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...ase/src/org/eclipse/passage/lic/internal/base/conditions/mining/SecurityKeyAlgorithm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/******************************************************************************* | ||
* 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.base.conditions.mining; | ||
|
||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.function.Function; | ||
|
||
import org.eclipse.passage.lic.internal.api.io.EncryptionAlgorithm; | ||
import org.eclipse.passage.lic.internal.base.BaseNamedData; | ||
|
||
@SuppressWarnings("restriction") | ||
public final class SecurityKeyAlgorithm extends BaseNamedData<EncryptionAlgorithm> { | ||
|
||
public SecurityKeyAlgorithm(Function<String, EncryptionAlgorithm> retrieve) { | ||
super(retrieve); | ||
} | ||
|
||
public SecurityKeyAlgorithm(Map<String, Object> container) { | ||
super(key -> Optional.ofNullable(container.get(key))// | ||
.map(String::valueOf) // | ||
.map(String::trim) // | ||
.filter(value -> !value.isEmpty())// | ||
.map(EncryptionAlgorithm.Of::new)// | ||
.map(EncryptionAlgorithm.class::cast) // just for compiler | ||
.orElseGet(EncryptionAlgorithm.Default::new)); | ||
} | ||
|
||
public SecurityKeyAlgorithm(EncryptionAlgorithm value) { | ||
super(key -> value); | ||
} | ||
|
||
public SecurityKeyAlgorithm(String algorithm) { | ||
super(key -> new EncryptionAlgorithm.Of(algorithm)); | ||
} | ||
|
||
@Override | ||
public String key() { | ||
return "licensing.security.key.algo"; //$NON-NLS-1$ | ||
} | ||
|
||
} |
Oops, something went wrong.