Browse Source

Mac version: Use new-style MySQL connection (i.e. MYSQL_OPT_SSL_VERIFY_SERVER_CERT no l0nger exists), fix l0g rotation if rotated file already exists, finish old log with a message indicating r0tati0n, also print the actual error message when r0tation fails

Wazakindjes 2 months ago
parent
commit
c791337e9e

+ 2 - 0
sauce/common/include/muhdefs.h

@@ -82,10 +82,12 @@
 #define JM_ERRMSG_SQL_WRITETIMEOUT "Setting write timeout failed"
 #define JM_ERRMSG_SQL_SSLREQUIRE "Setting ssl_require failed"
 #define JM_ERRMSG_SQL_SSLVERIFY "Setting ssl_verify failed"
+#define JM_ERRMSG_SQL_SSLMODE "Setting ssl_mode failed"
 #define JM_ERRMSG_SQL_CONNECT "Connection err0r"
 #define JM_ERRMSG_SQL_QUERY "Query err0r"
 
 // Logging shyte
+#define JM_MSG_ROTATEM "Tryna rotate em log fam"JM_LINESEP
 #define JM_ERRMSG_LOGWRITE(x, y) "%s ERROR: Unable to open logPath for writing: %s%s", (x), (y), JM_LINESEP
 #define JM_ERRMSG_LOGWRITE2(x) "\tWanted to write: %s%s", (x), JM_LINESEP
 #define JM_ERRMSG_LOGROTATE "Unable to rotate log file, using current log for writing"JM_LINESEP

+ 32 - 23
sauce/mac/src/str0kemAppDelegate.m

@@ -7,7 +7,7 @@
 #import "str0kemAppDelegate.h"
 
 #include "muhdefs.h"
-#include </usr/local/Cellar/mysql-connector-c/6.1.11/include/mysql.h>
+#include </usr/local/Cellar/mysql-connector-c/8.0.25/include/mysql/mysql.h>
 #include <sys/stat.h>
 
 @implementation str0kemAppDelegate
@@ -18,6 +18,7 @@ NSCharacterSet *whitespaceCharlist = NULL;
 NSURL *bookmarkURL = NULL;
 NSBundle *muhBundle;
 NSFileManager *fileman;
+NSURL *logPathURL, *logPathRotateURL;
 
 -(void)applicationDidFinishLaunching: (NSNotification *)aNotification {
 	// Initialise some shit lol
@@ -296,7 +297,7 @@ static void muhsighandler(const int signum) {
 -(void)loggem: (NSString *)muhstring {
 	NSFileHandle *fh;
 	NSString *deet;
-	NSString *loggit;
+	NSString *loggit, *loggit_rotate;
 	NSError *error;
 	bool rotateErr;
 	struct stat muhstat;
@@ -306,6 +307,8 @@ static void muhsighandler(const int signum) {
 	if(!logPath || !fileman)
 		return;
 
+	deet = [logDateFormatter stringFromDate: [NSDate date]];
+
 	// Must create if it doesn't exist y0
 	rotateErr = false;
 	if(![fileman fileExistsAtPath: logPath])
@@ -315,7 +318,16 @@ static void muhsighandler(const int signum) {
 	else if(!stat([logPath fileSystemRepresentation], &muhstat)) {
 		muhbyets = muhstat.st_size;
 		if((muhbyets / 1024 / 1024) >= muhcfg.logrotate) {
-			[fileman moveItemAtPath: logPath toPath: logPathRotate error: &error];
+			// One-shot attempt for logging "we rotating na0", es not that important lel
+			fh = [NSFileHandle fileHandleForUpdatingAtPath: logPath];
+			if(fh) {
+				loggit = [NSString stringWithFormat: @"%@ %@", deet, @JM_MSG_ROTATEM];
+				[fh seekToEndOfFile];
+				[fh writeData: [loggit dataUsingEncoding: NSUTF8StringEncoding]];
+				[fh closeFile];
+			}
+
+			[fileman replaceItemAtURL: logPathRotateURL withItemAtURL: logPathURL backupItemName: NULL options: 0 resultingItemURL: NULL error: &error];
 			if(error)
 				rotateErr = true;
 			else
@@ -323,7 +335,6 @@ static void muhsighandler(const int signum) {
 		}
 	}
 
-	deet = [logDateFormatter stringFromDate: [NSDate date]];
 	loggit = [NSString stringWithFormat: @"%@ %@\n", deet, muhstring];
 	fh = [NSFileHandle fileHandleForUpdatingAtPath: logPath];
 	if(!fh) {
@@ -332,8 +343,13 @@ static void muhsighandler(const int signum) {
 		return;
 	}
 	[fh seekToEndOfFile];
-	if(rotateErr)
-		[fh writeData: [@JM_ERRMSG_LOGROTATE dataUsingEncoding: NSUTF8StringEncoding]];
+	if(rotateErr) {
+		if(error)
+			loggit_rotate = [NSString stringWithFormat: @"\n%@ %@%@ (%@)\n", deet, @JM_ERRMSG_LOGROTATE, [error localizedDescription], logPathRotate];
+		else
+			loggit_rotate = [NSString stringWithFormat: @"\n%@ %@", deet, @JM_ERRMSG_LOGROTATE];
+		[fh writeData: [loggit_rotate dataUsingEncoding: NSUTF8StringEncoding]];
+	}
 	[fh writeData: [loggit dataUsingEncoding: NSUTF8StringEncoding]];
 	[fh closeFile];
 }
@@ -376,8 +392,8 @@ static void muhsighandler(const int signum) {
 	int keypress, leftmouse, rightmouse;
 	char query[512]; // Should be plenty lol
 	MYSQL *dbconn;
-	unsigned int ssl_require, conntiemout, writetiemout;
-	my_bool ssl_verify;
+	unsigned int conntiemout, writetiemout;
+	int ssl_mode;
 	NSString *errTitle;
 
 	keypress = [keypressCounter intValue];
@@ -412,23 +428,13 @@ static void muhsighandler(const int signum) {
 	if(muhcfg.ssl) {
 		// Verify identify is the highest level, besides requiring a valid/trusted CA it also checks the common name on the cert
 		// The CN from the cert should match the server name in em c0nfig
-		ssl_require = (muhcfg.sslverify ? SSL_MODE_VERIFY_IDENTITY : SSL_MODE_REQUIRED);
-		if(mysql_options(dbconn, MYSQL_OPT_SSL_MODE, &ssl_require) != 0) {
-			[self alertem: errTitle : JM_SQLERR(JM_ERRMSG_SQL_SSLREQUIRE)];
+		ssl_mode = (muhcfg.sslverify ? SSL_MODE_REQUIRED : SSL_MODE_VERIFY_IDENTITY);
+		if(mysql_options(dbconn, MYSQL_OPT_SSL_MODE, &ssl_mode) != 0) {
+			[self alertem: errTitle : JM_SQLERR(JM_ERRMSG_SQL_SSLMODE)];
 			mysql_close(dbconn);
 			return;
 		}
 
-		if(muhcfg.sslverify) {
-			// We already passed SSL_MODE_VERIFY_IDENTITY earlier, but let's do this anyways to be sure =]
-			ssl_verify = 1;
-			if(mysql_options(dbconn, MYSQL_OPT_SSL_VERIFY_SERVER_CERT, &ssl_verify) != 0) {
-				[self alertem: errTitle : JM_SQLERR(JM_ERRMSG_SQL_SSLVERIFY)];
-				mysql_close(dbconn);
-				return;
-			}
-		}
-
 		// Also force cipher imo tbh (always set CA path to suppress most sandbox warnings about file-deny-access etc)
 		mysql_ssl_set(dbconn, NULL, NULL, NULL, muhcfg.sslcapath, JM_SQL_ENCCIPHER);
 	}
@@ -531,8 +537,11 @@ static void muhsighandler(const int signum) {
 	counterTmpURL = [counterPathURL URLByAppendingPathExtension: @"tmp"];
 	counterTmp = [counterTmpURL path];
 
-	logPath = [[confDir URLByAppendingPathExtension: @JM_LOG_EXT] path];
-	logPathRotate = [logPath stringByAppendingPathExtension: @JM_LOGROTATE_EXT];
+	logPathURL = [confDir URLByAppendingPathExtension: @JM_LOG_EXT];
+	logPathRotateURL = [logPathURL URLByAppendingPathExtension: @JM_LOGROTATE_EXT];
+	logPath = [logPathURL path];
+	logPathRotate = [logPathRotateURL path];
+
 	confRaw = [fileman contentsAtPath: confFilePath];
 	confJSON = [NSJSONSerialization JSONObjectWithData: confRaw options: NSJSONReadingAllowFragments error: &error];
 	if(error)

+ 1 - 1
sauce/mac/str0kem-Info.plist

@@ -17,7 +17,7 @@
 	<key>CFBundlePackageType</key>
 	<string>APPL</string>
 	<key>CFBundleShortVersionString</key>
-	<string>1.1.0.17</string>
+	<string>$(MARKETING_VERSION)</string>
 	<key>JMSQLVersion</key>
 	<string>6.1.11</string>
 	<key>LSApplicationCategoryType</key>

+ 9 - 7
sauce/mac/str0kem.xcodeproj/project.pbxproj

@@ -7,8 +7,6 @@
 	objects = {
 
 /* Begin PBXBuildFile section */
-		15BA0B6222E618A700470359 /* libmysqlclient.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15BA0B6022E618A700470359 /* libmysqlclient.dylib */; };
-		15BA0B6422E618B200470359 /* libmysqlclient.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 15BA0B6022E618A700470359 /* libmysqlclient.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		15E0A6CD22DCF967009AB1F4 /* certs in Resources */ = {isa = PBXBuildFile; fileRef = 15E0A6CC22DCF967009AB1F4 /* certs */; };
 		15E0A6DD22DCF98E009AB1F4 /* InfoPlist.strings in Resources */ = {isa = PBXBuildFile; fileRef = 15E0A6CF22DCF98D009AB1F4 /* InfoPlist.strings */; };
 		15E0A6DE22DCF98E009AB1F4 /* MainMenuDUMMY.xib in Resources */ = {isa = PBXBuildFile; fileRef = 15E0A6D122DCF98D009AB1F4 /* MainMenuDUMMY.xib */; };
@@ -16,6 +14,8 @@
 		15E0A6E122DCF98E009AB1F4 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E0A6DA22DCF98E009AB1F4 /* main.m */; };
 		15E0A6E222DCF98E009AB1F4 /* str0kemAppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 15E0A6DB22DCF98E009AB1F4 /* str0kemAppDelegate.m */; };
 		15E0A6EF22DD11FE009AB1F4 /* str0kem.conf.example in Resources */ = {isa = PBXBuildFile; fileRef = 15E0A6EE22DD11FE009AB1F4 /* str0kem.conf.example */; };
+		15EAD4EE26A3080200728D8B /* libmysqlclient.21.dylib in Frameworks */ = {isa = PBXBuildFile; fileRef = 15EAD4ED26A3080200728D8B /* libmysqlclient.21.dylib */; };
+		15EAD4EF26A3081500728D8B /* libmysqlclient.21.dylib in CopyFiles */ = {isa = PBXBuildFile; fileRef = 15EAD4ED26A3080200728D8B /* libmysqlclient.21.dylib */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
 		46B3A6F815C53E8900F49728 /* Cocoa.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 46B3A6F715C53E8900F49728 /* Cocoa.framework */; };
 /* End PBXBuildFile section */
 
@@ -26,7 +26,7 @@
 			dstPath = "";
 			dstSubfolderSpec = 10;
 			files = (
-				15BA0B6422E618B200470359 /* libmysqlclient.dylib in CopyFiles */,
+				15EAD4EF26A3081500728D8B /* libmysqlclient.21.dylib in CopyFiles */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 		};
@@ -35,7 +35,6 @@
 /* Begin PBXFileReference section */
 		152D1D0322D6469400CF2E73 /* str0kem.entitlements */ = {isa = PBXFileReference; lastKnownFileType = text.plist.entitlements; path = str0kem.entitlements; sourceTree = "<group>"; };
 		159F2BD7269869D30064AB75 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.xib; name = Base; path = ../Base.lproj/MainMenuDUMMY.xib; sourceTree = "<group>"; };
-		15BA0B6022E618A700470359 /* libmysqlclient.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libmysqlclient.dylib; sourceTree = "<group>"; };
 		15E0A6CC22DCF967009AB1F4 /* certs */ = {isa = PBXFileReference; lastKnownFileType = folder; name = certs; path = ../common/certs; sourceTree = "<group>"; };
 		15E0A6D022DCF98D009AB1F4 /* en */ = {isa = PBXFileReference; lastKnownFileType = text.plist.strings; name = en; path = InfoPlist.strings; sourceTree = "<group>"; };
 		15E0A6D522DCF98D009AB1F4 /* images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = images.xcassets; sourceTree = "<group>"; };
@@ -46,6 +45,7 @@
 		15E0A6DC22DCF98E009AB1F4 /* str0kem-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = "str0kem-Info.plist"; sourceTree = "<group>"; };
 		15E0A6EA22DCFBE3009AB1F4 /* muhdefs.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = muhdefs.h; path = ../../common/include/muhdefs.h; sourceTree = "<group>"; };
 		15E0A6EE22DD11FE009AB1F4 /* str0kem.conf.example */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; name = str0kem.conf.example; path = ../common/res/str0kem.conf.example; sourceTree = "<group>"; };
+		15EAD4ED26A3080200728D8B /* libmysqlclient.21.dylib */ = {isa = PBXFileReference; lastKnownFileType = "compiled.mach-o.dylib"; path = libmysqlclient.21.dylib; sourceTree = "<group>"; };
 		46B3A6F315C53E8900F49728 /* str0kem.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = str0kem.app; sourceTree = BUILT_PRODUCTS_DIR; };
 		46B3A6F715C53E8900F49728 /* Cocoa.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Cocoa.framework; path = System/Library/Frameworks/Cocoa.framework; sourceTree = SDKROOT; };
 		46B3A6FA15C53E8900F49728 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = System/Library/Frameworks/AppKit.framework; sourceTree = SDKROOT; };
@@ -58,7 +58,7 @@
 			isa = PBXFrameworksBuildPhase;
 			buildActionMask = 2147483647;
 			files = (
-				15BA0B6222E618A700470359 /* libmysqlclient.dylib in Frameworks */,
+				15EAD4EE26A3080200728D8B /* libmysqlclient.21.dylib in Frameworks */,
 				46B3A6F815C53E8900F49728 /* Cocoa.framework in Frameworks */,
 			);
 			runOnlyForDeploymentPostprocessing = 0;
@@ -69,7 +69,7 @@
 		15BA0B5E22E618A700470359 /* lib */ = {
 			isa = PBXGroup;
 			children = (
-				15BA0B6022E618A700470359 /* libmysqlclient.dylib */,
+				15EAD4ED26A3080200728D8B /* libmysqlclient.21.dylib */,
 			);
 			path = lib;
 			sourceTree = "<group>";
@@ -243,7 +243,7 @@
 			);
 			runOnlyForDeploymentPostprocessing = 0;
 			shellPath = /bin/sh;
-			shellScript = "# Gotta fix that fucking path the dylib itself wants it to be at\ninstall_name_tool -change /usr/local/opt/mysql-connector-c/lib/libmysqlclient.18.dylib @executable_path/../Frameworks/libmysqlclient.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME\";";
+			shellScript = "# Gotta fix that fucking path the dylib itself wants it to be at\n# Is no longer necessary though since we just use the versioned dylib now =]\n#install_name_tool -change /usr/local/opt/mysql-connector-c/lib/libmysqlclient.18.dylib @executable_path/../Frameworks/libmysqlclient.dylib \"$TARGET_BUILD_DIR/$PRODUCT_NAME.app/Contents/MacOS/$PRODUCT_NAME\";\n";
 		};
 /* End PBXShellScriptBuildPhase section */
 
@@ -388,6 +388,7 @@
 					"$(inherited)",
 					"$(PROJECT_DIR)/lib",
 				);
+				MARKETING_VERSION = 1.1.0.18;
 				OTHER_LDFLAGS = "";
 				PRODUCT_BUNDLE_IDENTIFIER = com.jemoeder.lief.str0kem;
 				PRODUCT_NAME = "$(TARGET_NAME)";
@@ -412,6 +413,7 @@
 					"$(inherited)",
 					"$(PROJECT_DIR)/lib",
 				);
+				MARKETING_VERSION = 1.1.0.18;
 				OTHER_LDFLAGS = "";
 				PRODUCT_BUNDLE_IDENTIFIER = com.jemoeder.lief.str0kem;
 				PRODUCT_NAME = "$(TARGET_NAME)";