예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="protoBatch"> The diagnosis key batch, from which the information to generate the bytes to verify are obtained. Keys inside the batch MUST be sorted</param>
        /// <returns></returns>
        public byte[] Sign(TemporaryExposureKeyGatewayBatchDto protoBatch, SortOrder keysSortOrder)
        {
            MemoryStream memStream = new MemoryStream();

            Func <byte[], string> keyEncodingForSortFunc = keySigBytes => _encodingService.EncodeToBase64(keySigBytes);
            var comparer = StringComparer.Ordinal;

            var query = protoBatch.Keys.Select(GenerateSignaturePayloadFromKey);

            query = (keysSortOrder == SortOrder.ASC) ? query.OrderBy(keyEncodingForSortFunc, comparer) : query.OrderByDescending(keyEncodingForSortFunc, comparer);

            var sortedKeySignatures = query.ToList();

            sortedKeySignatures.ForEach(sig =>
            {
                memStream.Write(sig);
            });

            return(SignWithCertificate(memStream.ToArray()));
        }
예제 #2
0
 public string TestEncodeToBase64(string stringToEncode)
 {
     return(_encodingService.EncodeToBase64(stringToEncode));
 }
예제 #3
0
        private bool TrySendKeyBatchToTheGateway(TemporaryExposureKeyGatewayBatchProtoDto protoBatch, SortOrder keySortOrderForSignature)
        {
            var upoadKeysEndpointUrl = _euGatewayConfig.UrlNormalized + EuGatewayContract.Endpoint.KeysUploadEndpoint;
            var batchBytes           = protoBatch.ToByteArray();

            //sign
            var signing       = _signatureService.Sign(protoBatch, keySortOrderForSignature);
            var signingBase64 = _encodingService.EncodeToBase64(signing);
            var body          = new ByteArrayContent(batchBytes);

            var uniqueTag = DateTimeOffset.UtcNow.ToUnixTimeMilliseconds().ToString();

            body.Headers.Add("batchTag", uniqueTag);
            body.Headers.Add("Content-Type", "application/protobuf;version=1.0");
            body.Headers.Add("batchSignature", signingBase64);

            var response = _gatewayHttpClient.PostAsync(upoadKeysEndpointUrl, body).Result;
            var message  = response.Content.ReadAsStringAsync().Result;
            var code     = response.StatusCode;

            switch (code)
            {
            case System.Net.HttpStatusCode.OK:
                _logger.LogInformation($"Response - OK. Message: {message}");
                var containsHtml = message.Contains("<body>");
                _logger.LogError($"UeGateway response with code 200 with HTML in the response: {containsHtml}. UeGateway Server is down!");
                // Server is down - https://github.com/eu-federation-gateway-service/efgs-federation-gateway/issues/151
                break;

            case System.Net.HttpStatusCode.Created:
                _logger.LogInformation("Keys successfully uploaded.");
                return(true);

            case System.Net.HttpStatusCode.MultiStatus:
                _logger.LogWarning($"Data partially added with warnings: {message}.");
                return(true);

            case System.Net.HttpStatusCode.BadRequest:
                _logger.LogError($"Bad request: {message}");
                break;

            case System.Net.HttpStatusCode.Forbidden:
                _logger.LogError($"Forbidden call in cause of missing or invalid client certificate. Message: {message}");
                break;

            case System.Net.HttpStatusCode.NotAcceptable:
                _logger.LogError($"Data format or content is not valid. Massage:{message}");
                break;

            case System.Net.HttpStatusCode.Conflict:
                _logger.LogError($"Data already exist. Message: {message}");
                break;

            case System.Net.HttpStatusCode.RequestEntityTooLarge:
                _logger.LogError($"Payload to large.  Message: {message}");
                break;

            case System.Net.HttpStatusCode.InternalServerError:
                _logger.LogError($"Are not able to write data. Retry please. Message: {message}");
                break;

            default:
                _logger.LogError($"Response code was not recognized. Status code: {code}, message: {message}");
                break;
            }
            return(false);
        }