File tree Expand file tree Collapse file tree 2 files changed +17
-7
lines changed
src/main/java/io/cos/cas/osf
authentication/handler/support Expand file tree Collapse file tree 2 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -165,14 +165,16 @@ protected final AuthenticationHandlerExecutionResult authenticateOsfPostgresInte
165
165
if (oneTimePassword == null ) {
166
166
throw new OneTimePasswordRequiredException ("2FA TOTP required for user [" + username + "]" );
167
167
}
168
+ final long transformedOneTimePassword = Long .parseLong (oneTimePassword );
169
+ boolean checkPassed ;
168
170
try {
169
- final long transformedOneTimePassword = Long .parseLong (oneTimePassword );
170
- if (!TotpUtils .checkCode (osfTotp .getTotpSecretBase32 (), transformedOneTimePassword )) {
171
- throw new InvalidOneTimePasswordException ("Invalid 2FA TOTP for user [" + username + "] (Type 1)" );
172
- }
173
- } catch (final Exception e ) {
171
+ checkPassed = TotpUtils .checkCode (osfTotp .getTotpSecretBase32 (), transformedOneTimePassword );
172
+ } catch (final Exception e ){
174
173
throw new InvalidOneTimePasswordException ("Invalid 2FA TOTP for user [" + username + "] (Type 2)" );
175
174
}
175
+ if (!checkPassed ) {
176
+ throw new InvalidOneTimePasswordException ("Invalid 2FA TOTP for user [" + username + "] (Type 1)" );
177
+ }
176
178
}
177
179
178
180
if (!osfUser .isTermsOfServiceAccepted () && !isTermsOfServiceChecked ) {
Original file line number Diff line number Diff line change 4
4
import lombok .Getter ;
5
5
import lombok .NoArgsConstructor ;
6
6
import lombok .ToString ;
7
+ import lombok .extern .slf4j .Slf4j ;
7
8
8
9
import org .apache .commons .codec .binary .Base32 ;
9
10
28
29
@ NoArgsConstructor
29
30
@ Getter
30
31
@ ToString
32
+ @ Slf4j
31
33
public class OsfTotp extends AbstractOsfModel {
32
34
33
35
@ OneToOne
@@ -50,8 +52,14 @@ private boolean isDeleted() {
50
52
}
51
53
52
54
public String getTotpSecretBase32 () {
53
- final byte [] bytes = DatatypeConverter .parseHexBinary (totpSecret );
54
- return new Base32 ().encodeAsString (bytes );
55
+ try {
56
+ // Handle totpSecret generated before OSF Python 3.12 upgrade
57
+ final byte [] bytes = DatatypeConverter .parseHexBinary (totpSecret );
58
+ return new Base32 ().encodeAsString (bytes );
59
+ } catch (final IllegalArgumentException e ) {
60
+ // Handle totpSecret generated after OSF Python 3.12 upgrade
61
+ return new Base32 ().encodeAsString (totpSecret .getBytes ());
62
+ }
55
63
}
56
64
57
65
public boolean isActive () {
You can’t perform that action at this time.
0 commit comments