____________________________________________________________
| 251 | // |
| 252 | // |
| 253 | static void start_crypt(BurpGlobals* tdgbl) |
| 254 | { |
| 255 | fb_assert(tdgbl->gbl_sw_keyholder); |
| 256 | if (tdgbl->gbl_crypt && tdgbl->gbl_crypt->crypt_plugin) |
| 257 | return; |
| 258 | |
| 259 | FbLocalStatus status; |
| 260 | |
| 261 | // Get per-DB config |
| 262 | Firebird::PathName dummy; |
| 263 | Firebird::RefPtr<const Firebird::Config> config; |
| 264 | expandDatabaseName(tdgbl->gbl_database_file_name, dummy, &config); |
| 265 | |
| 266 | // Prepare key holders |
| 267 | Firebird::IKeyHolderPlugin* keyHolder = mvol_get_holder(tdgbl, config); |
| 268 | |
| 269 | // Load crypt plugin |
| 270 | if (!tdgbl->mvol_crypt) |
| 271 | tdgbl->mvol_crypt = tdgbl->gbl_sw_crypt; |
| 272 | if (!tdgbl->mvol_crypt) |
| 273 | BURP_error(378, true); |
| 274 | |
| 275 | Firebird::GetPlugins<Firebird::IDbCryptPlugin> |
| 276 | cryptControl(Firebird::IPluginManager::TYPE_DB_CRYPT, config, tdgbl->mvol_crypt); |
| 277 | if (!cryptControl.hasData()) |
| 278 | (Firebird::Arg::Gds(isc_no_crypt_plugin) << tdgbl->mvol_crypt).raise(); |
| 279 | |
| 280 | Firebird::RefPtr<DbInfo> dbInfo(FB_NEW DbInfo(tdgbl)); |
| 281 | Firebird::IDbCryptPlugin* p = cryptControl.plugin(); |
| 282 | p->setInfo(&status, dbInfo); |
| 283 | if (!status.isSuccess()) |
| 284 | { |
| 285 | const ISC_STATUS* v = status->getErrors(); |
| 286 | if (v[0] == isc_arg_gds && v[1] != isc_arg_end && v[1] != isc_interface_version_too_old) |
| 287 | Firebird::status_exception::raise(&status); |
| 288 | } |
| 289 | |
| 290 | // Initialize key in crypt plugin |
| 291 | p->setKey(&status, 1, &keyHolder, tdgbl->mvol_keyname); |
| 292 | check(&status); |
| 293 | |
| 294 | // Validate hash |
| 295 | if (tdgbl->gbl_key_hash[0]) |
| 296 | { |
| 297 | Firebird::string hash; |
| 298 | calc_hash(hash, p); |
| 299 | if (hash != tdgbl->gbl_key_hash) |
| 300 | (Firebird::Arg::Gds(isc_bad_crypt_key) << tdgbl->mvol_keyname).raise(); |
| 301 | } |
| 302 | |
| 303 | // crypt plugin is ready |
| 304 | BurpCrypt* g = tdgbl->gbl_crypt; |
| 305 | g->db_info.moveFrom(dbInfo); |
| 306 | g->crypt_plugin = p; |
| 307 | p->addRef(); |
| 308 | } |
| 309 | |
| 310 | //____________________________________________________________ |
no test coverage detected