How to get attributes from SecKeyRef without Password dialog? - macos

I need to get info about private kSecAttrKeyType, kSecAttrApplicationLabel, kSecAttrCanSign, kSecAttrCanDecrypt, kSecAttrCanUnwrap, kSecAttrIsExtractable
But I've got System password dialog on SecKeyCopyAttributes using
Is there any way to get this public info without System password dialog?
I tried to get some public info from public key. But I've got the same System dialog on SecKeyCopyPublicKey

It's possible to do via kSecReturnAttributes parameter of SecItemCopyMatching function
Here is C++ example which returns attributes for each key in keychain
CFMutableDictionaryRef matchAttr = CFDictionaryCreateMutable(kCFAllocatorDefault,
0,
&kCFTypeDictionaryKeyCallBacks,
&kCFTypeDictionaryValueCallBacks);
CFDictionaryAddValue(matchAttr, kSecClass, kSecClassKey);
CFDictionaryAddValue(matchAttr, kSecMatchLimit, kSecMatchLimitAll);
CFDictionaryAddValue(matchAttr, kSecReturnAttributes, kCFBooleanTrue);
CFArrayRef result;
OSStatus status = SecItemCopyMatching(matchAttr, (CFTypeRef*)&result);
if (status == kCCSuccess) {
CFIndex arrayCount = CFArrayGetCount(result);
for (CFIndex index = 0; index < arrayCount; index++) {
CFShow(CFArrayGetValueAtIndex(result, index));
}
}

Related

Google Play In-app Billing - list purchases

I wish to get list of in-app purchases that I purchased but have not consumed.
Does Google Play provide such API?
https://developer.android.com/google/play/billing/billing_integrate.html#QueryPurchases
Bundle ownedItems = mService.getPurchases(3, getPackageName(), "inapp", null);
int response = ownedItems.getInt("RESPONSE_CODE");
if (response == 0) {
ArrayList<String> ownedSkus =
ownedItems.getStringArrayList("INAPP_PURCHASE_ITEM_LIST");
ArrayList<String> purchaseDataList =
ownedItems.getStringArrayList("INAPP_PURCHASE_DATA_LIST");
ArrayList<String> signatureList =
ownedItems.getStringArrayList("INAPP_DATA_SIGNATURE_LIST");
String continuationToken =
ownedItems.getString("INAPP_CONTINUATION_TOKEN");
for (int i = 0; i < purchaseDataList.size(); ++i) {
String purchaseData = purchaseDataList.get(i);
String signature = signatureList.get(i);
String sku = ownedSkus.get(i);
// do something with this purchase information
// e.g. display the updated list of products owned by user
}
// if continuationToken != null, call getPurchases again
// and pass in the token to retrieve more items
}

Issue in configuring a TAPI address line

I am developing a telephony application with TAPI API's. I am able to get some sample codes to develop an Application using TAPI API's, but I am not able to configure Address for the TAPI application to work. Any help would be of greatly appreciated.
Thanks,
Ganesan S
Adding piece of code , which I have tried
private int InitializePhoneDevices()
{
var parms = new PHONEINITIALIZEEXPARAMS();
parms.dwTotalSize = parms.dwNeededSize = parms.dwUsedSize = Marshal.SizeOf(parms);
parms.dwOptions = NativeMethods.PHONEINITIALIZEEXOPTION_USEEVENT;
parms.dwCompletionKey = 0;
parms.hEvent = IntPtr.Zero;
int numDevices; uint hTapi;
int rc = NativeMethods.phoneInitializeEx(out hTapi, 0, null, _appName,
out numDevices, ref _phoneVersion, ref parms);
if (rc == NativeMethods.PHONEERR_OK)
{
_hTapiPhone = new HTPHONEAPP(hTapi, true);
_evtReceivedPhoneEvent.SafeWaitHandle = new SafeWaitHandle(parms.hEvent, false);
_phoneArray = new List<TapiPhone>();
for (int i = 0; i < numDevices; i++)
{
_phoneArray.Add(new TapiPhone(this, i));
}
}
else
{
numDevices = 0;
}
return numDevices;
}
The number of devices in the list is always coming as empty, that is the problem, what configurations I have top do in my system to get it populated.
Are you certain your PBX is exposing via Phone Devices? In my experience most TAPI 2.2 drivers will expose via Line Devices. Try using lineInitializeEx instead.
MSDN lineInitializeEx function

How to create certificate choosing window like one in Safari?

I was looking for a way to create a window like that one in my program, but I haven't found any implementation of that. All I can do for now is get all certificates from keychain, but I can't get a cert in pem or der format. It is needed to supply certificate to a particular site.
- (void)logMessageForStatus:(OSStatus)status
functionName:(NSString *)functionName
{
CFStringRef errorMessage;
errorMessage = SecCopyErrorMessageString(status, NULL);
NSLog(#"error after %#: %#", functionName, (__bridge NSString *)errorMessage);
CFRelease(errorMessage);
}
- (void)listCertificates
{
OSStatus status;
SecKeychainSearchRef search = NULL;
// The first argument being NULL indicates the user's current keychain list
status = SecKeychainSearchCreateFromAttributes(NULL,
kSecCertificateItemClass, NULL, &search);
if (status != errSecSuccess) {
[self logMessageForStatus:status
functionName:#"SecKeychainSearchCreateFromAttributes()"];
return;
}
SecKeychainItemRef searchItem = NULL;
while (SecKeychainSearchCopyNext(search, &searchItem) != errSecItemNotFound) {
SecKeychainAttributeList attrList;
CSSM_DATA certData;
attrList.count = 0;
attrList.attr = NULL;
status = SecKeychainItemCopyContent(searchItem, NULL, &attrList,
(UInt32 *)(&certData.Length),
(void **)(&certData.Data));
if (status != errSecSuccess) {
[self logMessageForStatus:status
functionName:#"SecKeychainItemCopyContent()"];
CFRelease(searchItem);
continue;
}
// At this point you should have a valid CSSM_DATA structure
// representing the certificate
SecCertificateRef certificate;
status = SecCertificateCreateFromData(&certData, CSSM_CERT_X_509v3,
CSSM_CERT_ENCODING_BER, &certificate);
if (status != errSecSuccess) {
[self logMessageForStatus:status
functionName:#"SecCertificateCreateFromData()"];
SecKeychainItemFreeContent(&attrList, certData.Data);
CFRelease(searchItem);
continue;
}
// Do whatever you want to do with the certificate
// For instance, print its common name (if there's one)
CFStringRef commonName = NULL;
CFErrorRef err = NULL;
///CFArrayRef arr = NULL;
SecCertificateCopyCommonName(certificate, &commonName);
certs = SecCertificateCopyValues(certificate, NULL, &err);
//NSLog(#"common name = %#", (__bridge NSString *)commonName);
//NSLog(#"data = %#", (__bridge NSArray *)arr);
//certs = arr;
if (commonName) CFRelease(commonName);
//if (arr) CFRelease(arr);
SecKeychainItemFreeContent(&attrList, certData.Data);
CFRelease(searchItem);
}
CFRelease(search);
}
example
Is there any standard api to call such window? Or maybe there is some library? And how can I get der data from SecCertificateRef.
Thank you in advance!

How to deserialize the IPXDefaultLibraryURLBookmark of the Photos plist

So, I've been trying to deserialize the IPXDefaultLibraryURLBookmark of the com.apple.Photos defaults (defaults read com.apple.Photos IPXDefaultLibraryURLBookmark) but no luck. Ideally I'd like a programmatic way in c++ to deserialize that value to retrieve the last known location of the photo
bookd0xUsersmateuscbPicturesPhotos Library.photoslibrary 0#˜ì5$r$Éò|åú¨A∫˙æJ file:///Macintosh HDÇ1tA∫‘}•$6465C0A4-1771-3C89-9055-147CEDFBBF2EÅÔ/∆72cd528f2dcfb4b3434986cf3caa02cc946333b8;00000000;00000000;0000000000000020;com.apple.app-sandbox.read-write;00000001;01000004;0000000002980783;/users/mateuscb/pictures/photos library.photoslibrary¥˛ˇˇˇdº‰#‘ î  H ( 8 t0 †–Ä®
I know its not a bplist, since the first format specifier denotes bookd.
But I have no clue what that is. I'm somewhat new to OSX development, so this may be something very basic I'm missing.
I want to retrieve the: /users/mateuscb/pictures/photos library.photoslibrary portion so I can find the defaults photoslibrary.
Unless there is another way to retrieve the default photoslibrary path?
I figured out how to retrieve the path to the .photoslibrary. I used CFURLCreateByResolvingBookmarkData to get a CFURLRef from the plist then used CFURLGetFileSystemRepresentation to get the full path as a string.
Help from this sample to retrieve sandbox preferences: https://gist.github.com/glebd/4759724
Here is my full solution:
int main(int argc, const char * argv[]) {
bool success = FALSE;
UInt8 photosUrlString[PATH_MAX];
struct passwd *pwd = getpwuid(getuid());
if (pwd == NULL){
Log("Unable to retrieve current user");
return 0;
}
const char *home = pwd->pw_dir;
if (home == NULL){
Log("Unable to retrieve current user directory");
return 0;
}
CFMutableStringRef preferencesPath = CFStringCreateMutable(NULL, 0);
if (preferencesPath) {
CFStringAppend(preferencesPath, CFStringCreateWithCStringNoCopy(NULL, home, kCFStringEncodingUTF8, NULL));
CFStringAppend(preferencesPath, CFSTR("/Library/Containers/com.apple.Photos/Data/Library/Preferences/com.apple.Photos"));
} else {
Log("Unable to create CFString of user directory");
return 0;
}
CFPropertyListRef photosUrlPrefs = CFPreferencesCopyValue(CFSTR("IPXDefaultLibraryURLBookmark"), preferencesPath, kCFPreferencesCurrentUser, kCFPreferencesCurrentHost);
CFRelease(preferencesPath);
if (photosUrlPrefs) {
CFTypeID prefsType = CFGetTypeID(photosUrlPrefs);
if (CFDataGetTypeID() == prefsType) {
CFDataRef photosUrlData = (CFDataRef) photosUrlPrefs;
CFErrorRef urlResolveError = nil;
CFURLRef photosUrl = CFURLCreateByResolvingBookmarkData(kCFAllocatorDefault, photosUrlData, NULL, NULL, NULL, NULL, &urlResolveError);
if (photosUrl == NULL) {
if(urlResolveError != NULL) {
CFStringRef resolveErrorString = CFErrorCopyDescription(urlResolveError);
if (resolveErrorString != NULL) {
char resolveErrorCString[PATH_MAX];
if (CFStringGetCString((CFStringRef) resolveErrorString, resolveErrorCString, sizeof(resolveErrorCString), kCFStringEncodingUTF8)) {
Log("Error resolving URL: %s", resolveErrorCString);
}
CFRelease(resolveErrorString);
}
} else {
Log("Error resolving URL, no resolveError");
}
} else {
success = CFURLGetFileSystemRepresentation(photosUrl, false, photosUrlString, sizeof(photosUrlString));
CFRelease(photosUrl);
}
} else {
Log("Url plist value is not CFData");
}
if (photosUrlPrefs != NULL) {
CFRelease(photosUrlPrefs);
}
}
if(success) {
Log("path: %s", photosUrlString);
}
return 0;
}

Windows Event Log : Event template - Output type: win:Xml

I am making Windows event log for my application that support Vista and above. I have a manifest created for each event, but I get a issue with the output type of win:Xml.
Below is what I specify for the data in event template.
<data name="StackTrace" inType="win:UnicodeString" outType="win:Xml">
</data>
I would like to set the StackTrace to be displayed as XML format in the Event logs. StackTrace must be input with well-formed XML. However, I still see it displayed as string(xs:string) in the Event Log viewer.
Do you know what I did wrong? How can I make it properly?
Below if update for my code:
const int NUM_OF_DATADESC = 6;
EVENT_DATA_DESCRIPTOR eventDataDesc[NUM_OF_DATADESC];
evDesc.Level = uLevel;
evDesc.Channel = nChannel;
evDesc.Keyword |= uKeyword;
for (int i = 0; i < NUM_OF_DATADESC; i++)
{
if (strings[i] != NULL)
EventDataDescCreate(&eventDataDesc[i], strings[i], ((ULONG)wcslen(strings[i])+1)*sizeof(WCHAR));
else
EventDataDescCreate(&eventDataDesc[i], L"", sizeof(WCHAR));
}
BOOL s = WriteEvent(evDesc,NUM_OF_DATADESC,&eventDataDesc[0]);
BOOL WriteEvent(EVENT_DESCRIPTOR eventID,DWORD userDataCount,PEVENT_DATA_DESCRIPTOR userData)
{
REGHANDLE hPub = NULL;
ULONG res = EventRegister(&MYCOMPANE_MYAPP_MYCOMPONENT, NULL, NULL, &hPub);
if (ERROR_SUCCESS != res){
return FALSE;
}
res = EventWrite(hPub, &eventID, userDataCount, userData);
if (ERROR_SUCCESS != res){
return FALSE;
}
EventUnregister(hPub);
return TRUE;
}
The code is working fine, but only issue with output type = win:Xml.

Resources