Beispiel #1
0
        public void Store_Local(DataReq store)
        {
            // getting published to - search results - patch

            SignedData signed = SignedData.Decode(store.Data);

            if (signed == null)
            {
                return;
            }

            G2Header embedded = new G2Header(signed.Data);

            // figure out data contained
            if (G2Protocol.ReadPacket(embedded))
            {
                if (embedded.Name == LocationPacket.Data)
                {
                    LocationData location = LocationData.Decode(signed.Data);

                    if (Utilities.CheckSignedData(location.Key, signed.Data, signed.Signature))
                    {
                        Process_LocationData(store, signed, location);
                    }
                    else
                    {
                        Debug.Assert(false);
                    }
                }
            }
        }
        public static TBSCertificate?GetSigningCertificate(PeFile peFile)
        {
            if (peFile == null)
            {
                throw new ArgumentNullException(nameof(peFile));
            }

            if (peFile.WinCertificate?.WCertificateType != PeNet.Header.Pe.WinCertificateType.PkcsSignedData)
            {
                return(null);
            }

            var pkcs7 = peFile.WinCertificate.BCertificate.ToArray();

            const string SignedDataOid = "1.2.840.113549.1.7.2";
            var          content       = ContentInfo.Decode(pkcs7);

            if (content.ContentType != SignedDataOid)
            {
                throw new CryptographicException("Cryptography_Cms_InvalidMessageType");
            }

            var data = SignedData.Decode(content.Content);

            var signerSerialNumber = data.SignerInfos
                                     ?.ElementAtOrDefault(0)
                                     ?.Sid?.IssuerAndSerialNumber?.SerialNumber;

            if (signerSerialNumber == null)
            {
                return(null);
            }

            var certificates = data.Certificates
                               ?.Select(x => x?.Certificate?.TbsCertificate)
                               .Where(x => x?.SerialNumber is { } sn&& sn == signerSerialNumber)
                               .ToArray();
            var signingCertificate = certificates?.Length switch
            {
                1 => certificates[0],
                _ => throw new CryptographicException($"Expected to find one certificate with serial number '{signerSerialNumber}' but found {certificates?.Length ?? 0}.")
            };

            return(signingCertificate);
        }
Beispiel #3
0
        void Store_Local(DataReq store)
        {
            // getting published to - search results - patch

            SignedData signed = SignedData.Decode(store.Data);

            if (signed == null)
            {
                return;
            }

            G2Header embedded = new G2Header(signed.Data);

            // figure out data contained
            if (G2Protocol.ReadPacket(embedded))
            {
                if (embedded.Name == DataPacket.VersionedFile)
                {
                    Process_VersionedFile(store, signed, VersionedFileHeader.Decode(signed.Data));
                }
            }
        }
Beispiel #4
0
        public void LoadHeaders()
        {
            List <string> goodPaths = new List <string>();

            try
            {
                goodPaths.Add(HeaderPath);

                if (!File.Exists(HeaderPath))
                {
                    return;
                }

                using (IVCryptoStream crypto = IVCryptoStream.Load(HeaderPath, LocalKey))
                {
                    PacketStream stream = new PacketStream(crypto, Network.Protocol, FileAccess.Read);

                    G2Header root = null;

                    while (stream.ReadPacket(ref root))
                    {
                        if (root.Name == DataPacket.SignedData)
                        {
                            SignedData signed   = SignedData.Decode(root);
                            G2Header   embedded = new G2Header(signed.Data);


                            // figure out data contained
                            if (G2Protocol.ReadPacket(embedded))
                            {
                                if (embedded.Name == DataPacket.VersionedFile)
                                {
                                    VersionedFileHeader header = VersionedFileHeader.Decode(embedded);

                                    if (header.FileHash != null)
                                    {
                                        goodPaths.Add(GetFilePath(header));
                                    }

                                    Process_VersionedFile(null, signed, header);
                                }
                            }
                        }
                    }
                }

                // remove loose files
                foreach (string testPath in Directory.GetFiles(CachePath))
                {
                    if (!goodPaths.Contains(testPath))
                    {
                        try { File.Delete(testPath); }
                        catch { }
                    }
                }
            }
            catch (Exception ex)
            {
                Core.Network.UpdateLog("VersionedFile", "Error loading data " + ex.Message);
            }
        }