|
4 | 4 |
|
5 | 5 | This service allows cryptographic keys, authentication tokens, cross-domain |
6 | 6 | user mappings, and similar to be cached in the kernel for the use of |
7 | | -filesystems other kernel services. |
| 7 | +filesystems and other kernel services. |
8 | 8 |
|
9 | 9 | Keyrings are permitted; these are a special type of key that can hold links to |
10 | 10 | other keys. Processes each have three standard keyring subscriptions that a |
@@ -726,6 +726,15 @@ call, and the key released upon close. How to deal with conflicting keys due to |
726 | 726 | two different users opening the same file is left to the filesystem author to |
727 | 727 | solve. |
728 | 728 |
|
| 729 | +To access the key manager, the following header must be #included: |
| 730 | + |
| 731 | + <linux/key.h> |
| 732 | + |
| 733 | +Specific key types should have a header file under include/keys/ that should be |
| 734 | +used to access that type. For keys of type "user", for example, that would be: |
| 735 | + |
| 736 | + <keys/user-type.h> |
| 737 | + |
729 | 738 | Note that there are two different types of pointers to keys that may be |
730 | 739 | encountered: |
731 | 740 |
|
@@ -791,6 +800,36 @@ payload contents" for more information. |
791 | 800 | passed to the key_type->request_key() op if it exists. |
792 | 801 |
|
793 | 802 |
|
| 803 | +(*) A key can be requested asynchronously by calling one of: |
| 804 | + |
| 805 | + struct key *request_key_async(const struct key_type *type, |
| 806 | + const char *description, |
| 807 | + const char *callout_string); |
| 808 | + |
| 809 | + or: |
| 810 | + |
| 811 | + struct key *request_key_async_with_auxdata(const struct key_type *type, |
| 812 | + const char *description, |
| 813 | + const char *callout_string, |
| 814 | + void *aux); |
| 815 | + |
| 816 | + which are asynchronous equivalents of request_key() and |
| 817 | + request_key_with_auxdata() respectively. |
| 818 | + |
| 819 | + These two functions return with the key potentially still under |
| 820 | + construction. To wait for contruction completion, the following should be |
| 821 | + called: |
| 822 | + |
| 823 | + int wait_for_key_construction(struct key *key, bool intr); |
| 824 | + |
| 825 | + The function will wait for the key to finish being constructed and then |
| 826 | + invokes key_validate() to return an appropriate value to indicate the state |
| 827 | + of the key (0 indicates the key is usable). |
| 828 | + |
| 829 | + If intr is true, then the wait can be interrupted by a signal, in which |
| 830 | + case error ERESTARTSYS will be returned. |
| 831 | + |
| 832 | + |
794 | 833 | (*) When it is no longer required, the key should be released using: |
795 | 834 |
|
796 | 835 | void key_put(struct key *key); |
@@ -924,7 +963,11 @@ DEFINING A KEY TYPE |
924 | 963 |
|
925 | 964 | A kernel service may want to define its own key type. For instance, an AFS |
926 | 965 | filesystem might want to define a Kerberos 5 ticket key type. To do this, it |
927 | | -author fills in a struct key_type and registers it with the system. |
| 966 | +author fills in a key_type struct and registers it with the system. |
| 967 | + |
| 968 | +Source files that implement key types should include the following header file: |
| 969 | + |
| 970 | + <linux/key-type.h> |
928 | 971 |
|
929 | 972 | The structure has a number of fields, some of which are mandatory: |
930 | 973 |
|
@@ -1053,22 +1096,44 @@ The structure has a number of fields, some of which are mandatory: |
1053 | 1096 | as might happen when the userspace buffer is accessed. |
1054 | 1097 |
|
1055 | 1098 |
|
1056 | | - (*) int (*request_key)(struct key *key, struct key *authkey, const char *op, |
| 1099 | + (*) int (*request_key)(struct key_construction *cons, const char *op, |
1057 | 1100 | void *aux); |
1058 | 1101 |
|
1059 | | - This method is optional. If provided, request_key() and |
1060 | | - request_key_with_auxdata() will invoke this function rather than |
1061 | | - upcalling to /sbin/request-key to operate upon a key of this type. |
| 1102 | + This method is optional. If provided, request_key() and friends will |
| 1103 | + invoke this function rather than upcalling to /sbin/request-key to operate |
| 1104 | + upon a key of this type. |
| 1105 | + |
| 1106 | + The aux parameter is as passed to request_key_async_with_auxdata() and |
| 1107 | + similar or is NULL otherwise. Also passed are the construction record for |
| 1108 | + the key to be operated upon and the operation type (currently only |
| 1109 | + "create"). |
| 1110 | + |
| 1111 | + This method is permitted to return before the upcall is complete, but the |
| 1112 | + following function must be called under all circumstances to complete the |
| 1113 | + instantiation process, whether or not it succeeds, whether or not there's |
| 1114 | + an error: |
| 1115 | + |
| 1116 | + void complete_request_key(struct key_construction *cons, int error); |
| 1117 | + |
| 1118 | + The error parameter should be 0 on success, -ve on error. The |
| 1119 | + construction record is destroyed by this action and the authorisation key |
| 1120 | + will be revoked. If an error is indicated, the key under construction |
| 1121 | + will be negatively instantiated if it wasn't already instantiated. |
| 1122 | + |
| 1123 | + If this method returns an error, that error will be returned to the |
| 1124 | + caller of request_key*(). complete_request_key() must be called prior to |
| 1125 | + returning. |
| 1126 | + |
| 1127 | + The key under construction and the authorisation key can be found in the |
| 1128 | + key_construction struct pointed to by cons: |
| 1129 | + |
| 1130 | + (*) struct key *key; |
| 1131 | + |
| 1132 | + The key under construction. |
1062 | 1133 |
|
1063 | | - The aux parameter is as passed to request_key_with_auxdata() or is NULL |
1064 | | - otherwise. Also passed are the key to be operated upon, the |
1065 | | - authorisation key for this operation and the operation type (currently |
1066 | | - only "create"). |
| 1134 | + (*) struct key *authkey; |
1067 | 1135 |
|
1068 | | - This function should return only when the upcall is complete. Upon return |
1069 | | - the authorisation key will be revoked, and the target key will be |
1070 | | - negatively instantiated if it is still uninstantiated. The error will be |
1071 | | - returned to the caller of request_key*(). |
| 1136 | + The authorisation key. |
1072 | 1137 |
|
1073 | 1138 |
|
1074 | 1139 | ============================ |
|
0 commit comments