diff --git a/.github/workflows/main-version-picker.yml b/.github/workflows/main-version-picker.yml new file mode 100644 index 0000000..006c74b --- /dev/null +++ b/.github/workflows/main-version-picker.yml @@ -0,0 +1,81 @@ +# This workflow will build a Java project with Ant +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant + +name: Build with custom Java and Lucee + +on: # Allows you to run this workflow manually from the Actions tab + workflow_dispatch: + inputs: + lucee_version_query: + required: true + type: string + default: '0/all/light' + java_version: + required: true + type: string + default: "11" + # Triggers the workflow on push or pull request events but only for the master branch + workflow_call: + inputs: + lucee_version_query: + required: true + type: string + default: '0/all/light' + java_version: + required: true + type: string + default: "11" + +jobs: + build: + runs-on: ubuntu-latest + env: + luceeVersion: ${{ inputs.lucee_version_query }} + luceeVersionQuery: ${{ inputs.lucee_version_query }} + steps: + - uses: actions/checkout@v4 + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: lucee-script-runner-maven-cache + enableCrossOsArchive: true + - name: Cache Lucee files + uses: actions/cache@v4 + with: + path: ~/work/_actions/lucee/script-runner/main/lucee-download-cache + key: lucee-downloads + enableCrossOsArchive: true + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'adopt' + - name: Build with Ant + run: ant -noinput -verbose -buildfile build.xml + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: argon2-lex + path: dist/*.lex + - name: Checkout Lucee + uses: actions/checkout@v4 + with: + repository: lucee/lucee + path: lucee + - name: Set up JDK ${{ inputs.java_version }} + uses: actions/setup-java@v4 + with: + java-version: ${{ inputs.java_version }} + distribution: 'adopt' + - name: Run Lucee Test Suite (testFilter="argon2") + uses: lucee/script-runner@main + with: + webroot: ${{ github.workspace }}/lucee/test + execute: /bootstrap-tests.cfm + luceeVersion: ${{ env.luceeVersion }} + luceeVersionQuery: ${{ env.luceeVersionQuery }} + extensionDir: ${{ github.workspace }}/dist + env: + testLabels: argon2 + testAdditional: ${{ github.workspace }}/tests diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml new file mode 100644 index 0000000..eb9346e --- /dev/null +++ b/.github/workflows/main.yml @@ -0,0 +1,56 @@ +# This workflow will build a Java project with Ant +# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-ant + +name: Java CI + +on: [push, pull_request,workflow_dispatch] + +jobs: + build: + + runs-on: ubuntu-latest + env: + luceeVersion: light-6.0.0.451-BETA + luceeVersionQuery: 0/all/light + steps: + - uses: actions/checkout@v4 + - name: Set up JDK 11 + uses: actions/setup-java@v4 + with: + java-version: '11' + distribution: 'adopt' + - name: Cache Maven packages + uses: actions/cache@v4 + with: + path: ~/.m2 + key: lucee-script-runner-maven-cache + enableCrossOsArchive: true + - name: Cache Lucee files + uses: actions/cache@v4 + with: + path: ~/work/_actions/lucee/script-runner/main/lucee-download-cache + key: lucee-downloads + enableCrossOsArchive: true + - name: Build with Ant + run: ant -noinput -verbose -buildfile build.xml + - name: Upload Artifact + uses: actions/upload-artifact@v4 + with: + name: argon2-lex + path: dist/*.lex + - name: Checkout Lucee + uses: actions/checkout@v4 + with: + repository: lucee/lucee + path: lucee + - name: Run Lucee Test Suite (testFilter="argon2") + uses: lucee/script-runner@main + with: + webroot: ${{ github.workspace }}/lucee/test + execute: /bootstrap-tests.cfm + luceeVersion: ${{ env.luceeVersion }} + luceeVersionQuery: ${{ env.luceeVersionQuery }} + extensionDir: ${{ github.workspace }}/dist + env: + testLabels: argon2 + testAdditional: ${{ github.workspace }}/tests diff --git a/source/java/src/META-INF/MANIFEST.MF b/source/java/src/META-INF/MANIFEST.MF index 676c00c..1ee2f7c 100644 --- a/source/java/src/META-INF/MANIFEST.MF +++ b/source/java/src/META-INF/MANIFEST.MF @@ -1,6 +1,4 @@ Manifest-Version: 1.0 Export-Package: org.lucee.extension.argon2 Bundle-ManifestVersion: 2 -Require-Bundle: org.lucee.argon2;bundle-version=2.11.0, - org.lucee.argon2-jvm-nolibs;bundle-version=2.11.0, - com.sun.jna;bundle-version=5.8.0 +Require-Bundle: org.lucee.argon2;bundle-version=2.7.0 \ No newline at end of file diff --git a/source/java/src/org/lucee/extension/argon2/Argon2CheckHash.java b/source/java/src/org/lucee/extension/argon2/Argon2CheckHash.java index 9e9a635..e451ce7 100644 --- a/source/java/src/org/lucee/extension/argon2/Argon2CheckHash.java +++ b/source/java/src/org/lucee/extension/argon2/Argon2CheckHash.java @@ -29,7 +29,7 @@ public static boolean call(PageContext pc, String input, String hash) throws Pag Argon2Types type; String variant = getVariant(pc, hash); if (Util.isEmpty(variant, true)) - throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 1, "variant", "The Variant should be ARGON2i or ARGON2d", null); + throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 1, "variant", "The Variant should be ARGON2i, ARGON2id or ARGON2d", null); variant = variant.trim(); switch (variant.toLowerCase()) { case "argon2i": @@ -38,8 +38,13 @@ public static boolean call(PageContext pc, String input, String hash) throws Pag case "argon2d": type = Argon2Types.ARGON2d; break; + case "argon2id": + type = Argon2Types.ARGON2id; + break; + default: - throw eng.getExceptionUtil().createFunctionException(pc, "Argon2CheckHash", 1, "variant", "The Variant should be ARGON2i or ARGON2d", null); + throw eng.getExceptionUtil().createFunctionException(pc, "Argon2CheckHash", 1, "variant", + "The Variant should be ARGON2i, ARGON2id or ARGON2d, was [" + variant + "]", null); } Argon2 argon2 = Argon2Factory.create(type); char[] carrInput = input == null ? new char[0] : input.toCharArray(); diff --git a/source/java/src/org/lucee/extension/argon2/GenerateArgon2Hash.java b/source/java/src/org/lucee/extension/argon2/GenerateArgon2Hash.java index f146192..907c54f 100644 --- a/source/java/src/org/lucee/extension/argon2/GenerateArgon2Hash.java +++ b/source/java/src/org/lucee/extension/argon2/GenerateArgon2Hash.java @@ -42,8 +42,12 @@ public Object invoke(PageContext pc, Object[] args) throws PageException { case "argon2d": variant = Argon2Types.ARGON2d; break; + case "argon2id": + variant = Argon2Types.ARGON2id; + break; default: - throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 1, "variant", "The Variant should be ARGON2i or ARGON2d", null); + throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 1, "variant", + "The Variant should be ARGON2i, ARGON2id or ARGON2d, was [" + tmp + "]" , null); } } else variant = null; @@ -54,7 +58,8 @@ public Object invoke(PageContext pc, Object[] args) throws PageException { if (args.length > 2) { parallelismFactor = cast.toIntValue(args[2]); if (parallelismFactor < 1 || parallelismFactor > 10) { - throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 2, "parallelismFactor", "The parallelism factor value should be between 1 and 10", + throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 2, "parallelismFactor", + "The parallelism factor value should be between 1 and 10, was [" + parallelismFactor + "]", null); } } @@ -64,7 +69,8 @@ public Object invoke(PageContext pc, Object[] args) throws PageException { if (args.length > 3) { memory = cast.toIntValue(args[3]); if (memory < 8 || memory > 100000) { - throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 3, "memoryCost", "The memory cost value should be between 8 and 100000", null); + throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 3, "memoryCost", + "The memory cost value should be between 8 and 100000, was [" + memory + "]", null); } } @@ -73,7 +79,8 @@ public Object invoke(PageContext pc, Object[] args) throws PageException { if (args.length > 4) { iterations = cast.toIntValue(args[4]); if (iterations < 1 || iterations > 20) { - throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 4, "iterations", "The iterations value should be between 1 and 20", null); + throw eng.getExceptionUtil().createFunctionException(pc, "GenerateArgon2Hash", 4, "iterations", + "The iterations value should be between 1 and 20, was [" + iterations + "]", null); } } diff --git a/tests/functions/Argon2CheckHash.cfc b/tests/functions/Argon2CheckHash.cfc index 34f1d1f..4d32873 100644 --- a/tests/functions/Argon2CheckHash.cfc +++ b/tests/functions/Argon2CheckHash.cfc @@ -1,11 +1,33 @@ -component extends="org.lucee.cfml.test.LuceeTestCase" labels="s3" { +component extends="org.lucee.cfml.test.LuceeTestCase" labels="argon2" { function run( testResults , testBox ) { describe( title="Test suite for Argon2CheckHash()", body=function() { - it(title="check Argon2CheckHash", body = function( currentSpec ) { + it(title="check Argon2CheckHash (default)", body = function( currentSpec ) { var hashedValue = GenerateArgon2Hash("CFDocs.org"); expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); - }); + }); + + it(title="check Argon2CheckHash (argon2i)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2i"); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash (argon2d)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2d"); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash (argon2id)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2id"); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("lucee","ARGON2i"); + var hashedValue = "$argon2i$v=19$m=8,t=1,p=1$ccCBeNYDdvv5FYAAjNYaoA$+sfZnhMn1IA1VIslUFqd6dk2+LX1But4mhC8Wx4Q+Dg"; + expect(Argon2CheckHash( "lucee", hashedValue)).ToBeTrue(); + }); }); } -} \ No newline at end of file +} + diff --git a/tests/functions/GenerateArgon2Hash.cfc b/tests/functions/GenerateArgon2Hash.cfc new file mode 100644 index 0000000..574dc4d --- /dev/null +++ b/tests/functions/GenerateArgon2Hash.cfc @@ -0,0 +1,32 @@ +component extends="org.lucee.cfml.test.LuceeTestCase" labels="argon2" { + + function run( testResults , testBox ) { + describe( title="Test suite for Argon2CheckHash()", body=function() { + it(title="check Argon2CheckHash (default)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org"); + expect( hashedValue ).toInclude( "$argon2i$" ); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash (argon2i)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2i"); + expect( hashedValue ).toInclude( "$argon2i$" ); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash (argon2d)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2d"); + expect( hashedValue ).toInclude( "$argon2d$" ); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + + it(title="check Argon2CheckHash (argon2id)", body = function( currentSpec ) { + var hashedValue = GenerateArgon2Hash("CFDocs.org", "argon2id"); + expect( hashedValue ).toInclude( "$argon2id$" ); + expect(Argon2CheckHash( "CFDocs.org", hashedValue)).ToBeTrue(); + }); + }); + } + +} +