2 #import <Foundation/Foundation.h>
3 #include <sys/sysctl.h>
5 #import "keychain/ckks/CKKS.h"
7 const SecCKKSItemEncryptionVersion currentCKKSItemEncryptionVersion = CKKSItemEncryptionVersion2;
9 NSString* const SecCKKSActionAdd = @"add";
10 NSString* const SecCKKSActionDelete = @"delete";
11 NSString* const SecCKKSActionModify = @"modify";
13 CKKSItemState* const SecCKKSStateNew = (CKKSItemState*) @"new";
14 CKKSItemState* const SecCKKSStateUnauthenticated = (CKKSItemState*) @"unauthenticated";
15 CKKSItemState* const SecCKKSStateInFlight = (CKKSItemState*) @"inflight";
16 CKKSItemState* const SecCKKSStateReencrypt = (CKKSItemState*) @"reencrypt";
17 CKKSItemState* const SecCKKSStateError = (CKKSItemState*) @"error";
18 CKKSItemState* const SecCKKSStateDeleted = (CKKSItemState*) @"deleted";
20 CKKSProcessedState* const SecCKKSProcessedStateLocal = (CKKSProcessedState*) @"local";
21 CKKSProcessedState* const SecCKKSProcessedStateRemote = (CKKSProcessedState*) @"remote";
23 CKKSKeyClass* const SecCKKSKeyClassTLK = (CKKSKeyClass*) @"tlk";
24 CKKSKeyClass* const SecCKKSKeyClassA = (CKKSKeyClass*) @"classA";
25 CKKSKeyClass* const SecCKKSKeyClassC = (CKKSKeyClass*) @"classC";
27 NSString* SecCKKSContainerName = @"com.apple.security.keychain";
28 bool SecCKKSContainerUsePCS = false;
30 NSString* const SecCKKSSubscriptionID = @"keychain-changes";
31 NSString* const SecCKKSAPSNamedPort = @"com.apple.securityd.aps";
33 NSString* const SecCKRecordItemType = @"item";
34 NSString* const SecCKRecordHostOSVersionKey = @"uploadver";
35 NSString* const SecCKRecordEncryptionVersionKey = @"encver";
36 NSString* const SecCKRecordDataKey = @"data";
37 NSString* const SecCKRecordParentKeyRefKey = @"parentkeyref";
38 NSString* const SecCKRecordWrappedKeyKey = @"wrappedkey";
39 NSString* const SecCKRecordGenerationCountKey = @"gen";
41 NSString* const SecCKRecordPCSServiceIdentifier = @"pcsservice";
42 NSString* const SecCKRecordPCSPublicKey = @"pcspublickey";
43 NSString* const SecCKRecordPCSPublicIdentity = @"pcspublicidentity";
44 NSString* const SecCKRecordServerWasCurrent = @"server_wascurrent";
46 NSString* const SecCKRecordIntermediateKeyType = @"synckey";
47 NSString* const SecCKRecordKeyClassKey = @"class";
49 NSString* const SecCKRecordTLKShareType = @"tlkshare";
50 NSString* const SecCKRecordSenderPeerID = @"sender";
51 NSString* const SecCKRecordReceiverPeerID = @"receiver";
52 NSString* const SecCKRecordReceiverPublicEncryptionKey = @"receiverPublicEncryptionKey";
53 NSString* const SecCKRecordCurve = @"curve";
54 NSString* const SecCKRecordEpoch = @"epoch";
55 NSString* const SecCKRecordPoisoned = @"poisoned";
56 NSString* const SecCKRecordSignature = @"signature";
57 NSString* const SecCKRecordVersion = @"version";
59 NSString* const SecCKRecordCurrentKeyType = @"currentkey";
61 NSString* const SecCKRecordCurrentItemType = @"currentitem";
62 NSString* const SecCKRecordItemRefKey = @"item";
64 NSString* const SecCKRecordDeviceStateType = @"devicestate";
65 NSString* const SecCKRecordOctagonPeerID = @"octagonpeerid";
66 NSString* const SecCKRecordOctagonStatus = @"octagonstatus";
67 NSString* const SecCKRecordCirclePeerID = @"peerid";
68 NSString* const SecCKRecordCircleStatus = @"circle";
69 NSString* const SecCKRecordKeyState = @"keystate";
70 NSString* const SecCKRecordCurrentTLK = @"currentTLK";
71 NSString* const SecCKRecordCurrentClassA = @"currentClassA";
72 NSString* const SecCKRecordCurrentClassC = @"currentClassC";
73 NSString* const SecCKSRecordLastUnlockTime = @"lastunlock";
74 NSString* const SecCKSRecordOSVersionKey = @"osver";
76 NSString* const SecCKRecordManifestType = @"manifest";
77 NSString* const SecCKRecordManifestDigestValueKey = @"digest_value";
78 NSString* const SecCKRecordManifestGenerationCountKey = @"generation_count";
79 NSString* const SecCKRecordManifestLeafRecordIDsKey = @"leaf_records";
80 NSString* const SecCKRecordManifestPeerManifestRecordIDsKey = @"peer_manifests";
81 NSString* const SecCKRecordManifestCurrentItemsKey = @"current_items";
82 NSString* const SecCKRecordManifestSignaturesKey = @"signatures";
83 NSString* const SecCKRecordManifestSignerIDKey = @"signer_id";
84 NSString* const SecCKRecordManifestSchemaKey = @"schema";
86 NSString* const SecCKRecordManifestLeafType = @"manifest_leaf";
87 NSString* const SecCKRecordManifestLeafDERKey = @"der";
88 NSString* const SecCKRecordManifestLeafDigestKey = @"digest";
90 CKKSZoneKeyState* const SecCKKSZoneKeyStateReady = (CKKSZoneKeyState*) @"ready";
91 CKKSZoneKeyState* const SecCKKSZoneKeyStateReadyPendingUnlock = (CKKSZoneKeyState*) @"readypendingunlock";
92 CKKSZoneKeyState* const SecCKKSZoneKeyStateError = (CKKSZoneKeyState*) @"error";
93 CKKSZoneKeyState* const SecCKKSZoneKeyStateCancelled = (CKKSZoneKeyState*) @"cancelled";
95 CKKSZoneKeyState* const SecCKKSZoneKeyStateInitializing = (CKKSZoneKeyState*) @"initializing";
96 CKKSZoneKeyState* const SecCKKSZoneKeyStateInitialized = (CKKSZoneKeyState*) @"initialized";
97 CKKSZoneKeyState* const SecCKKSZoneKeyStateFetch = (CKKSZoneKeyState*) @"fetching";
98 CKKSZoneKeyState* const SecCKKSZoneKeyStateFetchComplete = (CKKSZoneKeyState*) @"fetchcomplete";
99 CKKSZoneKeyState* const SecCKKSZoneKeyStateNeedFullRefetch = (CKKSZoneKeyState*) @"needrefetch";
100 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForTLK = (CKKSZoneKeyState*) @"waitfortlk";
102 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForTLKCreation = (CKKSZoneKeyState*) @"waitfortlkcreation";
103 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForTLKUpload = (CKKSZoneKeyState*) @"waitfortlkupload";
104 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForUnlock = (CKKSZoneKeyState*) @"waitforunlock";
105 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForTrust = (CKKSZoneKeyState*) @"waitfortrust";
106 CKKSZoneKeyState* const SecCKKSZoneKeyStateUnhealthy = (CKKSZoneKeyState*) @"unhealthy";
107 CKKSZoneKeyState* const SecCKKSZoneKeyStateBadCurrentPointers = (CKKSZoneKeyState*) @"badcurrentpointers";
108 CKKSZoneKeyState* const SecCKKSZoneKeyStateNewTLKsFailed = (CKKSZoneKeyState*) @"newtlksfailed";
109 CKKSZoneKeyState* const SecCKKSZoneKeyStateHealTLKShares = (CKKSZoneKeyState*) @"healtlkshares";
110 CKKSZoneKeyState* const SecCKKSZoneKeyStateHealTLKSharesFailed = (CKKSZoneKeyState*) @"healtlksharesfailed";
111 CKKSZoneKeyState* const SecCKKSZoneKeyStateWaitForFixupOperation = (CKKSZoneKeyState*) @"waitforfixupoperation";
112 CKKSZoneKeyState* const SecCKKSZoneKeyStateResettingZone = (CKKSZoneKeyState*) @"resetzone";
113 CKKSZoneKeyState* const SecCKKSZoneKeyStateResettingLocalData = (CKKSZoneKeyState*) @"resetlocal";
114 CKKSZoneKeyState* const SecCKKSZoneKeyStateLoggedOut = (CKKSZoneKeyState*) @"loggedout";
115 CKKSZoneKeyState* const SecCKKSZoneKeyStateZoneCreationFailed = (CKKSZoneKeyState*) @"zonecreationfailed";
116 CKKSZoneKeyState* const SecCKKSZoneKeyStateProcess = (CKKSZoneKeyState*) @"process";
118 NSString* const CKKSErrorDomain = @"CKKSErrorDomain";
119 NSString* const CKKSServerExtensionErrorDomain = @"CKKSServerExtensionErrorDomain";
121 const NSUInteger SecCKKSItemPaddingBlockSize = 20;
123 NSString* const SecCKKSAggdPropagationDelay = @"com.apple.security.ckks.propagationdelay";
124 NSString* const SecCKKSAggdPrimaryKeyConflict = @"com.apple.security.ckks.pkconflict";
125 NSString* const SecCKKSAggdViewKeyCount = @"com.apple.security.ckks.keycount";
126 NSString* const SecCKKSAggdItemReencryption = @"com.apple.security.ckks.reencrypt";
128 NSString* const SecCKKSUserDefaultsSuite = @"com.apple.security.ckks";
130 NSString* SecCKKSHostOSVersion()
133 // Use complicated macro magic to get the string value passed in as preprocessor define PLATFORM.
134 #define PLATFORM_VALUE(f) #f
135 #define PLATFORM_OBJCSTR(f) @PLATFORM_VALUE(f)
136 NSString* platform = (PLATFORM_OBJCSTR(PLATFORM));
137 #undef PLATFORM_OBJCSTR
138 #undef PLATFORM_VALUE
140 NSString* platform = "unknown";
141 #warning No PLATFORM defined; why?
144 NSString* osversion = nil;
146 // If we can get the build information from sysctl, use it.
148 size_t releasesize = sizeof(release);
149 bool haveSysctlInfo = true;
150 haveSysctlInfo &= (0 == sysctlbyname("kern.osrelease", release, &releasesize, NULL, 0));
153 size_t versionsize = sizeof(version);
154 haveSysctlInfo &= (0 == sysctlbyname("kern.osversion", version, &versionsize, NULL, 0));
157 // Null-terminate for extra safety
158 release[sizeof(release)-1] = '\0';
159 version[sizeof(version)-1] = '\0';
160 osversion = [NSString stringWithFormat:@"%s (%s)", release, version];
164 // Otherwise, use the not-really-supported fallback.
165 osversion = [[NSProcessInfo processInfo] operatingSystemVersionString];
167 // subtly improve osversion (but it's okay if that does nothing)
168 osversion = [osversion stringByReplacingOccurrencesOfString:@"Version" withString:@""];
171 return [NSString stringWithFormat:@"%@ %@", platform, osversion];