Exemple #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.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));
        }
Exemple #2
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));
        }