我正在尝试获取 Microsoft.SharePoint.Client.Site.CreateMigrationJobEncrypted 创建的作业来读取我的元数据文件。我尝试了各种方法但没有任何效果。让我描述一下它们以及我遇到的各种错误。
我为数据和元数据以及队列提供容器(队列存储进度消息):
// ... getting context and such first
ClientResult<ProvisionedMigrationContainersInfo> containers = clientContext.Site.ProvisionMigrationContainers();
clientContext.ExecuteQuery();
ClientResult<ProvisionedMigrationQueueInfo> queue = clientContext.Site.ProvisionMigrationQueue();
clientContext.ExecuteQuery();
然后我从返回的容器结构中获取加密密钥。
var encryptOption = new EncryptionOption
{
AES256CBCKey = containers?.Value.EncryptionKey,
};
然后我上传数据文件(它们与 ATM 无关,因为我从未达到使用它们的程度)。
然后我将元数据文件上传到应该存储导入作业元数据的容器。我还使用
encryptOption.AES256CBCKey
来加密它们,遵循 AES CBC 256 标准,并使用 IV
生成 System.Security.Cryptography.Aes
。然后,我为生成的 blob 添加元数据(每个 blob 代表一个 xml 元数据文件)。我仅在 blob 上添加集合 IV
的元数据。我还创建了所需的快照。这是设置 IV
的部分。
// ... other things
// Convert IV to a string format (e.g., Base64) for storing as metadata
string ivBase64 = Convert.ToBase64String(iv);
// Set the IV as metadata
IDictionary<string, string> metadata = new Dictionary<string, string>
{
{ "IV", ivBase64 }
};
blobClient.SetMetadata(metadata);
// 3 Create snapshot for all files
blobClient.CreateSnapshot();
然后我创建作业并执行它:
var jobReadInfo = clientContext.Site.CreateMigrationJobEncrypted(
Guid.Parse(targetWebId), // gWebId
containers.Value.DataContainerUri, // azureContainerSourceUri
containers.Value.MetadataContainerUri, // azureContainerManifestUri
queue.Value.JobQueueUri, //azureQueueReportUri
encryptOption);
clientContext.ExecuteQuery();
当我阅读作业生成的日志时,我收到这种错误(每次调用都有点不同):
[1/16/2024 7:36:58 AM] Start Time: 1/16/2024 7:36:58 AM.
[1/16/2024 7:36:58 AM] Correlation Id: 805102a1-c02f-7000-f07b-b7c87b4b59b8
[1/16/2024 7:36:58 AM] [Progress] Initializing Import.
[1/16/2024 7:36:58 AM] [Progress] Downloaded SystemData.xml: SnapShotTime == ; MD5 == b7y78P4VFYpmAW7Tx79NfA==; Size == 400 bytes
[1/16/2024 7:36:58 AM] [FatalError] [-2146232000] [System.Xml.XmlException] [Data at the root level is invalid. Line 1, position 1.]
[1/16/2024 7:36:58 AM] [Debug] at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.ParseRootLevelWhitespace()
at System.Xml.XmlTextReaderImpl.ParseDocumentContent()
at System.Xml.XsdValidatingReader.Read()
at Microsoft.SharePoint.Deployment.SPImport.EnsureVersion()
at Microsoft.SharePoint.Deployment.SPImport.Run()
或
[1/16/2024 7:40:11 AM] Start Time: 1/16/2024 7:40:11 AM.
[1/16/2024 7:40:11 AM] Correlation Id: af5102a1-2057-8000-099d-2916a2a0a0a5
[1/16/2024 7:40:11 AM] [Progress] Initializing Import.
[1/16/2024 7:40:11 AM] [Progress] Downloaded SystemData.xml: SnapShotTime == ; MD5 == Kej88c87xr7WGI1nYq9uxA==; Size == 400 bytes
[1/16/2024 7:40:11 AM] [FatalError] [-2146232000] [System.Xml.XmlException] [Invalid character in the given encoding. Line 1, position 1.]
[1/16/2024 7:40:11 AM] [Debug] at System.Xml.XmlTextReaderImpl.Throw(Exception e)
at System.Xml.XmlTextReaderImpl.InvalidCharRecovery(Int32& bytesCount, Int32& charsCount)
at System.Xml.XmlTextReaderImpl.GetChars(Int32 maxCharsCount)
at System.Xml.XmlTextReaderImpl.ReadData()
at System.Xml.XmlTextReaderImpl.SwitchEncoding(Encoding newEncoding)
at System.Xml.XmlTextReaderImpl.ParseXmlDeclaration(Boolean isTextDecl)
at System.Xml.XmlTextReaderImpl.Read()
at System.Xml.XsdValidatingReader.Read()
at Microsoft.SharePoint.Deployment.SPImport.EnsureVersion()
at Microsoft.SharePoint.Deployment.SPImport.Run()
[1/16/2024 7:40:11 AM] [Progress] Import did not complete.
[1/16/2024 7:40:11 AM] Finish Time: 1/16/2024 7:40:11 AM.
[1/16/2024 7:40:11 AM] Duration: 00:00:00
[1/16/2024 7:40:11 AM] Byte imported: 0.00 at 0.00 bytes per second
[1/16/2024 7:40:11 AM] Total Processed Objects: 0
[1/16/2024 7:40:11 AM] Finished with 0 warnings.
[1/16/2024 7:40:11 AM] Finished with 1 errors.
这看起来导入作业在解析其 XML 时尝试将我加密的文件作为纯文本读取。它应该首先解密它们,但它没有。
现在,我在想也许我不需要加密这些文件。我放弃了 xml 元数据文件的加密。但我保持其余部分不变。所以我仍然调用
CreateMigrationJobEncrypted
方法并通过生成的容器变量 (encryptionOption
) 为其提供 containers?.Value.EncryptionKey
。
我现在遇到的错误是:
[1/16/2024 6:54:53 AM] Start Time: 1/16/2024 6:54:52 AM.
[1/16/2024 6:54:53 AM] Correlation Id: 174f02a1-209c-7000-f07b-bf1736dce42f
[1/16/2024 6:54:53 AM] [Progress] Initializing Import.
[1/16/2024 6:54:53 AM] [Error] Unable to download SystemData.xml with exception 'Must specify IV in Manifest or blob metadata'
[1/16/2024 6:54:53 AM] [Error] Unable to download Requirements.xml with exception 'Must specify IV in Manifest or blob metadata'
[1/16/2024 6:54:53 AM] [Warning] Import requirement file Requirements.xml was not found no verifications ran.
[1/16/2024 6:54:53 AM] [Error] Unable to download ExportSettings.xml with exception 'Must specify IV in Manifest or blob metadata'
[1/16/2024 6:54:53 AM] [FatalError] [-2147024894] [System.IO.FileNotFoundException] [Missing Export Settings file stream]
[1/16/2024 6:54:53 AM] [Debug] at Microsoft.SharePoint.Deployment.SPImport.DeserializeExportSettings()
at Microsoft.SharePoint.Deployment.SPImport.Run()
[1/16/2024 6:54:53 AM] [Progress] Import did not complete.
[1/16/2024 6:54:53 AM] Finish Time: 1/16/2024 6:54:53 AM.
[1/16/2024 6:54:53 AM] Duration: 00:00:00
[1/16/2024 6:54:53 AM] Byte imported: 0.00 at 0.00 bytes per second
[1/16/2024 6:54:53 AM] Total Processed Objects: 0
[1/16/2024 6:54:53 AM] Finished with 1 warnings.
[1/16/2024 6:54:53 AM] Finished with 4 errors.
:54 AM] Total Processed Objects: 0
[1/16/2024 6:53:54 AM] Finished with 0 warnings.
[1/16/2024 6:53:54 AM] Finished with 1 errors.
这让我觉得,在使用
CreateMigrationJobEncrypted
方法时我需要加密这些文件。
我决定使用
CreateMigrationJob
方法而不是CreateMigrationJobEncrypted
。它不需要 encryptOption
参数。我没有加密 xml 元数据文件,当我尝试使用此方法创建作业时,它失败了(ExecuteQuery
):
var jobReadInfo = clientContext.Site.CreateMigrationJob(
Guid.Parse(targetWebId), // gWebId (same as clientContext.Web.Id)
containers.Value.DataContainerUri, // azureContainerSourceUri
containers.Value.MetadataContainerUri, // azureContainerManifestUri
queue.Value.JobQueueUri);
clientContext.ExecuteQuery(); // throws exception
抛出的异常是:
Error: Invalid use of SPOContainer.
我只能假设这些为迁移而创建的容器需要加密,因为它们为我们提供了加密密钥。此方法可能会与自行提供的未加密容器一起使用。我没有尝试过这种方式。
除了尝试我自己的容器之外,我不知道该怎么办。但我想避免它。
这里有人能指出我正确的方向吗?
谢谢!
我意识到我在加密的每个文件的开头添加了
IV
。不需要它,因为它已添加到 blob 的元数据中。删除了我描述的“方法 1”后,现在可以工作了。