2 * Copyright (c) 2009 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
29 #ifndef _SYS_CPROTECT_H_
30 #define _SYS_CPROTECT_H_
38 #include <sys/cdefs.h>
39 #include <sys/content_protection.h>
40 #include <sys/kernel_types.h>
42 #define CP_KEYSIZE 32 /* 8x4 = 32, 32x8 = 256 */
43 #define CP_WRAPPEDKEYSIZE 40 /* 2x4 = 8, 8x8 = 64 */
45 /* lock events from AppleKeyStore */
46 #define CP_LOCKED_STATE 0 /* Device is locked */
47 #define CP_UNLOCKED_STATE 1 /* Device is unlocked */
49 #define CP_LOCKED_KEYCHAIN 0
50 #define CP_UNLOCKED_KEYCHAIN 1
52 /* For struct cprotect: cp_flags */
53 #define CP_NEEDS_KEYS 0x1 /* File needs persistent keys */
54 #define CP_KEY_FLUSHED 0x2 /* File's unwrapped key has been purged from memory */
55 #define CP_NO_XATTR 0x4 /* Key info has not been saved as EA to the FS */
57 /* Content Protection VNOP Operation flags */
58 #define CP_READ_ACCESS 0x1
59 #define CP_WRITE_ACCESS 0x2
61 #define CONTENT_PROTECTION_XATTR_NAME "com.apple.system.cprotect"
62 #define CP_CURRENT_MAJOR_VERS 2
63 #define CP_CURRENT_MINOR_VERS 0
66 typedef struct cprotect
*cprotect_t
;
67 typedef struct cp_wrap_func
*cp_wrap_func_t
;
68 typedef struct cp_global_state
*cp_global_state_t
;
69 typedef struct cp_xattr
*cp_xattr_t
;
71 typedef struct cnode
* cnode_ptr_t
;
72 //forward declare the struct.
75 /* The wrappers are invoked by the AKS kext */
76 typedef int wrapper_t(uint32_t properties
, void *key_bytes
, size_t key_length
, void *wrapped_data
, size_t *wrapped_length
);
77 typedef int unwrapper_t(uint32_t properties
, void *wrapped_data
, size_t wrapped_data_length
, void *key_bytes
, size_t *key_length
);
80 * Runtime-only structure containing the content protection status
81 * for the given file. This is contained within the cnode
84 uint8_t cp_cache_key
[CP_KEYSIZE
];
85 uint8_t cp_persistent_key
[CP_WRAPPEDKEYSIZE
];
92 unwrapper_t
*unwrapper
;
95 struct cp_global_state
{
96 uint8_t wrap_functions_set
;
101 * On-disk structure written as the per-file EA payload
102 * All on-disk multi-byte fields for the CP XATTR must be stored
103 * little-endian on-disk. This means they must be endian swapped to
104 * L.E on getxattr() and converted to LE on setxattr().
107 u_int16_t xattr_major_version
;
108 u_int16_t xattr_minor_version
;
110 u_int32_t persistent_class
;
112 uint8_t persistent_key
[CP_WRAPPEDKEYSIZE
];
115 /* Same is true for the root EA, all fields must be written little endian. */
116 struct cp_root_xattr
{
117 u_int16_t major_version
;
118 u_int16_t minor_version
;
128 * Functions to check the status of a CP and to query
129 * the containing filesystem to see if it is supported.
131 int cp_vnode_getclass(vnode_t
, int *);
132 int cp_vnode_setclass(vnode_t
, uint32_t);
134 int cp_key_store_action(int);
135 int cp_register_wraps(cp_wrap_func_t
);
137 int cp_entry_init(cnode_ptr_t
, struct mount
*);
138 int cp_entry_create_keys(cnode_ptr_t
);
139 void cp_entry_destroy(cnode_ptr_t
);
141 cnode_ptr_t
cp_get_protected_cnode(vnode_t
);
142 int cp_handle_vnop(cnode_ptr_t
, int);
143 int cp_fs_protected (mount_t
);
144 int cp_getrootxattr (struct hfsmount
*hfsmp
, struct cp_root_xattr
*outxattr
);
145 int cp_setrootxattr (struct hfsmount
*hfsmp
, struct cp_root_xattr
*newxattr
);
146 int cp_handle_relocate (cnode_ptr_t cp
);
148 #endif /* KERNEL_PRIVATE */
154 #endif /* !_SYS_CPROTECT_H_ */