Skip to content

Commit 86b1763

Browse files
authored
GAM TOTP EO migration to Github (#895)
* GAM EO for TOTP * Overwrite transitive vulnerable dependency * Add gamtotp module to readme file
1 parent 8556bc4 commit 86b1763

File tree

4 files changed

+158
-11
lines changed

4 files changed

+158
-11
lines changed

README.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,17 @@ These are the source of the GeneXus Standard Classes for Java, valid since GeneX
99

1010
## Modules
1111

12-
| Name | Description
13-
|---|---
14-
| common | Classes common to Android and Java
15-
| gxcryptocommon | Classes common to Android and Java related to Cryptography
16-
| gxmail | Classes related to mail handling
17-
| java | Java standard classes, output is gxclassr.jar
18-
| wrappercommon | Interfaces to encapsulate Java EE and Jakarta EE support, output is gxwrappercommon.jar
19-
| wrapperjavax | Implement the interfaces defined in wrappercommon in Java EE, output is gxwrapperjavax.jar
20-
| wrapperjakarta | Implement the interfaces defined in wrappercommon in Jakarta EE, output is gxwrapperjakarta.jar
21-
| gxoffice | Formerly Java classes are now separated to be included only when using office.
22-
| gxsearch | Formerly in Java classes are now separated to be included only when using search.
12+
| Name | Description
13+
|--------------------------------|---
14+
| common | Classes common to Android and Java
15+
| gxcryptocommon | Classes common to Android and Java related to Cryptography
16+
| gxmail | Classes related to mail handling
17+
| java | Java standard classes, output is gxclassr.jar
18+
| wrappercommon | Interfaces to encapsulate Java EE and Jakarta EE support, output is gxwrappercommon.jar
19+
| wrapperjavax | Implement the interfaces defined in wrappercommon in Java EE, output is gxwrapperjavax.jar
20+
| wrapperjakarta | Implement the interfaces defined in wrappercommon in Jakarta EE, output is gxwrapperjakarta.jar
21+
| gxoffice | Formerly Java classes are now separated to be included only when using office.
22+
| gxsearch | Formerly in Java classes are now separated to be included only when using search.
2323
| gxandroidpublisher and javapns | They are necessary for when you have Push Notifications in your old implementation. These are projects that should disappear in the short term.
2424
| android | The standard Android classes. **Note that this is not the full runtime for Android, the full runtime can be created by using the Android Flexible Client project**.
2525
| gxexternalproviders | Implements service provider for IBM Cloud, Google, Azure, Amazon
@@ -32,6 +32,7 @@ These are the source of the GeneXus Standard Classes for Java, valid since GeneX
3232
| gxftps | SecurityAPI's GeneXusFTPS module
3333
| gxsftp | SecurityAPI's GeneXusSFTP module
3434
| gamutils | GAM external object with utilities
35+
| gamtotp | GAM external object for RFC6238 implementation
3536

3637
The dependencies between the projects are specified in each pom.xml within their directory.
3738

gamtotp/pom.xml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<parent>
7+
<groupId>com.genexus</groupId>
8+
<artifactId>parent</artifactId>
9+
<version>${revision}${changelist}</version>
10+
</parent>
11+
12+
<artifactId>gamtotp</artifactId>
13+
<name>GAM TOTP</name>
14+
15+
<properties>
16+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
17+
</properties>
18+
19+
<dependencies>
20+
<dependency>
21+
<groupId>org.apache.logging.log4j</groupId>
22+
<artifactId>log4j-core</artifactId>
23+
<version>${log4j.version}</version>
24+
</dependency>
25+
<dependency>
26+
<groupId>dev.samstevens.totp</groupId>
27+
<artifactId>totp</artifactId>
28+
<version>1.7.1</version>
29+
</dependency>
30+
<dependency>
31+
<groupId>com.beust</groupId>
32+
<artifactId>jcommander</artifactId>
33+
<version>1.78</version>
34+
</dependency>
35+
36+
37+
</dependencies>
38+
39+
<build>
40+
<finalName>gamtotp</finalName>
41+
<plugins>
42+
<plugin>
43+
<groupId>org.apache.maven.plugins</groupId>
44+
<artifactId>maven-compiler-plugin</artifactId>
45+
<version>3.8.0</version>
46+
<configuration>
47+
</configuration>
48+
</plugin>
49+
</plugins>
50+
</build>
51+
</project>
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.genexus.totp;
2+
3+
import dev.samstevens.totp.code.CodeGenerator;
4+
import dev.samstevens.totp.code.DefaultCodeGenerator;
5+
import dev.samstevens.totp.code.DefaultCodeVerifier;
6+
import dev.samstevens.totp.code.HashingAlgorithm;
7+
import dev.samstevens.totp.qr.QrData;
8+
import dev.samstevens.totp.qr.QrGenerator;
9+
import dev.samstevens.totp.qr.ZxingPngQrGenerator;
10+
import dev.samstevens.totp.secret.DefaultSecretGenerator;
11+
import dev.samstevens.totp.secret.SecretGenerator;
12+
import dev.samstevens.totp.time.SystemTimeProvider;
13+
import dev.samstevens.totp.time.TimeProvider;
14+
import org.apache.logging.log4j.LogManager;
15+
import org.apache.logging.log4j.Logger;
16+
17+
import static dev.samstevens.totp.util.Utils.getDataUriForImage;
18+
19+
@SuppressWarnings("unused")
20+
public class TOTPAuthenticator {
21+
22+
private static final Logger logger = LogManager.getLogger(TOTPAuthenticator.class);
23+
24+
public static String GenerateKey(int keyLength) {
25+
logger.debug("GenerateKey");
26+
SecretGenerator secretGenerator = new DefaultSecretGenerator(keyLength * 8);
27+
String str = secretGenerator.generate();
28+
try {
29+
return str.substring(0, keyLength);
30+
} catch (Exception e) {
31+
logger.error("GenerateKey", e);
32+
return str;
33+
}
34+
}
35+
36+
public static String GenerateQRData(String accountName, String secretKey, String appName, String algorithm, int digits, int period) {
37+
logger.debug("GenerateQRData");
38+
HashingAlgorithm hashAlg;
39+
if (algorithm.equalsIgnoreCase("SHA512")) {
40+
hashAlg = HashingAlgorithm.SHA512;
41+
} else if (algorithm.equalsIgnoreCase("SHA256")) {
42+
hashAlg = HashingAlgorithm.SHA256;
43+
} else {
44+
hashAlg = HashingAlgorithm.SHA1;
45+
}
46+
47+
QrData data = new QrData.Builder()
48+
.label(accountName)
49+
.secret(secretKey)
50+
.issuer(appName)
51+
.algorithm(hashAlg)
52+
.digits(digits)
53+
.period(period)
54+
.build();
55+
56+
57+
QrGenerator generator = new ZxingPngQrGenerator();
58+
try {
59+
return getDataUriForImage(generator.generate(data), generator.getImageMimeType());
60+
} catch (Exception e) {
61+
logger.error("GenerateQRData", e);
62+
return null;
63+
}
64+
}
65+
66+
public static boolean VerifyTOTPCode(String secretKey, String code, String algorithm, int digits, int period) {
67+
logger.debug("VerifyTOTPCode");
68+
HashingAlgorithm hashAlg;
69+
if (algorithm.equalsIgnoreCase("SHA512")) {
70+
hashAlg = HashingAlgorithm.SHA512;
71+
} else if (algorithm.equalsIgnoreCase("SHA256")) {
72+
hashAlg = HashingAlgorithm.SHA256;
73+
} else {
74+
hashAlg = HashingAlgorithm.SHA1;
75+
}
76+
77+
TimeProvider timeProvider = new SystemTimeProvider();
78+
79+
CodeGenerator codeGenerator = new DefaultCodeGenerator(hashAlg, digits);
80+
DefaultCodeVerifier verifier = new DefaultCodeVerifier(codeGenerator, timeProvider);
81+
82+
// sets the time period for codes to be valid for to X seconds
83+
verifier.setTimePeriod(period);
84+
85+
// allow codes valid for 1 time periods before/after to pass as valid
86+
verifier.setAllowedTimePeriodDiscrepancy(0);
87+
88+
// secret = the shared secret for the user
89+
// code = the code submitted by the user
90+
return verifier.isValidCode(secretKey, code);
91+
}
92+
}
93+
94+

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@
120120
<module>gxsftp</module>
121121
<module>gxftps</module>
122122
<module>gamutils</module>
123+
<module>gamtotp</module>
123124
</modules>
124125

125126
<dependencies>

0 commit comments

Comments
 (0)