From 9bc6c46dc391f166aaa16477bce8afc7061979ab Mon Sep 17 00:00:00 2001 From: bwhitn Date: Sat, 16 Dec 2017 09:10:52 -0500 Subject: [PATCH 1/3] Fixed HOTP, TOTP and added test for HOTP --- src/core/operations/OTP.js | 5 +++-- test/index.js | 1 + test/tests/operations/OTP.js | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/tests/operations/OTP.js diff --git a/src/core/operations/OTP.js b/src/core/operations/OTP.js index ff67d1c8..20205053 100755 --- a/src/core/operations/OTP.js +++ b/src/core/operations/OTP.js @@ -1,5 +1,6 @@ import otp from "otp"; import Base64 from "./Base64.js"; +import Utils from "../Utils.js"; /** * One-Time Password operations. @@ -24,7 +25,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(input, []), + secret: Base64.runTo32(Utils.strToByteArray(input), []), epoch: args[3], timeSlice: args[4] }); @@ -44,7 +45,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(input, []), + secret: Base64.runTo32(Utils.strToByteArray(input), []), }); const counter = args[3]; return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`; diff --git a/test/index.js b/test/index.js index 773a5b14..d444fc51 100644 --- a/test/index.js +++ b/test/index.js @@ -25,6 +25,7 @@ import "./tests/operations/Hash.js"; import "./tests/operations/Image.js"; import "./tests/operations/MorseCode.js"; import "./tests/operations/MS.js"; +import "./tests/operations/OTP.js"; import "./tests/operations/StrUtils.js"; import "./tests/operations/SeqUtils.js"; diff --git a/test/tests/operations/OTP.js b/test/tests/operations/OTP.js new file mode 100644 index 00000000..b321e7cf --- /dev/null +++ b/test/tests/operations/OTP.js @@ -0,0 +1,23 @@ +/** + * OTP HOTP tests. + * + * @author bwhitn [brian.m.whitney@outlook.com] + * + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister.js"; + +TestRegister.addTests([ + { + name: "Generate HOTP", + input: "12345678901234567890", + expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224", + recipeConfig: [ + { + op: "Generate HOTP", + args: ["", 32, 6, 0], + }, + ], + }, +]); From 435ed587a53757ada3a7f00b48ccd8257b95c2f1 Mon Sep 17 00:00:00 2001 From: bwhitn Date: Sat, 16 Dec 2017 09:10:52 -0500 Subject: [PATCH 2/3] Fixed HOTP, TOTP and added test for HOTP --- src/core/operations/OTP.js | 5 +++-- test/index.js | 1 + test/tests/operations/OTP.js | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 test/tests/operations/OTP.js diff --git a/src/core/operations/OTP.js b/src/core/operations/OTP.js index ff67d1c8..20205053 100755 --- a/src/core/operations/OTP.js +++ b/src/core/operations/OTP.js @@ -1,5 +1,6 @@ import otp from "otp"; import Base64 from "./Base64.js"; +import Utils from "../Utils.js"; /** * One-Time Password operations. @@ -24,7 +25,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(input, []), + secret: Base64.runTo32(Utils.strToByteArray(input), []), epoch: args[3], timeSlice: args[4] }); @@ -44,7 +45,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(input, []), + secret: Base64.runTo32(Utils.strToByteArray(input), []), }); const counter = args[3]; return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`; diff --git a/test/index.js b/test/index.js index 748e1103..7f029b8d 100644 --- a/test/index.js +++ b/test/index.js @@ -26,6 +26,7 @@ import "./tests/operations/Image.js"; import "./tests/operations/MorseCode.js"; import "./tests/operations/MS.js"; import "./tests/operations/PHP.js"; +import "./tests/operations/OTP.js"; import "./tests/operations/StrUtils.js"; import "./tests/operations/SeqUtils.js"; diff --git a/test/tests/operations/OTP.js b/test/tests/operations/OTP.js new file mode 100644 index 00000000..b321e7cf --- /dev/null +++ b/test/tests/operations/OTP.js @@ -0,0 +1,23 @@ +/** + * OTP HOTP tests. + * + * @author bwhitn [brian.m.whitney@outlook.com] + * + * @copyright Crown Copyright 2017 + * @license Apache-2.0 + */ +import TestRegister from "../../TestRegister.js"; + +TestRegister.addTests([ + { + name: "Generate HOTP", + input: "12345678901234567890", + expectedOutput: "URI: otpauth://hotp/OTPAuthentication?secret=GEZDGNBVGY3TQOJQGEZDGNBVGY3TQOJQ\n\nPassword: 755224", + recipeConfig: [ + { + op: "Generate HOTP", + args: ["", 32, 6, 0], + }, + ], + }, +]); From f7e958e7a1cf0511c9736d7152400708fa92ddf4 Mon Sep 17 00:00:00 2001 From: n1474335 Date: Tue, 19 Dec 2017 14:38:13 +0000 Subject: [PATCH 3/3] Changed HOTP inputType to byteArray --- src/core/config/OperationConfig.js | 2 +- src/core/operations/OTP.js | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/core/config/OperationConfig.js b/src/core/config/OperationConfig.js index 56b6cca1..38dad80b 100755 --- a/src/core/config/OperationConfig.js +++ b/src/core/config/OperationConfig.js @@ -3840,7 +3840,7 @@ const OperationConfig = { "Generate HOTP": { module: "Default", description: "The HMAC-based One-Time Password algorithm (HOTP) is an algorithm that computes a one-time password from a shared secret key and an incrementing counter. It has been adopted as Internet Engineering Task Force standard RFC 4226, is the cornerstone of Initiative For Open Authentication (OATH), and is used in a number of two-factor authentication systems.

Enter the secret as the input or leave it blank for a random secret to be generated.", - inputType: "string", + inputType: "byteArray", outputType: "string", args: [ { diff --git a/src/core/operations/OTP.js b/src/core/operations/OTP.js index 20205053..f7862310 100755 --- a/src/core/operations/OTP.js +++ b/src/core/operations/OTP.js @@ -1,6 +1,6 @@ import otp from "otp"; import Base64 from "./Base64.js"; -import Utils from "../Utils.js"; + /** * One-Time Password operations. @@ -25,7 +25,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(Utils.strToByteArray(input), []), + secret: Base64.runTo32(input, []), epoch: args[3], timeSlice: args[4] }); @@ -45,7 +45,7 @@ const OTP = { name: args[0], keySize: args[1], codeLength: args[2], - secret: Base64.runTo32(Utils.strToByteArray(input), []), + secret: Base64.runTo32(input, []), }); const counter = args[3]; return `URI: ${otpObj.hotpURL}\n\nPassword: ${otpObj.hotp(counter)}`;