Skip to content

Commit 5fbfeb6

Browse files
committed
Merge branch 'feature/modern-password-1' into develop
2 parents 3bbb7cd + 71c1968 commit 5fbfeb6

File tree

7 files changed

+103
-12
lines changed

7 files changed

+103
-12
lines changed

Logic/LSAccount/LSChangePasswordCommand.m

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -296,6 +296,19 @@ - (void)_executeInContext:(id)_context {
296296
[self _writePasswordToLdap:_context writeOnly:NO];
297297
else {
298298
[super _executeInContext:_context];
299+
300+
// 2025-04-25: See LSLoginAccountCommand for details!
301+
extern NSString *GetSHA512PasswordUpdate(NSString *, NSString *);
302+
id obj = [self object];
303+
304+
NSString *sql = GetSHA512PasswordUpdate(
305+
self->newPlainTextPassword, [[obj valueForKey:@"companyId"] stringValue]);
306+
307+
EOAdaptorChannel *adChannel = [[self databaseChannel] adaptorChannel];
308+
id error;
309+
if ((error = [adChannel evaluateExpressionX:sql]) != nil) {
310+
[self errorWithFormat:@"Couldn't write modern_password: %@", error];
311+
}
299312

300313
if (WritePasswordToLDAP)
301314
[self _writePasswordToLdap:_context writeOnly:YES];

Logic/LSAccount/LSLoginAccountCommand.m

Lines changed: 75 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
#include "LSGetAccountCommand.h"
23+
#import <openssl/sha.h> // hh(2025-04-25) will this build?
2324

2425
@class NSString, NSNumber;
2526

@@ -56,6 +57,54 @@ - (id)initWithUserDefaults:(NSUserDefaults *)_ud
5657
andContext:(LSCommandContext *)_tx;
5758
@end
5859

60+
NSString *GetSHA512PasswordUpdate(NSString *plainPassword, NSString *companyId)
61+
{
62+
const char *cstr = [plainPassword UTF8String];
63+
unsigned char hash[SHA512_DIGEST_LENGTH];
64+
SHA512((const unsigned char*)cstr, strlen(cstr), hash);
65+
66+
NSMutableString *sha512 =
67+
[NSMutableString stringWithCapacity:SHA512_DIGEST_LENGTH * 2 + 8];
68+
[sha512 appendString:@"{SHA512}"];
69+
70+
int i;
71+
for (i = 0; i < SHA512_DIGEST_LENGTH; i++) {
72+
[sha512 appendFormat:@"%02x", hash[i]];
73+
}
74+
75+
/* What we do here should be pretty safe wrt SQL injection given the
76+
* nature of the values. Would be better to do with the entity/adaptor
77+
* anyways */
78+
NSMutableString *sql = [NSMutableString stringWithCapacity:256];
79+
/*
80+
DO $$
81+
BEGIN
82+
BEGIN
83+
EXECUTE 'UPDATE my_table SET missing_column = 42';
84+
EXCEPTION
85+
WHEN undefined_column THEN
86+
RAISE NOTICE 'Column does not exist, update skipped.';
87+
END;
88+
END;
89+
$$;*/
90+
[sql appendString:@"DO $$ BEGIN BEGIN EXECUTE '"];
91+
92+
[sql appendString:@"UPDATE person SET modern_password = ''"];
93+
[sql appendString:sha512];
94+
[sql appendString:@"'' WHERE company_id = "];
95+
[sql appendString:companyId];
96+
[sql appendString:@" AND (modern_password != ''"];
97+
[sql appendString:sha512];
98+
[sql appendString:@"'' OR modern_password IS NULL)"];
99+
100+
[sql appendString:@"'; "];
101+
102+
[sql appendString:@"EXCEPTION WHEN undefined_column THEN "];
103+
[sql appendString:@"RAISE NOTICE 'Column does not exist, update skipped.'; "];
104+
[sql appendString:@"END; END; $$;"];
105+
return sql;
106+
}
107+
59108
@implementation LSLoginAccountCommand
60109

61110
- (id)initForOperation:(NSString *)_operation inDomain:(NSString *)_domain {
@@ -120,7 +169,7 @@ - (void)_executeInContext:(id)_context {
120169
qualifierFormat:
121170
@"login='%@' AND isAccount=1 AND "
122171
@"(NOT login='template') AND "
123-
@"(isLocked=0 OR isLocked is null)",
172+
@"(isLocked=0 OR isLocked IS NULL)",
124173
userName];
125174
isArchivedQualifier =
126175
[[EOSQLQualifier alloc] initWithEntity:[self entity]
@@ -186,14 +235,14 @@ - (void)_executeInContext:(id)_context {
186235
}
187236
}
188237
else { /* use table for authorization */
189-
NSString *cryptedPwd = nil;
190-
id accountPassword;
191-
192-
accountPassword = [account valueForKey:@"password"];
193-
238+
239+
// This is the hashed password in the account.
240+
id accountPassword = [account valueForKey:@"password"];
194241
if (accountPassword == nil)
195242
accountPassword = @"";
196-
243+
244+
// The crypted version of the password.
245+
NSString *cryptedPwd = nil;
197246
if (![self->crypted boolValue] && [[self password] isNotEmpty]) {
198247
id cmd = LSLookupCommandV(@"system", @"crypt",
199248
@"password", [self password],
@@ -232,6 +281,25 @@ - (void)_executeInContext:(id)_context {
232281
if (account) {
233282
NSUserDefaults *defs;
234283

284+
// 2025-04-25:
285+
// HH: Persist a better hash.
286+
// We could also upgrade from crypt to SHA512, but for that we would need
287+
// to support this everywhere, doesn't seem worthwile, just yet? Move Auth
288+
// out of OGo itself into Apache instead?
289+
// TODO: protect by default
290+
if (![self->crypted boolValue]) {
291+
NSString *sql = GetSHA512PasswordUpdate(
292+
[self password], [[account valueForKey:@"companyId"] stringValue]);
293+
294+
EOAdaptorChannel *adChannel = [[self databaseChannel] adaptorChannel];
295+
id error;
296+
if ((error = [adChannel evaluateExpressionX:sql]) != nil) {
297+
[self errorWithFormat:@"Couldn't write modern_password: %@", error];
298+
}
299+
}
300+
301+
302+
235303
/* load defaults */
236304

237305
Class defaultsClass = NGClassFromString(@"LSUserDefaults");

Logic/LSFoundation/OGoContextManager.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ - (BOOL)isLoginAuthorized:(NSString *)_login password:(NSString *)_pwd
503503
return NO;
504504
}
505505

506-
if (_crypted) {
506+
if (_crypted && [LSCommandContext useLDAPAuthorization]) {
507507
[self errorWithFormat:
508508
@"%s: cannot not perform LDAP-Login with crypted password",
509509
__PRETTY_FUNCTION__];

WebUI/Common/OGoUIElements/SkyCalendarPopUp.m

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,11 @@ - (NSString *)popupScript {
140140

141141
return [NSString stringWithFormat:
142142
@"<!--\n"
143-
@" var calendar_%@ = new skycalendar(%@);\n"
144-
@" calendar_%@.setCalendarPage('%@');\n"
145-
@" calendar_%@.setDateFormat('%@');\n"
143+
@" setTimeout(function() {\n"
144+
@" window.calendar_%@ = new skycalendar(%@);\n"
145+
@" window.calendar_%@.setCalendarPage('%@');\n"
146+
@" window.calendar_%@.setDateFormat('%@');\n"
147+
@" }, 50);\n"
146148
@"// -->",
147149
self->elementName, fullName,
148150
self->elementName, [self calendarPageURL],

WebUI/Templates/LSWProject/LSWProjectEditor.wod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ ProjectEditor: LSWObjectEditor {
3030
{ key = "name"; },
3131
{ key = "number"; label = "code"; },
3232
{ key = "startDate"; calendarFormat = "%Y-%m-%d"; time = "00:00:00"; },
33+
{ key = "endDate"; calendarFormat = "%Y-%m-%d"; time = "23:59:59"; }
3334
);
3435
}
3536

WebUI/Templates/LSWProject/SkyProjectInlineViewer.html

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,13 @@
1515
<tr>
1616
<#SubAttributeCell><#Font><#StartDateLabel/>:</#Font></#SubAttributeCell>
1717
<#SubValueCell><#Font>
18-
<#ProjectStartDate/> <!-- - <#ProjectEndDate/> -->
18+
<#ProjectStartDate/>
19+
</#Font></#SubValueCell>
20+
</tr>
21+
<tr>
22+
<#SubAttributeCell><#Font><#EndDateLabel/>:</#Font></#SubAttributeCell>
23+
<#SubValueCell><#Font>
24+
<#ProjectEndDate/>
1925
</#Font></#SubValueCell>
2026
</tr>
2127

WebUI/Templates/LSWProject/SkyProjectInlineViewer.wod

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Buttons: SkyButtonRow {
2525
NameLabel: WOString { value = labels.name; }
2626
NumberLabel: WOString { value = labels.number; }
2727
StartDateLabel: WOString { value = labels.startDate; }
28+
EndDateLabel: WOString { value = labels.endDate; }
2829

2930
ProjectName: WOString { value = project.name; }
3031
ProjectNumber: WOString { value = project.number; }

0 commit comments

Comments
 (0)