Ejemplo n.º 1
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.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 new ZippedContentBuilder().BuildEks(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));
        }