| 1074 | } |
| 1075 | |
| 1076 | FSCryptDenc *FSCrypt::init_denc(const FSCryptContextRef& ctx, FSCryptKeyValidatorRef *kv, |
| 1077 | std::function<FSCryptDenc *()> gen_denc) |
| 1078 | { |
| 1079 | if (!ctx) { |
| 1080 | return nullptr; |
| 1081 | } |
| 1082 | |
| 1083 | FSCryptKeyHandlerRef master_kh; |
| 1084 | int r = key_store.find(ctx->master_key_identifier, master_kh); |
| 1085 | if (r == 0) { |
| 1086 | ldout(cct, 0) << __FILE__ << ":" << __LINE__ << ": fscrypt_key handler found" << dendl; |
| 1087 | } else if (r == -ENOENT) { |
| 1088 | ldout(cct, 0) << __FILE__ << ":" << __LINE__ << ": fscrypt_key handler not found" << dendl; |
| 1089 | return nullptr; |
| 1090 | } else { |
| 1091 | ldout(cct, 0) << __FILE__ << ":" << __LINE__ << ": error: r=" << r << dendl; |
| 1092 | return nullptr; |
| 1093 | } |
| 1094 | |
| 1095 | if (kv) { |
| 1096 | *kv = make_shared<FSCryptKeyValidator>(cct, master_kh, master_kh->get_epoch()); |
| 1097 | } |
| 1098 | |
| 1099 | auto& master_key = master_kh->get_key(); |
| 1100 | |
| 1101 | if (!master_key) { |
| 1102 | ldout(cct, 0) << __FILE__ << ":" << __LINE__ << ": fscrypt_key key is null" << dendl; |
| 1103 | return nullptr; |
| 1104 | } |
| 1105 | |
| 1106 | auto fscrypt_denc = gen_denc(); |
| 1107 | |
| 1108 | if (!fscrypt_denc->setup(ctx, master_key)) { |
| 1109 | ldout(cct, 0) << __FILE__ << ":" << __LINE__ << ":" << __func__ << "(): ERROR: failed to setup denc" << dendl; |
| 1110 | return nullptr; |
| 1111 | } |
| 1112 | |
| 1113 | return fscrypt_denc; |
| 1114 | } |
| 1115 | |
| 1116 | FSCryptFNameDencRef FSCrypt::get_fname_denc(const FSCryptContextRef& ctx, FSCryptKeyValidatorRef *kv, bool calc_key) |
| 1117 | { |