Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
# Conflicts:
#	source/java/libs/org.lucee.argon2-2.11.0.jar
#	source/java/libs/org.lucee.argon2-jvm-nolibs-2.11.0.jar
  • Loading branch information
michaeloffner committed Aug 30, 2024
2 parents 6709c70 + ade0db2 commit 4a97aba
Show file tree
Hide file tree
Showing 7 changed files with 214 additions and 13 deletions.
81 changes: 81 additions & 0 deletions .github/workflows/main-version-picker.yml
Original file line number Diff line number Diff line change
@@ -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
56 changes: 56 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions source/java/src/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Expand All @@ -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();
Expand Down
15 changes: 11 additions & 4 deletions source/java/src/org/lucee/extension/argon2/GenerateArgon2Hash.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
}
}
Expand All @@ -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);
}
}

Expand All @@ -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);
}
}

Expand Down
30 changes: 26 additions & 4 deletions tests/functions/Argon2CheckHash.cfc
Original file line number Diff line number Diff line change
@@ -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();
});
});
}

}
}

32 changes: 32 additions & 0 deletions tests/functions/GenerateArgon2Hash.cfc
Original file line number Diff line number Diff line change
@@ -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();
});
});
}

}

0 comments on commit 4a97aba

Please sign in to comment.