Post

Replies

Boosts

Views

Activity

SecKeyCreateDecryptedData returns "RSAdecrypt wrong input" for OpenSSL's PKCS1
Hello I have created a signature of a chunk of text using the following OpenSSL CLI command: echo -n "sample text" | openssl dgst -sha1 -binary | openssl rsautl -sign -inkey "privatekey.pem" Basically what it does it calculating sha1 digest of text, and then signing this calculated digest as a binary blob with OpenSSL RSA signing using a private key in a PEM format. Now I would like to verify whether this "sample text" was signed by the owner of the privatekey.pem using a matching publickey.pem file, from within a macOS application. I can easily verify the signature by "decrypting" it using openssl dylib, something like this: int returnedDigestSize = RSA_public_decrypt((int)signatureLength, signatureBytes, destination, rsa_key, RSA_PKCS1_PADDING); (this will return me an original SHA1 digest, which I can then compare with the original string's SHA1 digest) However I wouldn't like to have any dependencies on openssl, and would like to move to MacOS security libraries I ended up attempting to use Security framework, since it is supported in earlier versions of macOS (I need all the way back to High Sierra). What I am doing is the following: NSData *pubKeyData = [kPublicRSAKey dataUsingEncoding:NSUTF8StringEncoding]; SecExternalFormat keyFormat = kSecFormatOpenSSL; SecExternalItemType keyType = kSecItemTypePublicKey; CFArrayRef cfImportedItems = NULL; OSStatus retval = 0; retval = SecItemImport((CFDataRef)pubKeyData, NULL, &keyFormat, &keyType, 0, NULL, NULL, &cfImportedItems); NSArray *importedItems = (__bridge NSArray*)cfImportedItems; 		 if(!retval && importedItems && importedItems.count == 1) { 		SecKeyRef pubKeyAppleFormat = (__bridge SecKeyRef)(importedItems[0]); 		CFErrorRef cfError = NULL; 								 		Boolean b = SecKeyIsAlgorithmSupported(pubKeyAppleFormat, kSecKeyOperationTypeDecrypt, kSecKeyAlgorithmRSAEncryptionPKCS1); 		NSLog(@"Algorithm supported: %d", b); 						 		CFDataRef cfDigestData = SecKeyCreateDecryptedData(pubKeyAppleFormat, kSecKeyAlgorithmRSAEncryptionPKCS1, (CFDataRef)signatureData, &cfError); 		if(!cfDigestData) { 				NSLog(@"SecKeyCreateDecryptedData error%@", (__bridge NSError*)cfError); 		} else { 				NSLog(@"%@", (__bridge NSData*)cfDigestData); 		} } This gives me an error: SecKeyCreateDecryptedData errorError Domain=NSOSStatusErrorDomain Code=-50 "RSAdecrypt wrong input (err -27)" (paramErr: error in user parameter list) UserInfo={numberOfErrorsDeep=0, NSDescription=RSAdecrypt wrong input (err -27)} Note that OpenSSL code above can decrypt this with RSA_PKCS1_PADDING argument. If instead of kSecKeyAlgorithmRSAEncryptionPKCS1 I put kSecKeyAlgorithmRSAEncryptionRaw, I do get some bytes and no errors, however they are incorrect, as OpenSSL CLI uses PKCS1. Is there a way to get a matching to OpenSSL signature verification via macOS APIs?
1
0
1.2k
Feb ’21
macOS WakeOnLan "magic packet" does nothing when MacBook is sleeping
I have a MacBook Pro 2018 running Catalina with a USB-to-Ethernet Dongle. The MacBook is connected to power source and with an Ethernet cable to a router. Just in case, In "System preferences > Energy Saver" I have set "Wake for Wi-Fi network access" checkbox. There is a Linux machine with an ethernet connection to the same router -- they are in same LAN segment. My goal is to wake a sleeping MacBook with a Magic WakeOnLan packet, sent from a Linux machine. However none of the Linux apps I tried worked: neither wakeonlan perl script (that sends broadcast UDP messages), nor etherwake (that sends raw MAC frames). On various internet sources I've found controversial information: some complaints that when Mac is sleeping it goes to hybernation, meaning you can't WakeOnLan a sleeping Mac. I am using a regular router, not Apple AirPort (and don't have Apple TVs on my network). Is my understanding correct, that 1) There is no way to wake up a sleeping Mac by sending a magic WoL packet anymore (even though it used to be possible in older macOS versions) 2) If I get AirPort Extreme, and connect it to my router, I will be able to wake up Mac just by trying to access any of the network services I have enabled in Sharing on my MacBook?
5
0
6.3k
Aug ’20
Cocoa - get the right sized NSImage from Assets.xcassets
Hello What is the right way to get the AppIcon image representation of the desired size? Say, I have filled out the AppIcon with all images from 16x16 up to 1024x1024. Whenever I do NSImage(named: "AppIcon") I get the largest possible image (judging by the image.size). Is there a way to get a, for example, 32x32 image? Or do I have to draw the image manually as shown here https://stackoverflow.com/questions/11949250/how-to-resize-nsimage/17396521 ? Thanks
1
0
574
Jun ’20
Accessibility API of the Books application
HelloFor my word processing app I need to be able to retrieve a specific paragraph of a book that is opened in Books.app on Mac. Using Accessibility APIs I am able to descend the tree of views down to AXStaticText, however whenever I try to read AXValue I always get nil. Also, I cannot read that text using Apple Script (of course, Script Editor is enabled as an Accessibility app in Security & Privacy)Xcode's Accessibility Inspector, however, returns correct text of the paragraph in Books I am pointing it to.I was wondering if it could be due to some DRM protection? But if so, I don't understand, how come Accessibility Inspector is able to read the text?Thanks!
Topic: UI Frameworks SubTopic: AppKit Tags:
5
0
2.2k
Jun ’20