byte[] CreateKeyVaultSignature(X509Certificate2 publicCert, SignatureManifest signatureManifest) { var chain = new X509Chain(); chain.Build(publicCert); // Get the chain as bc certs var additionals = chain.ChainElements.Cast <X509ChainElement>() .Select(ce => DotNetUtilities.FromX509Certificate(ce.Certificate)) .ToList(); chain.Dispose(); var bcCer = DotNetUtilities.FromX509Certificate(publicCert); var store = X509StoreFactory.Create("Certificate/Collection", new X509CollectionStoreParameters(additionals)); var generator = new CmsSignedDataGenerator(); var builder = new SignerInfoGeneratorBuilder(); var b = builder.Build(new RsaSignatureFactory("SHA256WITHRSA", provider), bcCer); generator.AddSignerInfoGenerator(b); generator.AddCertificates(store); var msg = new CmsProcessableByteArray(signatureManifest.GetBytes()); var data = generator.Generate(msg, true); var encoded = data.GetEncoded(); return(encoded); }
public void Finialize(SignatureManifest manifest) { // Here we want to make sure that all // resources have been released and // all signature/temp files have been // erased. using (RdcServices rdcServices = new RdcServices()) { rdcServices.PurgeSignatureStore(manifest.Signatures); } }
private IList <LocalRemotePair> PrepareSigPairs(SignatureManifest signatureManifest) { var remoteSignatures = signatureManifest.Signatures; var localSignatures = localSignatureRepository.GetByFileName().ToList(); var length = Math.Min(remoteSignatures.Count, localSignatures.Count); var remoteSignatureNames = remoteSignatures.Skip(remoteSignatures.Count - length).Take(length).Select(item => item.Name).ToList(); var localSignatureNames = localSignatures.Skip(localSignatures.Count - length).Take(length).Select(item => item.Name).ToList(); return(localSignatureNames.Zip(remoteSignatureNames, (local, remote) => new LocalRemotePair { Local = local, Remote = remote }).ToList()); }
public Task <SignatureManifest> GetSignatureManifestAsync(DataInfo dataInfo) { return(Task.Factory.StartNew(() => { signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim()) .EnterUpgradeableReadLock(); IEnumerable <SignatureInfo> signatureInfos = null; try { var lastUpdate = _signatureRepository.GetLastUpdate(); if (lastUpdate == null || lastUpdate < dataInfo.LastModified) { signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim()) .EnterWriteLock(); try { signatureInfos = PrepareSignatures(dataInfo.Name); } finally { signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim()) .ExitWriteLock(); } } else { signatureInfos = _signatureRepository.GetByFileName(); } } finally { signatureBuidInProgress.GetOrAdd(dataInfo.Name, new ReaderWriterLockSlim()) .ExitUpgradeableReadLock(); } var result = new SignatureManifest { FileLength = dataInfo.Length, FileName = dataInfo.Name, Signatures = SignatureInfosToSignatures(signatureInfos) }; return result; })); }
private async Task <SynchronizationReport> SynchronizeTo(IAsyncFilesSynchronizationCommands destination, ISignatureRepository localSignatureRepository, ISignatureRepository remoteSignatureRepository, SignatureManifest sourceSignatureManifest, SignatureManifest destinationSignatureManifest) { var seedSignatureInfo = SignatureInfo.Parse(destinationSignatureManifest.Signatures.Last().Name); var sourceSignatureInfo = SignatureInfo.Parse(sourceSignatureManifest.Signatures.Last().Name); using (var localFile = StorageStream.Reading(Storage, FileName)) { IList <RdcNeed> needList; using (var needListGenerator = new NeedListGenerator(remoteSignatureRepository, localSignatureRepository)) { needList = needListGenerator.CreateNeedsList(seedSignatureInfo, sourceSignatureInfo, Cts.Token); } return(await PushByUsingMultipartRequest(destination, localFile, needList)); } }
public SignatureManifest GetSignatureManifest(string file, int recursionDepth) { SignatureManifest manifest; SignatureCollection signatures; // Open the source Stream using (FileStream stream = File.OpenRead(file)) { // Initialize our managed RDC wrapper RdcServices rdcServices = new RdcServices(); rdcServices.WorkingDirectory = Path.GetTempPath(); rdcServices.RecursionDepth = recursionDepth; GC.Collect(); GC.WaitForPendingFinalizers(); // Generate the signature files signatures = rdcServices.GenerateSignatures(stream, Path.GetFileName(file)); if (signatures.Count < 1) { throw new RdcException("Failed to generate the signatures."); } manifest = new SignatureManifest(file, signatures); manifest.FileLength = stream.Length; // Let's close the signature streams. foreach (SignatureInfo sig in signatures) { sig.InnerStream.Close(); } } return(manifest); }
public async Task <Signature> CreateSignatureAsync(SignPackageRequest request, SignatureManifest signatureManifest, ILogger logger, CancellationToken token) { if (request == null) { throw new ArgumentNullException(nameof(request)); } if (signatureManifest == null) { throw new ArgumentNullException(nameof(signatureManifest)); } if (logger == null) { throw new ArgumentNullException(nameof(logger)); } var authorSignature = CreateKeyVaultSignature(request.Certificate, signatureManifest); var timestamped = await TimestampSignature(request, logger, authorSignature, token); return(timestamped); }