├── .gitignore ├── .travis.secrets.tar.enc ├── .travis.yml ├── Assembly ├── assembly.xml └── pom.xml ├── CHANGELOG.rst ├── Core ├── pom.xml └── source │ ├── production │ ├── java │ │ └── io │ │ │ └── oddsource │ │ │ └── java │ │ │ └── licensing │ │ │ ├── DataSignatureManager.java │ │ │ ├── DefaultLicenseValidator.java │ │ │ ├── DeserializingLicenseProvider.java │ │ │ ├── FeatureObject.java │ │ │ ├── FeatureRestriction.java │ │ │ ├── FeatureRestrictionOperand.java │ │ │ ├── FileLicenseProvider.java │ │ │ ├── License.java │ │ │ ├── LicenseManager.java │ │ │ ├── LicenseManagerProperties.java │ │ │ ├── LicenseProvider.java │ │ │ ├── LicenseSecurityManager.java │ │ │ ├── LicenseValidator.java │ │ │ ├── LicensingCharsets.java │ │ │ ├── ObjectSerializer.java │ │ │ ├── SignedLicense.java │ │ │ ├── encryption │ │ │ ├── Encryptor.java │ │ │ ├── FilePublicKeyDataProvider.java │ │ │ ├── Hasher.java │ │ │ ├── KeyFileUtilities.java │ │ │ ├── PasswordProvider.java │ │ │ ├── PublicKeyDataProvider.java │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── AlgorithmNotSupportedException.java │ │ │ ├── CorruptSignatureException.java │ │ │ ├── ExpiredLicenseException.java │ │ │ ├── FailedToDecryptException.java │ │ │ ├── FailedToEncryptException.java │ │ │ ├── InappropriateKeyException.java │ │ │ ├── InappropriateKeySpecificationException.java │ │ │ ├── InsecureEnvironmentError.java │ │ │ ├── InvalidLicenseException.java │ │ │ ├── InvalidSignatureException.java │ │ │ ├── KeyNotFoundException.java │ │ │ ├── ObjectDeserializationException.java │ │ │ ├── ObjectSerializationException.java │ │ │ ├── ObjectTypeNotExpectedException.java │ │ │ └── package-info.java │ │ │ ├── immutable │ │ │ ├── Immutable.java │ │ │ ├── ImmutableAbstractCollection.java │ │ │ ├── ImmutableArrayList.java │ │ │ ├── ImmutableIterator.java │ │ │ ├── ImmutableLinkedHashSet.java │ │ │ ├── ImmutableListIterator.java │ │ │ ├── ImmutableModifiedThroughReflectionError.java │ │ │ ├── ValidObject.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ └── .gitkeep │ └── test │ ├── java │ └── unit │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ ├── MockLicenseHelper.java │ │ ├── TestDataSignatureManager.java │ │ ├── TestDefaultLicenseValidator.java │ │ ├── TestDeserializingLicenseProvider.java │ │ ├── TestFileLicenseProvider.java │ │ ├── TestLicense.java │ │ ├── TestLicenseBuilder.java │ │ ├── TestLicenseManager.java │ │ ├── TestLicenseManagerProperties.java │ │ ├── TestLicenseSecurityManager.java │ │ ├── TestLicensingCharsets.java │ │ ├── TestObjectSerializer.java │ │ ├── TestSignedLicense.java │ │ ├── encryption │ │ ├── TestEncryptor.java │ │ ├── TestFilePublicKeyDataProvider.java │ │ ├── TestHasher.java │ │ └── TestKeyFileUtilities.java │ │ ├── immutable │ │ ├── MockValidObject.java │ │ ├── TestImmutableAbstractCollection.java │ │ ├── TestImmutableArrayList.java │ │ ├── TestImmutableIterator.java │ │ ├── TestImmutableLinkedHashSet.java │ │ └── TestImmutableListIterator.java │ │ └── mock │ │ ├── MockFeatureObject.java │ │ └── StateFlag.java │ └── resources │ └── .gitkeep ├── LICENSE.txt ├── Licensor-Base ├── pom.xml └── source │ ├── production │ ├── java │ │ └── io │ │ │ └── oddsource │ │ │ └── java │ │ │ └── licensing │ │ │ └── licensor │ │ │ ├── LicenseCreator.java │ │ │ ├── LicenseCreatorProperties.java │ │ │ ├── encryption │ │ │ ├── FilePrivateKeyDataProvider.java │ │ │ ├── PrivateKeyDataProvider.java │ │ │ ├── RSAKeyPairGenerator.java │ │ │ ├── RSAKeyPairGeneratorInterface.java │ │ │ └── package-info.java │ │ │ ├── exception │ │ │ ├── RSA2048NotSupportedException.java │ │ │ └── package-info.java │ │ │ └── package-info.java │ └── resources │ │ └── .gitkeep │ └── test │ ├── java │ └── unit │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ └── licensor │ │ ├── TestLicenseCreator.java │ │ ├── TestLicenseCreatorProperties.java │ │ └── encryption │ │ ├── TestFilePrivateKeyDataProvider.java │ │ └── TestRSAKeyPairGenerator.java │ └── resources │ └── .gitkeep ├── Licensor-UI-CLI ├── pom.xml └── source │ ├── production │ ├── java │ │ └── io │ │ │ └── oddsource │ │ │ └── java │ │ │ └── licensing │ │ │ └── licensor │ │ │ └── interfaces │ │ │ └── cli │ │ │ ├── ConsoleLicenseGenerator.java │ │ │ ├── ConsoleRSAKeyPairGenerator.java │ │ │ ├── ConsoleUtilities.java │ │ │ ├── Periods.java │ │ │ ├── package-info.java │ │ │ └── spi │ │ │ ├── AbstractTextInterfaceDevice.java │ │ │ ├── ConsoleInterfaceDevice.java │ │ │ ├── TextInterfaceDevice.java │ │ │ └── package-info.java │ └── resources │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ └── licensor │ │ └── interfaces │ │ └── cli │ │ └── spi │ │ ├── ConsoleLicenseGenerator.sh │ │ └── ConsoleRSAKeyPairGenerator.sh │ └── test │ ├── java │ └── unit │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ ├── licensor │ │ └── interfaces │ │ │ └── cli │ │ │ ├── TestConsoleLicenseGenerator.java │ │ │ ├── TestConsoleRSAKeyPairGenerator.java │ │ │ ├── TestConsoleUtilities.java │ │ │ ├── TestPeriods.java │ │ │ └── spi │ │ │ ├── TestAbstractTextInterfaceDevice.java │ │ │ └── TestConsoleInterfaceDevice.java │ │ └── mock │ │ ├── MockEmbeddedPrivateKeyDataProvider.java │ │ ├── MockFilePrivateKeyDataProvider.java │ │ ├── MockPasswordProvider.java │ │ └── mock.private.key │ └── resources │ └── .gitkeep ├── Licensor-UI-Core ├── pom.xml └── source │ ├── production │ ├── java │ │ └── io │ │ │ └── oddsource │ │ │ └── java │ │ │ └── licensing │ │ │ └── licensor │ │ │ └── interfaces │ │ │ └── spi │ │ │ ├── AbstractPasswordPrompter.java │ │ │ ├── OutputDevice.java │ │ │ ├── PasswordPrompter.java │ │ │ └── package-info.java │ └── resources │ │ └── .gitkeep │ └── test │ ├── java │ └── unit │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ └── licensor │ │ └── interfaces │ │ └── spi │ │ └── TestAbstractPasswordPrompter.java │ └── resources │ └── .gitkeep ├── Licensor-UI-Desktop ├── pom.xml └── source │ ├── production │ ├── java │ │ └── io │ │ │ └── oddsource │ │ │ └── java │ │ │ └── licensing │ │ │ └── licensor │ │ │ └── interfaces │ │ │ └── desktop │ │ │ └── .gitkeep │ └── resources │ │ └── .gitkeep │ └── test │ ├── java │ └── unit │ │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ └── licensor │ │ └── interfaces │ │ └── desktop │ │ └── .gitkeep │ └── resources │ └── .gitkeep ├── NOTICE.txt ├── README.rst ├── Samples ├── pom.xml └── source │ └── production │ ├── java │ └── io │ │ └── oddsource │ │ └── java │ │ └── licensing │ │ └── samples │ │ ├── SampleEmbeddedPrivateKeyDataProvider.java │ │ ├── SampleEmbeddedPublicKeyDataProvider.java │ │ ├── SampleFilePrivateKeyDataProvider.java │ │ ├── SampleFilePublicKeyDataProvider.java │ │ ├── SampleLicenseRestrictedObject.java │ │ ├── SamplePasswordProvider.java │ │ └── package-info.java │ └── resources │ └── io │ └── oddsource │ └── java │ └── licensing │ └── samples │ ├── sample.private.key │ └── sample.public.key ├── build ├── checkstyle-suppressions.xml ├── jar │ └── META-INF │ │ ├── LICENSE.txt │ │ └── NOTICE.txt └── spotbugs-exclude.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | *.iml 3 | .travis.gpg 4 | target 5 | dist 6 | -------------------------------------------------------------------------------- /.travis.secrets.tar.enc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/.travis.secrets.tar.enc -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2010-2019 OddSource Code (license@oddsource.io) 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | # This build is overkill for a POM-packaged artifact, but it serves as a test bed for some principles we'll use in 16 | # child projects. Also, here's some documentation about Maven and GitHub publication: 17 | # 18 | # $ gpg --full-generate-key 19 | # $ gpg --list-keys 20 | # $ gpg --export-secret-keys [key ID] > travis.gpg 21 | # $ gpg --keyserver pgp.mit.edu --send-key [key ID] 22 | # $ tar -cvf .travis.secrets.tar settings.xml travis.gpg 23 | # $ travis login --org 24 | # $ travis encrypt-file .travis.secrets.tar 25 | # $ rm .travis.secrets.tar settings.xml travis.gpg 26 | # $ travis setup releases 27 | 28 | language: java 29 | sudo: false 30 | cache: 31 | directories: 32 | - "$HOME/.cache" 33 | jobs: 34 | include: 35 | - stage: build 36 | os: linux 37 | dist: trusty 38 | jdk: oraclejdk8 39 | script: 40 | - mvn test -B -V -e 41 | - stage: build 42 | os: linux 43 | dist: trusty 44 | jdk: openjdk8 45 | script: 46 | - mvn test -B -V -e 47 | - stage: build 48 | os: linux 49 | dist: xenial 50 | jdk: oraclejdk11 51 | script: 52 | - mvn test -B -V -e 53 | - stage: build 54 | os: linux 55 | dist: xenial 56 | jdk: openjdk11 57 | script: 58 | - mvn test -B -V -e 59 | - stage: deploy 60 | os: linux 61 | dist: xenial 62 | jdk: openjdk8 63 | deploy: 64 | - provider: script 65 | script: 66 | openssl aes-256-cbc -K $encrypted_a3a662639502_key -iv $encrypted_a3a662639502_iv -in .travis.secrets.tar.enc -out .travis.secrets.tar -d && 67 | tar -xvf .travis.secrets.tar && 68 | rm .travis.secrets.tar && 69 | gpg --import travis.gpg && 70 | rm travis.gpg && 71 | mv settings.xml $HOME/.m2/settings.xml && 72 | mvn clean deploy -Dmaven.test.skip=true -Dmaven.javadoc.skip=true -P sign -B -V -e 73 | on: 74 | tags: true 75 | skip_cleanup: true 76 | - provider: releases 77 | api_key: 78 | secure: P46R90OY2vUkvC2qN+j3excHP/Wui501K3IyY/9GarSu3M8XqgmiSTjS/zkF6osUoV7l5mbuccDeULPfwx/LpTxgZAMum+XQqVQ9IcMHLquKC/y+j463wR9rAtfyhxzpRDgYDiH/sMY2mfwvdeLFK1NemQ1QWi8zkTJs9Hl738aNf4mPgvf6/eThYOwbpxr7lLanatVk/YesFFPio16NVcKmq8+SDgjwHQCqMhXGL7BNMGoIKH2qD4GVXZLqh4DpTNhBhcva7BNiHVPMHyS1G00HNVna/l37eZzH2wc8JfJZnA/Wv9dqLptbuphi6BtqJQ38/xTXLiX1eI2ZY+kUUB0nZfWAiVoAz+2NjtlDuC99PrwKFO49EOb6JCc9H+yOauAcAx593+w2014hhX6e//fIig4/qFpsM3M6FE4qJH+qEQ3AIawZbXrzIVBmyzNMpdXX7ThZMdO8RL7tGMp9iDX36UMFgNEiOopDimSbhFgomxjEkvkVUexjPu6bpDmhCx0Vzpm/UhEOVXJn4cD8iRtVE7kVeL6EcQCSFly1I8zUAViic9yB2tOmIOvCNYv4LLsY4unYirEd6HeKJIO+cnyjbtfZVsgqMDKV5qrjJI6RZdv/vfPsdwuvUYD/3YlMHOkqO2P1dJ6xNT75w4BvJYgJ334X5icfwO2B+BsVZ8U= 79 | file_glob: true 80 | file: 81 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.zip 82 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.zip.asc 83 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.zip.md5 84 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.zip.sha1 85 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.tar.gz 86 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.tar.gz.asc 87 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.tar.gz.md5 88 | - $HOME/.m2/repository/io/oddsource/java/licensing/licensing-assembly/*/licensing-assembly-*.tar.gz.sha1 89 | on: 90 | tags: true 91 | stages: 92 | - build 93 | - name: deploy 94 | if: tag =~ ^[0-9]+\.[0-9]+(\.[0-9]+)?(-[0-9A-Za-z-]+(\.[0-9A-Za-z-]+)*)?$ 95 | install: 96 | - gpg --version 97 | script: 98 | - mvn --version 99 | -------------------------------------------------------------------------------- /Assembly/assembly.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 23 | all 24 | 25 | zip 26 | tar.gz 27 | 28 | false 29 | false 30 | 31 | 32 | 33 | io.oddsource.java.licensing:* 34 | 35 | 36 | io.oddsource.java.licensing:licensing-assembly 37 | 38 | true 39 | 40 | dist 41 | false 42 | 43 | 44 | 45 | 46 | 47 | ../Core/target 48 | *-sources.jar 49 | sources 50 | 51 | 52 | ../Licensor-Base/target 53 | *-sources.jar 54 | sources 55 | 56 | 57 | ../Licensor-UI-Core/target 58 | *-sources.jar 59 | sources 60 | 61 | 62 | ../Licensor-UI-CLI/target 63 | *-sources.jar 64 | sources 65 | 66 | 67 | ../Licensor-UI-Desktop/target 68 | *-sources.jar 69 | sources 70 | 71 | 72 | ../Samples/target 73 | *-sources.jar 74 | sources 75 | 76 | 77 | target 78 | *-javadoc.jar 79 | ./ 80 | 81 | 82 | 83 | 84 | ../build/jar/META-INF/LICENSE.txt 85 | 86 | 87 | ../build/jar/META-INF/NOTICE.txt 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /CHANGELOG.rst: -------------------------------------------------------------------------------- 1 | Changelog 2 | ========= 3 | 4 | 2.0.0 (2019-01-??) 5 | ------------------- 6 | - [MAJOR] Re-branded all projects from NWTSJavaCode to OddSource Code 7 | - [MAJOR] The base package for all classes and packages in this project has been renamed from 8 | ``net.nicholaswilliams.java.licensing`` to ``io.oddsource.java.licensing``. Except as otherwise noted in other 9 | "[MAJOR]" changes below, all the classes remain interface compatible with 1.x, so you should need only to perform a 10 | bulk replace in your project. 11 | - [MAJOR] ``ImmutableModifiedThroughReflectionException`` has been renamed to 12 | ``ImmutableModifiedThroughReflectionError`` to follow proper Java exception naming procedures. 13 | - [MAJOR] ``InsecureEnvironmentException`` has been renamed to ``InsecureEnvironmentError`` to follow proper Java 14 | exception naming procedures. 15 | - [MAJOR] The following methods in ``License.Builder``, previously marked as deprecated in 1.x, have now been removed: 16 | 17 | - ``withFeature(String featureName)``: Use ``addFeature(String featureName)``, instead. 18 | - ``withFeature(String featureName, long goodBeforeDate)``: Use 19 | ``addFeature(String featureName, long goodBeforeDate)``, instead. 20 | - ``withFeature(License.Feature feature)``: Use ``addFeature(License.Feature feature)``, instead. 21 | 22 | - [MAJOR] The properties for the private key properties file and license-generate properties file used by the CLI have 23 | changed. The properties were previously prefixed with ``net.nicholaswilliams.java.licensing``. They are now prefixed 24 | with ``io.oddsource.java.licensing``. 25 | - [MAJOR] Switched to using Travis CI for all continuous integration 26 | - [MAJOR] Switched to the ``nexus-staging-maven-plugin`` for deployments instead of ``maven-deploy-plugin`` 27 | - [MAJOR] Switched from tabs to spaces 28 | - [MINOR] Codified explicit code style rules 29 | - [MINOR] Configured mandatory license header check in Maven build 30 | - [MINOR] Fixed #3: License Manager should now run under Java 10 31 | - [MINOR] Complete code reformat 32 | 33 | 1.1.0 (2013-04-25) 34 | ------------------ 35 | - [MINOR] A few simple bug fixes in the POM 36 | 37 | 1.0.0 (2011-05-01) 38 | ------------------ 39 | - [MAJOR] Initial release 40 | -------------------------------------------------------------------------------- /Core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-core 30 | jar 31 | 32 | OddSource Code Java License Manager - Core 33 | 34 | 35 | 36 | commons-codec 37 | commons-codec 38 | compile 39 | 40 | 41 | 42 | commons-io 43 | commons-io 44 | compile 45 | 46 | 47 | 48 | 49 | source/production/java 50 | 51 | 52 | source/production/resources 53 | 54 | 55 | META-INF 56 | ../build/jar/META-INF 57 | 58 | 59 | 60 | source/test/java/unit 61 | 62 | 63 | source/test/resources 64 | 65 | 66 | 67 | 68 | 69 | org.apache.maven.plugins 70 | maven-jar-plugin 71 | 72 | 73 | 74 | test-jar 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | io/oddsource/java/licensing 83 | 84 | true 85 | 86 | 87 | 88 | io/oddsource/java/licensing/immutable 89 | 90 | true 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/DefaultLicenseValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import java.text.SimpleDateFormat; 19 | import java.util.Calendar; 20 | import java.util.Date; 21 | 22 | import io.oddsource.java.licensing.exception.ExpiredLicenseException; 23 | import io.oddsource.java.licensing.exception.InvalidLicenseException; 24 | 25 | /** 26 | * A default implementation of {@link LicenseValidator}, which simply checks that the license is active and not expired. 27 | * 28 | * @author Nick Williams 29 | * @version 1.0.0 30 | * @since 1.0.0 31 | */ 32 | public class DefaultLicenseValidator implements LicenseValidator 33 | { 34 | /** 35 | * Constructor. 36 | */ 37 | public DefaultLicenseValidator() 38 | { 39 | 40 | } 41 | 42 | /** 43 | * Ensures the current date is between the license's good-after and good-before dates (the license 44 | * has taken effect and hasn't expired). 45 | * 46 | * @param license The license to validate 47 | * 48 | * @throws InvalidLicenseException when the license is invalid for any reason; the implementer is required to 49 | * provide adequate description in this exception to indicate why the license is invalid; extending the 50 | * exception is encouraged 51 | * @see InvalidLicenseException 52 | * @see ExpiredLicenseException 53 | */ 54 | @Override 55 | public void validateLicense(final License license) throws InvalidLicenseException 56 | { 57 | final long time = Calendar.getInstance().getTimeInMillis(); 58 | if(license.getGoodAfterDate() > time) 59 | { 60 | throw new InvalidLicenseException( 61 | "The " + this.getLicenseDescription(license) + " does not take effect until " + 62 | this.getFormattedDate(license.getGoodAfterDate()) + "." 63 | ); 64 | } 65 | if(license.getGoodBeforeDate() < time) 66 | { 67 | throw new ExpiredLicenseException( 68 | "The " + this.getLicenseDescription(license) + " expired on " + 69 | this.getFormattedDate(license.getGoodAfterDate()) + "." 70 | ); 71 | } 72 | } 73 | 74 | /** 75 | * Gets a description for the given license, usually for displaying in some user interface. 76 | * 77 | * @param license The license 78 | * 79 | * @return the description. 80 | */ 81 | public String getLicenseDescription(final License license) 82 | { 83 | return license.getSubject() + " license for " + license.getHolder(); 84 | } 85 | 86 | /** 87 | * Gets a formatted date from the given milliseconds since January 1, 1970, 00:00:00 GMT, usually for displaying in 88 | * some user interface. 89 | * 90 | * @param time The milliseconds since January 1, 1970, 00:00:00 GMT 91 | * 92 | * @return the formatted date. 93 | */ 94 | public String getFormattedDate(final long time) 95 | { 96 | return new SimpleDateFormat("EEE, d MMM yyyy HH:mm:ss z (Z)").format(new Date(time)); 97 | } 98 | } 99 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/DeserializingLicenseProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | /** 19 | * An abstract implementation of the {@link LicenseProvider} interface that assumes the license will be stored in 20 | * serialized form. Users need only implement the method returning the raw byte data of the serialized license in order 21 | * to complete this implementation. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | public abstract class DeserializingLicenseProvider implements LicenseProvider 28 | { 29 | /** 30 | * Gets the stored, still-encrypted license content and signature from the persistence store. 31 | * 32 | * @param context The context for which to get the license 33 | * 34 | * @return the signed license object. 35 | */ 36 | @Override 37 | public final SignedLicense getLicense(final Object context) 38 | { 39 | final byte[] data = this.getLicenseData(context); 40 | 41 | return data == null ? null : this.deserializeLicense(data); 42 | } 43 | 44 | /** 45 | * Deserializes and returns the decrypted license content and signature from the provided bytes. 46 | * 47 | * @param data The license bytes 48 | * 49 | * @return the signed license object. 50 | */ 51 | public final SignedLicense deserializeLicense(final byte[] data) 52 | { 53 | return new ObjectSerializer().readObject(SignedLicense.class, data); 54 | } 55 | 56 | /** 57 | * Gets the stored, still-encrypted, still-serialized license content and signature from the persistence store. If 58 | * no license is found, this method should return null (not an empty array). 59 | * 60 | * @param context The context for which to get the license 61 | * 62 | * @return the signed license data. 63 | */ 64 | protected abstract byte[] getLicenseData(Object context); 65 | } 66 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/FeatureObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | /** 19 | * An interface that other objects can implement to indicate that they represent features. This can be especially 20 | * useful for decorating enums, for example, to represent valid features. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 27 | public interface FeatureObject 28 | { 29 | /** 30 | * Returns the name of this feature. 31 | * 32 | * @return The name 33 | */ 34 | public abstract String getName(); 35 | } 36 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/FeatureRestriction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import java.lang.annotation.Documented; 19 | import java.lang.annotation.ElementType; 20 | import java.lang.annotation.Retention; 21 | import java.lang.annotation.RetentionPolicy; 22 | import java.lang.annotation.Target; 23 | 24 | /** 25 | * An annotation for indicating license-restricted methods, packages and types. For example, one might set an AspectJ 26 | * pointcut that is intercepted and asserts that annotated accesses are done with permission. If not, it might throw an 27 | * exception, which would be caught by the user interface (such as a servlet filter in a Java EE environment) and 28 | * handled accordingly. 29 | * 30 | * @author Nick Williams 31 | * @version 1.0.0 32 | * @since 1.0.0 33 | */ 34 | @Documented 35 | @Target({ElementType.METHOD, ElementType.PACKAGE, ElementType.TYPE}) 36 | @Retention(RetentionPolicy.RUNTIME) 37 | public @interface FeatureRestriction 38 | { 39 | /** 40 | * The enum value. 41 | * 42 | * @return the value. 43 | */ 44 | String[] value(); 45 | 46 | /** 47 | * The operand that applies to this feature restriction. 48 | * 49 | * @return the operand. 50 | */ 51 | FeatureRestrictionOperand operand() default FeatureRestrictionOperand.AND; 52 | } 53 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/FeatureRestrictionOperand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | /** 19 | * Indicates whether feature restrictions are "all-or-nothing" ({@link #AND}) or "any" ({@link #OR}). 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | public enum FeatureRestrictionOperand 26 | { 27 | /** 28 | * This means the listed feature restrictions are all-or-nothing. 29 | */ 30 | AND, 31 | 32 | /** 33 | * This means the listed feature restrictions are any. 34 | */ 35 | OR, 36 | } 37 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/LicenseProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | /** 19 | * This specifies an interface for providing and persisting the stored, still-encrypted license content and signature 20 | * object. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 27 | public interface LicenseProvider 28 | { 29 | /** 30 | * Gets the stored, still-encrypted license content and signature from the persistence store. 31 | * 32 | * @param context The context for which to get the license 33 | * 34 | * @return the signed license object. 35 | */ 36 | public abstract SignedLicense getLicense(Object context); 37 | } 38 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/LicenseValidator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import io.oddsource.java.licensing.exception.ExpiredLicenseException; 19 | import io.oddsource.java.licensing.exception.InvalidLicenseException; 20 | 21 | /** 22 | * Specifies an interface for validating licenses. Users of License Manager do not have to implement this interface. 23 | * If it is not implemented, it is assumed that all licenses are valid. Users are encouraged, however, to implement 24 | * interface.
25 | *
26 | * There is a default implementation, {@link DefaultLicenseValidator}, that ensures the current date is between the 27 | * license's good-after and good-before dates (the license has taken effect and hasn't expired). 28 | * 29 | * @author Nick Williams 30 | * @version 1.0.1 31 | * @since 1.0.0 32 | */ 33 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 34 | public interface LicenseValidator 35 | { 36 | /** 37 | * Validates the license provided and throws an exception if the license is invalid for any reason 38 | * (expired, not who it belongs to, etc.). 39 | * 40 | * @param license The license to validate 41 | * 42 | * @throws InvalidLicenseException when the license is invalid for any reason; the implementer is required to 43 | * provide adequate description in this exception to indicate why the license is invalid; extending the 44 | * exception is encouraged. 45 | * @throws ExpiredLicenseException when the license is expired. 46 | */ 47 | public abstract void validateLicense(License license) throws InvalidLicenseException; 48 | } 49 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/LicensingCharsets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import java.nio.charset.Charset; 19 | import java.nio.charset.StandardCharsets; 20 | 21 | /** 22 | * Defines the default character set used in license serialization and deserialization. 23 | * 24 | * @author Nick Williams 25 | * @version 1.0.0 26 | * @since 1.1.0 27 | */ 28 | public final class LicensingCharsets 29 | { 30 | /** 31 | * All operations in License Manager use the universal UTF-8 character set. 32 | */ 33 | public static final Charset UTF_8 = StandardCharsets.UTF_8; 34 | 35 | /** 36 | * This class cannot be instantiated. 37 | */ 38 | private LicensingCharsets() 39 | { 40 | throw new AssertionError("This class cannot be instantiated."); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/ObjectSerializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import java.io.ByteArrayInputStream; 19 | import java.io.IOException; 20 | import java.io.ObjectInputStream; 21 | import java.io.ObjectOutputStream; 22 | import java.io.Serializable; 23 | 24 | import org.apache.commons.io.output.ByteArrayOutputStream; 25 | 26 | import io.oddsource.java.licensing.exception.ObjectDeserializationException; 27 | import io.oddsource.java.licensing.exception.ObjectSerializationException; 28 | import io.oddsource.java.licensing.exception.ObjectTypeNotExpectedException; 29 | 30 | /** 31 | * This is a helper class for writing any object and reading simple objects (no 32 | * arrays, collections, or generic top-level objects) to and from byte arrays. 33 | * 34 | * @author Nick Williams 35 | * @version 1.0.0 36 | * @since 1.0.0 37 | */ 38 | public final class ObjectSerializer 39 | { 40 | /** 41 | * Constructor. 42 | */ 43 | public ObjectSerializer() 44 | { 45 | 46 | } 47 | 48 | /** 49 | * Deserializes an object of the specified type from the provided byte stream. 50 | * 51 | * @param expectedType The type that is expected to be retrieved from {@code byteStream} (must implement {@link 52 | * Serializable}) 53 | * @param byteStream The byte stream to retrieve the object from (it must contain exactly one object, of the 54 | * exact type passed to {@code expectedType}) 55 | * @param Any serializable object type 56 | * 57 | * @return the requested unserialized object, presumably in the stream. 58 | * 59 | * @throws ObjectTypeNotExpectedException If the object found in the stream does not match the type {@code 60 | * expectedType} or if a {@link ClassNotFoundException} or {@link NoClassDefFoundError} occurs 61 | * @throws ObjectDeserializationException If an I/O exception occurs while deserializing the object from the 62 | * stream 63 | */ 64 | public final T readObject(final Class expectedType, final byte[] byteStream) 65 | throws ObjectDeserializationException 66 | { 67 | final ByteArrayInputStream bytes = new ByteArrayInputStream(byteStream); 68 | try(final ObjectInputStream stream = new ObjectInputStream(bytes)) 69 | { 70 | final Object allegedObject = stream.readObject(); 71 | if(!expectedType.isInstance(allegedObject)) 72 | { 73 | throw new ObjectTypeNotExpectedException( 74 | expectedType.getName(), 75 | allegedObject.getClass().getName() 76 | ); 77 | } 78 | 79 | return expectedType.cast(allegedObject); 80 | } 81 | catch(final IOException e) 82 | { 83 | throw new ObjectDeserializationException( 84 | "An I/O error occurred while reading the object from the byte array.", 85 | e 86 | ); 87 | } 88 | catch(final ClassNotFoundException | NoClassDefFoundError e) 89 | { 90 | throw new ObjectTypeNotExpectedException( 91 | expectedType.getName(), 92 | e.getMessage(), 93 | e 94 | ); 95 | } 96 | } 97 | 98 | /** 99 | * Serializes the {@link Serializable} object passed and returns it as a byte array. 100 | * 101 | * @param object The object to serialize 102 | * 103 | * @return the byte stream with the object serialized in it. 104 | * 105 | * @throws ObjectSerializationException if an I/O exception occurs while serializing the object. 106 | */ 107 | public final byte[] writeObject(final Serializable object) throws ObjectSerializationException 108 | { 109 | final ByteArrayOutputStream bytes = new ByteArrayOutputStream(); 110 | 111 | try(final ObjectOutputStream stream = new ObjectOutputStream(bytes)) 112 | { 113 | stream.writeObject(object); 114 | } 115 | catch(final IOException e) 116 | { 117 | throw new ObjectSerializationException(e); 118 | } 119 | 120 | return bytes.toByteArray(); 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/SignedLicense.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import java.io.Serializable; 19 | import java.util.Arrays; 20 | 21 | /** 22 | * This class contains the encrypted license content and the signature for the encrypted license content. 23 | * 24 | * @author Nick Williams 25 | * @version 1.0.0 26 | * @since 1.0.0 27 | */ 28 | public final class SignedLicense implements Serializable 29 | { 30 | private final static long serialVersionUID = -8465360339059185020L; 31 | 32 | private final byte[] licenseContent; 33 | 34 | private final byte[] signatureContent; 35 | 36 | /** 37 | * Constructor. 38 | * 39 | * @param licenseContent The license content 40 | * @param signatureContent The signature for the license content 41 | */ 42 | public SignedLicense(final byte[] licenseContent, final byte[] signatureContent) 43 | { 44 | this.licenseContent = Arrays.copyOf(licenseContent, licenseContent.length); 45 | this.signatureContent = Arrays.copyOf(signatureContent, signatureContent.length); 46 | } 47 | 48 | /** 49 | * Get the content of the actual license object. This is encrypted and 50 | * corresponds to {@link License}. For security reasons, only a copy of 51 | * the content is returned. 52 | * 53 | * @return the encrypted license content. 54 | */ 55 | public final byte[] getLicenseContent() 56 | { 57 | return Arrays.copyOf(this.licenseContent, this.licenseContent.length); 58 | } 59 | 60 | /** 61 | * Get the signature for the license content. For security reasons, only a 62 | * copy of the signature is returned. 63 | * 64 | * @return the license signature. 65 | */ 66 | public final byte[] getSignatureContent() 67 | { 68 | return Arrays.copyOf(this.signatureContent, this.signatureContent.length); 69 | } 70 | 71 | /** 72 | * Erase the contents of this object. This is a security feature to write 73 | * zeroes to the license and signature data so that it doesn't hang around 74 | * in memory where it might be reverse engineered. 75 | */ 76 | protected final void erase() 77 | { 78 | Arrays.fill(this.licenseContent, (byte) 0); 79 | Arrays.fill(this.signatureContent, (byte) 0); 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/encryption/FilePublicKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.encryption; 17 | 18 | import java.io.File; 19 | import java.io.FileNotFoundException; 20 | import java.io.IOException; 21 | 22 | import org.apache.commons.io.FileUtils; 23 | 24 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 25 | 26 | /** 27 | * A default implementation of {@link PublicKeyDataProvider} that reads the public key from a file.
28 | *
29 | * This provider is immutable. Once created, the file that the public key is located at cannot be changed. 30 | * 31 | * @author Nick Williams 32 | * @version 1.0.0 33 | * @since 1.0.0 34 | */ 35 | public class FilePublicKeyDataProvider implements PublicKeyDataProvider 36 | { 37 | private final File publicKeyFile; 38 | 39 | /** 40 | * Create a new provider, specifying the file from which the public key can be read. 41 | * 42 | * @param publicKeyFile the public key file 43 | */ 44 | public FilePublicKeyDataProvider(final File publicKeyFile) 45 | { 46 | this.publicKeyFile = publicKeyFile.getAbsoluteFile(); 47 | } 48 | 49 | /** 50 | * Create a new provider, specifying the name of the file from which the public key can be read. 51 | * 52 | * @param publicKeyFileName The public key file name 53 | */ 54 | public FilePublicKeyDataProvider(final String publicKeyFileName) 55 | { 56 | this.publicKeyFile = new File(publicKeyFileName).getAbsoluteFile(); 57 | } 58 | 59 | /** 60 | * This method returns the data from the file containing the encrypted 61 | * public key from the public/private key pair. The contract for this 62 | * method can be fulfilled by storing the data in a byte array literal 63 | * in the source code itself.
64 | *
65 | * It is imperative that you obfuscate the bytecode for the 66 | * implementation of this class. It is also imperative that the byte 67 | * array exist only for the life of this method (i.e., DO NOT store it as 68 | * an instance or class field). 69 | * 70 | * @return the encrypted file contents from the public key file. 71 | * 72 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 73 | * must be provided. 74 | */ 75 | @Override 76 | public byte[] getEncryptedPublicKeyData() throws KeyNotFoundException 77 | { 78 | try 79 | { 80 | return FileUtils.readFileToByteArray(this.publicKeyFile); 81 | } 82 | catch(final FileNotFoundException e) 83 | { 84 | throw new KeyNotFoundException( 85 | "The public key file [" + this.publicKeyFile.getPath() + "] does not exist." 86 | ); 87 | } 88 | catch(final IOException e) 89 | { 90 | throw new KeyNotFoundException( 91 | "Could not read from the public key file [" + this.publicKeyFile.getPath() + "].", 92 | e 93 | ); 94 | } 95 | } 96 | 97 | /** 98 | * Gets the file that the public key is located at. 99 | * 100 | * @return the file. 101 | */ 102 | public File getPublicKeyFile() 103 | { 104 | return this.publicKeyFile; 105 | } 106 | } 107 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/encryption/Hasher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.encryption; 17 | 18 | import java.security.MessageDigest; 19 | import java.security.NoSuchAlgorithmException; 20 | 21 | import org.apache.commons.codec.binary.Base64; 22 | 23 | import io.oddsource.java.licensing.LicensingCharsets; 24 | import io.oddsource.java.licensing.exception.AlgorithmNotSupportedException; 25 | 26 | /** 27 | * Used for creating hash keys of things that won't need to be unencrypted. 28 | * 29 | * @author Nick Williams 30 | * @version 1.0.0 31 | * @since 1.0.0 32 | */ 33 | public final class Hasher 34 | { 35 | /** 36 | * The algorithm we use to hash strings. 37 | */ 38 | private static final String algorithm = "SHA-512"; 39 | 40 | /** 41 | * The salt that we use to hash strings. 42 | */ 43 | private static final String salt = "j4KgU305PZp't.\"%ordAY7q*?z9%8]amNL(0Wx5eG49b1sRj(^;8Kg2w0EoM"; 44 | 45 | /** 46 | * This class cannot be instantiated. 47 | */ 48 | private Hasher() 49 | { 50 | throw new RuntimeException("This class cannot be instantiated."); 51 | } 52 | 53 | /** 54 | * Calculate the SHA-512 message digest hash of the 55 | * provided string and return it with its binary 56 | * data Base64 encoded. 57 | * 58 | * @param string The string to hash 59 | * 60 | * @return the hashed string Base64 encoded. 61 | */ 62 | public static String hash(final String string) 63 | { 64 | try 65 | { 66 | return new String( 67 | Base64.encodeBase64( 68 | MessageDigest.getInstance(Hasher.algorithm).digest( 69 | (string + Hasher.salt).getBytes(LicensingCharsets.UTF_8) 70 | ) 71 | ), 72 | LicensingCharsets.UTF_8 73 | ); 74 | } 75 | catch(final NoSuchAlgorithmException e) 76 | { 77 | throw new AlgorithmNotSupportedException(Hasher.algorithm, e); 78 | } 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/encryption/PasswordProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.encryption; 17 | 18 | import io.oddsource.java.licensing.LicenseManager; 19 | 20 | /** 21 | * This specifies an interface for providing a password for decrypting a key or license. Every user of this library 22 | * must implement this (one to three times). See the documentation for 23 | * {@code io.oddsource.java.licensing.encryption.RSAKeyPairGenerator}, 24 | * {@code io.oddsource.java.licensing.licensor.LicenseCreator} and 25 | * {@link LicenseManager} for more information. 26 | * 27 | * @author Nick Williams 28 | * @version 1.5.0 29 | * @since 1.0.0 30 | */ 31 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 32 | public interface PasswordProvider 33 | { 34 | /** 35 | * When integrating the license manager in your application, you must 36 | * implement this interface. It should return the password that you used 37 | * when encrypting the key or license.
38 | *
39 | * Also, do not implement this using any strings, i.e:
40 | *
41 | * 42 | * return "myInsecurePassword".toCharArray(); 43 | *
44 | *
45 | * Strings persist in memory for a long time, and the string's contents 46 | * cannot be overwritten. Using only a character array allows the license 47 | * manager to overwrite the password when it is finished with it, thus 48 | * keeping it in the memory pool for as short a time as possible.
49 | *
50 | * Finally, the password must be between six and 32 characters 51 | * (inclusively). We recommend it be at least 10 characters.
52 | *
53 | * It is imperative that you obfuscate the bytecode for the 54 | * implementation of this class. It is also imperative that the character 55 | * array exist only for the life of this method (i.e., DO NOT store it as 56 | * an instance or class field). 57 | * 58 | * @return the password in character array form. 59 | */ 60 | public abstract char[] getPassword(); 61 | } 62 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/encryption/PublicKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.encryption; 17 | 18 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 19 | 20 | /** 21 | * Specifies an interface for retrieving the public key file data. This 22 | * interface only needs to be implemented in the application using the 23 | * licenses. It need not be implemented in the application generating the 24 | * licenses. 25 | * 26 | * @author Nick Williams 27 | * @version 1.0.0 28 | * @since 1.0.0 29 | */ 30 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 31 | public interface PublicKeyDataProvider 32 | { 33 | /** 34 | * This method returns the data from the file containing the encrypted 35 | * public key from the public/private key pair. The contract for this 36 | * method can be fulfilled by storing the data in a byte array literal 37 | * in the source code itself.
38 | *
39 | * It is imperative that you obfuscate the bytecode for the 40 | * implementation of this class. It is also imperative that the byte 41 | * array exist only for the life of this method (i.e., DO NOT store it as 42 | * an instance or class field). 43 | * 44 | * @return the encrypted file contents from the public key file. 45 | * 46 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 47 | * must be provided. 48 | */ 49 | public abstract byte[] getEncryptedPublicKeyData() throws KeyNotFoundException; 50 | } 51 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/encryption/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains helpers and utilities for encryption and decryption. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.encryption; 24 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/AlgorithmNotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This exception is thrown when the specified algorithm is not supported by 20 | * this JVM. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class AlgorithmNotSupportedException extends RuntimeException 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | */ 34 | public AlgorithmNotSupportedException() 35 | { 36 | super("The specified algorithm is not supported on this system."); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param algorithm The algorithm 43 | */ 44 | public AlgorithmNotSupportedException(final String algorithm) 45 | { 46 | super("The algorithm \"" + algorithm + "\" is not supported on this system."); 47 | } 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param cause The cause 53 | */ 54 | public AlgorithmNotSupportedException(final Throwable cause) 55 | { 56 | super(cause); 57 | } 58 | 59 | /** 60 | * Constructor. 61 | * 62 | * @param algorithm The algorithm 63 | * @param cause The cause 64 | */ 65 | public AlgorithmNotSupportedException(final String algorithm, final Throwable cause) 66 | { 67 | super("The algorithm \"" + algorithm + "\" is not supported on this system.", cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/CorruptSignatureException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This is thrown when a corrupt signature ar non-signature is provided. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | @SuppressWarnings("unused") 26 | public class CorruptSignatureException extends RuntimeException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | public CorruptSignatureException() 34 | { 35 | super("The signature provided is corrupt or not a signature."); 36 | } 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param message The message 42 | */ 43 | public CorruptSignatureException(final String message) 44 | { 45 | super(message); 46 | } 47 | 48 | /** 49 | * Constructor. 50 | * 51 | * @param cause The cause 52 | */ 53 | public CorruptSignatureException(final Throwable cause) 54 | { 55 | super("The signature provided is corrupt or not a signature.", cause); 56 | } 57 | 58 | /** 59 | * Constructor. 60 | * 61 | * @param message The message 62 | * @param cause The cause 63 | */ 64 | public CorruptSignatureException(final String message, final Throwable cause) 65 | { 66 | super(message, cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/ExpiredLicenseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | import io.oddsource.java.licensing.LicenseValidator; 19 | 20 | /** 21 | * This exception is thrown whenever a license is validated that has expired. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @see LicenseValidator 26 | * @since 1.0.0 27 | */ 28 | @SuppressWarnings("unused") 29 | public class ExpiredLicenseException extends InvalidLicenseException 30 | { 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Constructor. 35 | */ 36 | public ExpiredLicenseException() 37 | { 38 | super("The license has expired."); 39 | } 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param message The message 45 | */ 46 | public ExpiredLicenseException(final String message) 47 | { 48 | super(message); 49 | } 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @param cause The cause 55 | */ 56 | public ExpiredLicenseException(final Throwable cause) 57 | { 58 | super("The license has expired.", cause); 59 | } 60 | 61 | /** 62 | * Constructor. 63 | * 64 | * @param message The message 65 | * @param cause The cause 66 | */ 67 | public ExpiredLicenseException(final String message, final Throwable cause) 68 | { 69 | super(message, cause); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/FailedToDecryptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This exception is thrown when the data was corrupt and undecryptable or when 20 | * the provided decryption password was incorrect. It is impossible to know 21 | * which is the actual cause. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | @SuppressWarnings("unused") 28 | public class FailedToDecryptException extends RuntimeException 29 | { 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Constructor. 34 | */ 35 | public FailedToDecryptException() 36 | { 37 | super("Failed to decrypt the data. Either the password was incorrect or the data was corrupt."); 38 | } 39 | 40 | /** 41 | * Constructor. 42 | * 43 | * @param message The message 44 | */ 45 | public FailedToDecryptException(final String message) 46 | { 47 | super(message); 48 | } 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param cause The cause 54 | */ 55 | public FailedToDecryptException(final Throwable cause) 56 | { 57 | super("Failed to decrypt the data. Either the password was incorrect or the data was corrupt.", cause); 58 | } 59 | 60 | /** 61 | * Constructor. 62 | * 63 | * @param message The message 64 | * @param cause The cause 65 | */ 66 | public FailedToDecryptException(final String message, final Throwable cause) 67 | { 68 | super(message, cause); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/FailedToEncryptException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This exception is thrown when the data was corrupt and undecryptable or when 20 | * the provided decryption password was incorrect. It is impossible to know 21 | * which is the actual cause. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | @SuppressWarnings("unused") 28 | public class FailedToEncryptException extends RuntimeException 29 | { 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Constructor. 34 | */ 35 | public FailedToEncryptException() 36 | { 37 | super("Failed to decrypt the data. Either the password was incorrect or the data was corrupt."); 38 | } 39 | 40 | /** 41 | * Constructor. 42 | * 43 | * @param message The message 44 | */ 45 | public FailedToEncryptException(final String message) 46 | { 47 | super(message); 48 | } 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param cause The cause 54 | */ 55 | public FailedToEncryptException(final Throwable cause) 56 | { 57 | super("Failed to decrypt the data. Either the password was incorrect or the data was corrupt.", cause); 58 | } 59 | 60 | /** 61 | * Constructor. 62 | * 63 | * @param message The message 64 | * @param cause The cause 65 | */ 66 | public FailedToEncryptException(final String message, final Throwable cause) 67 | { 68 | super(message, cause); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/InappropriateKeyException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This exception is thrown when the specified key is inappropriate for the 20 | * given cipher. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class InappropriateKeyException extends RuntimeException 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | */ 34 | public InappropriateKeyException() 35 | { 36 | super("The specified key is inappropriate for the cipher."); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param message The message 43 | */ 44 | public InappropriateKeyException(final String message) 45 | { 46 | super(message); 47 | } 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param cause The cause 53 | */ 54 | public InappropriateKeyException(final Throwable cause) 55 | { 56 | super("The specified key is inappropriate for the cipher.", cause); 57 | } 58 | 59 | /** 60 | * Constructor. 61 | * 62 | * @param message The message 63 | * @param cause The cause 64 | */ 65 | public InappropriateKeyException(final String message, final Throwable cause) 66 | { 67 | super(message, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/InappropriateKeySpecificationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This exception is thrown when an inappropriate key specification is provided 20 | * for the key factory. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class InappropriateKeySpecificationException extends RuntimeException 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | */ 34 | public InappropriateKeySpecificationException() 35 | { 36 | super("The specified key specification is inappropriate for the factory."); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param message The message 43 | */ 44 | public InappropriateKeySpecificationException(final String message) 45 | { 46 | super(message); 47 | } 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param cause The cause 53 | */ 54 | public InappropriateKeySpecificationException(final Throwable cause) 55 | { 56 | super("The specified key specification is inappropriate for the factory.", cause); 57 | } 58 | 59 | /** 60 | * Constructor. 61 | * 62 | * @param message The message 63 | * @param cause The cause 64 | */ 65 | public InappropriateKeySpecificationException(final String message, final Throwable cause) 66 | { 67 | super(message, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/InsecureEnvironmentError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * Thrown when a security manager is already installed that allows reflection access but doesn't allow a more secure 20 | * security manager to be installed. See {@code LicenseSecurityManager}. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class InsecureEnvironmentError extends Error 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | * 34 | * @param message The message 35 | * @param cause The cause 36 | */ 37 | public InsecureEnvironmentError(final String message, final Throwable cause) 38 | { 39 | super("The license manager was activated in an insecure environment. " + message, cause); 40 | } 41 | 42 | /** 43 | * Constructor. 44 | * 45 | * @param cause The cause 46 | */ 47 | public InsecureEnvironmentError(final SecurityException cause) 48 | { 49 | super("The license manager was activated in an insecure environment. A security manager has already been " + 50 | "installed, but it allows reflection access to the license cache and doesn't allow a new security " + 51 | "manager to be installed.", cause); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/InvalidLicenseException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | import io.oddsource.java.licensing.LicenseValidator; 19 | 20 | /** 21 | * This exception is thrown whenever a license is validated that isn't valid for some reason. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @see LicenseValidator 26 | * @since 1.0.0 27 | */ 28 | @SuppressWarnings("unused") 29 | public class InvalidLicenseException extends RuntimeException 30 | { 31 | private static final long serialVersionUID = 1L; 32 | 33 | /** 34 | * Constructor. 35 | */ 36 | public InvalidLicenseException() 37 | { 38 | super("The license is not valid."); 39 | } 40 | 41 | /** 42 | * Constructor. 43 | * 44 | * @param message The message 45 | */ 46 | public InvalidLicenseException(final String message) 47 | { 48 | super(message); 49 | } 50 | 51 | /** 52 | * Constructor. 53 | * 54 | * @param cause The cause 55 | */ 56 | public InvalidLicenseException(final Throwable cause) 57 | { 58 | super("The license is not valid.", cause); 59 | } 60 | 61 | /** 62 | * Constructor. 63 | * 64 | * @param message The message 65 | * @param cause The cause 66 | */ 67 | public InvalidLicenseException(final String message, final Throwable cause) 68 | { 69 | super(message, cause); 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/InvalidSignatureException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This is thrown when a signature is invalid and cannot be verified. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | @SuppressWarnings("unused") 26 | public class InvalidSignatureException extends RuntimeException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | public InvalidSignatureException() 34 | { 35 | super("The signature provided is invalid and cannot be verified."); 36 | } 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param message The message 42 | */ 43 | public InvalidSignatureException(final String message) 44 | { 45 | super(message); 46 | } 47 | 48 | /** 49 | * Constructor. 50 | * 51 | * @param cause The cause 52 | */ 53 | public InvalidSignatureException(final Throwable cause) 54 | { 55 | super("The signature provided is invalid and cannot be verified.", cause); 56 | } 57 | 58 | /** 59 | * Constructor. 60 | * 61 | * @param message The message 62 | * @param cause The cause 63 | */ 64 | public InvalidSignatureException(final String message, final Throwable cause) 65 | { 66 | super(message, cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/KeyNotFoundException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This is thrown when the key (file) could not be found. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | @SuppressWarnings("unused") 26 | public class KeyNotFoundException extends RuntimeException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | public KeyNotFoundException() 34 | { 35 | super("The key file could not be found."); 36 | } 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param message The message 42 | */ 43 | public KeyNotFoundException(final String message) 44 | { 45 | super(message); 46 | } 47 | 48 | /** 49 | * Constructor. 50 | * 51 | * @param cause The cause 52 | */ 53 | public KeyNotFoundException(final Throwable cause) 54 | { 55 | super("The key file could not be found.", cause); 56 | } 57 | 58 | /** 59 | * Constructor. 60 | * 61 | * @param message The message 62 | * @param cause The cause 63 | */ 64 | public KeyNotFoundException(final String message, final Throwable cause) 65 | { 66 | super(message, cause); 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/ObjectDeserializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This class is thrown when an error occurs while reading an object from a 20 | * byte array. The general form of this error indicates an I/O problem. 21 | * Sub-classes of this exception indicate more specific problems. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | @SuppressWarnings("unused") 28 | public class ObjectDeserializationException extends RuntimeException 29 | { 30 | private static final long serialVersionUID = 1L; 31 | 32 | /** 33 | * Constructor. 34 | */ 35 | public ObjectDeserializationException() 36 | { 37 | super("An error occurred while reading the object from the byte array."); 38 | } 39 | 40 | /** 41 | * Constructor. 42 | * 43 | * @param message The message 44 | */ 45 | public ObjectDeserializationException(final String message) 46 | { 47 | super(message); 48 | } 49 | 50 | /** 51 | * Constructor. 52 | * 53 | * @param cause The cause 54 | */ 55 | public ObjectDeserializationException(final Throwable cause) 56 | { 57 | super("An error occurred while reading the object from the byte array.", cause); 58 | } 59 | 60 | /** 61 | * Constructor. 62 | * 63 | * @param message The message 64 | * @param cause The cause 65 | */ 66 | public ObjectDeserializationException(final String message, final Throwable cause) 67 | { 68 | super(message, cause); 69 | } 70 | } 71 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/ObjectSerializationException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This class is thrown when an I/O error occurs while writing an object to a 20 | * byte array. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class ObjectSerializationException extends RuntimeException 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | */ 34 | public ObjectSerializationException() 35 | { 36 | super("An I/O error occurred while writing the object to the byte array."); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param message The message 43 | */ 44 | public ObjectSerializationException(final String message) 45 | { 46 | super(message); 47 | } 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param cause The cause 53 | */ 54 | public ObjectSerializationException(final Throwable cause) 55 | { 56 | super("An I/O error occurred while writing the object to the byte array.", cause); 57 | } 58 | 59 | /** 60 | * Constructor. 61 | * 62 | * @param message The message 63 | * @param cause The cause 64 | */ 65 | public ObjectSerializationException(final String message, final Throwable cause) 66 | { 67 | super(message, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/ObjectTypeNotExpectedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.exception; 17 | 18 | /** 19 | * This class class is thrown when an object is deserialized that does not match the type that was expected. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | @SuppressWarnings("unused") 26 | public class ObjectTypeNotExpectedException extends ObjectDeserializationException 27 | { 28 | private static final long serialVersionUID = 1L; 29 | 30 | /** 31 | * Constructor. 32 | */ 33 | public ObjectTypeNotExpectedException() 34 | { 35 | super("The type of object read did not match the type expected."); 36 | } 37 | 38 | /** 39 | * Constructor. 40 | * 41 | * @param message The message 42 | */ 43 | public ObjectTypeNotExpectedException(final String message) 44 | { 45 | super(message); 46 | } 47 | 48 | /** 49 | * Constructor. 50 | * 51 | * @param expectedType The expected type 52 | * @param encounteredType The encountered type 53 | */ 54 | public ObjectTypeNotExpectedException(final String expectedType, final String encounteredType) 55 | { 56 | super("While deserializing an object of expected type \"" + expectedType + "\", got an object of type \"" + 57 | encounteredType + "\" instead."); 58 | } 59 | 60 | /** 61 | * Constructor. 62 | * 63 | * @param cause The cause. 64 | */ 65 | public ObjectTypeNotExpectedException(final Throwable cause) 66 | { 67 | super("The type of object read did not match the type expected.", cause); 68 | } 69 | 70 | /** 71 | * Constructor. 72 | * 73 | * @param message The message 74 | * @param cause The cause 75 | */ 76 | public ObjectTypeNotExpectedException(final String message, final Throwable cause) 77 | { 78 | super(message, cause); 79 | } 80 | 81 | /** 82 | * Constructor. 83 | * 84 | * @param expectedType The expected type 85 | * @param encounteredType The encountered type 86 | * @param cause The cause 87 | */ 88 | public ObjectTypeNotExpectedException( 89 | final String expectedType, 90 | final String encounteredType, 91 | final Throwable cause 92 | ) 93 | { 94 | super("While deserializing an object of expected type \"" + expectedType + "\", got an object of type \"" + 95 | encounteredType + "\" instead.", cause); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains all custom exceptions thrown by the License Manager. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.exception; 24 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/Immutable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | /** 19 | * This interface denotes a collection or other object as being unmodifiable. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | @SuppressWarnings("unused") 26 | public interface Immutable 27 | { 28 | 29 | } 30 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/ImmutableIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | import java.util.Iterator; 19 | 20 | /** 21 | * Wraps an iterator such that it cannot be modified. 22 | * 23 | * @param Any object 24 | * 25 | * @author Nick Williams 26 | * @version 1.0.0 27 | * @since 1.0.0 28 | */ 29 | public final class ImmutableIterator implements Immutable, Iterator 30 | { 31 | private final Iterator internal; 32 | 33 | private final ValidObject validObject; 34 | 35 | ImmutableIterator(final Iterator iterator, final ValidObject validObject) 36 | { 37 | this.internal = iterator; 38 | this.validObject = validObject; 39 | } 40 | 41 | @Override 42 | public boolean hasNext() 43 | { 44 | synchronized(this.validObject) 45 | { 46 | this.validObject.checkValidity(); 47 | return this.internal.hasNext(); 48 | } 49 | } 50 | 51 | @Override 52 | public E next() 53 | { 54 | synchronized(this.validObject) 55 | { 56 | this.validObject.checkValidity(); 57 | return this.internal.next(); 58 | } 59 | } 60 | 61 | @Override 62 | public void remove() 63 | { 64 | throw new UnsupportedOperationException("This iterator cannot be modified."); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/ImmutableLinkedHashSet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | import java.io.Serializable; 19 | import java.util.ArrayList; 20 | import java.util.LinkedHashSet; 21 | import java.util.Set; 22 | 23 | /** 24 | * Wraps a set such that it cannot be modified. There is some overhead 25 | * associated with this due to verification of hash codes on every call to 26 | * prevent tampering with via reflection, but this is well worth it if your goal 27 | * is security and you truly need an unmodifiable set. 28 | * 29 | * @param Any object 30 | * 31 | * @author Nick Williams 32 | * @version 1.5.0 33 | * @since 1.0.0 34 | */ 35 | public final class ImmutableLinkedHashSet extends ImmutableAbstractCollection 36 | implements Set, Serializable, Cloneable 37 | { 38 | private final static long serialVersionUID = 2284350955829958161L; 39 | 40 | private final LinkedHashSet internalSet; 41 | 42 | private final ArrayList internalList; 43 | 44 | /** 45 | * Constructor that copies. 46 | * 47 | * @param list the set to decorate, must not be null 48 | * 49 | * @throws IllegalArgumentException if list is null 50 | */ 51 | public ImmutableLinkedHashSet(final Set list) 52 | { 53 | super(new LinkedHashSet<>(list)); 54 | 55 | this.internalSet = (LinkedHashSet) this.internalCollection; 56 | this.internalList = new ArrayList<>(list); 57 | } 58 | 59 | @Override 60 | @SuppressWarnings({"unchecked", "CloneDoesntCallSuperClone"}) 61 | public final ImmutableLinkedHashSet clone() 62 | { 63 | synchronized(this.internalSet) 64 | { 65 | this.checkValidity(); 66 | return new ImmutableLinkedHashSet<>((Set) this.internalSet.clone()); 67 | } 68 | } 69 | 70 | /** 71 | * Retrieves the indexed element specified. 72 | * 73 | * @param index The element to retrieve. 74 | * 75 | * @return The element requested. 76 | */ 77 | public E get(final int index) 78 | { 79 | return index < 0 ? null : this.internalList.get(index); 80 | } 81 | 82 | /** 83 | * Retrieves the matching element specified. 84 | * 85 | * @param object The element to match. 86 | * 87 | * @return The element requested. 88 | */ 89 | public E get(final E object) 90 | { 91 | return this.get(this.internalList.indexOf(object)); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/ImmutableListIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | import java.util.ListIterator; 19 | 20 | /** 21 | * Wraps a list iterator such that it cannot be modified. 22 | * 23 | * @param Any object 24 | * 25 | * @author Nick Williams 26 | * @version 1.0.0 27 | * @since x.x.x 28 | */ 29 | public final class ImmutableListIterator implements Immutable, ListIterator 30 | { 31 | private final ListIterator internal; 32 | 33 | private final ValidObject validObject; 34 | 35 | ImmutableListIterator(final ListIterator iterator, final ValidObject validObject) 36 | { 37 | this.internal = iterator; 38 | this.validObject = validObject; 39 | } 40 | 41 | @Override 42 | public boolean hasNext() 43 | { 44 | synchronized(this.validObject) 45 | { 46 | this.validObject.checkValidity(); 47 | return this.internal.hasNext(); 48 | } 49 | } 50 | 51 | @Override 52 | public boolean hasPrevious() 53 | { 54 | synchronized(this.validObject) 55 | { 56 | this.validObject.checkValidity(); 57 | return this.internal.hasPrevious(); 58 | } 59 | } 60 | 61 | @Override 62 | public E next() 63 | { 64 | synchronized(this.validObject) 65 | { 66 | this.validObject.checkValidity(); 67 | return this.internal.next(); 68 | } 69 | } 70 | 71 | @Override 72 | public int nextIndex() 73 | { 74 | synchronized(this.validObject) 75 | { 76 | this.validObject.checkValidity(); 77 | return this.internal.nextIndex(); 78 | } 79 | } 80 | 81 | @Override 82 | public E previous() 83 | { 84 | synchronized(this.validObject) 85 | { 86 | this.validObject.checkValidity(); 87 | return this.internal.previous(); 88 | } 89 | } 90 | 91 | @Override 92 | public int previousIndex() 93 | { 94 | synchronized(this.validObject) 95 | { 96 | this.validObject.checkValidity(); 97 | return this.internal.previousIndex(); 98 | } 99 | } 100 | 101 | @Override 102 | public void add(final E e) 103 | { 104 | throw new UnsupportedOperationException(ImmutableAbstractCollection.modificationProhibited); 105 | } 106 | 107 | @Override 108 | public void remove() 109 | { 110 | throw new UnsupportedOperationException(ImmutableAbstractCollection.modificationProhibited); 111 | } 112 | 113 | @Override 114 | public void set(final E e) 115 | { 116 | throw new UnsupportedOperationException(ImmutableAbstractCollection.modificationProhibited); 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/ImmutableModifiedThroughReflectionError.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | /** 19 | * This exception is thrown when an unmodifiable list is modified illegally 20 | * through exception. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class ImmutableModifiedThroughReflectionError extends Error 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | private static final String defaultMessage = 32 | "This immutable object appears to have been modified through reflection."; 33 | 34 | /** 35 | * Constructor. 36 | */ 37 | public ImmutableModifiedThroughReflectionError() 38 | { 39 | super(ImmutableModifiedThroughReflectionError.defaultMessage); 40 | } 41 | 42 | /** 43 | * Constructor. 44 | * 45 | * @param message The message 46 | */ 47 | public ImmutableModifiedThroughReflectionError(final String message) 48 | { 49 | super(message); 50 | } 51 | 52 | /** 53 | * Constructor. 54 | * 55 | * @param cause The cause 56 | */ 57 | public ImmutableModifiedThroughReflectionError(final Throwable cause) 58 | { 59 | super(ImmutableModifiedThroughReflectionError.defaultMessage, cause); 60 | } 61 | 62 | /** 63 | * Constructor. 64 | * 65 | * @param message The message 66 | * @param cause The cause 67 | */ 68 | public ImmutableModifiedThroughReflectionError(final String message, final Throwable cause) 69 | { 70 | super(message, cause); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/ValidObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | /** 19 | * This class specifies an interface for checking the validity of an object. It 20 | * is specified as an abstract class instead of an interface so that the 21 | * implementing classes can keep the target method protected. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | abstract class ValidObject 28 | { 29 | /** 30 | * Checks the validity of this object, and throws an 31 | * {@link ImmutableModifiedThroughReflectionError} if that check fails. 32 | * 33 | * @throws ImmutableModifiedThroughReflectionError if the validity check fails. 34 | */ 35 | protected abstract void checkValidity(); 36 | } 37 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/immutable/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains several immutable collection types used to keep license data secure. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.immutable; 24 | -------------------------------------------------------------------------------- /Core/source/production/java/io/oddsource/java/licensing/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * The base package for all OddSource Code Java License Manager classes and packages. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing; 24 | -------------------------------------------------------------------------------- /Core/source/production/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Core/source/production/resources/.gitkeep -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/MockLicenseHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | public final class MockLicenseHelper 19 | { 20 | private MockLicenseHelper() 21 | { 22 | 23 | } 24 | 25 | public static License deserialize(byte[] data) 26 | { 27 | return License.deserialize(data); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/TestDeserializingLicenseProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import org.easymock.EasyMock; 21 | import org.junit.After; 22 | import org.junit.Before; 23 | import org.junit.Test; 24 | 25 | /** 26 | * Test class for DeserializingLicenseProvider. 27 | */ 28 | public class TestDeserializingLicenseProvider 29 | { 30 | private DeserializingLicenseProvider provider; 31 | 32 | @Before 33 | public void setUp() 34 | { 35 | this.provider = EasyMock.createMockBuilder(DeserializingLicenseProvider.class). 36 | addMockedMethod("getLicenseData").createStrictMock(); 37 | } 38 | 39 | @After 40 | public void tearDown() 41 | { 42 | EasyMock.verify(this.provider); 43 | } 44 | 45 | @Test 46 | public void testGetLicense01() 47 | { 48 | EasyMock.expect(this.provider.getLicenseData("nullCustomer01")).andReturn(null); 49 | EasyMock.replay(this.provider); 50 | 51 | SignedLicense retrieved = this.provider.getLicense("nullCustomer01"); 52 | 53 | assertNull("The retrieved license should be null.", retrieved); 54 | } 55 | 56 | @Test 57 | public void testGetLicense02() 58 | { 59 | byte[] licenseContent = new byte[] {0x1F}; 60 | byte[] signatureContent = new byte[] {0x2F}; 61 | SignedLicense license = new SignedLicense(licenseContent, signatureContent); 62 | byte[] serialized = new ObjectSerializer().writeObject(license); 63 | 64 | EasyMock.expect(this.provider.getLicenseData("testCustomer02")).andReturn(serialized); 65 | EasyMock.replay(this.provider); 66 | 67 | SignedLicense retrieved = this.provider.getLicense("testCustomer02"); 68 | 69 | assertNotNull("The retrieved license should not be null.", retrieved); 70 | assertArrayEquals("The license is not correct.", licenseContent, retrieved.getLicenseContent()); 71 | assertArrayEquals("The signature is not correct.", signatureContent, retrieved.getSignatureContent()); 72 | } 73 | 74 | @Test 75 | public void testGetLicense03() 76 | { 77 | byte[] licenseContent = new byte[] {0x3F}; 78 | byte[] signatureContent = new byte[] {0x4F}; 79 | SignedLicense license = new SignedLicense(licenseContent, signatureContent); 80 | byte[] serialized = new ObjectSerializer().writeObject(license); 81 | 82 | EasyMock.expect(this.provider.getLicenseData("anotherCustomer03")).andReturn(serialized); 83 | EasyMock.replay(this.provider); 84 | 85 | SignedLicense retrieved = this.provider.getLicense("anotherCustomer03"); 86 | 87 | assertNotNull("The retrieved license should not be null.", retrieved); 88 | assertArrayEquals("The license is not correct.", licenseContent, retrieved.getLicenseContent()); 89 | assertArrayEquals("The signature is not correct.", signatureContent, retrieved.getSignatureContent()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/TestLicenseBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import org.junit.After; 21 | import org.junit.AfterClass; 22 | import org.junit.Before; 23 | import org.junit.BeforeClass; 24 | import org.junit.Test; 25 | 26 | /** 27 | * Test class for License.Builder. 28 | */ 29 | @SuppressWarnings("EmptyMethod") 30 | public class TestLicenseBuilder 31 | { 32 | public TestLicenseBuilder() 33 | { 34 | 35 | } 36 | 37 | @BeforeClass 38 | public static void setUpClass() 39 | { 40 | 41 | } 42 | 43 | @AfterClass 44 | public static void tearDownClass() 45 | { 46 | 47 | } 48 | 49 | @Before 50 | public void setUp() 51 | { 52 | 53 | } 54 | 55 | @After 56 | public void tearDown() 57 | { 58 | 59 | } 60 | 61 | @Test 62 | public void testBuild01() 63 | { 64 | License license = new License.Builder(). 65 | withProductKey("5565-1039-AF89-GGX7-TN31-14AL"). 66 | withIssuer("CN=Nick Williams, C=US, ST=TN"). 67 | withHolder("CN=Tim Williams, C=US, ST=AL"). 68 | withIssueDate(1234567890000L). 69 | withGoodAfterDate(1199145600000L). 70 | withGoodBeforeDate(1924991999000L). 71 | withNumberOfLicenses(15). 72 | addFeature("FEATURE1"). 73 | addFeature("FEATURE3"). 74 | build(); 75 | 76 | assertEquals("The product key is not correct.", "5565-1039-AF89-GGX7-TN31-14AL", license.getProductKey()); 77 | assertEquals("The issuer is not correct.", "CN=Nick Williams, C=US, ST=TN", license.getIssuer()); 78 | assertEquals("The holder is not correct.", "CN=Tim Williams, C=US, ST=AL", license.getHolder()); 79 | assertEquals("The issue date is not correct.", 1234567890000L, license.getIssueDate()); 80 | assertEquals("The good after date is not correct.", 1199145600000L, license.getGoodAfterDate()); 81 | assertEquals("The good before date is not correct.", 1924991999000L, license.getGoodBeforeDate()); 82 | assertEquals("The number of licenses is not correct.", 15, license.getNumberOfLicenses()); 83 | assertTrue("Feature mismatch #1.", license.hasLicenseForAllFeatures("FEATURE1")); 84 | assertTrue("Feature mismatch #2.", license.hasLicenseForAllFeatures("FEATURE3")); 85 | assertFalse("Feature mismatch #3.", license.hasLicenseForAllFeatures("FEATURE2")); 86 | } 87 | 88 | @Test 89 | public void testBuild02() 90 | { 91 | License license = new License.Builder(). 92 | withProductKey("5655-9301-98AF-X7GE-RTV5-1092"). 93 | withIssuer("CN=UUID-5581CAD6-A0C5-1A88-C32B6117B700B53F, C=US, ST=TN"). 94 | withHolder("CN=UUID-5581CAE6-0232-5353-1DC9AF6A79FE7106, C=US, ST=AL"). 95 | withIssueDate(1285629859000L). 96 | withGoodAfterDate(1136073600000L). 97 | withGoodBeforeDate(1230767999000L). 98 | withNumberOfLicenses(5). 99 | addFeature("FEATURE2"). 100 | build(); 101 | 102 | assertEquals("The product key is not correct.", "5655-9301-98AF-X7GE-RTV5-1092", license.getProductKey()); 103 | assertEquals("The issuer is not correct.", 104 | "CN=UUID-5581CAD6-A0C5-1A88-C32B6117B700B53F, C=US, ST=TN", license.getIssuer() 105 | ); 106 | assertEquals( 107 | "The holder is not correct.", 108 | "CN=UUID-5581CAE6-0232-5353-1DC9AF6A79FE7106, C=US, ST=AL", 109 | license.getHolder() 110 | ); 111 | assertEquals("The issue date is not correct.", 1285629859000L, license.getIssueDate()); 112 | assertEquals("The good after date is not correct.", 1136073600000L, license.getGoodAfterDate()); 113 | assertEquals("The good before date is not correct.", 1230767999000L, license.getGoodBeforeDate()); 114 | assertEquals("The number of licenses is not correct.", 5, license.getNumberOfLicenses()); 115 | assertTrue("Feature mismatch #1.", license.hasLicenseForAllFeatures("FEATURE2")); 116 | assertFalse("Feature mismatch #2.", license.hasLicenseForAllFeatures("FEATURE1")); 117 | assertFalse("Feature mismatch #3.", license.hasLicenseForAllFeatures("FEATURE3")); 118 | } 119 | } 120 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/TestLicenseManagerProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | /** 28 | * Test class for LicenseManagerProperties. 29 | */ 30 | @SuppressWarnings("EmptyMethod") 31 | public class TestLicenseManagerProperties 32 | { 33 | @Before 34 | public void setUp() 35 | { 36 | 37 | } 38 | 39 | @After 40 | public void tearDown() 41 | { 42 | 43 | } 44 | 45 | @Test 46 | public void testConstructionForbidden() 47 | throws IllegalAccessException, InstantiationException, NoSuchMethodException 48 | { 49 | Constructor constructor = LicenseManagerProperties.class.getDeclaredConstructor(); 50 | constructor.setAccessible(true); 51 | 52 | try 53 | { 54 | constructor.newInstance(); 55 | fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); 56 | } 57 | catch(InvocationTargetException e) 58 | { 59 | Throwable cause = e.getCause(); 60 | assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); 61 | assertSame( 62 | "Expected exception java.lang.RuntimeException, but got " + cause.getClass(), 63 | AssertionError.class, 64 | cause.getClass() 65 | ); 66 | assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/TestLicensingCharsets.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.nio.charset.StandardCharsets; 23 | 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | @SuppressWarnings("EmptyMethod") 29 | public class TestLicensingCharsets 30 | { 31 | @Before 32 | public void setUp() 33 | { 34 | 35 | } 36 | 37 | @After 38 | public void tearDown() 39 | { 40 | 41 | } 42 | 43 | @Test 44 | public void testConstructionForbidden() 45 | throws IllegalAccessException, InstantiationException, NoSuchMethodException 46 | { 47 | Constructor constructor = LicensingCharsets.class.getDeclaredConstructor(); 48 | constructor.setAccessible(true); 49 | 50 | try 51 | { 52 | constructor.newInstance(); 53 | fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); 54 | } 55 | catch(InvocationTargetException e) 56 | { 57 | Throwable cause = e.getCause(); 58 | assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); 59 | assertSame( 60 | "Expected exception java.lang.RuntimeException, but got " + cause.getClass(), 61 | AssertionError.class, 62 | cause.getClass() 63 | ); 64 | assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); 65 | } 66 | } 67 | 68 | @Test 69 | public void testUtf8() 70 | { 71 | assertEquals("The UTF-8 charset is not correct.", StandardCharsets.UTF_8, LicensingCharsets.UTF_8); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/TestSignedLicense.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing; 17 | 18 | import static org.junit.Assert.assertArrayEquals; 19 | 20 | import org.junit.After; 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | 24 | /** 25 | * Test class for SignedLicense. 26 | */ 27 | @SuppressWarnings("EmptyMethod") 28 | public class TestSignedLicense 29 | { 30 | private SignedLicense license; 31 | 32 | @Before 33 | public void setUp() 34 | { 35 | this.license = new SignedLicense(new byte[] {0x29, 0x7F, 0x3C}, new byte[] {0x01, 0x02, 0x77, 0x40, 0x0F}); 36 | } 37 | 38 | @After 39 | public void tearDown() 40 | { 41 | 42 | } 43 | 44 | @Test 45 | public void testLicenseContent() 46 | { 47 | assertArrayEquals("The license content is not correct.", new byte[] {0x29, 0x7F, 0x3C}, 48 | this.license.getLicenseContent() 49 | ); 50 | } 51 | 52 | @Test 53 | public void testSignatureContent() 54 | { 55 | assertArrayEquals("The signature content is not correct.", new byte[] {0x01, 0x02, 0x77, 0x40, 0x0F}, 56 | this.license.getSignatureContent() 57 | ); 58 | } 59 | 60 | @Test 61 | public void testDeserialization() throws ClassNotFoundException 62 | { 63 | Class.forName("io.oddsource.java.licensing.LicenseSecurityManager"); 64 | 65 | byte[] data = new ObjectSerializer().writeObject(this.license); 66 | 67 | SignedLicense signedLicense = new ObjectSerializer().readObject(SignedLicense.class, data); 68 | 69 | assertArrayEquals("The license content is not correct.", 70 | this.license.getLicenseContent(), signedLicense.getLicenseContent() 71 | ); 72 | assertArrayEquals("The signature content is not correct.", 73 | this.license.getSignatureContent(), signedLicense.getSignatureContent() 74 | ); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/encryption/TestHasher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.encryption; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | /** 28 | * Test class for Hasher. 29 | */ 30 | @SuppressWarnings("EmptyMethod") 31 | public class TestHasher 32 | { 33 | @Before 34 | public void setUp() 35 | { 36 | 37 | } 38 | 39 | @After 40 | public void tearDown() 41 | { 42 | 43 | } 44 | 45 | @Test 46 | public void testConstructionForbidden() 47 | throws IllegalAccessException, InstantiationException, NoSuchMethodException 48 | { 49 | Constructor constructor = Hasher.class.getDeclaredConstructor(); 50 | constructor.setAccessible(true); 51 | 52 | try 53 | { 54 | constructor.newInstance(); 55 | fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); 56 | } 57 | catch(InvocationTargetException e) 58 | { 59 | Throwable cause = e.getCause(); 60 | assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); 61 | assertSame( 62 | "Expected exception java.lang.RuntimeException, but got " + cause.getClass(), 63 | RuntimeException.class, 64 | cause.getClass() 65 | ); 66 | assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); 67 | } 68 | } 69 | 70 | @Test 71 | public void testHashSameStrings() 72 | { 73 | String unhashed = "myTestString"; 74 | 75 | String enc1 = Hasher.hash(unhashed); 76 | String enc2 = Hasher.hash(unhashed); 77 | String enc3 = Hasher.hash(unhashed); 78 | 79 | assertNotNull("The first encrypted string was null.", enc1); 80 | assertNotNull("The second encrypted string was null.", enc2); 81 | assertNotNull("The third encrypted string was null.", enc3); 82 | 83 | assertNotEquals("The first encrypted string was not encrypted properly.", enc1, unhashed); 84 | assertNotEquals("The second encrypted string was not encrypted properly.", enc2, unhashed); 85 | assertNotEquals("The third encrypted string was not encrypted properly.", enc3, unhashed); 86 | 87 | assertEquals("The first and second encrypted strings do not match.", enc1, enc2); 88 | assertEquals("The first and third encrypted strings do not match.", enc1, enc3); 89 | assertEquals("The second and third encrypted strings do not match.", enc2, enc3); 90 | } 91 | 92 | @Test 93 | public void testHashDifferentString() 94 | { 95 | String unhashed1 = "myTestString1"; 96 | String unhashed2 = "myTestString2"; 97 | 98 | String encrypted1 = Hasher.hash(unhashed1); 99 | String encrypted2 = Hasher.hash(unhashed2); 100 | 101 | assertNotNull("The first encrypted string was null.", encrypted1); 102 | assertNotNull("The second encrypted string was null.", encrypted2); 103 | 104 | assertNotEquals( 105 | "The first encrypted string matches the second encrypted string, and it shouldn't.", 106 | encrypted1, 107 | encrypted2 108 | ); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/immutable/MockValidObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | /** 19 | * This class is a mock object for testing purposes. 20 | * 21 | * @author Nick Williams 22 | * @version 1.0.0 23 | * @since 1.0.0 24 | */ 25 | final class MockValidObject extends ValidObject 26 | { 27 | protected boolean valid = true; 28 | 29 | @Override 30 | protected final void checkValidity() 31 | { 32 | if(!this.valid) 33 | { 34 | throw new ImmutableModifiedThroughReflectionError(); 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/immutable/TestImmutableAbstractCollection.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | import org.junit.After; 19 | import org.junit.Before; 20 | import org.junit.Test; 21 | 22 | /** 23 | * Test class for ImmutableAbstractCollection. 24 | */ 25 | @SuppressWarnings("EmptyMethod") 26 | public class TestImmutableAbstractCollection 27 | { 28 | @Before 29 | public void setUp() 30 | { 31 | 32 | } 33 | 34 | @After 35 | public void tearDown() 36 | { 37 | 38 | } 39 | 40 | @Test(expected = IllegalArgumentException.class) 41 | public void testConstruct01() 42 | { 43 | new ImmutableAbstractCollection(null) 44 | { 45 | private static final long serialVersionUID = 1L; 46 | }; 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/immutable/TestImmutableIterator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.immutable; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.util.TreeSet; 21 | 22 | import org.junit.After; 23 | import org.junit.AfterClass; 24 | import org.junit.Before; 25 | import org.junit.BeforeClass; 26 | import org.junit.Test; 27 | 28 | /** 29 | * Test class for ImmutableIterator. 30 | */ 31 | @SuppressWarnings("EmptyMethod") 32 | public class TestImmutableIterator 33 | { 34 | final private ImmutableIterator iterator; 35 | 36 | final private MockValidObject valid; 37 | 38 | public TestImmutableIterator() 39 | { 40 | TreeSet temp = new TreeSet<>(); 41 | temp.add("MyString1"); 42 | temp.add("YourString2"); 43 | temp.add("HisString3"); 44 | temp.add("HerString4"); 45 | 46 | this.valid = new MockValidObject(); 47 | 48 | this.iterator = new ImmutableIterator<>(temp.iterator(), this.valid); 49 | } 50 | 51 | @BeforeClass 52 | public static void setUpClass() 53 | { 54 | } 55 | 56 | @AfterClass 57 | public static void tearDownClass() 58 | { 59 | } 60 | 61 | @Before 62 | public void setUp() 63 | { 64 | 65 | } 66 | 67 | @After 68 | public void tearDown() 69 | { 70 | 71 | } 72 | 73 | @Test(expected = UnsupportedOperationException.class) 74 | public void testRemoveNotAllowed() 75 | { 76 | this.iterator.remove(); 77 | } 78 | 79 | @Test 80 | public void testNext01() 81 | { 82 | this.valid.valid = true; 83 | 84 | String[] array = new String[] {"HerString4", "HisString3", "MyString1", "YourString2"}; 85 | int i = 0; 86 | 87 | while(this.iterator.hasNext()) 88 | { 89 | String string = this.iterator.next(); 90 | 91 | assertNotNull("This string should not be null " + i, string); 92 | assertEquals("This string is not correct " + i, array[i++], string); 93 | } 94 | } 95 | 96 | @SuppressWarnings("ResultOfMethodCallIgnored") 97 | @Test(expected = ImmutableModifiedThroughReflectionError.class) 98 | public void testNext02() 99 | { 100 | this.valid.valid = false; 101 | this.iterator.hasNext(); 102 | } 103 | 104 | @Test(expected = ImmutableModifiedThroughReflectionError.class) 105 | public void testNext03() 106 | { 107 | this.valid.valid = false; 108 | this.iterator.next(); 109 | } 110 | 111 | @SuppressWarnings("ResultOfMethodCallIgnored") 112 | @Test(expected = ImmutableModifiedThroughReflectionError.class) 113 | public void testNext04() 114 | { 115 | try 116 | { 117 | this.valid.valid = true; 118 | this.iterator.hasNext(); 119 | } 120 | catch(Throwable t) 121 | { 122 | t.printStackTrace(); 123 | fail(t.toString()); 124 | } 125 | this.valid.valid = false; 126 | this.iterator.next(); 127 | } 128 | 129 | @SuppressWarnings("ResultOfMethodCallIgnored") 130 | @Test(expected = ImmutableModifiedThroughReflectionError.class) 131 | public void testNext05() 132 | { 133 | try 134 | { 135 | this.valid.valid = true; 136 | this.iterator.hasNext(); 137 | this.iterator.next(); 138 | this.iterator.hasNext(); 139 | this.iterator.next(); 140 | this.iterator.hasNext(); 141 | } 142 | catch(Throwable t) 143 | { 144 | t.printStackTrace(); 145 | fail(t.toString()); 146 | } 147 | this.valid.valid = false; 148 | this.iterator.next(); 149 | } 150 | } 151 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/mock/MockFeatureObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.mock; 17 | 18 | import io.oddsource.java.licensing.FeatureObject; 19 | 20 | public class MockFeatureObject implements FeatureObject 21 | { 22 | private final String name; 23 | 24 | public MockFeatureObject(String name) 25 | { 26 | this.name = name; 27 | } 28 | 29 | @Override 30 | public String getName() 31 | { 32 | return this.name; 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /Core/source/test/java/unit/io/oddsource/java/licensing/mock/StateFlag.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.mock; 17 | 18 | public class StateFlag 19 | { 20 | public boolean state; 21 | 22 | @Override 23 | public String toString() 24 | { 25 | return Boolean.toString(this.state); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /Core/source/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Core/source/test/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-Base/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-licensor-base 30 | jar 31 | 32 | OddSource Code Java License Manager - Licensor Base 33 | 34 | 35 | 36 | io.oddsource.java.licensing 37 | licensing-core 38 | ${project.version} 39 | compile 40 | 41 | 42 | 43 | commons-io 44 | commons-io 45 | compile 46 | 47 | 48 | 49 | io.oddsource.java.licensing 50 | licensing-core 51 | ${project.version} 52 | test-jar 53 | test 54 | 55 | 56 | 57 | 58 | source/production/java 59 | 60 | 61 | source/production/resources 62 | 63 | 64 | META-INF 65 | ../build/jar/META-INF 66 | 67 | 68 | 69 | source/test/java/unit 70 | 71 | 72 | source/test/resources 73 | 74 | 75 | 76 | 77 | 78 | org.apache.maven.plugins 79 | maven-surefire-plugin 80 | 81 | 82 | false 83 | 84 | 85 | 86 | 87 | 88 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/LicenseCreatorProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor; 17 | 18 | import io.oddsource.java.licensing.encryption.PasswordProvider; 19 | import io.oddsource.java.licensing.licensor.encryption.PrivateKeyDataProvider; 20 | 21 | /** 22 | * This class is used to set properties that will be used to instantiate the {@link LicenseCreator}. Read the 23 | * documentation for each property below. 24 | * 25 | * @author Nick Williams 26 | * @version 1.0.0 27 | * @since 1.0.0 28 | */ 29 | public final class LicenseCreatorProperties 30 | { 31 | private static PrivateKeyDataProvider privateKeyDataProvider; 32 | 33 | private static PasswordProvider privateKeyPasswordProvider; 34 | 35 | /** 36 | * This class cannot be instantiated. 37 | */ 38 | private LicenseCreatorProperties() 39 | { 40 | throw new AssertionError("This class cannot be instantiated."); 41 | } 42 | 43 | /** 44 | * Sets the provider of the data for the private key used to sign the license object.
45 | *
46 | * This field is required. 47 | * 48 | * @param privateKeyDataProvider The provider of the data for the private key used to sign the license object 49 | */ 50 | public static void setPrivateKeyDataProvider(final PrivateKeyDataProvider privateKeyDataProvider) 51 | { 52 | LicenseCreatorProperties.privateKeyDataProvider = privateKeyDataProvider; 53 | } 54 | 55 | static PrivateKeyDataProvider getPrivateKeyDataProvider() 56 | { 57 | return LicenseCreatorProperties.privateKeyDataProvider; 58 | } 59 | 60 | /** 61 | * Sets the provider of the password for decrypting the private key.
62 | *
63 | * This field is required. 64 | * 65 | * @param privateKeyPasswordProvider The provider of the password for decrypting the private key 66 | */ 67 | public static void setPrivateKeyPasswordProvider(final PasswordProvider privateKeyPasswordProvider) 68 | { 69 | LicenseCreatorProperties.privateKeyPasswordProvider = privateKeyPasswordProvider; 70 | } 71 | 72 | static PasswordProvider getPrivateKeyPasswordProvider() 73 | { 74 | return LicenseCreatorProperties.privateKeyPasswordProvider; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/encryption/FilePrivateKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.encryption; 17 | 18 | import java.io.File; 19 | import java.io.FileNotFoundException; 20 | import java.io.IOException; 21 | 22 | import org.apache.commons.io.FileUtils; 23 | 24 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 25 | 26 | /** 27 | * A default implementation of {@link PrivateKeyDataProvider} that reads the private key from a file.
28 | *
29 | * This provider is immutable. Once created, the file that the private key is located at cannot be changed. 30 | * 31 | * @author Nick Williams 32 | * @version 1.0.0 33 | * @since 1.0.0 34 | */ 35 | public class FilePrivateKeyDataProvider implements PrivateKeyDataProvider 36 | { 37 | private final File privateKeyFile; 38 | 39 | /** 40 | * Create a new provider, specifying the file from which the private key can be read. 41 | * 42 | * @param privateKeyFile the private key file 43 | */ 44 | public FilePrivateKeyDataProvider(final File privateKeyFile) 45 | { 46 | this.privateKeyFile = privateKeyFile.getAbsoluteFile(); 47 | } 48 | 49 | /** 50 | * Create a new provider, specifying the name of the file from which the private key can be read. 51 | * 52 | * @param privateKeyFileName The private key file name 53 | */ 54 | public FilePrivateKeyDataProvider(final String privateKeyFileName) 55 | { 56 | this.privateKeyFile = new File(privateKeyFileName).getAbsoluteFile(); 57 | } 58 | 59 | /** 60 | * This method returns the data from the file containing the encrypted 61 | * private key from the public/private key pair. The contract for this 62 | * method can be fulfilled by storing the data in a byte array literal 63 | * in the source code itself.
64 | *
65 | * It is imperative that you obfuscate the bytecode for the 66 | * implementation of this class. It is also imperative that the byte 67 | * array exist only for the life of this method (i.e., DO NOT store it as 68 | * an instance or class field). 69 | * 70 | * @return the encrypted file contents from the private key file. 71 | * 72 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 73 | * must be provided. 74 | */ 75 | @Override 76 | public byte[] getEncryptedPrivateKeyData() throws KeyNotFoundException 77 | { 78 | try 79 | { 80 | return FileUtils.readFileToByteArray(this.privateKeyFile); 81 | } 82 | catch(final FileNotFoundException e) 83 | { 84 | throw new KeyNotFoundException("The private key file [" + this.privateKeyFile.getPath() + 85 | "] does not exist."); 86 | } 87 | catch(final IOException e) 88 | { 89 | throw new KeyNotFoundException("Could not read from the private key file [" + 90 | this.privateKeyFile.getPath() + "].", e); 91 | } 92 | } 93 | 94 | /** 95 | * Gets the file that the private key is located at. 96 | * 97 | * @return the file. 98 | */ 99 | public File getPrivateKeyFile() 100 | { 101 | return this.privateKeyFile; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/encryption/PrivateKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.encryption; 17 | 18 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 19 | 20 | /** 21 | * Specifies an interface for retrieving the private key file data. This 22 | * interface only needs to be implemented in the application generating the 23 | * licenses. It need not (and for security reasons should not) be implemented 24 | * in the application using the licenses. 25 | * 26 | * @author Nick Williams 27 | * @version 1.0.0 28 | * @since 1.0.0 29 | */ 30 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 31 | public interface PrivateKeyDataProvider 32 | { 33 | /** 34 | * This method returns the data from the file containing the encrypted 35 | * private key from the public/private key pair. The contract for this 36 | * method can be fulfilled by storing the data in a byte array literal 37 | * in the source code itself.
38 | *
39 | * It is imperative that you obfuscate the bytecode for the 40 | * implementation of this class. It is also imperative that the byte 41 | * array exist only for the life of this method (i.e., DO NOT store it as 42 | * an instance or class field). 43 | * 44 | * @return the encrypted file contents from the private key file. 45 | * 46 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 47 | * must be provided. 48 | */ 49 | public abstract byte[] getEncryptedPrivateKeyData() throws KeyNotFoundException; 50 | } 51 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/encryption/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains helpers and utilities for encryption and decryption used by licensors. 18 | * 19 | * @author Nick Williams 20 | * @version 2.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor.encryption; 24 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/exception/RSA2048NotSupportedException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.exception; 17 | 18 | /** 19 | * This exception is thrown when 2048-bit RSA security, which is required for 20 | * this library to run, is not supported with the current JVM. 21 | * 22 | * @author Nick Williams 23 | * @version 1.0.0 24 | * @since 1.0.0 25 | */ 26 | @SuppressWarnings("unused") 27 | public class RSA2048NotSupportedException extends RuntimeException 28 | { 29 | private static final long serialVersionUID = 1L; 30 | 31 | /** 32 | * Constructor. 33 | */ 34 | public RSA2048NotSupportedException() 35 | { 36 | super("2048-bit RSA Security is not supported on this system."); 37 | } 38 | 39 | /** 40 | * Constructor. 41 | * 42 | * @param message The message 43 | */ 44 | public RSA2048NotSupportedException(final String message) 45 | { 46 | super(message); 47 | } 48 | 49 | /** 50 | * Constructor. 51 | * 52 | * @param cause The cause 53 | */ 54 | public RSA2048NotSupportedException(final Throwable cause) 55 | { 56 | super("2048-bit RSA Security is not supported on this system.", cause); 57 | } 58 | 59 | /** 60 | * Constructor. 61 | * 62 | * @param message The message 63 | * @param cause The cause 64 | */ 65 | public RSA2048NotSupportedException(final String message, final Throwable cause) 66 | { 67 | super(message, cause); 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/exception/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains some common custom exceptions thrown by License Manager licensors. 18 | * 19 | * @author Nick Williams 20 | * @version 2.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor.exception; 24 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/java/io/oddsource/java/licensing/licensor/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains some base classes used by all licensor code (whether built-in or user interfaces). 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor; 24 | -------------------------------------------------------------------------------- /Licensor-Base/source/production/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-Base/source/production/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-Base/source/test/java/unit/io/oddsource/java/licensing/licensor/TestLicenseCreatorProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | 23 | import org.junit.After; 24 | import org.junit.Before; 25 | import org.junit.Test; 26 | 27 | /** 28 | * Test class for LicenseCreatorProperties. 29 | */ 30 | @SuppressWarnings("EmptyMethod") 31 | public class TestLicenseCreatorProperties 32 | { 33 | @Before 34 | public void setUp() 35 | { 36 | 37 | } 38 | 39 | @After 40 | public void tearDown() 41 | { 42 | 43 | } 44 | 45 | @Test 46 | public void testConstructionForbidden() 47 | throws IllegalAccessException, InstantiationException, NoSuchMethodException 48 | { 49 | Constructor constructor = LicenseCreatorProperties.class.getDeclaredConstructor(); 50 | constructor.setAccessible(true); 51 | 52 | try 53 | { 54 | constructor.newInstance(); 55 | fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); 56 | } 57 | catch(InvocationTargetException e) 58 | { 59 | Throwable cause = e.getCause(); 60 | assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); 61 | assertSame( 62 | "Expected exception java.lang.RuntimeException, but got " + cause.getClass(), 63 | AssertionError.class, 64 | cause.getClass() 65 | ); 66 | assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Licensor-Base/source/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-Base/source/test/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-CLI/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-licensor-ui-cli 30 | jar 31 | 32 | OddSource Code Java License Manager - Licensor CLI UI 33 | 34 | 35 | 36 | io.oddsource.java.licensing 37 | licensing-core 38 | ${project.version} 39 | compile 40 | 41 | 42 | 43 | io.oddsource.java.licensing 44 | licensing-licensor-base 45 | ${project.version} 46 | compile 47 | 48 | 49 | 50 | io.oddsource.java.licensing 51 | licensing-licensor-ui-core 52 | ${project.version} 53 | compile 54 | 55 | 56 | 57 | commons-cli 58 | commons-cli 59 | compile 60 | 61 | 62 | 63 | io.oddsource.java.licensing 64 | licensing-core 65 | ${project.version} 66 | test-jar 67 | test 68 | 69 | 70 | 71 | 72 | source/production/java 73 | 74 | 75 | source/production/resources 76 | 77 | 78 | META-INF 79 | ../build/jar/META-INF 80 | 81 | 82 | 83 | source/test/java/unit 84 | 85 | 86 | source/test/resources 87 | 88 | 89 | 90 | 91 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/java/io/oddsource/java/licensing/licensor/interfaces/cli/ConsoleUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.cli; 17 | 18 | import io.oddsource.java.licensing.licensor.interfaces.cli.spi.TextInterfaceDevice; 19 | 20 | /** 21 | * Utilities used by the text interface classes. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | final class ConsoleUtilities 28 | { 29 | private ConsoleUtilities() 30 | { 31 | throw new AssertionError("This class cannot be instantiated."); 32 | } 33 | 34 | /** 35 | * Sets up a shutdown hook to ensure that the text device always exits to a newline. 36 | * 37 | * @param interfaceDevice The interface device to configure 38 | */ 39 | public static void configureInterfaceDevice(final TextInterfaceDevice interfaceDevice) 40 | { 41 | interfaceDevice.registerShutdownHook(new Thread(interfaceDevice::printOutLn)); 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/java/io/oddsource/java/licensing/licensor/interfaces/cli/Periods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.cli; 17 | 18 | import java.io.PrintStream; 19 | 20 | /** 21 | * Displays periods on the text while an operation completes in a separate 22 | * thread. 23 | * 24 | * @author Nick Williams 25 | * @version 1.0.0 26 | * @since 1.0.0 27 | */ 28 | class Periods implements Runnable 29 | { 30 | private boolean run; 31 | 32 | private final long timeBetweenPeriods; 33 | 34 | private final PrintStream outputStream; 35 | 36 | public Periods(final long timeBetweenPeriods, final PrintStream outputStream) 37 | { 38 | this.run = true; 39 | this.timeBetweenPeriods = timeBetweenPeriods; 40 | this.outputStream = outputStream; 41 | } 42 | 43 | @Override 44 | public void run() 45 | { 46 | while(this.run) 47 | { 48 | this.outputStream.print('.'); 49 | try 50 | { 51 | Thread.sleep(this.timeBetweenPeriods); 52 | } 53 | catch(final InterruptedException e) 54 | { 55 | break; 56 | } 57 | } 58 | } 59 | 60 | public void stop() 61 | { 62 | this.run = false; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/java/io/oddsource/java/licensing/licensor/interfaces/cli/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains the base classes used by the Licensor CLI. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor.interfaces.cli; 24 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/java/io/oddsource/java/licensing/licensor/interfaces/cli/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains console-implementation-specific classes used by the Licensor CLI. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor.interfaces.cli.spi; 24 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/resources/io/oddsource/java/licensing/licensor/interfaces/cli/spi/ConsoleLicenseGenerator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright © 2010-2019 OddSource Code (license@oddsource.io) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 19 | 20 | GP="$( cd "$BASE_DIR/../../../../../../../../../../../.." >/dev/null 2>&1 && pwd )" 21 | 22 | CP="$GP/lib/*:$GP/out/production/LicenseManager" 23 | 24 | java -cp "$CP" io.oddsource.java.licensing.licensor.interfaces.text.ConsoleLicenseGenerator "$@" 25 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/production/resources/io/oddsource/java/licensing/licensor/interfaces/cli/spi/ConsoleRSAKeyPairGenerator.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright © 2010-2019 OddSource Code (license@oddsource.io) 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | # 17 | 18 | BASE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )" 19 | 20 | GP="$( cd "$BASE_DIR/../../../../../../../../../../../.." >/dev/null 2>&1 && pwd )" 21 | 22 | CP="$GP/lib/*:$GP/out/production/LicenseManager" 23 | 24 | java -cp "$CP" io.oddsource.java.licensing.licensor.interfaces.text.ConsoleRSAKeyPairGenerator "$@" 25 | 26 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/licensor/interfaces/cli/TestConsoleUtilities.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.cli; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | 23 | import org.easymock.Capture; 24 | import org.easymock.EasyMock; 25 | import org.junit.After; 26 | import org.junit.Before; 27 | import org.junit.Test; 28 | 29 | import io.oddsource.java.licensing.licensor.interfaces.cli.spi.TextInterfaceDevice; 30 | 31 | /** 32 | * Test class for ConsoleUtilities. 33 | */ 34 | @SuppressWarnings("EmptyMethod") 35 | public class TestConsoleUtilities 36 | { 37 | @Before 38 | public void setUp() 39 | { 40 | 41 | } 42 | 43 | @After 44 | public void tearDown() 45 | { 46 | 47 | } 48 | 49 | @Test 50 | public void testConstructionForbidden() 51 | throws IllegalAccessException, InstantiationException, NoSuchMethodException 52 | { 53 | Constructor constructor = ConsoleUtilities.class.getDeclaredConstructor(); 54 | constructor.setAccessible(true); 55 | 56 | try 57 | { 58 | constructor.newInstance(); 59 | fail("Expected exception java.lang.reflect.InvocationTargetException, but got no exception."); 60 | } 61 | catch(InvocationTargetException e) 62 | { 63 | Throwable cause = e.getCause(); 64 | assertNotNull("Expected cause for InvocationTargetException, but got no cause.", cause); 65 | assertSame( 66 | "Expected exception java.lang.RuntimeException, but got " + cause.getClass(), 67 | AssertionError.class, 68 | cause.getClass() 69 | ); 70 | assertEquals("The message was incorrect.", "This class cannot be instantiated.", cause.getMessage()); 71 | } 72 | } 73 | 74 | @Test 75 | public void testConfigureInterfaceDevice() throws InterruptedException 76 | { 77 | TextInterfaceDevice textInterfaceDevice = EasyMock.createStrictMock(TextInterfaceDevice.class); 78 | 79 | Capture threadCapture = EasyMock.newCapture(); 80 | 81 | textInterfaceDevice.registerShutdownHook(EasyMock.capture(threadCapture)); 82 | EasyMock.expectLastCall(); 83 | textInterfaceDevice.printOutLn(); 84 | EasyMock.expectLastCall(); 85 | 86 | EasyMock.replay(textInterfaceDevice); 87 | 88 | ConsoleUtilities.configureInterfaceDevice(textInterfaceDevice); 89 | 90 | Thread captured = threadCapture.getValue(); 91 | 92 | assertNotNull("The thread should not be null.", captured); 93 | 94 | captured.start(); 95 | 96 | int i = 0; 97 | while(captured.getState() != Thread.State.TERMINATED && i < 10) 98 | { 99 | Thread.sleep(100); 100 | i++; 101 | } 102 | 103 | assertTrue("The thread took too long to complete.", i < 10); 104 | 105 | EasyMock.verify(textInterfaceDevice); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/licensor/interfaces/cli/TestPeriods.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.cli; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import java.io.PrintStream; 21 | import java.util.Arrays; 22 | 23 | import org.apache.commons.io.output.ByteArrayOutputStream; 24 | import org.junit.After; 25 | import org.junit.Before; 26 | import org.junit.Test; 27 | 28 | /** 29 | * Test class for Periods. 30 | */ 31 | @SuppressWarnings("EmptyMethod") 32 | public class TestPeriods 33 | { 34 | private Periods periods; 35 | 36 | private ByteArrayOutputStream outputStream; 37 | 38 | @Before 39 | public void setUp() 40 | { 41 | this.outputStream = new ByteArrayOutputStream(); 42 | 43 | PrintStream printStream = new PrintStream(outputStream); 44 | 45 | this.periods = new Periods(25, printStream); 46 | } 47 | 48 | @After 49 | public void tearDown() 50 | { 51 | 52 | } 53 | 54 | @Test 55 | public void testRun01() throws InterruptedException 56 | { 57 | new Thread(this.periods).start(); 58 | 59 | Thread.sleep(100); 60 | 61 | this.periods.stop(); 62 | 63 | byte[] bytes = this.outputStream.toByteArray(); 64 | assertTrue("The length is not correct.", bytes.length >= 3); 65 | assertArrayEquals("The arrays are not correct.", Arrays.copyOf(bytes, 3), new byte[] {'.', '.', '.'}); 66 | } 67 | 68 | @Test 69 | public void testRun02() throws InterruptedException 70 | { 71 | Thread thread = new Thread(this.periods); 72 | thread.start(); 73 | 74 | Thread.sleep(200); 75 | 76 | thread.interrupt(); 77 | 78 | byte[] bytes = this.outputStream.toByteArray(); 79 | assertTrue("The length is not correct.", bytes.length >= 6); 80 | assertArrayEquals( 81 | "The arrays are not correct.", 82 | Arrays.copyOf(bytes, 6), 83 | new byte[] {'.', '.', '.', '.', '.', '.'} 84 | ); 85 | } 86 | 87 | @Test 88 | public void testRun03() throws InterruptedException 89 | { 90 | PrintStream printStream = new PrintStream(outputStream); 91 | this.periods = new Periods(50, printStream); 92 | 93 | new Thread(this.periods).start(); 94 | 95 | Thread.sleep(400); 96 | 97 | this.periods.stop(); 98 | 99 | byte[] bytes = this.outputStream.toByteArray(); 100 | assertTrue("The length is not correct.", bytes.length >= 6); 101 | assertArrayEquals( 102 | "The arrays are not correct.", 103 | Arrays.copyOf(bytes, 6), 104 | new byte[] {'.', '.', '.', '.', '.', '.'} 105 | ); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/licensor/interfaces/cli/spi/TestConsoleInterfaceDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.cli.spi; 17 | 18 | import static org.junit.Assert.*; 19 | 20 | import org.junit.After; 21 | import org.junit.Before; 22 | import org.junit.Test; 23 | 24 | /** 25 | * Test class for ConsoleInterfaceDevice. 26 | */ 27 | @SuppressWarnings("EmptyMethod") 28 | public class TestConsoleInterfaceDevice 29 | { 30 | private ConsoleInterfaceDevice device; 31 | 32 | @Before 33 | public void setUp() 34 | { 35 | this.device = new ConsoleInterfaceDevice(); 36 | } 37 | 38 | @After 39 | public void tearDown() 40 | { 41 | 42 | } 43 | 44 | @Test 45 | public void testConsoleProperty() 46 | { 47 | assertSame("The console object should be the same.", System.console(), this.device.getConsole()); 48 | } 49 | 50 | @Test 51 | public void testRuntimeProperty() 52 | { 53 | assertSame("The runtime object should be the same.", Runtime.getRuntime(), this.device.getRuntime()); 54 | } 55 | 56 | @Test 57 | public void testRegisterShutdownHook() 58 | { 59 | Thread thread = new Thread(); 60 | 61 | this.device.registerShutdownHook(thread); 62 | 63 | assertTrue("The hook should have been unregistered.", this.device.unregisterShutdownHook(thread)); 64 | assertFalse("The hook should not have been unregistered again.", this.device.unregisterShutdownHook(thread)); 65 | } 66 | 67 | @Test(expected = NullPointerException.class) 68 | public void testFormat() 69 | { 70 | this.device.format("Test formatted string %d", 10923.0D); 71 | } 72 | 73 | @Test(expected = NullPointerException.class) 74 | public void testPrintf() 75 | { 76 | this.device.printf("Test formatted string %d", 10923.0D); 77 | } 78 | 79 | @Test(expected = NullPointerException.class) 80 | public void testFlush() 81 | { 82 | this.device.flush(); 83 | } 84 | 85 | @Test(expected = NullPointerException.class) 86 | public void testReadLine01() 87 | { 88 | this.device.readLine(); 89 | } 90 | 91 | @Test(expected = NullPointerException.class) 92 | public void testReadLine02() 93 | { 94 | this.device.readLine("Test formatted string %d", 10923.0D); 95 | } 96 | 97 | @Test(expected = NullPointerException.class) 98 | public void testReadPassword01() 99 | { 100 | this.device.readPassword(); 101 | } 102 | 103 | @Test(expected = NullPointerException.class) 104 | public void testReadPassword02() 105 | { 106 | this.device.readPassword("Test formatted string %d", 10923.0D); 107 | } 108 | 109 | @Test(expected = NullPointerException.class) 110 | public void testGetReader() 111 | { 112 | this.device.getReader(); 113 | } 114 | 115 | @Test(expected = NullPointerException.class) 116 | public void testGetWriter() 117 | { 118 | this.device.getWriter(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/mock/MockFilePrivateKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.mock; 17 | 18 | import java.io.IOException; 19 | 20 | import org.apache.commons.io.IOUtils; 21 | 22 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 23 | import io.oddsource.java.licensing.licensor.encryption.PrivateKeyDataProvider; 24 | 25 | public class MockFilePrivateKeyDataProvider implements PrivateKeyDataProvider 26 | { 27 | /** 28 | * This method returns the data from the file containing the encrypted 29 | * private key from the public/private key pair. The contract for this 30 | * method can be fulfilled by storing the data in a byte array literal 31 | * in the source code itself. 32 | * 33 | * @return the encrypted file contents from the private key file. 34 | * 35 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 36 | * must be provided. 37 | */ 38 | public byte[] getEncryptedPrivateKeyData() throws KeyNotFoundException 39 | { 40 | try 41 | { 42 | return IOUtils.toByteArray( 43 | this.getClass().getResourceAsStream("mock.private.key") 44 | ); 45 | } 46 | catch(IOException e) 47 | { 48 | throw new KeyNotFoundException("The private key file was not found.", e); 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/mock/MockPasswordProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.mock; 17 | 18 | import io.oddsource.java.licensing.encryption.PasswordProvider; 19 | 20 | public class MockPasswordProvider implements PasswordProvider 21 | { 22 | public char[] getPassword() 23 | { 24 | return new char[] { 25 | 's', 'a', 'm', 'p', 'l', 'e', 'K', 'e', 'y', '1', '9', '8', '4', 26 | }; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/mock/mock.private.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-CLI/source/test/java/unit/io/oddsource/java/licensing/mock/mock.private.key -------------------------------------------------------------------------------- /Licensor-UI-CLI/source/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-CLI/source/test/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Core/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-licensor-ui-core 30 | jar 31 | 32 | OddSource Code Java License Manager - Licensor UI Core 33 | 34 | 35 | 36 | io.oddsource.java.licensing 37 | licensing-core 38 | ${project.version} 39 | compile 40 | 41 | 42 | 43 | io.oddsource.java.licensing 44 | licensing-licensor-base 45 | ${project.version} 46 | compile 47 | 48 | 49 | 50 | io.oddsource.java.licensing 51 | licensing-core 52 | ${project.version} 53 | test-jar 54 | test 55 | 56 | 57 | 58 | 59 | source/production/java 60 | 61 | 62 | source/production/resources 63 | 64 | 65 | META-INF 66 | ../build/jar/META-INF 67 | 68 | 69 | 70 | source/test/java/unit 71 | 72 | 73 | source/test/resources 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /Licensor-UI-Core/source/production/java/io/oddsource/java/licensing/licensor/interfaces/spi/AbstractPasswordPrompter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.spi; 17 | 18 | import java.io.IOError; 19 | import java.util.Arrays; 20 | 21 | /** 22 | * Abstract class for prompting for passwords. 23 | * 24 | * @author Nick Williams 25 | * @version 1.0.0 26 | * @since 1.0.0 27 | */ 28 | public abstract class AbstractPasswordPrompter implements PasswordPrompter 29 | { 30 | /** 31 | * Checks whether the two passwords match. 32 | * 33 | * @param password1 The entered password 34 | * @param password2 The confirmed password 35 | * 36 | * @return {@code true} if the passwords match, {@code false} otherwise. 37 | */ 38 | @Override 39 | public boolean passwordsMatch(final char[] password1, final char[] password2) 40 | { 41 | return Arrays.equals(password1, password2); 42 | } 43 | 44 | /** 45 | * Prompts for a valid password by asking for the password using {@link #readPassword(String, Object...)}, checking 46 | * its length against the constraints, asking for the password to be confirmed, and checking to make sure the 47 | * passwords match.
48 | *
49 | * This method should continue to ask for the password over and over again until a valid password is entered and 50 | * confirmed or the user cancels the operation. 51 | * 52 | * @param minLength The minimum legal length for the password 53 | * @param maxLength The maximum legal length for the password 54 | * @param promptMessage The message to prompt for the password initially (the message should not include format 55 | * specifiers) 56 | * @param promptConfirmMessage The message to prompt to confirm the password (the message should not include 57 | * format specifiers) 58 | * @param lengthError The message to display if the password does not meet the minimum or maximum length 59 | * requirements (the message should not include format specifiers) 60 | * @param matchError The message to display if the two entered passwords do not match (the message should not 61 | * include format specifiers) 62 | * @param device The device that should be used to output messages and errors 63 | * 64 | * @return the valid, confirmed password entered by the user. 65 | * 66 | * @throws IOError if an I/O error occurs. 67 | */ 68 | @Override 69 | public char[] promptForValidPassword( 70 | final int minLength, final int maxLength, final String promptMessage, 71 | final String promptConfirmMessage, final String lengthError, final String matchError, 72 | final OutputDevice device 73 | ) 74 | throws IOError 75 | { 76 | char[] password1 = null; 77 | char[] password2 = null; 78 | boolean passwordVerified = false; 79 | 80 | try 81 | { 82 | while(!passwordVerified) 83 | { 84 | password1 = this.readPassword(promptMessage); 85 | 86 | if(password1.length < minLength || password1.length > maxLength) 87 | { 88 | device.outputErrorMessage(lengthError); 89 | continue; 90 | } 91 | 92 | password2 = this.readPassword(promptConfirmMessage); 93 | 94 | passwordVerified = this.passwordsMatch(password1, password2); 95 | if(!passwordVerified) 96 | { 97 | device.outputErrorMessage(matchError); 98 | } 99 | } 100 | 101 | return Arrays.copyOf(password1, password1.length); 102 | } 103 | finally 104 | { 105 | if(password1 != null) 106 | { 107 | Arrays.fill(password1, '\u0000'); 108 | } 109 | if(password2 != null) 110 | { 111 | Arrays.fill(password2, '\u0000'); 112 | } 113 | } 114 | } 115 | } 116 | -------------------------------------------------------------------------------- /Licensor-UI-Core/source/production/java/io/oddsource/java/licensing/licensor/interfaces/spi/OutputDevice.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.licensor.interfaces.spi; 17 | 18 | import java.io.IOError; 19 | 20 | /** 21 | * Marker for a class capable of outputting simple messages. 22 | * 23 | * @author Nick Williams 24 | * @version 1.0.0 25 | * @since 1.0.0 26 | */ 27 | @SuppressWarnings({"UnusedReturnValue", "unused"}) 28 | public interface OutputDevice 29 | { 30 | /** 31 | * Outputs an informational message to the output device. 32 | * 33 | * @param message The message 34 | * 35 | * @throws IOError if an I/O error occurs while outputting the message. 36 | */ 37 | public abstract void outputMessage(String message) throws IOError; 38 | 39 | /** 40 | * Outputs an error message to the output device. 41 | * 42 | * @param message The message 43 | * 44 | * @throws IOError if an I/O error occurs while outputting the message. 45 | */ 46 | public abstract void outputErrorMessage(String message) throws IOError; 47 | } 48 | -------------------------------------------------------------------------------- /Licensor-UI-Core/source/production/java/io/oddsource/java/licensing/licensor/interfaces/spi/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains some base classes used by all licensor user interface code. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | package io.oddsource.java.licensing.licensor.interfaces.spi; 24 | -------------------------------------------------------------------------------- /Licensor-UI-Core/source/production/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Core/source/production/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Core/source/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Core/source/test/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Desktop/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-licensor-ui-desktop 30 | jar 31 | 32 | OddSource Code Java License Manager - Licensor Desktop UI 33 | 34 | 35 | 36 | io.oddsource.java.licensing 37 | licensing-core 38 | ${project.version} 39 | compile 40 | 41 | 42 | 43 | io.oddsource.java.licensing 44 | licensing-licensor-base 45 | ${project.version} 46 | compile 47 | 48 | 49 | 50 | io.oddsource.java.licensing 51 | licensing-licensor-ui-core 52 | ${project.version} 53 | compile 54 | 55 | 56 | 57 | io.oddsource.java.licensing 58 | licensing-core 59 | ${project.version} 60 | test-jar 61 | test 62 | 63 | 64 | 65 | 66 | source/production/java 67 | 68 | 69 | source/production/resources 70 | 71 | 72 | META-INF 73 | ../build/jar/META-INF 74 | 75 | 76 | 77 | source/test/java/unit 78 | 79 | 80 | source/test/resources 81 | 82 | 83 | 84 | 85 | -------------------------------------------------------------------------------- /Licensor-UI-Desktop/source/production/java/io/oddsource/java/licensing/licensor/interfaces/desktop/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Desktop/source/production/java/io/oddsource/java/licensing/licensor/interfaces/desktop/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Desktop/source/production/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Desktop/source/production/resources/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Desktop/source/test/java/unit/io/oddsource/java/licensing/licensor/interfaces/desktop/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Desktop/source/test/java/unit/io/oddsource/java/licensing/licensor/interfaces/desktop/.gitkeep -------------------------------------------------------------------------------- /Licensor-UI-Desktop/source/test/resources/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Licensor-UI-Desktop/source/test/resources/.gitkeep -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Licensing 2 | --------- 3 | OddSource Code License Manager 4 | Copyright (c) 2010-2019 Nicholas Williams 5 | Licensed under the Apache License version 2.0 (see LICENSE.txt) 6 | 7 | This product includes software developed by 8 | The Apache Software Foundation (http://www.apache.org/). 9 | 10 | 11 | Cryptographic Software Notice 12 | ----------------------------- 13 | 14 | This distribution may include software that has been designed for use 15 | with cryptographic software. The country in which you currently reside 16 | may have restrictions on the import, possession, use, and/or re-export 17 | to another country, of encryption software. BEFORE using any encryption 18 | software, please check your country's laws, regulations and policies 19 | concerning the import, possession, or use, and re-export of encryption 20 | software, to see if this is permitted. See 21 | for more information. 22 | 23 | The U.S. Government Department of Commerce, Bureau of Industry and 24 | Security (BIS), has classified this software as Export Commodity 25 | Control Number (ECCN) 5D002.c.1, which includes information security 26 | software using or performing cryptographic functions with symmetric and 27 | asymmetric algorithms (5A002.a.1.a and 5A002.a.1.b, respectively). 28 | The form and manner of this OddSource Code Java Code distribution makes it 29 | eligible for export under the License Exception ENC Technology Software 30 | Unrestricted (TSU) exception (see the BIS Export Administration 31 | Regulations, Section 740.13) for both object code and source code. 32 | 33 | The following provides more details on the included software that 34 | may be subject to export controls on cryptographic software: 35 | 36 | OddSource Code License Manager interfaces with the 37 | Java(TM) Cryptography Architecture (JCA) API to provide: 38 | 39 | o Shared key-based encryption and decryption 40 | of licensing components 41 | 42 | o Key pair-based signature and verification 43 | of licensing data 44 | 45 | OddSource Code License Manager does not include any implementation 46 | of JCA. 47 | 48 | 49 | Contact 50 | ------- 51 | 52 | o For general information visit the main project site at 53 | http://oddsource.io/java/license-manager 54 | 55 | o For help and bug reports visit the issue tracker at 56 | https://github.com/OddSource/java-license-manager/issues 57 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | OddSource Code Java License Manager 2 | =================================== 3 | 4 | .. image:: https://api.travis-ci.org/OddSource/java-license-manager.svg 5 | :target: https://travis-ci.org/OddSource/java-license-manager 6 | 7 | .. image:: https://img.shields.io/github/license/OddSource/java-license-manager.svg 8 | :target: https://github.com/OddSource/java-license-manager/blob/master/LICENSE.txt 9 | 10 | .. image:: https://img.shields.io/maven-central/v/io.oddsource.java/oss-parent.svg 11 | :target: https://search.maven.org/artifact/io.oddsource.java/oss-parent/ 12 | 13 | .. image:: https://img.shields.io/github/release/OddSource/java-license-manager/all.svg 14 | :target: https://github.com/OddSource/java-license-manager/releases 15 | 16 | A Java-based licensing tool for licensing commercial applications. 17 | 18 | Introduction 19 | ------------ 20 | 21 | An introduction and documentation are coming soon. 22 | -------------------------------------------------------------------------------- /Samples/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 21 | 4.0.0 22 | 23 | 24 | io.oddsource.java.licensing 25 | licensing-parent 26 | 2.0.0-SNAPSHOT 27 | 28 | 29 | licensing-samples 30 | 31 | OddSource Code Java License Manager - Samples 32 | 33 | 34 | 35 | io.oddsource.java.licensing 36 | licensing-core 37 | ${project.version} 38 | compile 39 | 40 | 41 | 42 | io.oddsource.java.licensing 43 | licensing-licensor-base 44 | ${project.version} 45 | compile 46 | 47 | 48 | 49 | 50 | source/production/java 51 | 52 | 53 | source/production/resources 54 | 55 | 56 | META-INF 57 | ../build/jar/META-INF 58 | 59 | 60 | 61 | 62 | 63 | 64 | org.apache.maven.plugins 65 | maven-surefire-plugin 66 | 2.9 67 | 68 | true 69 | 70 | 71 | 72 | 73 | 74 | 75 | -------------------------------------------------------------------------------- /Samples/source/production/java/io/oddsource/java/licensing/samples/SampleFilePrivateKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.samples; 17 | 18 | import java.io.IOException; 19 | 20 | import org.apache.commons.io.IOUtils; 21 | 22 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 23 | import io.oddsource.java.licensing.licensor.encryption.PrivateKeyDataProvider; 24 | 25 | /** 26 | * A sample implementation of the {@link PrivateKeyDataProvider} interface that retrieves the private key from a file. 27 | * The License Manager user interfaces can generate this code for you. 28 | * 29 | * @author Nick Williams 30 | * @version 1.0.0 31 | * @see PrivateKeyDataProvider 32 | * @since 1.0.0 33 | */ 34 | @SuppressWarnings("unused") 35 | public final class SampleFilePrivateKeyDataProvider implements PrivateKeyDataProvider 36 | { 37 | /** 38 | * Constructor. 39 | */ 40 | public SampleFilePrivateKeyDataProvider() 41 | { 42 | 43 | } 44 | 45 | /** 46 | * This method returns the data from the file containing the encrypted 47 | * private key from the public/private key pair. The contract for this 48 | * method can be fulfilled by storing the data in a byte array literal 49 | * in the source code itself. 50 | * 51 | * @return the encrypted file contents from the private key file. 52 | * 53 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 54 | * must be provided. 55 | */ 56 | public byte[] getEncryptedPrivateKeyData() throws KeyNotFoundException 57 | { 58 | try 59 | { 60 | return IOUtils.toByteArray( 61 | SampleFilePrivateKeyDataProvider.class.getResourceAsStream("sample.private.key") 62 | ); 63 | } 64 | catch(IOException e) 65 | { 66 | throw new KeyNotFoundException("The private key file was not found.", e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Samples/source/production/java/io/oddsource/java/licensing/samples/SampleFilePublicKeyDataProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.samples; 17 | 18 | import java.io.IOException; 19 | 20 | import org.apache.commons.io.IOUtils; 21 | 22 | import io.oddsource.java.licensing.encryption.PublicKeyDataProvider; 23 | import io.oddsource.java.licensing.exception.KeyNotFoundException; 24 | 25 | /** 26 | * A sample implementation of the {@link PublicKeyDataProvider} interface that retrieves the public key from a file. 27 | * The License Manager user interfaces can generate this code for you. 28 | * 29 | * @author Nick Williams 30 | * @version 1.0.0 31 | * @see PublicKeyDataProvider 32 | * @since 1.0.0 33 | */ 34 | @SuppressWarnings("unused") 35 | public final class SampleFilePublicKeyDataProvider implements PublicKeyDataProvider 36 | { 37 | /** 38 | * Constructor. 39 | */ 40 | public SampleFilePublicKeyDataProvider() 41 | { 42 | 43 | } 44 | 45 | /** 46 | * This method returns the data from the file containing the encrypted 47 | * public key from the public/private key pair. The contract for this 48 | * method can be fulfilled by storing the data in a byte array literal 49 | * in the source code itself. 50 | * 51 | * @return the encrypted file contents from the public key file. 52 | * 53 | * @throws KeyNotFoundException if the key data could not be retrieved; an acceptable message or chained cause 54 | * must be provided. 55 | */ 56 | public byte[] getEncryptedPublicKeyData() throws KeyNotFoundException 57 | { 58 | try 59 | { 60 | return IOUtils.toByteArray( 61 | SampleFilePublicKeyDataProvider.class.getResourceAsStream("sample.public.key") 62 | ); 63 | } 64 | catch(IOException e) 65 | { 66 | throw new KeyNotFoundException("The public key file was not found.", e); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /Samples/source/production/java/io/oddsource/java/licensing/samples/SampleLicenseRestrictedObject.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.samples; 17 | 18 | import io.oddsource.java.licensing.FeatureRestriction; 19 | import io.oddsource.java.licensing.FeatureRestrictionOperand; 20 | 21 | /** 22 | * Gives some examples of how to use the {@code @FeatureRestriction} annotation. 23 | * 24 | * @author Nicholas Williams 25 | * @version 1.0.0 26 | * @since 1.0.0 27 | */ 28 | @FeatureRestriction("FEATURE1") 29 | @SuppressWarnings({"unused", "EmptyMethod"}) 30 | public class SampleLicenseRestrictedObject 31 | { 32 | /** 33 | * Constructor. 34 | */ 35 | public SampleLicenseRestrictedObject() 36 | { 37 | 38 | } 39 | 40 | /** 41 | * Demonstrates using {@code @FeatureRestriction} to require that both features be licensed in order to invoke 42 | * this method. 43 | */ 44 | @FeatureRestriction({"FEATURE2", "FEATURE3"}) 45 | public void furtherRestrictedFeature() 46 | { 47 | 48 | } 49 | 50 | /** 51 | * Demonstrates using {@code @FeatureRestriction} to require that at least one of these features be licensed in 52 | * order to invoke this method. 53 | */ 54 | @FeatureRestriction(value = {"FEATURE2", "FEATURE3"}, operand = FeatureRestrictionOperand.OR) 55 | public void furtherLessRestrictedFeature() 56 | { 57 | 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /Samples/source/production/java/io/oddsource/java/licensing/samples/SamplePasswordProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package io.oddsource.java.licensing.samples; 17 | 18 | import io.oddsource.java.licensing.encryption.PasswordProvider; 19 | 20 | /** 21 | * A sample implementation of the {@link PasswordProvider} interface. The License Manager user interfaces can generate 22 | * this code for you. 23 | * 24 | * @author Nick Williams 25 | * @version 1.0.0 26 | * @see PasswordProvider 27 | * @since 1.0.0 28 | */ 29 | @SuppressWarnings("unused") 30 | public final class SamplePasswordProvider implements PasswordProvider 31 | { 32 | /** 33 | * Constructor. 34 | */ 35 | public SamplePasswordProvider() 36 | { 37 | 38 | } 39 | 40 | /** 41 | * Returns the password. 42 | * 43 | * @return The password 44 | */ 45 | public char[] getPassword() 46 | { 47 | return new char[] { 48 | 's', 'a', 'm', 'p', 'l', 'e', 'K', 'e', 'y', '1', '9', '8', '4', 49 | }; 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Samples/source/production/java/io/oddsource/java/licensing/samples/package-info.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2010-2019 OddSource Code (license@oddsource.io) 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | /** 17 | * This package contains samples for using the OddSource Code Java License Manager. 18 | * 19 | * @author Nick Williams 20 | * @version 1.0.0 21 | * @since 1.0.0 22 | */ 23 | @FeatureRestriction("PACKAGE1") 24 | package io.oddsource.java.licensing.samples; 25 | 26 | import io.oddsource.java.licensing.FeatureRestriction; 27 | 28 | -------------------------------------------------------------------------------- /Samples/source/production/resources/io/oddsource/java/licensing/samples/sample.private.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Samples/source/production/resources/io/oddsource/java/licensing/samples/sample.private.key -------------------------------------------------------------------------------- /Samples/source/production/resources/io/oddsource/java/licensing/samples/sample.public.key: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OddSource/java-license-manager/ee9039e42c47733af4bbd04a404fd96cf11dc939/Samples/source/production/resources/io/oddsource/java/licensing/samples/sample.public.key -------------------------------------------------------------------------------- /build/checkstyle-suppressions.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | -------------------------------------------------------------------------------- /build/jar/META-INF/NOTICE.txt: -------------------------------------------------------------------------------- 1 | Licensing 2 | --------- 3 | OddSource Code License Manager 4 | Copyright (c) 2010-2019 Nicholas Williams 5 | Licensed under the Apache License version 2.0 (see LICENSE.txt) 6 | 7 | This product includes software developed by 8 | The Apache Software Foundation (http://www.apache.org/). 9 | 10 | 11 | Cryptographic Software Notice 12 | ----------------------------- 13 | 14 | This distribution may include software that has been designed for use 15 | with cryptographic software. The country in which you currently reside 16 | may have restrictions on the import, possession, use, and/or re-export 17 | to another country, of encryption software. BEFORE using any encryption 18 | software, please check your country's laws, regulations and policies 19 | concerning the import, possession, or use, and re-export of encryption 20 | software, to see if this is permitted. See 21 | for more information. 22 | 23 | The U.S. Government Department of Commerce, Bureau of Industry and 24 | Security (BIS), has classified this software as Export Commodity 25 | Control Number (ECCN) 5D002.c.1, which includes information security 26 | software using or performing cryptographic functions with symmetric and 27 | asymmetric algorithms (5A002.a.1.a and 5A002.a.1.b, respectively). 28 | The form and manner of this OddSource Code Java Code distribution makes it 29 | eligible for export under the License Exception ENC Technology Software 30 | Unrestricted (TSU) exception (see the BIS Export Administration 31 | Regulations, Section 740.13) for both object code and source code. 32 | 33 | The following provides more details on the included software that 34 | may be subject to export controls on cryptographic software: 35 | 36 | OddSource Code License Manager interfaces with the 37 | Java(TM) Cryptography Architecture (JCA) API to provide: 38 | 39 | o Shared key-based encryption and decryption 40 | of licensing components 41 | 42 | o Key pair-based signature and verification 43 | of licensing data 44 | 45 | OddSource Code License Manager does not include any implementation 46 | of JCA. 47 | 48 | 49 | Contact 50 | ------- 51 | 52 | o For general information visit the main project site at 53 | http://oddsource.io/java/license-manager 54 | 55 | o For help and bug reports visit the issue tracker at 56 | https://github.com/OddSource/java-license-manager/issues 57 | -------------------------------------------------------------------------------- /build/spotbugs-exclude.xml: -------------------------------------------------------------------------------- 1 | 2 | 19 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | --------------------------------------------------------------------------------