| 1 | /* |
| 2 | * COPYRIGHT (c) International Business Machines Corp. 2022 |
| 3 | * |
| 4 | * This program is provided under the terms of the Common Public License, |
| 5 | * version 1.0 (CPL-1.0). Any use, reproduction or distribution for this |
| 6 | * software constitutes recipient's acceptance of CPL-1.0 terms which can be |
| 7 | * found in the file LICENSE file or at |
| 8 | * https://opensource.org/licenses/cpl1.0.php |
| 9 | */ |
| 10 | |
| 11 | /* |
| 12 | * pkcshsm_mk_change - A tool to manage and control the re-enciphering of |
| 13 | * secure keys for a concurrent HSM master key change. |
| 14 | */ |
| 15 | |
| 16 | #include "platform.h"cxx . . $ `<file>/usr/lib/common/platform.h`/ |
| 17 | #include <errno.h> |
| 18 | #include <string.h> |
| 19 | #include <stdio.h> |
| 20 | #include <stdlib.h> |
| 21 | #include <stdbool.h> |
| 22 | #include <dlfcn.h> |
| 23 | #include <signal.h> |
| 24 | #include <unistd.h> |
| 25 | |
| 26 | #include "pkcs11types.h"cxx . . $ `<file>/usr/include/pkcs11types.h`/ |
| 27 | #include "p11util.h"cxx . . $ `<file>/usr/lib/common/p11util.h`/ |
| 28 | #include "event_client.h"cxx . . $ `<file>/usr/lib/common/event_client.h`/ |
| 29 | #include "pkcs_utils.h"cxx . . $ `<file>/usr/lib/common/pkcs_utils.h`/ |
| 30 | #include "hsm_mk_change.h"cxx . . $ `<file>/usr/lib/hsm_mk_change/hsm_mk_change.h`/ |
| 31 | #include "pin_prompt.h"cxx . . $ `<file>/usr/lib/common/pin_prompt.h`/ |
| 32 | |
| 33 | #if defined(_AIX) |
| 34 | #include <libgen.h> |
| 35 | #define ELIBACC EINVAL |
| 36 | const char *__progname = "pkcshsm_mk_change"; |
| 37 | #endif |
| 38 | |
| 39 | #define CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`! 1 |
| 40 | #define CMD_FINALIZEcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:40:9`! 2 |
| 41 | #define CMD_CANCELcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:41:9`! 3 |
| 42 | #define CMD_LISTcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:42:9`! 4 |
| 43 | |
| 44 | #define CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`! 8 |
| 45 | #define EP11_WKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:45:9`! 16 |
| 46 | |
| 47 | #define UNUSEDcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:47:9`!(var) ((void)(var)) |
| 48 | |
| 49 | pkcs_trace_level_tcxx . . $ pkcs_trace_level_t# trace_levelcxx . . $ trace_level. = TRACE_LEVEL_NONEcxx . . $ TRACE_LEVEL_NONE.; |
| 50 | |
| 51 | static void *dllcxx . . $ dll. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 52 | static CK_FUNCTION_LISTcxx . . $ CK_FUNCTION_LIST# *func_listcxx . . $ func_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 53 | static int event_fdcxx . . $ event_fd. = -1; |
| 54 | static struct apqncxx . . $ apqn# *apqnscxx . . $ apqns. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 55 | static unsigned int num_apqnscxx . . $ num_apqns. = 0; |
| 56 | static const char *idcxx . . $ id. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 57 | static unsigned char ep11_wkvpcxx . . $ ep11_wkvp.[EP11_WKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:45:9`!] = { 0 }; |
| 58 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! ep11_wkvp_setcxx . . $ ep11_wkvp_set. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 59 | static unsigned char cca_sym_mkvpcxx . . $ cca_sym_mkvp.[CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!] = { 0 }; |
| 60 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cca_sym_mkvp_setcxx . . $ cca_sym_mkvp_set. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 61 | static unsigned char cca_asym_mkvpcxx . . $ cca_asym_mkvp.[CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!] = { 0 }; |
| 62 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cca_asym_mkvp_setcxx . . $ cca_asym_mkvp_set. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 63 | static unsigned char cca_aes_mkvpcxx . . $ cca_aes_mkvp.[CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!] = { 0 }; |
| 64 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cca_aes_mkvp_setcxx . . $ cca_aes_mkvp_set. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 65 | static unsigned char cca_apka_mkvpcxx . . $ cca_apka_mkvp.[CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!] = { 0 }; |
| 66 | static boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cca_apka_mkvp_setcxx . . $ cca_apka_mkvp_set. = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 67 | |
| 68 | struct token_infocxx . . $ token_info# { |
| 69 | CK_SLOT_IDcxx . . $ CK_SLOT_ID# idcxx . . $ token_info#id.; |
| 70 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! presentcxx . . $ token_info#present.; |
| 71 | CK_TOKEN_INFOcxx . . $ CK_TOKEN_INFO# infocxx . . $ token_info#info.; |
| 72 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! affectedcxx . . $ token_info#affected.; |
| 73 | CK_SESSION_HANDLEcxx . . $ CK_SESSION_HANDLE# sessioncxx . . $ token_info#session.; |
| 74 | }; |
| 75 | |
| 76 | CK_ULONGcxx . . $ CK_ULONG# num_affected_slotscxx . . $ num_affected_slots. = 0; |
| 77 | CK_SLOT_ID_PTRcxx . . $ CK_SLOT_ID_PTR# affected_slotscxx . . $ affected_slots. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 78 | static unsigned int num_tokenscxx . . $ num_tokens. = 0; |
| 79 | static struct token_infocxx . . $ token_info# *tokenscxx . . $ tokens. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 80 | |
| 81 | struct hsm_mk_change_opcxx . . $ hsm_mk_change_op# opcxx . . $ op.; |
| 82 | struct hsm_mkvpcxx . . $ hsm_mkvp# mkvpscxx . . $ mkvps.[HSM_MK_TYPE_MAXcxx . . $ `usr/lib/hsm_mk_change/hsm_mk_change.h:35:9`!]; |
| 83 | |
| 84 | static void usagecxx . . $ usage(fda57c8427c60377).(char *progname) |
| 85 | { |
| 86 | printfcxx . . $ printf(581fddd72a8db8fc).("Usage: %s COMMAND [OPTIONS]\n\n", progname); |
| 87 | printfcxx . . $ printf(581fddd72a8db8fc).("Manage and control the re-enciphering of secure keys for a concurrent\n" |
| 88 | "HSM master key change.\n\n"); |
| 89 | printfcxx . . $ printf(581fddd72a8db8fc).("COMMAND:\n"); |
| 90 | printfcxx . . $ printf(581fddd72a8db8fc).(" reencipher initiate a master key change operation for the\n" |
| 91 | " specified APQNs and master key types and re-encipher\n" |
| 92 | " all session and token key objects of the affected\n" |
| 93 | " tokens.\n"); |
| 94 | printfcxx . . $ printf(581fddd72a8db8fc).(" finalize finalize a master key change operation when the\n" |
| 95 | " new master key has been activated on the APQNs.\n"); |
| 96 | printfcxx . . $ printf(581fddd72a8db8fc).(" cancel cancel a master key change operation.\n"); |
| 97 | printfcxx . . $ printf(581fddd72a8db8fc).(" list list currently active master key change operations.\n"); |
| 98 | printfcxx . . $ printf(581fddd72a8db8fc).("\nOPTIONS:\n"); |
| 99 | printfcxx . . $ printf(581fddd72a8db8fc).(" -a, --apqns APQNS specifies a comma separated list of APQNs for\n" |
| 100 | " which a master key change is to be performed.\n" |
| 101 | #if !defined(__s390__) |
| 102 | " MUST be '0.0' on AIX, Linux on x64, and Linux on\n" |
| 103 | " Power for operation to succeed.\n" |
| 104 | #endif |
| 105 | " Only valid with the 'reencipher' command.\n"); |
| 106 | printfcxx . . $ printf(581fddd72a8db8fc).(" -e, --ep11-wkvp WKVP specifies the EP11 wrapping key verification pattern\n" |
| 107 | " of the new, to be set EP11 wrapping key as a\n" |
| 108 | " 16 bytes hex string.\n" |
| 109 | " Only valid with the 'reencipher' command.\n"); |
| 110 | printfcxx . . $ printf(581fddd72a8db8fc).(" -s, --cca-sym-mkvp MKVP specifies the CCA master key verification pattern\n" |
| 111 | " of the new, to be set CCA SYM master key as a\n" |
| 112 | " 8 bytes hex string.\n" |
| 113 | " Only valid with the 'reencipher' command.\n"); |
| 114 | printfcxx . . $ printf(581fddd72a8db8fc).(" -S, --cca-asym-mkvp MKVP specifies the CCA master key verification pattern\n" |
| 115 | " of the new, to be set CCA ASYM master key as a\n" |
| 116 | " 8 bytes hex string.\n" |
| 117 | " Only valid with the 'reencipher' command.\n"); |
| 118 | printfcxx . . $ printf(581fddd72a8db8fc).(" -A, --cca-aes-mkvp MKVP specifies the CCA master key verification pattern\n" |
| 119 | " of the new, to be set CCA AES master key as a\n" |
| 120 | " 8 bytes hex string.\n" |
| 121 | " Only valid with the 'reencipher' command.\n"); |
| 122 | printfcxx . . $ printf(581fddd72a8db8fc).(" -p, --cca-apka-mkvp MKVP specifies the CCA master key verification pattern\n" |
| 123 | " of the new, to be set CCA APKA master key as a\n" |
| 124 | " 8 bytes hex string.\n" |
| 125 | " Only valid with the 'reencipher' command.\n"); |
| 126 | printfcxx . . $ printf(581fddd72a8db8fc).(" -i, --id OPERATION-ID specifies the ID of the master key change operation\n" |
| 127 | " to finalize, cancel, or list.\n"); |
| 128 | printfcxx . . $ printf(581fddd72a8db8fc).(" -v, --verbose LEVEL set verbose level (optional):\n"); |
| 129 | printfcxx . . $ printf(581fddd72a8db8fc).(" none (default), error, warn, info, devel, debug\n"); |
| 130 | printfcxx . . $ printf(581fddd72a8db8fc).(" -h, --help display help information.\n"); |
| 131 | |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | static int parse_apqncxx . . $ parse_apqn(1ef8e6ec083aabb9).(char *apqn) |
| 136 | { |
| 137 | unsigned int card, domain, num; |
| 138 | struct apqncxx . . $ apqn# *tmp; |
| 139 | |
| 140 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("APQN: '%s'\n", apqn); |
| 141 | |
| 142 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(apqn, "%x.%x%n", &card, &domain, (int *)&num) != 2 || |
| 143 | num != strlencxx . . $ strlen(751346f8406fd082).(apqn) || card > 0xff || domain > 0xFFFF) { |
| 144 | warnxcxx . . $ warnx(326aeb464d16410c).("Invalid APQN specification: %s", apqn); |
| 145 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 146 | } |
| 147 | |
| 148 | tmp = realloccxx . . $ realloc(417ab160f6baadc6).(apqnscxx . . $ apqns., (num_apqnscxx . . $ num_apqns. + 1) * sizeof(struct apqncxx . . $ apqn#)); |
| 149 | if (tmp == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 150 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to allocate memory for APQN list"); |
| 151 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 152 | } |
| 153 | |
| 154 | tmp[num_apqnscxx . . $ num_apqns.].cardcxx . . $ apqn#card. = card; |
| 155 | tmp[num_apqnscxx . . $ num_apqns.].domaincxx . . $ apqn#domain. = domain; |
| 156 | |
| 157 | num_apqnscxx . . $ num_apqns.++; |
| 158 | apqnscxx . . $ apqns. = tmp; |
| 159 | |
| 160 | return 0; |
| 161 | } |
| 162 | |
| 163 | static int parse_apqnscxx . . $ parse_apqns(1ef8e6ec083aabb9).(char *apqns) |
| 164 | { |
| 165 | char *saveptr, *tok; |
| 166 | int rc = 0; |
| 167 | |
| 168 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("APQNs: '%s'\n", apqns); |
| 169 | |
| 170 | tok = strtok_rcxx . . $ strtok_r(a42394c85d6397dd).(apqns, ", ", &saveptr); |
| 171 | while(tok != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 172 | rc = parse_apqncxx . . $ parse_apqn(1ef8e6ec083aabb9).(tok); |
| 173 | if (rc != 0) |
| 174 | return rc; |
| 175 | |
| 176 | tok = strtok_rcxx . . $ strtok_r(a42394c85d6397dd).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ", ", &saveptr); |
| 177 | } |
| 178 | |
| 179 | if (apqns == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || num_apqnscxx . . $ num_apqns. == 0) { |
| 180 | warnxcxx . . $ warnx(326aeb464d16410c).("No APQNs specified with option -a/--apqns"); |
| 181 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 182 | } |
| 183 | |
| 184 | return 0; |
| 185 | } |
| 186 | |
| 187 | static int parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(char *mkvp_str, size_t min_size, unsigned char *mkvp, |
| 188 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *set, const char *option) |
| 189 | { |
| 190 | unsigned int i, val; |
| 191 | |
| 192 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("MKVP: '%s'\n", mkvp_str); |
| 193 | |
| 194 | if (strncasecmpcxx . . $ strncasecmp(fd278af2f295fa2e).(mkvp_str, "0x", 2) == 0) |
| 195 | mkvp_str += 2; |
| 196 | |
| 197 | if (strlencxx . . $ strlen(751346f8406fd082).(mkvp_str) < min_size * 2) { |
| 198 | warnxcxx . . $ warnx(326aeb464d16410c).("option %s must specify at least %zu bytes", option, min_size); |
| 199 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 200 | } |
| 201 | |
| 202 | for (i = 0; i < min_size; i++) { |
| 203 | if (sscanfcxx . . $ sscanf(5e8a2c12db2ea735).(mkvp_str + (i * 2), "%02x", &val) != 1) { |
| 204 | warnxcxx . . $ warnx(326aeb464d16410c).("option %s does not specify a valid hex string", option); |
| 205 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 206 | } |
| 207 | mkvp[i] = val; |
| 208 | } |
| 209 | |
| 210 | if (strlencxx . . $ strlen(751346f8406fd082).(mkvp_str) > min_size * 2) |
| 211 | warnxcxx . . $ warnx(326aeb464d16410c).("option %s specifies more than %zu bytes, remaining bytes are ignored", |
| 212 | option, min_size); |
| 213 | |
| 214 | *set = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 215 | return 0; |
| 216 | } |
| 217 | |
| 218 | static const char *get_mk_type_stringcxx . . $ get_mk_type_string(678310b2c96f82d9).(enum hsm_mk_typecxx . . $ hsm_mk_type# mk_type) |
| 219 | { |
| 220 | switch (mk_type) { |
| 221 | case HSM_MK_TYPE_EP11cxx . . $ HSM_MK_TYPE_EP11.: |
| 222 | return "EP11 WK"; |
| 223 | case HSM_MK_TYPE_CCA_SYMcxx . . $ HSM_MK_TYPE_CCA_SYM.: |
| 224 | return"CCA SYM"; |
| 225 | case HSM_MK_TYPE_CCA_ASYMcxx . . $ HSM_MK_TYPE_CCA_ASYM.: |
| 226 | return"CCA ASYM"; |
| 227 | case HSM_MK_TYPE_CCA_AEScxx . . $ HSM_MK_TYPE_CCA_AES.: |
| 228 | return "CCA_AES"; |
| 229 | case HSM_MK_TYPE_CCA_APKAcxx . . $ HSM_MK_TYPE_CCA_APKA.: |
| 230 | return "CCA APKA"; |
| 231 | default: |
| 232 | return "UNKNOWN"; |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | static CK_RVcxx . . $ CK_RV# check_intersecting_ops_cbcxx . . $ check_intersecting_ops_cb(52df439a4941eb10).(struct hsm_mk_change_opcxx . . $ hsm_mk_change_op# *other_op, |
| 237 | void *private) |
| 238 | { |
| 239 | unsigned int i, k; |
| 240 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! *error = private; |
| 241 | |
| 242 | for (i = 0; i < opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_apqnscxx . . $ hsm_mk_change_info#num_apqns.; i++) { |
| 243 | if (hsm_mk_change_apqns_findcxx . . $ hsm_mk_change_apqns_find(3b84e1178fdab556).(other_op->infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns., |
| 244 | other_op->infocxx . . $ hsm_mk_change_op#info..num_apqnscxx . . $ hsm_mk_change_info#num_apqns., |
| 245 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns.[i].cardcxx . . $ apqn#card., |
| 246 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns.[i].domaincxx . . $ apqn#domain.)) { |
| 247 | /* Same APQN found */ |
| 248 | for (k = 0; k < opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.; k++) { |
| 249 | if (hsm_mk_change_mkvps_findcxx . . $ hsm_mk_change_mkvps_find(eb8f0eda561226cc).(other_op->infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps., |
| 250 | other_op->infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps., |
| 251 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps.[k].typecxx . . $ hsm_mkvp#type., 0)) { |
| 252 | /* Same MKVP type */ |
| 253 | warnxcxx . . $ warnx(326aeb464d16410c).("Operation '%s' also affects APQN %02X.%04X and MK type '%s'", |
| 254 | other_op->idcxx . . $ hsm_mk_change_op#id., apqnscxx . . $ apqns.[i].cardcxx . . $ apqn#card., apqnscxx . . $ apqns.[i].domaincxx . . $ apqn#domain., |
| 255 | get_mk_type_stringcxx . . $ get_mk_type_string(678310b2c96f82d9).(opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps.[k].typecxx . . $ hsm_mkvp#type.)); |
| 256 | *error = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 257 | } |
| 258 | } |
| 259 | } |
| 260 | } |
| 261 | |
| 262 | return CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!; |
| 263 | } |
| 264 | |
| 265 | static int check_intersecting_opscxx . . $ check_intersecting_ops(b126dc7c1de90089).(void) |
| 266 | { |
| 267 | CK_RVcxx . . $ CK_RV# rv; |
| 268 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! error = falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!; |
| 269 | |
| 270 | rv = hsm_mk_change_op_iteratecxx . . $ hsm_mk_change_op_iterate(8f1e4f5666c58214).(check_intersecting_ops_cbcxx . . $ check_intersecting_ops_cb(52df439a4941eb10)., &error); |
| 271 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 272 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to iterate over active operations"); |
| 273 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 274 | } |
| 275 | |
| 276 | if (error != falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!) { |
| 277 | warnxcxx . . $ warnx(326aeb464d16410c).("Intersecting master key operations are active, aborting"); |
| 278 | return EALREADYcxx . . $ `<external>/17922322188510340118/errno.h:98:9`!; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int check_tokens_presentcxx . . $ check_tokens_present(b126dc7c1de90089).(void) |
| 285 | { |
| 286 | CK_ULONGcxx . . $ CK_ULONG# i; |
| 287 | boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! all_present = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 288 | ssize_tcxx . . $ ssize_t# num_chars; |
| 289 | char *buff = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 290 | size_t buflen = 0; |
| 291 | |
| 292 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) |
| 293 | all_present &= tokenscxx . . $ tokens.[i].presentcxx . . $ token_info#present.; |
| 294 | |
| 295 | if (all_present) |
| 296 | return 0; |
| 297 | |
| 298 | printfcxx . . $ printf(581fddd72a8db8fc).("WARNING: The following slots have no token present:\n"); |
| 299 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) { |
| 300 | if (tokenscxx . . $ tokens.[i].presentcxx . . $ token_info#present. == falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!) |
| 301 | printfcxx . . $ printf(581fddd72a8db8fc).(" Slot %lu\n", tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.); |
| 302 | } |
| 303 | printfcxx . . $ printf(581fddd72a8db8fc).("Reasons for a token not being present can be that a prereq of the token\n" |
| 304 | "is not fulfilled, or the current user '%s' has no permissions to use\n" |
| 305 | "the token, i.e. because it is not a member of the token's user group.\n\n", |
| 306 | cuseridcxx . . $ cuserid(7a9722d75b371431).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)); |
| 307 | printfcxx . . $ printf(581fddd72a8db8fc).("ATTENTION: If you start a concurrent master key change operation while not\n" |
| 308 | "all expected tokens are present, the key objects of those tokens may be lost,\n" |
| 309 | "if the token would be affected by the master key change.\n"); |
| 310 | printfcxx . . $ printf(581fddd72a8db8fc).("Continue [y/N]? "); |
| 311 | fflushcxx . . $ fflush(89bc1efcdac0ca22).(stdoutcxx . . $ `<external>/232824719582829767/stdio.h:154:9`!); |
| 312 | num_chars = getlinecxx . . $ getline(960b3da7d5d5ad33).(&buff, &buflen, stdincxx . . $ `<external>/232824719582829767/stdio.h:153:9`!); |
| 313 | if (num_chars < 0 || strncmpcxx . . $ strncmp(fd278af2f295fa2e).(buff, "y", 1) != 0) { |
| 314 | printfcxx . . $ printf(581fddd72a8db8fc).("Aborted by user.\n"); |
| 315 | freecxx . . $ free(5d22bdacc48458e8).(buff); |
| 316 | return ECANCELEDcxx . . $ `<external>/17922322188510340118/errno.h:111:9`!; |
| 317 | } |
| 318 | freecxx . . $ free(5d22bdacc48458e8).(buff); |
| 319 | |
| 320 | return 0; |
| 321 | } |
| 322 | |
| 323 | static int create_mk_change_opcxx . . $ create_mk_change_op(b126dc7c1de90089).(void) |
| 324 | { |
| 325 | CK_RVcxx . . $ CK_RV# rv; |
| 326 | |
| 327 | rv = hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 328 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 329 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to obtain lock"); |
| 330 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 331 | } |
| 332 | |
| 333 | rv = hsm_mk_change_op_createcxx . . $ hsm_mk_change_op_create(4d93bd20ebed33d8).(&opcxx . . $ op.); |
| 334 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 335 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to create MK change operation file"); |
| 336 | hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 337 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 338 | } |
| 339 | |
| 340 | rv = hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 341 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 342 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to release lock"); |
| 343 | hsm_mk_change_op_removecxx . . $ hsm_mk_change_op_remove(751346f8406fd082).(opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.); |
| 344 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 345 | } |
| 346 | |
| 347 | return 0; |
| 348 | } |
| 349 | |
| 350 | static int save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(void) |
| 351 | { |
| 352 | CK_RVcxx . . $ CK_RV# rv; |
| 353 | |
| 354 | rv = hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 355 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 356 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to obtain lock"); |
| 357 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 358 | } |
| 359 | |
| 360 | rv = hsm_mk_change_op_savecxx . . $ hsm_mk_change_op_save(2c34cef8f523a504).(&opcxx . . $ op.); |
| 361 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 362 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to save MK change operation file"); |
| 363 | hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 364 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 365 | } |
| 366 | |
| 367 | rv = hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 368 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 369 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to release lock"); |
| 370 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 371 | } |
| 372 | |
| 373 | return 0; |
| 374 | } |
| 375 | |
| 376 | static int load_mk_change_opcxx . . $ load_mk_change_op(5c4306d8553b3696).(const char *id) |
| 377 | { |
| 378 | CK_RVcxx . . $ CK_RV# rv; |
| 379 | |
| 380 | rv = hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 381 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 382 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to obtain lock"); |
| 383 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 384 | } |
| 385 | |
| 386 | rv = hsm_mk_change_op_loadcxx . . $ hsm_mk_change_op_load(5303606949ca2b7).(id, &opcxx . . $ op.); |
| 387 | if (rv != 0) { |
| 388 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to load MK change operation file"); |
| 389 | hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 390 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 391 | } |
| 392 | |
| 393 | rv = hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 394 | if (rv != 0) { |
| 395 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to release lock"); |
| 396 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 397 | } |
| 398 | |
| 399 | return 0; |
| 400 | } |
| 401 | |
| 402 | static int remove_mk_change_opcxx . . $ remove_mk_change_op(b126dc7c1de90089).(void) |
| 403 | { |
| 404 | CK_RVcxx . . $ CK_RV# rv; |
| 405 | |
| 406 | rv = hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 407 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 408 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to obtain lock"); |
| 409 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 410 | } |
| 411 | |
| 412 | rv = hsm_mk_change_op_removecxx . . $ hsm_mk_change_op_remove(751346f8406fd082).(opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.); |
| 413 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 414 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to remove MK change operation file(s)"); |
| 415 | hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 416 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 417 | } |
| 418 | |
| 419 | rv = hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 420 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 421 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to release lock"); |
| 422 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 423 | } |
| 424 | |
| 425 | return 0; |
| 426 | } |
| 427 | |
| 428 | static int build_event_payloadcxx . . $ build_event_payload(7dfb11f88b31285e).(unsigned char **payload, size_t *payload_len) |
| 429 | { |
| 430 | event_mk_change_data_tcxx . . $ event_mk_change_data_t# *hdr; |
| 431 | size_t info_len = 0; |
| 432 | CK_RVcxx . . $ CK_RV# rv; |
| 433 | |
| 434 | rv = hsm_mk_change_info_flattencxx . . $ hsm_mk_change_info_flatten(c36f8cc6d28aeeb).(&opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &info_len); |
| 435 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 436 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to query size of event payload buffer"); |
| 437 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 438 | } |
| 439 | |
| 440 | *payload_len = sizeof(*hdr) + info_len; |
| 441 | *payload = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, *payload_len); |
| 442 | if (*payload == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 443 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to allocate event payload buffer"); |
| 444 | *payload_len = 0; |
| 445 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 446 | } |
| 447 | |
| 448 | hdr = (event_mk_change_data_tcxx . . $ event_mk_change_data_t# *)*payload; |
| 449 | strncpycxx . . $ strncpy(255158a415b673b0).(hdr->idcxx . . $ $anonymous_type_e2682f69c603a7d3_3#id., opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id., sizeof(hdr->idcxx . . $ $anonymous_type_e2682f69c603a7d3_3#id.)); |
| 450 | hdr->tool_pidcxx . . $ $anonymous_type_e2682f69c603a7d3_3#tool_pid. = getpidcxx . . $ getpid(b126dc7c1de90089).(); |
| 451 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = 0; |
| 452 | |
| 453 | rv = hsm_mk_change_info_flattencxx . . $ hsm_mk_change_info_flatten(c36f8cc6d28aeeb).(&opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info., *payload + sizeof(*hdr), |
| 454 | &info_len); |
| 455 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 456 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to flatten operation info"); |
| 457 | freecxx . . $ free(5d22bdacc48458e8).(*payload); |
| 458 | *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 459 | *payload_len = 0; |
| 460 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 461 | } |
| 462 | |
| 463 | return 0; |
| 464 | } |
| 465 | |
| 466 | static int send_query_eventcxx . . $ send_query_event(160c5089f9e5b4f7).(unsigned int event, const char *msg_cmd, |
| 467 | CK_ULONGcxx . . $ CK_ULONG# *num_affected_slots) |
| 468 | { |
| 469 | size_t payload_len; |
| 470 | unsigned char *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 471 | struct event_destinationcxx . . $ event_destination# dest; |
| 472 | struct event_replycxx . . $ event_reply# reply; |
| 473 | CK_ULONGcxx . . $ CK_ULONG# i, num_errors = 0; |
| 474 | int rc = 0; |
| 475 | |
| 476 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Event: 0x%08x\n", event); |
| 477 | |
| 478 | *num_affected_slots = 0; |
| 479 | |
| 480 | rc = build_event_payloadcxx . . $ build_event_payload(7dfb11f88b31285e).(&payload, &payload_len); |
| 481 | if (rc != 0) |
| 482 | return rc; |
| 483 | |
| 484 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) { |
| 485 | if (tokenscxx . . $ tokens.[i].presentcxx . . $ token_info#present. == falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!) |
| 486 | continue; |
| 487 | |
| 488 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Slot %lu\n", tokens[i].id); |
| 489 | |
| 490 | dest.process_idcxx . . $ event_destination#process_id. = getpidcxx . . $ getpid(b126dc7c1de90089).(); /* Send to current process only */ |
| 491 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 492 | memcpycxx . . $ memcpy(cc817cb175f282d).(dest.token_labelcxx . . $ event_destination#token_label., tokenscxx . . $ tokens.[i].infocxx . . $ token_info#info..labelcxx . . $ CK_TOKEN_INFO#label., |
| 493 | sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); /* selected token only */ |
| 494 | |
| 495 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 496 | |
| 497 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., event, EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, |
| 498 | payload_len, (char *)payload, &dest, &reply); |
| 499 | if (rc != 0) { |
| 500 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 501 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 502 | goto out; |
| 503 | } |
| 504 | |
| 505 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 506 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 507 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 508 | |
| 509 | if (reply.positive_repliescxx . . $ event_reply#positive_replies. > 1 || |
| 510 | reply.negative_repliescxx . . $ event_reply#negative_replies. > 1 || |
| 511 | reply.nothandled_repliescxx . . $ event_reply#nothandled_replies. > 1) { |
| 512 | warnxcxx . . $ warnx(326aeb464d16410c).("More than one token responded to the query event for slot %lu", |
| 513 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.); |
| 514 | warnxcxx . . $ warnx(326aeb464d16410c).("Possibly multiple tokens use the same label?"); |
| 515 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 516 | goto out; |
| 517 | } |
| 518 | |
| 519 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. == 1) { |
| 520 | warnxcxx . . $ warnx(326aeb464d16410c).("Token in slot %lu is unable to perform the %s.", |
| 521 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id., msg_cmd); |
| 522 | num_errors++; |
| 523 | } |
| 524 | |
| 525 | if (reply.positive_repliescxx . . $ event_reply#positive_replies. == 1) { |
| 526 | tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 527 | (*num_affected_slots)++; |
| 528 | } |
| 529 | } |
| 530 | |
| 531 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("num_errors: %lu\n", num_errors); |
| 532 | |
| 533 | if (num_errors > 0) { |
| 534 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token is unable to perform the %s, aborting.", |
| 535 | msg_cmd); |
| 536 | rc = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 537 | goto out; |
| 538 | } |
| 539 | |
| 540 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("num_affected_slots: %lu\n", *num_affected_slots); |
| 541 | |
| 542 | out: |
| 543 | freecxx . . $ free(5d22bdacc48458e8).(payload); |
| 544 | |
| 545 | return rc; |
| 546 | } |
| 547 | |
| 548 | static int query_tokens_initiate_mk_changecxx . . $ query_tokens_initiate_mk_change(b126dc7c1de90089).(void) |
| 549 | { |
| 550 | CK_ULONGcxx . . $ CK_ULONG# i, k; |
| 551 | int rc; |
| 552 | |
| 553 | rc = send_query_eventcxx . . $ send_query_event(160c5089f9e5b4f7).(EVENT_TYPE_MK_CHANGE_INITIATE_QUERYcxx . . $ `usr/include/events.h:57:9`!, |
| 554 | "master key change", &num_affected_slotscxx . . $ num_affected_slots.); |
| 555 | if (rc != 0) |
| 556 | return rc; |
| 557 | |
| 558 | if (num_affected_slotscxx . . $ num_affected_slots. == 0) { |
| 559 | warnxcxx . . $ warnx(326aeb464d16410c).("No token is affected by this master key change, aborting"); |
| 560 | return ECANCELEDcxx . . $ `<external>/17922322188510340118/errno.h:111:9`!; |
| 561 | } |
| 562 | |
| 563 | affected_slotscxx . . $ affected_slots. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_affected_slotscxx . . $ num_affected_slots., sizeof(CK_SLOT_IDcxx . . $ CK_SLOT_ID#)); |
| 564 | if (affected_slotscxx . . $ affected_slots. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 565 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to allocate list of affected slots"); |
| 566 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 567 | } |
| 568 | |
| 569 | for (i = 0, k = 0; i < num_tokenscxx . . $ num_tokens. && k < num_affected_slotscxx . . $ num_affected_slots.; i++) { |
| 570 | if (tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. == truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!) { |
| 571 | affected_slotscxx . . $ affected_slots.[k] = tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.; |
| 572 | k++; |
| 573 | } |
| 574 | } |
| 575 | |
| 576 | printfcxx . . $ printf(581fddd72a8db8fc).("The following tokens are affected by this master key change:\n"); |
| 577 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) { |
| 578 | if (tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. == truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!) |
| 579 | printfcxx . . $ printf(581fddd72a8db8fc).(" Slot %lu: Label: %.32s\n", tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id., tokenscxx . . $ tokens.[i].infocxx . . $ token_info#info..labelcxx . . $ CK_TOKEN_INFO#label.); |
| 580 | } |
| 581 | |
| 582 | return 0; |
| 583 | } |
| 584 | |
| 585 | static int login_tokenscxx . . $ login_tokens(b126dc7c1de90089).(void) |
| 586 | { |
| 587 | char msg[200]; |
| 588 | const char *userpin = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 589 | char *buf_user = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 590 | CK_ULONGcxx . . $ CK_ULONG# i; |
| 591 | int rc = 0; |
| 592 | CK_RVcxx . . $ CK_RV# rv; |
| 593 | |
| 594 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) { |
| 595 | if (tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. == falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!) |
| 596 | continue; |
| 597 | |
| 598 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Slot %lu\n", tokens[i].id); |
| 599 | |
| 600 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(msg, sizeof(msg), "Enter the USER PIN for slot %lu: ", |
| 601 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.); |
| 602 | get_pin: |
| 603 | userpin = pin_promptcxx . . $ pin_prompt(ce6e284d80333bb0).(&buf_user, msg); |
| 604 | if (userpin == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 605 | warnxcxx . . $ warnx(326aeb464d16410c).("Aborted by user."); |
| 606 | rc = ECANCELEDcxx . . $ `<external>/17922322188510340118/errno.h:111:9`!; |
| 607 | goto out; |
| 608 | } |
| 609 | |
| 610 | if (strlencxx . . $ strlen(751346f8406fd082).(userpin) == 0) { |
| 611 | warnxcxx . . $ warnx(326aeb464d16410c).("Empty pin entered, try again."); |
| 612 | pin_freecxx . . $ pin_free(3ed91490e421178f).(&buf_user); |
| 613 | goto get_pin; |
| 614 | } |
| 615 | |
| 616 | rv = func_listcxx . . $ func_list.->C_OpenSessioncxx . . $ CK_FUNCTION_LIST#C_OpenSession.(tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id., |
| 617 | CKF_SERIAL_SESSIONcxx . . $ `usr/include/pkcs11types.h:362:9`! | CKF_RW_SESSIONcxx . . $ `usr/include/pkcs11types.h:361:9`!, |
| 618 | NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &tokenscxx . . $ tokens.[i].sessioncxx . . $ token_info#session.); |
| 619 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 620 | warnxcxx . . $ warnx(326aeb464d16410c).("Error opening an R/W session with slot %lu: 0x%lX (%s)", |
| 621 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id., rv, p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rv)); |
| 622 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 623 | goto out; |
| 624 | } |
| 625 | |
| 626 | rv = func_listcxx . . $ func_list.->C_Logincxx . . $ CK_FUNCTION_LIST#C_Login.(tokenscxx . . $ tokens.[i].sessioncxx . . $ token_info#session., CKU_USERcxx . . $ `usr/include/pkcs11types.h:331:9`!, |
| 627 | (CK_CHAR_PTRcxx . . $ CK_CHAR_PTR#)userpin, strlencxx . . $ strlen(751346f8406fd082).(userpin)); |
| 628 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 629 | warnxcxx . . $ warnx(326aeb464d16410c).("Error logging in for slot %lu: 0x%lX (%s)", |
| 630 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id., rv, p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rv)); |
| 631 | rc = EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 632 | goto out; |
| 633 | } |
| 634 | |
| 635 | pin_freecxx . . $ pin_free(3ed91490e421178f).(&buf_user); |
| 636 | } |
| 637 | |
| 638 | out: |
| 639 | pin_freecxx . . $ pin_free(3ed91490e421178f).(&buf_user); |
| 640 | return rc; |
| 641 | } |
| 642 | |
| 643 | static void logout_tokenscxx . . $ logout_tokens(49f6e7a06ebc5aa8).(void) |
| 644 | { |
| 645 | CK_ULONGcxx . . $ CK_ULONG# i; |
| 646 | |
| 647 | for (i = 0; i < num_tokenscxx . . $ num_tokens.; i++) { |
| 648 | if (tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. == falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!) |
| 649 | continue; |
| 650 | if (tokenscxx . . $ tokens.[i].sessioncxx . . $ token_info#session. == CK_INVALID_HANDLEcxx . . $ `usr/include/pkcs11types.h:99:9`!) |
| 651 | continue; |
| 652 | |
| 653 | func_listcxx . . $ func_list.->C_Logoutcxx . . $ CK_FUNCTION_LIST#C_Logout.(tokenscxx . . $ tokens.[i].sessioncxx . . $ token_info#session.); |
| 654 | func_listcxx . . $ func_list.->C_CloseAllSessionscxx . . $ CK_FUNCTION_LIST#C_CloseAllSessions.(tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.); |
| 655 | } |
| 656 | } |
| 657 | |
| 658 | static int reencipher_tokenscxx . . $ reencipher_tokens(b126dc7c1de90089).(void) |
| 659 | { |
| 660 | size_t payload_len; |
| 661 | unsigned char *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 662 | event_mk_change_data_tcxx . . $ event_mk_change_data_t# *hdr; |
| 663 | struct event_destinationcxx . . $ event_destination# dest; |
| 664 | struct event_replycxx . . $ event_reply# reply; |
| 665 | int rc = 0; |
| 666 | |
| 667 | rc = build_event_payloadcxx . . $ build_event_payload(7dfb11f88b31285e).(&payload, &payload_len); |
| 668 | if (rc != 0) |
| 669 | return rc; |
| 670 | |
| 671 | /* |
| 672 | * Let all tokens re-encipher their session objects. |
| 673 | * This activates the MK change operation for the processes. |
| 674 | * New token objects will be re-enciphered by the processes, existing |
| 675 | * token objects are not yet re-enciphered. Since the new WK is not yet |
| 676 | * set/activated on the APQNs at that point in time, this does not matter. |
| 677 | */ |
| 678 | hdr = (event_mk_change_data_tcxx . . $ event_mk_change_data_t# *)payload; |
| 679 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_NONEcxx . . $ `usr/include/events.h:99:9`!; |
| 680 | |
| 681 | dest.process_idcxx . . $ event_destination#process_id. = 0; |
| 682 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 683 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 684 | |
| 685 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 686 | |
| 687 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., EVENT_TYPE_MK_CHANGE_REENCIPHERcxx . . $ `usr/include/events.h:58:9`!, |
| 688 | EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, payload_len, (char *)payload, |
| 689 | &dest, &reply); |
| 690 | if (rc != 0) { |
| 691 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 692 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 693 | goto out; |
| 694 | } |
| 695 | |
| 696 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 697 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 698 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 699 | |
| 700 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0 || reply.positive_repliescxx . . $ event_reply#positive_replies. == 0) |
| 701 | goto cancel; |
| 702 | |
| 703 | /* |
| 704 | * Let the tool process re-encipher the token objects. |
| 705 | * After that, all objects are re-enciphered. |
| 706 | */ |
| 707 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_TOK_OBJScxx . . $ `usr/include/events.h:100:9`!; |
| 708 | |
| 709 | dest.process_idcxx . . $ event_destination#process_id. = getpidcxx . . $ getpid(b126dc7c1de90089).(); /* Send to current process only */ |
| 710 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 711 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 712 | |
| 713 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 714 | |
| 715 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., EVENT_TYPE_MK_CHANGE_REENCIPHERcxx . . $ `usr/include/events.h:58:9`!, |
| 716 | EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, payload_len, (char *)payload, |
| 717 | &dest, &reply); |
| 718 | if (rc != 0) { |
| 719 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 720 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 721 | goto out; |
| 722 | } |
| 723 | |
| 724 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 725 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 726 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 727 | |
| 728 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0 || reply.positive_repliescxx . . $ event_reply#positive_replies. == 0) |
| 729 | goto cancel; |
| 730 | |
| 731 | out: |
| 732 | freecxx . . $ free(5d22bdacc48458e8).(payload); |
| 733 | |
| 734 | return rc; |
| 735 | |
| 736 | cancel: |
| 737 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to perform the key re-encryption."); |
| 738 | warnxcxx . . $ warnx(326aeb464d16410c).("Check the syslog for details about the errors reported by the tokens."); |
| 739 | |
| 740 | /* Cancel the MK change operation */ |
| 741 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = HSM_MK_CH_STATE_CANCELINGcxx . . $ HSM_MK_CH_STATE_CANCELING.; |
| 742 | |
| 743 | rc = save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(); |
| 744 | if (rc != 0) |
| 745 | goto out; |
| 746 | |
| 747 | /* Let all tokens cancel their session object re-enciphering */ |
| 748 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_NONEcxx . . $ `usr/include/events.h:99:9`!; |
| 749 | |
| 750 | dest.process_idcxx . . $ event_destination#process_id. = 0; |
| 751 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 752 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 753 | |
| 754 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., EVENT_TYPE_MK_CHANGE_CANCELcxx . . $ `usr/include/events.h:62:9`!, |
| 755 | EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, payload_len, (char *)payload, |
| 756 | &dest, &reply); |
| 757 | if (rc != 0) { |
| 758 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 759 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 760 | goto out; |
| 761 | } |
| 762 | |
| 763 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 764 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 765 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 766 | |
| 767 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0) |
| 768 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to cancel the key re-encryption."); |
| 769 | |
| 770 | /* Let the tool process cancel the token object re-enciphering */ |
| 771 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_TOK_OBJS_FINALcxx . . $ `usr/include/events.h:101:9`!; |
| 772 | |
| 773 | dest.process_idcxx . . $ event_destination#process_id. = getpidcxx . . $ getpid(b126dc7c1de90089).(); /* Send to current process only */ |
| 774 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 775 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 776 | |
| 777 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., EVENT_TYPE_MK_CHANGE_CANCELcxx . . $ `usr/include/events.h:62:9`!, |
| 778 | EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, payload_len, (char *)payload, |
| 779 | &dest, &reply); |
| 780 | if (rc != 0) { |
| 781 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 782 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 783 | goto out; |
| 784 | } |
| 785 | |
| 786 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 787 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 788 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 789 | |
| 790 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0) |
| 791 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to cancel the key re-encryption."); |
| 792 | |
| 793 | rc = remove_mk_change_opcxx . . $ remove_mk_change_op(b126dc7c1de90089).(); |
| 794 | if (rc != 0) |
| 795 | goto out; |
| 796 | |
| 797 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 798 | |
| 799 | goto out; |
| 800 | } |
| 801 | |
| 802 | static int perform_reenciphercxx . . $ perform_reencipher(b126dc7c1de90089).(void) |
| 803 | { |
| 804 | unsigned int i; |
| 805 | int rc; |
| 806 | |
| 807 | /* Setup the MK change operation */ |
| 808 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Num APQNs: %u\n", num_apqns); |
| 809 | for (i = 0; i < num_apqnscxx . . $ num_apqns.; i++) { |
| 810 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("APQN: %02x.%04x\n", apqns[i].card, apqns[i].domain); |
| 811 | } |
| 812 | |
| 813 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = HSM_MK_CH_STATE_INITIALcxx . . $ HSM_MK_CH_STATE_INITIAL.; |
| 814 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_apqnscxx . . $ hsm_mk_change_info#num_apqns. = num_apqnscxx . . $ num_apqns.; |
| 815 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns. = apqnscxx . . $ apqns.; |
| 816 | |
| 817 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps. = 0; |
| 818 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps. = mkvpscxx . . $ mkvps.; |
| 819 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("EP11 WKVP set: %d\n", ep11_wkvp_set); |
| 820 | if (ep11_wkvp_setcxx . . $ ep11_wkvp_set.) { |
| 821 | TRACE_DEBUG_DUMPcxx . . $ `usr/lib/common/pkcs_utils.h:89:9`!("EP11 WKVP: ", (CK_BYTE *)ep11_wkvp, EP11_WKVP_LENGTH); |
| 822 | |
| 823 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].typecxx . . $ hsm_mkvp#type. = HSM_MK_TYPE_EP11cxx . . $ HSM_MK_TYPE_EP11.; |
| 824 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvpcxx . . $ hsm_mkvp#mkvp. = ep11_wkvpcxx . . $ ep11_wkvp.; |
| 825 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvp_lencxx . . $ hsm_mkvp#mkvp_len. = EP11_WKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:45:9`!; |
| 826 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.++; |
| 827 | } |
| 828 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("CCA SYM MKVP set: %d\n", cca_sym_mkvp_set); |
| 829 | if (cca_sym_mkvp_setcxx . . $ cca_sym_mkvp_set.) { |
| 830 | TRACE_DEBUG_DUMPcxx . . $ `usr/lib/common/pkcs_utils.h:89:9`!("CCA SYM MKVP: ", (CK_BYTE *)cca_sym_mkvp, CCA_MKVP_LENGTH); |
| 831 | |
| 832 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].typecxx . . $ hsm_mkvp#type. = HSM_MK_TYPE_CCA_SYMcxx . . $ HSM_MK_TYPE_CCA_SYM.; |
| 833 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvpcxx . . $ hsm_mkvp#mkvp. = cca_sym_mkvpcxx . . $ cca_sym_mkvp.; |
| 834 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvp_lencxx . . $ hsm_mkvp#mkvp_len. = CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!; |
| 835 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.++; |
| 836 | } |
| 837 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("CCA ASYM MKVP set: %d\n", cca_asym_mkvp_set); |
| 838 | if (cca_asym_mkvp_setcxx . . $ cca_asym_mkvp_set.) { |
| 839 | TRACE_DEBUG_DUMPcxx . . $ `usr/lib/common/pkcs_utils.h:89:9`!("CCA ASYM MKVP: ", (CK_BYTE *)cca_asym_mkvp, CCA_MKVP_LENGTH); |
| 840 | |
| 841 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].typecxx . . $ hsm_mkvp#type. = HSM_MK_TYPE_CCA_ASYMcxx . . $ HSM_MK_TYPE_CCA_ASYM.; |
| 842 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvpcxx . . $ hsm_mkvp#mkvp. = cca_asym_mkvpcxx . . $ cca_asym_mkvp.; |
| 843 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvp_lencxx . . $ hsm_mkvp#mkvp_len. = CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!; |
| 844 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.++; |
| 845 | |
| 846 | } |
| 847 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("CCA AES MKVP set: %d\n", cca_aes_mkvp_set); |
| 848 | if (cca_aes_mkvp_setcxx . . $ cca_aes_mkvp_set.) { |
| 849 | TRACE_DEBUG_DUMPcxx . . $ `usr/lib/common/pkcs_utils.h:89:9`!("CCA SYM MKVP: ", (CK_BYTE *)cca_aes_mkvp, CCA_MKVP_LENGTH); |
| 850 | |
| 851 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].typecxx . . $ hsm_mkvp#type. = HSM_MK_TYPE_CCA_AEScxx . . $ HSM_MK_TYPE_CCA_AES.; |
| 852 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvpcxx . . $ hsm_mkvp#mkvp. = cca_aes_mkvpcxx . . $ cca_aes_mkvp.; |
| 853 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvp_lencxx . . $ hsm_mkvp#mkvp_len. = CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!; |
| 854 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.++; |
| 855 | } |
| 856 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("CCA APKA MKVP set: %d\n", cca_apka_mkvp_set); |
| 857 | if (cca_apka_mkvp_setcxx . . $ cca_apka_mkvp_set.) { |
| 858 | TRACE_DEBUG_DUMPcxx . . $ `usr/lib/common/pkcs_utils.h:89:9`!("CCA SYM MKVP: ", (CK_BYTE *)cca_apka_mkvp, CCA_MKVP_LENGTH); |
| 859 | |
| 860 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].typecxx . . $ hsm_mkvp#type. = HSM_MK_TYPE_CCA_APKAcxx . . $ HSM_MK_TYPE_CCA_APKA.; |
| 861 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvpcxx . . $ hsm_mkvp#mkvp. = cca_apka_mkvpcxx . . $ cca_apka_mkvp.; |
| 862 | mkvpscxx . . $ mkvps.[opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.].mkvp_lencxx . . $ hsm_mkvp#mkvp_len. = CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!; |
| 863 | opcxx . . $ op..infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.++; |
| 864 | } |
| 865 | |
| 866 | /* Check that no intersecting MK change operation is active */ |
| 867 | rc = check_intersecting_opscxx . . $ check_intersecting_ops(b126dc7c1de90089).(); |
| 868 | if (rc != 0) |
| 869 | return rc; |
| 870 | |
| 871 | /* Check that all tokens are present, warn & prompt user if not */ |
| 872 | rc = check_tokens_presentcxx . . $ check_tokens_present(b126dc7c1de90089).(); |
| 873 | if (rc != 0) |
| 874 | return rc; |
| 875 | |
| 876 | /* Create the MK change operation file */ |
| 877 | rc = create_mk_change_opcxx . . $ create_mk_change_op(b126dc7c1de90089).(); |
| 878 | if (rc != 0) |
| 879 | goto error; |
| 880 | |
| 881 | /* Query each token if it is affected by this MK change */ |
| 882 | rc = query_tokens_initiate_mk_changecxx . . $ query_tokens_initiate_mk_change(b126dc7c1de90089).(); |
| 883 | if (rc != 0) |
| 884 | goto error; |
| 885 | |
| 886 | /* Prompt for pin, login and open R/W session for each affected token */ |
| 887 | rc = login_tokenscxx . . $ login_tokens(b126dc7c1de90089).(); |
| 888 | if (rc != 0) |
| 889 | goto error; |
| 890 | |
| 891 | /* Update MK operation with affected slots and state */ |
| 892 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = HSM_MK_CH_STATE_REENCIPHERINGcxx . . $ HSM_MK_CH_STATE_REENCIPHERING.; |
| 893 | opcxx . . $ op..num_slotscxx . . $ hsm_mk_change_op#num_slots. = num_affected_slotscxx . . $ num_affected_slots.; |
| 894 | opcxx . . $ op..slotscxx . . $ hsm_mk_change_op#slots. = affected_slotscxx . . $ affected_slots.; |
| 895 | |
| 896 | rc = save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(); |
| 897 | if (rc != 0) |
| 898 | goto error; |
| 899 | |
| 900 | printfcxx . . $ printf(581fddd72a8db8fc).("Re-enciphering, please wait...\n"); |
| 901 | |
| 902 | /* Let each affected token reencipher its keys */ |
| 903 | rc = reencipher_tokenscxx . . $ reencipher_tokens(b126dc7c1de90089).(); |
| 904 | if (rc != 0) |
| 905 | goto error; |
| 906 | |
| 907 | printfcxx . . $ printf(581fddd72a8db8fc).("Completed.\n"); |
| 908 | |
| 909 | /* Update MK operation state */ |
| 910 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = HSM_MK_CH_STATE_REENCIPHEREDcxx . . $ HSM_MK_CH_STATE_REENCIPHERED.; |
| 911 | |
| 912 | rc = save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(); |
| 913 | if (rc != 0) |
| 914 | goto error; |
| 915 | |
| 916 | printfcxx . . $ printf(581fddd72a8db8fc).("\nMaster key change operation '%s' created.\n\n", opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.); |
| 917 | printfcxx . . $ printf(581fddd72a8db8fc).("Once the new master keys have been set/activated:\n"); |
| 918 | printfcxx . . $ printf(581fddd72a8db8fc).(" - If you specified EXPECTED_MKVPS in your token configuration file(s),\n" |
| 919 | " you must now replace the old MKVPs with the new MKVPs."); |
| 920 | printfcxx . . $ printf(581fddd72a8db8fc).(" - Run 'pkcshsm_mk_change finalize --id %s' when the new master\n" |
| 921 | " keys have been set/activated.\n", opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.); |
| 922 | |
| 923 | return 0; |
| 924 | |
| 925 | error: |
| 926 | if (opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.[0] != '\0') { |
| 927 | /* Try to remove just created MK operation */ |
| 928 | hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 929 | hsm_mk_change_op_removecxx . . $ hsm_mk_change_op_remove(751346f8406fd082).(opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id.); |
| 930 | hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 931 | } |
| 932 | |
| 933 | return rc; |
| 934 | } |
| 935 | |
| 936 | static int finalize_cancel_tokenscxx . . $ finalize_cancel_tokens(5b0a8aebfaf6ded3).(unsigned int event, |
| 937 | enum hsm_mk_change_statecxx . . $ hsm_mk_change_state# state, |
| 938 | const char *msg_cmd) |
| 939 | { |
| 940 | size_t payload_len; |
| 941 | unsigned char *payload = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 942 | event_mk_change_data_tcxx . . $ event_mk_change_data_t# *hdr; |
| 943 | struct event_destinationcxx . . $ event_destination# dest; |
| 944 | struct event_replycxx . . $ event_reply# reply; |
| 945 | int rc = 0; |
| 946 | |
| 947 | rc = build_event_payloadcxx . . $ build_event_payload(7dfb11f88b31285e).(&payload, &payload_len); |
| 948 | if (rc != 0) |
| 949 | return rc; |
| 950 | |
| 951 | /* |
| 952 | * Let the tool process cancel/finalize the token object re-enciphering. |
| 953 | * Processes may still create new token objects at that time. |
| 954 | */ |
| 955 | hdr = (event_mk_change_data_tcxx . . $ event_mk_change_data_t# *)payload; |
| 956 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_TOK_OBJScxx . . $ `usr/include/events.h:100:9`!; |
| 957 | |
| 958 | dest.process_idcxx . . $ event_destination#process_id. = getpidcxx . . $ getpid(b126dc7c1de90089).(); /* Send to current process only */ |
| 959 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 960 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 961 | |
| 962 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 963 | |
| 964 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., event, EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, |
| 965 | payload_len, (char *)payload, |
| 966 | &dest, &reply); |
| 967 | if (rc != 0) { |
| 968 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 969 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 970 | goto out; |
| 971 | } |
| 972 | |
| 973 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 974 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 975 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 976 | |
| 977 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0 || reply.positive_repliescxx . . $ event_reply#positive_replies. == 0) { |
| 978 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to %s the master key change " |
| 979 | "operation.", msg_cmd); |
| 980 | warnxcxx . . $ warnx(326aeb464d16410c).("Check the syslog for details about the errors reported by " |
| 981 | "the tokens."); |
| 982 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 983 | goto out; |
| 984 | } |
| 985 | |
| 986 | /* |
| 987 | * Change state of MK change op. From now on, new processes will no longer |
| 988 | * detect an active MK change operation. Any token objects created by such |
| 989 | * new processes will use the new WK anyway, and will not have the |
| 990 | * re-enciphered blob stored. Existing processes still running with the |
| 991 | * MK change operation active using such token objects that have no |
| 992 | * re-enciphered will use the normal blob, even though the MK change |
| 993 | * operation might still be active and the new WK is set. |
| 994 | */ |
| 995 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = state; |
| 996 | rc = save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(); |
| 997 | if (rc != 0) |
| 998 | goto out; |
| 999 | |
| 1000 | /* |
| 1001 | * Let all tokens cancel/finalize their session object re-enciphering. |
| 1002 | * This deactivates the MK change operation for the processes. |
| 1003 | */ |
| 1004 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_NONEcxx . . $ `usr/include/events.h:99:9`!; |
| 1005 | |
| 1006 | dest.process_idcxx . . $ event_destination#process_id. = 0; |
| 1007 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 1008 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 1009 | |
| 1010 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 1011 | |
| 1012 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., event, EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, |
| 1013 | payload_len, (char *)payload, |
| 1014 | &dest, &reply); |
| 1015 | if (rc != 0) { |
| 1016 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 1017 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1018 | goto out; |
| 1019 | } |
| 1020 | |
| 1021 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 1022 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 1023 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 1024 | |
| 1025 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0 || reply.positive_repliescxx . . $ event_reply#positive_replies. == 0) { |
| 1026 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to %s the master key change " |
| 1027 | "operation.", msg_cmd); |
| 1028 | warnxcxx . . $ warnx(326aeb464d16410c).("Check the syslog for details about the errors reported by " |
| 1029 | "the tokens."); |
| 1030 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1031 | goto out; |
| 1032 | } |
| 1033 | |
| 1034 | /* |
| 1035 | * Let the tool process cancel/finalize the token object re-enciphering |
| 1036 | * again to re-encipher token objects created by processes after the |
| 1037 | * initial token-object re-enciphering, but before the tokens deactivated |
| 1038 | * the MK change operation. |
| 1039 | */ |
| 1040 | hdr->flagscxx . . $ $anonymous_type_e2682f69c603a7d3_3#flags. = EVENT_MK_CHANGE_FLAGS_TOK_OBJS_FINALcxx . . $ `usr/include/events.h:101:9`!; |
| 1041 | |
| 1042 | dest.process_idcxx . . $ event_destination#process_id. = getpidcxx . . $ getpid(b126dc7c1de90089).(); /* Send to current process only */ |
| 1043 | dest.token_typecxx . . $ event_destination#token_type. = EVENT_TOK_TYPE_CCAcxx . . $ `usr/include/events.h:70:9`! | EVENT_TOK_TYPE_EP11cxx . . $ `usr/include/events.h:71:9`!; |
| 1044 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(dest.token_labelcxx . . $ event_destination#token_label., ' ', sizeof(dest.token_labelcxx . . $ event_destination#token_label.)); |
| 1045 | |
| 1046 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&reply, 0, sizeof(reply)); |
| 1047 | |
| 1048 | rc = send_eventcxx . . $ send_event(57191bea34a38fb).(event_fdcxx . . $ event_fd., event, EVENT_FLAGS_REPLY_REQcxx . . $ `usr/include/events.h:66:9`!, |
| 1049 | payload_len, (char *)payload, |
| 1050 | &dest, &reply); |
| 1051 | if (rc != 0) { |
| 1052 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to send event: %d", rc); |
| 1053 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1054 | goto out; |
| 1055 | } |
| 1056 | |
| 1057 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Positive: %lu\n", reply.positive_replies); |
| 1058 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Negative: %lu\n", reply.negative_replies); |
| 1059 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Not handled: %lu\n", reply.nothandled_replies); |
| 1060 | |
| 1061 | if (reply.negative_repliescxx . . $ event_reply#negative_replies. != 0 || reply.positive_repliescxx . . $ event_reply#positive_replies. == 0) { |
| 1062 | warnxcxx . . $ warnx(326aeb464d16410c).("At least one token failed to %s the master key change " |
| 1063 | "operation.", msg_cmd); |
| 1064 | warnxcxx . . $ warnx(326aeb464d16410c).("Check the syslog for details about the errors reported by " |
| 1065 | "the tokens."); |
| 1066 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1067 | goto out; |
| 1068 | } |
| 1069 | |
| 1070 | out: |
| 1071 | freecxx . . $ free(5d22bdacc48458e8).(payload); |
| 1072 | |
| 1073 | return rc; |
| 1074 | } |
| 1075 | |
| 1076 | |
| 1077 | static int perform_finalize_cancelcxx . . $ perform_finalize_cancel(73da94e76e6bd037).(boolcxx . . $ `<external>/14268322491693841775/stdbool.h:36:9`! cancel) |
| 1078 | { |
| 1079 | CK_RVcxx . . $ CK_RV# rv; |
| 1080 | int rc, rc2; |
| 1081 | unsigned int i, k; |
| 1082 | CK_ULONGcxx . . $ CK_ULONG# num_affected = 0; |
| 1083 | |
| 1084 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("ID: '%s'\n", id); |
| 1085 | |
| 1086 | rv = load_mk_change_opcxx . . $ load_mk_change_op(5c4306d8553b3696).(idcxx . . $ id.); |
| 1087 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1088 | warnxcxx . . $ warnx(326aeb464d16410c).("HSM master key change operation '%s' not found.", idcxx . . $ id.); |
| 1089 | return ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 1090 | } |
| 1091 | |
| 1092 | if (opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. != HSM_MK_CH_STATE_REENCIPHEREDcxx . . $ HSM_MK_CH_STATE_REENCIPHERED. && |
| 1093 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. != HSM_MK_CH_STATE_ERRORcxx . . $ HSM_MK_CH_STATE_ERROR. ) { |
| 1094 | warnxcxx . . $ warnx(326aeb464d16410c).("The HSM master key change operation '%s' is in a state where\n" |
| 1095 | "it can not be %s.", idcxx . . $ id., cancel ? "canceled": "finalized"); |
| 1096 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 1097 | } |
| 1098 | |
| 1099 | /* Check if all affected tokens are able to finalize/cancel */ |
| 1100 | rc = send_query_eventcxx . . $ send_query_event(160c5089f9e5b4f7).(cancel ? EVENT_TYPE_MK_CHANGE_CANCEL_QUERYcxx . . $ `usr/include/events.h:61:9`! : |
| 1101 | EVENT_TYPE_MK_CHANGE_FINALIZE_QUERYcxx . . $ `usr/include/events.h:59:9`!, |
| 1102 | cancel ? "cancel action" : "finalize action", |
| 1103 | &num_affected); |
| 1104 | if (rc != 0) |
| 1105 | return rc; |
| 1106 | |
| 1107 | /* Ensure the affected slots are still the same */ |
| 1108 | if (num_affected != opcxx . . $ op..num_slotscxx . . $ hsm_mk_change_op#num_slots.) { |
| 1109 | warnxcxx . . $ warnx(326aeb464d16410c).("The list of slots affected by this master key change has changed\n" |
| 1110 | "since initiating this master key change operation."); |
| 1111 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 1112 | } |
| 1113 | for (i = 0, k = 0; i < num_tokenscxx . . $ num_tokens. && k < num_affected; i++) { |
| 1114 | if (tokenscxx . . $ tokens.[i].affectedcxx . . $ token_info#affected. == truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!) { |
| 1115 | if (opcxx . . $ op..slotscxx . . $ hsm_mk_change_op#slots.[k] != tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id.) { |
| 1116 | warnxcxx . . $ warnx(326aeb464d16410c).("The list of slots affected by this master key change has changed\n" |
| 1117 | "since initiating this master key change operation."); |
| 1118 | return EINVALcxx . . $ `<external>/8987895939074593727/errno-base.h:26:9`!; |
| 1119 | } |
| 1120 | k++; |
| 1121 | } |
| 1122 | } |
| 1123 | |
| 1124 | /* Prompt for pin, login and open R/W session for each affected token */ |
| 1125 | rc = login_tokenscxx . . $ login_tokens(b126dc7c1de90089).(); |
| 1126 | if (rc != 0) |
| 1127 | return rc; |
| 1128 | |
| 1129 | printfcxx . . $ printf(581fddd72a8db8fc).("%s, please wait...\n", cancel ? "Canceling" : "Finalizing"); |
| 1130 | |
| 1131 | /* Start finalizing/canceling */ |
| 1132 | rc = finalize_cancel_tokenscxx . . $ finalize_cancel_tokens(5b0a8aebfaf6ded3).(cancel ? EVENT_TYPE_MK_CHANGE_CANCELcxx . . $ `usr/include/events.h:62:9`! : |
| 1133 | EVENT_TYPE_MK_CHANGE_FINALIZEcxx . . $ `usr/include/events.h:60:9`!, |
| 1134 | cancel ? HSM_MK_CH_STATE_CANCELINGcxx . . $ HSM_MK_CH_STATE_CANCELING. : |
| 1135 | HSM_MK_CH_STATE_FINALIZINGcxx . . $ HSM_MK_CH_STATE_FINALIZING., |
| 1136 | cancel ? "cancel" : "finalize"); |
| 1137 | if (rc != 0) { |
| 1138 | /* Set error state */ |
| 1139 | opcxx . . $ op..statecxx . . $ hsm_mk_change_op#state. = HSM_MK_CH_STATE_ERRORcxx . . $ HSM_MK_CH_STATE_ERROR.; |
| 1140 | rc2 = save_mk_change_opcxx . . $ save_mk_change_op(b126dc7c1de90089).(); |
| 1141 | if (rc2 != 0) |
| 1142 | return rc2; |
| 1143 | |
| 1144 | return rc; |
| 1145 | } |
| 1146 | |
| 1147 | /* Operation complete, remove it */ |
| 1148 | rc = remove_mk_change_opcxx . . $ remove_mk_change_op(b126dc7c1de90089).(); |
| 1149 | if (rc != 0) |
| 1150 | return rc; |
| 1151 | |
| 1152 | printfcxx . . $ printf(581fddd72a8db8fc).("\nMaster key change operation '%s' successfully %s.\n", |
| 1153 | opcxx . . $ op..idcxx . . $ hsm_mk_change_op#id., cancel ? "canceled" : "finalized"); |
| 1154 | |
| 1155 | return 0; |
| 1156 | } |
| 1157 | |
| 1158 | static CK_RVcxx . . $ CK_RV# perform_list_cbcxx . . $ perform_list_cb(52df439a4941eb10).(struct hsm_mk_change_opcxx . . $ hsm_mk_change_op# *op, void *private) |
| 1159 | { |
| 1160 | unsigned int i, j, k; |
| 1161 | int *first = private; |
| 1162 | struct hsm_mkvpcxx . . $ hsm_mkvp# *mkvps = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1163 | unsigned int num_mkvps = 0; |
| 1164 | CK_RVcxx . . $ CK_RV# rc; |
| 1165 | |
| 1166 | if (*first) |
| 1167 | *first = FALSEcxx . . $ `usr/include/pkcs11types.h:35:9`!; |
| 1168 | else |
| 1169 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 1170 | |
| 1171 | printfcxx . . $ printf(581fddd72a8db8fc).("Operation: %s\n", op->idcxx . . $ hsm_mk_change_op#id.); |
| 1172 | |
| 1173 | switch (op->statecxx . . $ hsm_mk_change_op#state.) { |
| 1174 | case HSM_MK_CH_STATE_INITIALcxx . . $ HSM_MK_CH_STATE_INITIAL.: |
| 1175 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Initial\n"); |
| 1176 | break; |
| 1177 | case HSM_MK_CH_STATE_REENCIPHERINGcxx . . $ HSM_MK_CH_STATE_REENCIPHERING.: |
| 1178 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Re-enciphering of key objects ongoing\n"); |
| 1179 | break; |
| 1180 | case HSM_MK_CH_STATE_REENCIPHEREDcxx . . $ HSM_MK_CH_STATE_REENCIPHERED.: |
| 1181 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Key objects have been re-enciphered,\n"); |
| 1182 | printfcxx . . $ printf(581fddd72a8db8fc).(" new master key(s) can now be set/activated\n"); |
| 1183 | break; |
| 1184 | case HSM_MK_CH_STATE_FINALIZINGcxx . . $ HSM_MK_CH_STATE_FINALIZING.: |
| 1185 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Finalizing\n"); |
| 1186 | break; |
| 1187 | case HSM_MK_CH_STATE_CANCELINGcxx . . $ HSM_MK_CH_STATE_CANCELING.: |
| 1188 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Canceling\n"); |
| 1189 | break; |
| 1190 | case HSM_MK_CH_STATE_ERRORcxx . . $ HSM_MK_CH_STATE_ERROR.: |
| 1191 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Finalizing or canceling has errored\n"); |
| 1192 | break; |
| 1193 | default: |
| 1194 | printfcxx . . $ printf(581fddd72a8db8fc).(" State: Unknown\n"); |
| 1195 | break; |
| 1196 | } |
| 1197 | |
| 1198 | printfcxx . . $ printf(581fddd72a8db8fc).(" APQNs:\n"); |
| 1199 | for (i = 0; i < op->infocxx . . $ hsm_mk_change_op#info..num_apqnscxx . . $ hsm_mk_change_info#num_apqns.; i++) { |
| 1200 | printfcxx . . $ printf(581fddd72a8db8fc).(" %02X.%04X\n", op->infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns.[i].cardcxx . . $ apqn#card., |
| 1201 | op->infocxx . . $ hsm_mk_change_op#info..apqnscxx . . $ hsm_mk_change_info#apqns.[i].domaincxx . . $ apqn#domain.); |
| 1202 | } |
| 1203 | |
| 1204 | printfcxx . . $ printf(581fddd72a8db8fc).(" New master key verification patterns:\n"); |
| 1205 | for (i = 0; i < op->infocxx . . $ hsm_mk_change_op#info..num_mkvpscxx . . $ hsm_mk_change_info#num_mkvps.; i++) { |
| 1206 | switch (op->infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps.[i].typecxx . . $ hsm_mkvp#type.) { |
| 1207 | case HSM_MK_TYPE_EP11cxx . . $ HSM_MK_TYPE_EP11.: |
| 1208 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: EP11\n"); |
| 1209 | break; |
| 1210 | case HSM_MK_TYPE_CCA_SYMcxx . . $ HSM_MK_TYPE_CCA_SYM.: |
| 1211 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA SYM\n"); |
| 1212 | break; |
| 1213 | case HSM_MK_TYPE_CCA_ASYMcxx . . $ HSM_MK_TYPE_CCA_ASYM.: |
| 1214 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA ASYM\n"); |
| 1215 | break; |
| 1216 | case HSM_MK_TYPE_CCA_AEScxx . . $ HSM_MK_TYPE_CCA_AES.: |
| 1217 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA AES\n"); |
| 1218 | break; |
| 1219 | case HSM_MK_TYPE_CCA_APKAcxx . . $ HSM_MK_TYPE_CCA_APKA.: |
| 1220 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA APKA\n"); |
| 1221 | break; |
| 1222 | } |
| 1223 | printfcxx . . $ printf(581fddd72a8db8fc).(" MKVP: "); |
| 1224 | for (k = 0; k < op->infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps.[i].mkvp_lencxx . . $ hsm_mkvp#mkvp_len.; k++) |
| 1225 | printfcxx . . $ printf(581fddd72a8db8fc).("%02X", op->infocxx . . $ hsm_mk_change_op#info..mkvpscxx . . $ hsm_mk_change_info#mkvps.[i].mkvpcxx . . $ hsm_mkvp#mkvp.[k]); |
| 1226 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 1227 | } |
| 1228 | |
| 1229 | printfcxx . . $ printf(581fddd72a8db8fc).(" Affected slots:\n"); |
| 1230 | for (i = 0; i < op->num_slotscxx . . $ hsm_mk_change_op#num_slots.; i++) { |
| 1231 | printfcxx . . $ printf(581fddd72a8db8fc).(" Slot: %lu", op->slotscxx . . $ hsm_mk_change_op#slots.[i]); |
| 1232 | for (k = 0; k < num_tokenscxx . . $ num_tokens.; k++) { |
| 1233 | if (tokenscxx . . $ tokens.[k].presentcxx . . $ token_info#present. && tokenscxx . . $ tokens.[k].idcxx . . $ token_info#id. == op->slotscxx . . $ hsm_mk_change_op#slots.[i]) { |
| 1234 | printfcxx . . $ printf(581fddd72a8db8fc).(" Label: %.32s", tokenscxx . . $ tokens.[k].infocxx . . $ token_info#info..labelcxx . . $ CK_TOKEN_INFO#label.); |
| 1235 | break; |
| 1236 | } |
| 1237 | } |
| 1238 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 1239 | |
| 1240 | rc = hsm_mk_change_token_mkvps_loadcxx . . $ hsm_mk_change_token_mkvps_load(77d7f5ca7d4ed2e6).(op->idcxx . . $ hsm_mk_change_op#id., op->slotscxx . . $ hsm_mk_change_op#slots.[i], |
| 1241 | &mkvps, &num_mkvps); |
| 1242 | if (rc == CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`! && num_mkvps > 0) { |
| 1243 | printfcxx . . $ printf(581fddd72a8db8fc).(" Current master key verification patterns:\n"); |
| 1244 | for (j = 0; j < num_mkvps; j++) { |
| 1245 | switch (mkvps[j].typecxx . . $ hsm_mkvp#type.) { |
| 1246 | case HSM_MK_TYPE_EP11cxx . . $ HSM_MK_TYPE_EP11.: |
| 1247 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: EP11\n"); |
| 1248 | break; |
| 1249 | case HSM_MK_TYPE_CCA_SYMcxx . . $ HSM_MK_TYPE_CCA_SYM.: |
| 1250 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA SYM\n"); |
| 1251 | break; |
| 1252 | case HSM_MK_TYPE_CCA_ASYMcxx . . $ HSM_MK_TYPE_CCA_ASYM.: |
| 1253 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA ASYM\n"); |
| 1254 | break; |
| 1255 | case HSM_MK_TYPE_CCA_AEScxx . . $ HSM_MK_TYPE_CCA_AES.: |
| 1256 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA AES\n"); |
| 1257 | break; |
| 1258 | case HSM_MK_TYPE_CCA_APKAcxx . . $ HSM_MK_TYPE_CCA_APKA.: |
| 1259 | printfcxx . . $ printf(581fddd72a8db8fc).(" Type: CCA APKA\n"); |
| 1260 | break; |
| 1261 | } |
| 1262 | printfcxx . . $ printf(581fddd72a8db8fc).(" MKVP: "); |
| 1263 | for (k = 0; k < mkvps[j].mkvp_lencxx . . $ hsm_mkvp#mkvp_len.; k++) |
| 1264 | printfcxx . . $ printf(581fddd72a8db8fc).("%02X", mkvps[j].mkvpcxx . . $ hsm_mkvp#mkvp.[k]); |
| 1265 | printfcxx . . $ printf(581fddd72a8db8fc).("\n"); |
| 1266 | } |
| 1267 | hsm_mk_change_mkvps_cleancxx . . $ hsm_mk_change_mkvps_clean(57b4b350f11eef87).(mkvps, num_mkvps); |
| 1268 | freecxx . . $ free(5d22bdacc48458e8).(mkvps); |
| 1269 | } |
| 1270 | mkvps = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1271 | num_mkvps = 0; |
| 1272 | } |
| 1273 | |
| 1274 | return CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!; |
| 1275 | } |
| 1276 | |
| 1277 | static int perform_listcxx . . $ perform_list(b126dc7c1de90089).(void) |
| 1278 | { |
| 1279 | CK_RVcxx . . $ CK_RV# rv; |
| 1280 | int rc = 0; |
| 1281 | int first = TRUEcxx . . $ `usr/include/pkcs11types.h:39:9`!; |
| 1282 | |
| 1283 | rv = hsm_mk_change_lockcxx . . $ hsm_mk_change_lock(c104ebd7d68b2193).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 1284 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1285 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to obtain lock"); |
| 1286 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1287 | } |
| 1288 | |
| 1289 | if (idcxx . . $ id. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1290 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("ID: '%s'\n", id); |
| 1291 | |
| 1292 | rv = hsm_mk_change_op_loadcxx . . $ hsm_mk_change_op_load(5303606949ca2b7).(idcxx . . $ id., &opcxx . . $ op.); |
| 1293 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1294 | warnxcxx . . $ warnx(326aeb464d16410c).("HSM master key change operation '%s' not found.", idcxx . . $ id.); |
| 1295 | rc = ENOENTcxx . . $ `<external>/8987895939074593727/errno-base.h:6:9`!; |
| 1296 | goto out; |
| 1297 | } |
| 1298 | |
| 1299 | rv = perform_list_cbcxx . . $ perform_list_cb(52df439a4941eb10).(&opcxx . . $ op., &first); |
| 1300 | hsm_mk_change_op_cleancxx . . $ hsm_mk_change_op_clean(a5440b5bf4f3417b).(&opcxx . . $ op.); |
| 1301 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1302 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to list HSM master key change operation '%s'.", idcxx . . $ id.); |
| 1303 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1304 | goto out; |
| 1305 | } |
| 1306 | } else { |
| 1307 | rv = hsm_mk_change_op_iteratecxx . . $ hsm_mk_change_op_iterate(8f1e4f5666c58214).(perform_list_cbcxx . . $ perform_list_cb(52df439a4941eb10)., &first); |
| 1308 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1309 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to list HSM master key change operations."); |
| 1310 | rc = EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1311 | goto out; |
| 1312 | } |
| 1313 | } |
| 1314 | |
| 1315 | out: |
| 1316 | rv = hsm_mk_change_unlockcxx . . $ hsm_mk_change_unlock(f708dce9a8856c70).(); |
| 1317 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1318 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to release lock"); |
| 1319 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1320 | } |
| 1321 | |
| 1322 | return rc; |
| 1323 | } |
| 1324 | |
| 1325 | static int init_ockcxx . . $ init_ock(b126dc7c1de90089).(void) |
| 1326 | { |
| 1327 | void (*sym_ptr)(CK_FUNCTION_LIST_PTR_PTRcxx . . $ CK_FUNCTION_LIST_PTR_PTR# ppFunctionList); |
| 1328 | CK_RVcxx . . $ CK_RV# rc; |
| 1329 | |
| 1330 | dllcxx . . $ dll. = dlopencxx . . $ dlopen(fb9ec0bb113f3da8).(OCK_API_LIBNAMEcxx . . $ `usr/lib/common/platform.h:44:9`!, DYNLIB_LDFLAGScxx . . $ `usr/lib/common/platform.h:45:9`!); |
| 1331 | if (dllcxx . . $ dll. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1332 | #if defined(_AIX) |
| 1333 | int err = errno; |
| 1334 | #else |
| 1335 | int err = ELIBACCcxx . . $ `<external>/17922322188510340118/errno.h:63:9`!; |
| 1336 | #endif |
| 1337 | warnxcxx . . $ warnx(326aeb464d16410c).("Error loading PKCS#11 library: dlopen: %s", dlerrorcxx . . $ dlerror(41208ce6ca65dd58).()); |
| 1338 | return err; |
| 1339 | } |
| 1340 | |
| 1341 | *(void **)(&sym_ptr) = dlsymcxx . . $ dlsym(5c3a2d84d269ab4b).(dllcxx . . $ dll., "C_GetFunctionList"); |
| 1342 | if (sym_ptr == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1343 | #if defined(_AIX) |
| 1344 | int err = errno; |
| 1345 | #else |
| 1346 | int err = ELIBACCcxx . . $ `<external>/17922322188510340118/errno.h:63:9`!; |
| 1347 | #endif |
| 1348 | warnxcxx . . $ warnx(326aeb464d16410c).("Error loading PKCS#11 library: dlsym(C_GetFunctionList): %s", |
| 1349 | dlerrorcxx . . $ dlerror(41208ce6ca65dd58).()); |
| 1350 | #ifndef WITH_SANITIZER |
| 1351 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dllcxx . . $ dll.); |
| 1352 | #endif |
| 1353 | dllcxx . . $ dll. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1354 | return err; |
| 1355 | } |
| 1356 | |
| 1357 | sym_ptr(&func_listcxx . . $ func_list.); |
| 1358 | if (func_listcxx . . $ func_list. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1359 | warnxcxx . . $ warnx(326aeb464d16410c).("Error getting function list from PKCS11 library"); |
| 1360 | #ifndef WITH_SANITIZER |
| 1361 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dllcxx . . $ dll.); |
| 1362 | #endif |
| 1363 | dllcxx . . $ dll. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1364 | return ELIBACCcxx . . $ `<external>/17922322188510340118/errno.h:63:9`!; |
| 1365 | } |
| 1366 | |
| 1367 | rc = (func_listcxx . . $ func_list.)->C_Initializecxx . . $ CK_FUNCTION_LIST#C_Initialize.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 1368 | if (rc != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1369 | warnxcxx . . $ warnx(326aeb464d16410c).("Error initializing the PKCS11 library: 0x%lX (%s)", rc, |
| 1370 | p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rc)); |
| 1371 | #ifndef WITH_SANITIZER |
| 1372 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dllcxx . . $ dll.); |
| 1373 | #endif |
| 1374 | dllcxx . . $ dll. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1375 | func_listcxx . . $ func_list. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 1376 | return ELIBACCcxx . . $ `<external>/17922322188510340118/errno.h:63:9`!; |
| 1377 | } |
| 1378 | |
| 1379 | TRACE_INFOcxx . . $ `usr/lib/common/pkcs_utils.h:79:9`!("PKCS#11 library initialized successfully\n"); |
| 1380 | |
| 1381 | return 0; |
| 1382 | } |
| 1383 | |
| 1384 | static int get_token_infoscxx . . $ get_token_infos(b126dc7c1de90089).(void) |
| 1385 | { |
| 1386 | CK_RVcxx . . $ CK_RV# rc; |
| 1387 | CK_ULONGcxx . . $ CK_ULONG# num_slots, i; |
| 1388 | CK_SLOT_ID_PTRcxx . . $ CK_SLOT_ID_PTR# slots; |
| 1389 | |
| 1390 | rc = func_listcxx . . $ func_list.->C_GetSlotListcxx . . $ CK_FUNCTION_LIST#C_GetSlotList.(FALSEcxx . . $ `usr/include/pkcs11types.h:35:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, &num_slots); |
| 1391 | if (rc != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1392 | warnxcxx . . $ warnx(326aeb464d16410c).("Error getting number of slots: 0x%lX (%s)", rc, |
| 1393 | p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rc)); |
| 1394 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1395 | } |
| 1396 | |
| 1397 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Num Slots: %lu\n", num_slots); |
| 1398 | |
| 1399 | if (num_slots == 0) { |
| 1400 | warnxcxx . . $ warnx(326aeb464d16410c).("C_GetSlotList returned 0 slots. Check that your tokens" |
| 1401 | " are installed correctly."); |
| 1402 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1403 | } |
| 1404 | |
| 1405 | slots = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_slots, sizeof(CK_SLOT_IDcxx . . $ CK_SLOT_ID#)); |
| 1406 | if (slots == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1407 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to allocate slot list"); |
| 1408 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 1409 | } |
| 1410 | |
| 1411 | rc = func_listcxx . . $ func_list.->C_GetSlotListcxx . . $ CK_FUNCTION_LIST#C_GetSlotList.(FALSEcxx . . $ `usr/include/pkcs11types.h:35:9`!, slots, &num_slots); |
| 1412 | if (rc != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1413 | warnxcxx . . $ warnx(326aeb464d16410c).("Error getting slot list: 0x%lX (%s)", rc, p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rc)); |
| 1414 | freecxx . . $ free(5d22bdacc48458e8).(slots); |
| 1415 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1416 | } |
| 1417 | |
| 1418 | num_tokenscxx . . $ num_tokens. = num_slots; |
| 1419 | tokenscxx . . $ tokens. = calloccxx . . $ calloc(63a7bf2941bfcd7a).(num_tokenscxx . . $ num_tokens., sizeof(struct token_infocxx . . $ token_info#)); |
| 1420 | if (tokenscxx . . $ tokens. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1421 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to allocate token list"); |
| 1422 | freecxx . . $ free(5d22bdacc48458e8).(slots); |
| 1423 | return ENOMEMcxx . . $ `<external>/8987895939074593727/errno-base.h:16:9`!; |
| 1424 | } |
| 1425 | |
| 1426 | for (i = 0; i < num_slots; i++) { |
| 1427 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Slot %lu: %lu\n", i, slots[i]); |
| 1428 | |
| 1429 | tokenscxx . . $ tokens.[i].idcxx . . $ token_info#id. = slots[i]; |
| 1430 | |
| 1431 | rc = func_listcxx . . $ func_list.->C_GetTokenInfocxx . . $ CK_FUNCTION_LIST#C_GetTokenInfo.(slots[i], &tokenscxx . . $ tokens.[i].infocxx . . $ token_info#info.); |
| 1432 | if (rc == CKR_TOKEN_NOT_PRESENTcxx . . $ `usr/include/pkcs11types.h:1404:9`!) { |
| 1433 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!(" Token not present\n"); |
| 1434 | continue; |
| 1435 | } |
| 1436 | if (rc != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) { |
| 1437 | warnxcxx . . $ warnx(326aeb464d16410c).("Error getting token infos for slot %lu: 0x%lX (%s)", |
| 1438 | slots[i], rc, p11_get_ckrcxx . . $ p11_get_ckr(30dde979ed96a187).(rc)); |
| 1439 | return 1; |
| 1440 | } |
| 1441 | |
| 1442 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!(" Label: %.32s\n", tokens[i].info.label); |
| 1443 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!(" Manufacturer: %.32s\n", tokens[i].info.manufacturerID); |
| 1444 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!(" Model: %.16s\n", tokens[i].info.model); |
| 1445 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!(" Serial Number: %.16s\n", tokens[i].info.serialNumber); |
| 1446 | |
| 1447 | tokenscxx . . $ tokens.[i].presentcxx . . $ token_info#present. = truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!; |
| 1448 | } |
| 1449 | |
| 1450 | freecxx . . $ free(5d22bdacc48458e8).(slots); |
| 1451 | return 0; |
| 1452 | } |
| 1453 | |
| 1454 | void sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).(int signal) |
| 1455 | { |
| 1456 | UNUSEDcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:47:9`!(signal); |
| 1457 | |
| 1458 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Cntl-C ignored\n"); |
| 1459 | } |
| 1460 | |
| 1461 | static void setup_signal_handlercxx . . $ setup_signal_handler(94eb4457dc8d4d10).(void (*handler)(int signal)) |
| 1462 | { |
| 1463 | struct sigactioncxx . . $ sigaction# int_act; |
| 1464 | |
| 1465 | /* Set a handler for SIGINT/SIGTERM */ |
| 1466 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(&int_act, 0, sizeof(int_act)); |
| 1467 | if (handler != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 1468 | int_act.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = handler; |
| 1469 | else |
| 1470 | int_act.sa_handlercxx . . $ `<external>/16635209305659446502/sigaction.h:39:10`! = SIG_DFLcxx . . $ `<external>/11773118241360591791/signum-generic.h:29:9`!; |
| 1471 | |
| 1472 | sigactioncxx . . $ sigaction(53aba09fe16b06c7).(SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!, &int_act, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 1473 | sigactioncxx . . $ sigaction(53aba09fe16b06c7).(SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!, &int_act, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 1474 | } |
| 1475 | |
| 1476 | static int initializecxx . . $ initialize(7864480464b09eea).(int cmd) |
| 1477 | { |
| 1478 | int rc; |
| 1479 | CK_RVcxx . . $ CK_RV# rv; |
| 1480 | |
| 1481 | setup_signal_handlercxx . . $ setup_signal_handler(94eb4457dc8d4d10).(sig_handlercxx . . $ sig_handler(d4f767463ce0a6b3).); |
| 1482 | |
| 1483 | rv = hsm_mk_change_lock_createcxx . . $ hsm_mk_change_lock_create(f708dce9a8856c70).(); |
| 1484 | if (rv != CKR_OKcxx . . $ `usr/include/pkcs11types.h:1316:9`!) |
| 1485 | return EIOcxx . . $ `<external>/8987895939074593727/errno-base.h:9:9`!; |
| 1486 | |
| 1487 | rc = init_ockcxx . . $ init_ock(b126dc7c1de90089).(); |
| 1488 | if (rc != 0) |
| 1489 | return rc; |
| 1490 | |
| 1491 | rc = get_token_infoscxx . . $ get_token_infos(b126dc7c1de90089).(); |
| 1492 | if (rc != 0) |
| 1493 | return rc; |
| 1494 | |
| 1495 | if (cmd == CMD_LISTcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:42:9`!) |
| 1496 | return 0; |
| 1497 | |
| 1498 | event_fdcxx . . $ event_fd. = init_event_clientcxx . . $ init_event_client(b126dc7c1de90089).(); |
| 1499 | if (event_fdcxx . . $ event_fd. < 0) { |
| 1500 | warnxcxx . . $ warnx(326aeb464d16410c).("Failed to connect to pkcsslotd's event socket: %s", |
| 1501 | strerrorcxx . . $ strerror(ff224f080444ee45).(-event_fdcxx . . $ event_fd.)); |
| 1502 | rc = -event_fdcxx . . $ event_fd.; |
| 1503 | return rc; |
| 1504 | } |
| 1505 | |
| 1506 | TRACE_INFOcxx . . $ `usr/lib/common/pkcs_utils.h:79:9`!("Event connection established\n"); |
| 1507 | |
| 1508 | return 0; |
| 1509 | } |
| 1510 | |
| 1511 | static void terminatecxx . . $ terminate(49f6e7a06ebc5aa8).(void) |
| 1512 | { |
| 1513 | if (tokenscxx . . $ tokens. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1514 | if (func_listcxx . . $ func_list. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 1515 | logout_tokenscxx . . $ logout_tokens(49f6e7a06ebc5aa8).(); |
| 1516 | freecxx . . $ free(5d22bdacc48458e8).(tokenscxx . . $ tokens.); |
| 1517 | } |
| 1518 | |
| 1519 | if (affected_slotscxx . . $ affected_slots. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 1520 | freecxx . . $ free(5d22bdacc48458e8).(affected_slotscxx . . $ affected_slots.); |
| 1521 | |
| 1522 | if (apqnscxx . . $ apqns. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 1523 | freecxx . . $ free(5d22bdacc48458e8).(apqnscxx . . $ apqns.); |
| 1524 | |
| 1525 | if (event_fdcxx . . $ event_fd. >= 0) |
| 1526 | term_event_clientcxx . . $ term_event_client(d4f767463ce0a6b3).(event_fdcxx . . $ event_fd.); |
| 1527 | |
| 1528 | if (dllcxx . . $ dll. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1529 | if (func_listcxx . . $ func_list. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) |
| 1530 | func_listcxx . . $ func_list.->C_Finalizecxx . . $ CK_FUNCTION_LIST#C_Finalize.(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 1531 | #ifndef WITH_SANITIZER |
| 1532 | dlclosecxx . . $ dlclose(dedf1e9b1c614a07).(dllcxx . . $ dll.); |
| 1533 | #endif |
| 1534 | } |
| 1535 | |
| 1536 | hsm_mk_change_lock_destroycxx . . $ hsm_mk_change_lock_destroy(49f6e7a06ebc5aa8).(); |
| 1537 | |
| 1538 | setup_signal_handlercxx . . $ setup_signal_handler(94eb4457dc8d4d10).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!); |
| 1539 | } |
| 1540 | |
| 1541 | static int verbose_str2levelcxx . . $ verbose_str2level(1ef8e6ec083aabb9).(char *str) |
| 1542 | { |
| 1543 | const char *tlevel[] = {"none", "error", "warn", "info", "devel", "debug"}; |
| 1544 | const int num = sizeof(tlevel) / sizeof(char *); |
| 1545 | int i; |
| 1546 | |
| 1547 | for (i = 0; i < num; i++) { |
| 1548 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str, tlevel[i]) == 0) { |
| 1549 | return i; |
| 1550 | } |
| 1551 | } |
| 1552 | |
| 1553 | return -1; |
| 1554 | } |
| 1555 | |
| 1556 | int maincxx . . $ main(afcd3168fc1188a4).(int argc, char **argv) |
| 1557 | { |
| 1558 | int rc = 0, opt = 0; |
| 1559 | int cmd = 0; |
| 1560 | |
| 1561 | static const struct optioncxx . . $ option# long_opts[] = { |
| 1562 | {"apqns", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'a'}, |
| 1563 | {"ep11-wkvp", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'e'}, |
| 1564 | {"cca-sym-mkvp", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 's'}, |
| 1565 | {"cca-asym-mkvp", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'S'}, |
| 1566 | {"cca-aes-mkvp", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'A'}, |
| 1567 | {"cca-apka-mkvp", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'p'}, |
| 1568 | {"id", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'i'}, |
| 1569 | {"verbose", required_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:63:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'v'}, |
| 1570 | {"help", no_argumentcxx . . $ `<external>/1746263805473775960/getopt_ext.h:62:9`!, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, 'h'}, |
| 1571 | {0, 0, 0, 0} |
| 1572 | }; |
| 1573 | |
| 1574 | if (argc >=2 && *argv[1] != '-') { |
| 1575 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "reencipher") == 0) { |
| 1576 | cmd = CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!; |
| 1577 | } else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "finalize") == 0) { |
| 1578 | cmd = CMD_FINALIZEcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:40:9`!; |
| 1579 | } else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "cancel") == 0) { |
| 1580 | cmd = CMD_CANCELcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:41:9`!; |
| 1581 | } else if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(argv[1], "list") == 0) { |
| 1582 | cmd = CMD_LISTcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:42:9`!; |
| 1583 | } else { |
| 1584 | warnxcxx . . $ warnx(326aeb464d16410c).("unrecognized command '%s'", argv[1]); |
| 1585 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1586 | } |
| 1587 | |
| 1588 | argv++; |
| 1589 | argc--; |
| 1590 | } |
| 1591 | |
| 1592 | while ((opt = getopt_longcxx . . $ getopt_long(41f665c090816971).(argc, argv, "a:e:s:S:A:p:i:v:h", long_opts, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!)) != -1) { |
| 1593 | switch (opt) { |
| 1594 | case 'a': |
| 1595 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1596 | warnxcxx . . $ warnx(326aeb464d16410c).("option -a/--apqns is only valid for the 'reencipher' command"); |
| 1597 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1598 | } |
| 1599 | rc = parse_apqnscxx . . $ parse_apqns(1ef8e6ec083aabb9).(optargcxx . . $ optarg.); |
| 1600 | if (rc != 0) |
| 1601 | goto out; |
| 1602 | break; |
| 1603 | |
| 1604 | case 'e': |
| 1605 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1606 | warnxcxx . . $ warnx(326aeb464d16410c).("option -e/--ep11-wkvp is only valid for the 'reencipher' command"); |
| 1607 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1608 | } |
| 1609 | rc = parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(optargcxx . . $ optarg., EP11_WKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:45:9`!, ep11_wkvpcxx . . $ ep11_wkvp., |
| 1610 | &ep11_wkvp_setcxx . . $ ep11_wkvp_set., "-e/--ep11-wkvp"); |
| 1611 | if (rc != 0) |
| 1612 | goto out; |
| 1613 | break; |
| 1614 | |
| 1615 | case 's': |
| 1616 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1617 | warnxcxx . . $ warnx(326aeb464d16410c).("option -s/--cca-sym-mkvp is only valid for the 'reencipher' command"); |
| 1618 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1619 | } |
| 1620 | rc = parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(optargcxx . . $ optarg., CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!, cca_sym_mkvpcxx . . $ cca_sym_mkvp., |
| 1621 | &cca_sym_mkvp_setcxx . . $ cca_sym_mkvp_set., "-s/--cca-sym-mkvp"); |
| 1622 | if (rc != 0) |
| 1623 | goto out; |
| 1624 | break; |
| 1625 | |
| 1626 | case 'S': |
| 1627 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1628 | warnxcxx . . $ warnx(326aeb464d16410c).("option -S/--cca-asym-mkvp is only valid for the 'reencipher' command"); |
| 1629 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1630 | } |
| 1631 | rc = parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(optargcxx . . $ optarg., CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!, cca_asym_mkvpcxx . . $ cca_asym_mkvp., |
| 1632 | &cca_asym_mkvp_setcxx . . $ cca_asym_mkvp_set., "-S/--cca-asym-mkvp"); |
| 1633 | if (rc != 0) |
| 1634 | goto out; |
| 1635 | break; |
| 1636 | |
| 1637 | case 'A': |
| 1638 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1639 | warnxcxx . . $ warnx(326aeb464d16410c).("option -A/--cca-aes-mkvp is only valid for the 'reencipher' command"); |
| 1640 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1641 | } |
| 1642 | rc = parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(optargcxx . . $ optarg., CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!, cca_aes_mkvpcxx . . $ cca_aes_mkvp., |
| 1643 | &cca_aes_mkvp_setcxx . . $ cca_aes_mkvp_set., "-A/--cca-aes-mkvp"); |
| 1644 | if (rc != 0) |
| 1645 | goto out; |
| 1646 | break; |
| 1647 | |
| 1648 | case 'p': |
| 1649 | if (cmd != CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!) { |
| 1650 | warnxcxx . . $ warnx(326aeb464d16410c).("option -p/--cca-apka-mkvp is only valid for the 'reencipher' command"); |
| 1651 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1652 | } |
| 1653 | rc = parse_mkvpcxx . . $ parse_mkvp(e28c293c99e92290).(optargcxx . . $ optarg., CCA_MKVP_LENGTHcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:44:9`!, cca_apka_mkvpcxx . . $ cca_apka_mkvp., |
| 1654 | &cca_apka_mkvp_setcxx . . $ cca_apka_mkvp_set., "-p/--cca-apka-mkvp"); |
| 1655 | if (rc != 0) |
| 1656 | goto out; |
| 1657 | break; |
| 1658 | |
| 1659 | case 'i': |
| 1660 | if (cmd != CMD_FINALIZEcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:40:9`! && cmd != CMD_CANCELcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:41:9`! && cmd != CMD_LISTcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:42:9`!) { |
| 1661 | warnxcxx . . $ warnx(326aeb464d16410c).("option -i/--id is only valid for the 'finalize', 'cancel or 'list' command"); |
| 1662 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1663 | } |
| 1664 | idcxx . . $ id. = optargcxx . . $ optarg.; |
| 1665 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("ID: '%s'\n", id); |
| 1666 | break; |
| 1667 | |
| 1668 | case 'v': |
| 1669 | trace_levelcxx . . $ trace_level. = verbose_str2levelcxx . . $ verbose_str2level(1ef8e6ec083aabb9).(optargcxx . . $ optarg.); |
| 1670 | if ((int)trace_levelcxx . . $ trace_level. < 0) { |
| 1671 | warnxcxx . . $ warnx(326aeb464d16410c).("Invalid verbose level '%s' specified.", optargcxx . . $ optarg.); |
| 1672 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1673 | } |
| 1674 | break; |
| 1675 | |
| 1676 | case 'h': |
| 1677 | usagecxx . . $ usage(fda57c8427c60377).(basenamecxx . . $ basename(a8b8e32347182212).(argv[0])); |
| 1678 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`!); |
| 1679 | default: |
| 1680 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1681 | } |
| 1682 | } |
| 1683 | |
| 1684 | if (optindcxx . . $ optind. < argc) { |
| 1685 | warnxcxx . . $ warnx(326aeb464d16410c).("unrecognized option '%s'", argv[optindcxx . . $ optind.]); |
| 1686 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1687 | } |
| 1688 | |
| 1689 | rc = initializecxx . . $ initialize(7864480464b09eea).(cmd); |
| 1690 | if (rc != 0) |
| 1691 | goto out; |
| 1692 | |
| 1693 | switch (cmd) { |
| 1694 | case CMD_REENCIPHERcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:39:9`!: |
| 1695 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Command: reencipher\n"); |
| 1696 | |
| 1697 | if (apqnscxx . . $ apqns. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`! || num_apqnscxx . . $ num_apqns. == 0) { |
| 1698 | warnxcxx . . $ warnx(326aeb464d16410c).("option -a/--apqns is required for the 'reencipher' command"); |
| 1699 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1700 | } |
| 1701 | if (!ep11_wkvp_setcxx . . $ ep11_wkvp_set. && !cca_sym_mkvp_setcxx . . $ cca_sym_mkvp_set. && !cca_asym_mkvp_setcxx . . $ cca_asym_mkvp_set. && |
| 1702 | !cca_aes_mkvp_setcxx . . $ cca_aes_mkvp_set. && !cca_apka_mkvp_setcxx . . $ cca_apka_mkvp_set.) { |
| 1703 | warnxcxx . . $ warnx(326aeb464d16410c).("at least one master key verification pattern must be specified"); |
| 1704 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1705 | } |
| 1706 | |
| 1707 | rc = perform_reenciphercxx . . $ perform_reencipher(b126dc7c1de90089).(); |
| 1708 | break; |
| 1709 | |
| 1710 | case CMD_FINALIZEcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:40:9`!: |
| 1711 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Command: finalize\n"); |
| 1712 | |
| 1713 | if (idcxx . . $ id. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1714 | warnxcxx . . $ warnx(326aeb464d16410c).("option -i/--id is required for the 'finalize' command"); |
| 1715 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1716 | } |
| 1717 | |
| 1718 | rc = perform_finalize_cancelcxx . . $ perform_finalize_cancel(73da94e76e6bd037).(falsecxx . . $ `<external>/14268322491693841775/stdbool.h:38:9`!); |
| 1719 | break; |
| 1720 | |
| 1721 | case CMD_CANCELcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:41:9`!: |
| 1722 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Command: cancel\n"); |
| 1723 | |
| 1724 | if (idcxx . . $ id. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!) { |
| 1725 | warnxcxx . . $ warnx(326aeb464d16410c).("option -i/--id is required for the 'cancel' command"); |
| 1726 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1727 | } |
| 1728 | |
| 1729 | rc = perform_finalize_cancelcxx . . $ perform_finalize_cancel(73da94e76e6bd037).(truecxx . . $ `<external>/14268322491693841775/stdbool.h:37:9`!); |
| 1730 | break; |
| 1731 | |
| 1732 | case CMD_LISTcxx . . $ `usr/sbin/pkcshsm_mk_change/pkcshsm_mk_change.c:42:9`!: |
| 1733 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Command: list\n"); |
| 1734 | |
| 1735 | rc = perform_listcxx . . $ perform_list(b126dc7c1de90089).(); |
| 1736 | break; |
| 1737 | |
| 1738 | default: |
| 1739 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("Command: %d\n", cmd); |
| 1740 | warnxcxx . . $ warnx(326aeb464d16410c).("no command specified"); |
| 1741 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!); |
| 1742 | } |
| 1743 | |
| 1744 | out: |
| 1745 | terminatecxx . . $ terminate(49f6e7a06ebc5aa8).(); |
| 1746 | |
| 1747 | TRACE_DEVELcxx . . $ `usr/lib/common/pkcs_utils.h:81:9`!("rc: %d\n", rc); |
| 1748 | |
| 1749 | return rc == 0 ? EXIT_SUCCESScxx . . $ `<external>/10696550936717951914/stdlib.h:93:9`! : EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:92:9`!; |
| 1750 | } |