@@ -367,7 +367,7 @@ namespace Jrd {
367367 return ;
368368
369369 fb_assert (tdbb);
370- lockAndReadHeader (tdbb, CRYPT_HDR_NOWAIT);
370+ lockAndReadHeader (tdbb, CRYPT_HDR_NOWAIT | CRYPT_RELOAD_PLUGIN );
371371 }
372372
373373 void CryptoManager::lockAndReadHeader (thread_db* tdbb, unsigned flags)
@@ -407,9 +407,15 @@ namespace Jrd {
407407 crypt = hdr->hdr_flags & Ods::hdr_encrypted;
408408 process = hdr->hdr_flags & Ods::hdr_crypt_process;
409409
410+ if (flags & CRYPT_RELOAD_PLUGIN && cryptPlugin)
411+ {
412+ PluginManagerInterfacePtr ()->releasePlugin (cryptPlugin);
413+ cryptPlugin = NULL ;
414+ }
415+
410416 // tdbb w/o attachment comes when database is shutting down in the end of detachDatabase()
411417 // the only needed here page is header, i.e. we can live w/o cryptPlugin
412- if ((crypt || process) && tdbb->getAttachment ())
418+ if ((crypt || process) && !cryptPlugin && tdbb->getAttachment ())
413419 {
414420 ClumpletWriter hc (ClumpletWriter::UnTagged, hdr->hdr_page_size );
415421 hdr.getClumplets (hc);
@@ -418,56 +424,18 @@ namespace Jrd {
418424 else
419425 keyName = " " ;
420426
421- if (!cryptPlugin)
427+ loadPlugin (tdbb, hdr->hdr_crypt_plugin );
428+ pluginName = hdr->hdr_crypt_plugin ;
429+ string valid;
430+ calcValidation (valid, cryptPlugin);
431+ if (hc.find (Ods::HDR_crypt_hash))
422432 {
423- loadPlugin (tdbb, hdr->hdr_crypt_plugin );
424- pluginName = hdr->hdr_crypt_plugin ;
425- string valid;
426- calcValidation (valid, cryptPlugin);
427- if (hc.find (Ods::HDR_crypt_hash))
428- {
429- hc.getString (hash);
430- if (hash != valid)
431- (Arg::Gds (isc_bad_crypt_key) << keyName).raise ();
432- }
433- else
434- hash = valid;
433+ hc.getString (hash);
434+ if (hash != valid)
435+ (Arg::Gds (isc_bad_crypt_key) << keyName).raise ();
435436 }
436437 else
437- {
438- for (GetPlugins<IKeyHolderPlugin> keyControl (IPluginManager::TYPE_KEY_HOLDER, dbb.dbb_config );
439- keyControl.hasData (); keyControl.next ())
440- {
441- // check does keyHolder want to provide a key for us
442- IKeyHolderPlugin* keyHolder = keyControl.plugin ();
443-
444- FbLocalStatus st;
445- int keyCallbackRc = keyHolder->keyCallback (&st, tdbb->getAttachment ()->att_crypt_callback );
446- st.check ();
447- if (!keyCallbackRc)
448- continue ;
449-
450- // validate a key
451- AutoPlugin<IDbCryptPlugin> crypt (checkFactory->makeInstance ());
452- setDbInfo (crypt);
453- crypt->setKey (&st, 1 , &keyHolder, keyName.c_str ());
454-
455-
456- string valid;
457- calcValidation (valid, crypt);
458- if (hc.find (Ods::HDR_crypt_hash))
459- {
460- hc.getString (hash);
461- if (hash == valid)
462- {
463- // unload old plugin and set new one
464- PluginManagerInterfacePtr ()->releasePlugin (cryptPlugin);
465- cryptPlugin = NULL ;
466- cryptPlugin = crypt.release ();
467- }
468- }
469- }
470- }
438+ hash = valid;
471439 }
472440
473441 if (cryptPlugin && (flags & CRYPT_HDR_INIT))
0 commit comments