Exemplo n.º 1
0
        public async Task <byte[]> SignedContentPacket(byte[] content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var signature = _ContentSigner.GetSignature(content);

            return(await CreateZipArchive(content, signature));
        }
        public async Task <byte[]> SignedContentPacket(byte[] content)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }

            var signature = _ContentSigner.GetSignature(content);

            return(await new ZippedContentBuilder().BuildStandard(content, signature));
        }
Exemplo n.º 3
0
 private async Task <byte[]> ReplaceSignatureAsync(byte[] archiveBytes)
 {
     await using var m = new MemoryStream();
     m.Write(archiveBytes, 0, archiveBytes.Length);
     using (var archive = new ZipArchive(m, ZipArchiveMode.Update, true))
     {
         var content = archive.ReadEntry(_contentEntryName);
         var sig     = _contentSigner.GetSignature(content);
         await archive.ReplaceEntryAsync(ZippedContentEntryNames.NlSignature, sig);
     }
     return(m.ToArray());
 }
Exemplo n.º 4
0
        public async Task <byte[]> BuildAsync(TemporaryExposureKeyArgs[] keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }

            if (keys.Any(x => x == null))
            {
                throw new ArgumentException("At least one key in null.", nameof(keys));
            }

            var securityInfo = GetGaenSignatureInfo();

            var content = new ExposureKeySetContentArgs
            {
                Header         = Header,
                Region         = "NL",
                BatchNum       = 1,
                BatchSize      = 1,
                SignatureInfos = new[] { securityInfo },
                StartTimestamp = _dateTimeProvider.Snapshot.AddDays(-1).ToUnixTimeU64(),
                EndTimestamp   = _dateTimeProvider.Snapshot.ToUnixTimeU64(),
                Keys           = keys
            };

            var contentBytes = _eksContentFormatter.GetBytes(content);
            var nlSig        = _nlContentSigner.GetSignature(contentBytes);
            var gaenSig      = _gaenContentSigner.GetSignature(contentBytes);

            _logger.WriteNlSig(nlSig);
            _logger.WriteGaenSig(gaenSig);

            var signatures = new ExposureKeySetSignaturesContentArgs
            {
                Items = new[]
                {
                    new ExposureKeySetSignatureContentArgs
                    {
                        SignatureInfo = securityInfo,
                        Signature     = gaenSig,
                        BatchSize     = content.BatchSize,
                        BatchNum      = content.BatchNum
                    },
                }
            };

            var gaenSigFile = _eksContentFormatter.GetBytes(signatures);

            return(await new ZippedContentBuilder().BuildEksAsync(contentBytes, gaenSigFile, nlSig));
        }
Exemplo n.º 5
0
        public async Task <byte[]> BuildAsync(TemporaryExposureKeyArgs[] keys)
        {
            if (keys == null)
            {
                throw new ArgumentNullException(nameof(keys));
            }
            if (keys.Any(x => x == null))
            {
                throw new ArgumentException("At least one key in null.", nameof(keys));
            }

            var securityInfo = GetGaenSignatureInfo();

            var content = new ExposureKeySetContentArgs
            {
                Header         = Header,
                Region         = "NL",
                BatchNum       = 1,
                BatchSize      = 1,
                SignatureInfos = new[] { securityInfo },
                StartTimestamp = _DateTimeProvider.Snapshot.AddDays(-1).ToUnixTimeU64(), //TODO real values?
                EndTimestamp   = _DateTimeProvider.Snapshot.ToUnixTimeU64(),             //TODO real values?
                Keys           = keys
            };

            var contentBytes = _EksContentFormatter.GetBytes(content);
            var nlSig        = _NlContentSigner.GetSignature(contentBytes);
            var gaenSig      = _GaenContentSigner.GetSignature(contentBytes);

            _Logger.LogDebug("GAEN Sig: {Convert.ToBase64String(GaenSig)}.", gaenSig);
            _Logger.LogDebug("NL Sig: {Convert.ToBase64String(NlSig)}.", nlSig);

            var signatures = new ExposureKeySetSignaturesContentArgs
            {
                Items = new[]
                {
                    new ExposureKeySetSignatureContentArgs
                    {
                        SignatureInfo = securityInfo,
                        Signature     = gaenSig,
                        BatchSize     = content.BatchSize,
                        BatchNum      = content.BatchNum
                    },
                }
            };

            var gaenSigFile = _EksContentFormatter.GetBytes(signatures);

            return(await CreateZipArchive(contentBytes, gaenSigFile, nlSig));
        }
        public async Task <byte[]> BuildAsync(TemporaryExposureKeyArgs[] keys)
        {
            var securityInfo = GetGaenSignatureInfo();

            var now = _DateTimeProvider.Now();

            var content = new ExposureKeySetContentArgs
            {
                Header         = Header,
                Region         = "NL",
                BatchNum       = 1,                            //TODO real values?
                BatchSize      = keys.Length,                  //TODO real values?
                SignatureInfos = new[] { securityInfo },
                StartTimestamp = now.AddDays(-1).ToUnixTime(), //TODO real values?
                EndTimestamp   = now.ToUnixTime(),             //TODO real values?
                Keys           = keys
            };

            var contentBytes = _ContentFormatter.GetBytes(content);

            var signatures = new ExposureKeySetSignaturesContentArgs
            {
                Items = new[]
                {
                    new ExposureKeySetSignatureContentArgs
                    {
                        SignatureInfo = securityInfo,
                        Signature     = _GaenContentSigner.GetSignature(contentBytes),
                        BatchSize     = 1,
                        BatchNum      = 1
                    },
                    //new ExposureKeySetSignatureContentArgs
                    //{
                    //    //TODO The NL sig.
                    //},
                }
            };

            var nlSig = _NlContentSigner.GetSignature(contentBytes);

            return(await CreateZipArchive(contentBytes, _ContentFormatter.GetBytes(signatures), nlSig));
        }
Exemplo n.º 7
0
        public async Task <byte[]> SignedContentPacket(byte[] content)
        {
            var signature = _ContentSigner.GetSignature(content);

            return(await CreateZipArchive(content, signature));
        }