Exemplo n.º 1
0
        protected override Tuple <Stream, Object> OnTransferEncrypted(Stream encrypted, Object parameters, ref byte[] keyId, ReadOnlyCollection <Recipient> recipients)
        {
            InputParameterData inputParameters = (InputParameterData)parameters;

            //construct the request from parameters and the encrypted message
            AskChap4MedicalAdvisorAgreementRequestType request = new AskChap4MedicalAdvisorAgreementRequestType();

            request.CommonInput            = inputParameters.CommonInput;
            request.RecordCommonInput      = inputParameters.RecordCommonInput;
            request.CareReceiver           = inputParameters.CareReceiverId;
            request.Request                = new SecuredContentType();
            request.Request.SecuredContent = ReadFully(encrypted);

            //Send the request and get the response.
            AskChap4MedicalAdvisorAgreementResponseType response;

            try
            {
                response = proxy.askChap4MedicalAdvisorAgreement(request);
            }
            catch (FaultException <SystemError> systemError)
            {
                String code = systemError.Detail.Nodes.Where(x => x.LocalName == "Code").Single().InnerText;
                String msg  = systemError.Detail.Nodes.Where(x => x.LocalName == "Message").Single().InnerText;
                String id   = systemError.Detail.Nodes.Where(x => x.LocalName == "Id").Single().InnerText;
                throw new InvalidOperationException(code + ": " + msg + " (" + id + ")");
            }

            //Verify the response for errors, return an exception if found.
            if (response.Status.Code != "200" || response.ReturnInfo != null)
            {
                throw new AgreementException(response.Status, response.ReturnInfo, response.CommonOutput, response.RecordCommonOutput);
            }

            //Extract the non encrypted data and the encrypted steam
            OutputParameterData outputParameters = new OutputParameterData(response.CommonOutput, response.RecordCommonOutput);

            return(new Tuple <Stream, Object>(new MemoryStream(response.Response.SecuredContent), outputParameters));
        }
Exemplo n.º 2
0
        protected override Tuple <Stream, object> OnTransferEncrypted(Stream encrypted, Object parameters, ref byte[] keyId, ReadOnlyCollection <Recipient> recipients)
        {
            if (!(parameters is InputParameterData))
            {
                throw new ArgumentException("The parameters agrument must be a input parameter data", "parameters");
            }
            InputParameterData inputParameters = (InputParameterData)parameters;

            //Create a new request, containing the unaddressed encrypted content.
            Object request = CreateIntermediateRequest(encrypted, keyId, inputParameters);

            X509Certificate2 sender;
            //send via the inner postmaster
            Tuple <Stream, Object> response = innerPostMaster.TransferAndDoCrypto(SerializeInMemory(request), parameters, new ReadOnlyCollection <Recipient>(mcnList.ToList <Recipient>()), out sender);

            //Prepare a new tuple with all the clear data (including the stream, since at this point it is clear data)
            OutputParameterData responseParameter = (OutputParameterData)response.Item2;

            responseParameter.ClearResponse = response.Item1;
            responseParameter.Sender        = sender;

            return(new Tuple <Stream, Object>(null, responseParameter)); //stream nust be null, otherwise the postmaster will try to decrypt it.
        }
Exemplo n.º 3
0
        /// <summary>
        /// Communicates with the Chapter IV agreement consult service.
        /// </summary>
        /// <param name="kmehr">The request kmehr, that must be double encrypted</param>
        /// <param name="parameters">Additional information required, see Chapter IV documentation</param>
        /// <param name="sender">The certificate of the IO that sent the response</param>
        /// <returns>The response kmehr (item1) and additional information (item2)</returns>
        /// <exception cref="AgreementException">When the service returns a fault in the business message</exception>
        public Tuple <Stream, OutputParameterData> Transfer(Stream kmehr, InputParameterData parameters, out X509Certificate2 sender)
        {
            //Create the request with the KMEHR
            Object request = CreateBusinessRequest(kmehr, Self.Token.GetEncoded());

            //Encrypte request and send, the response isn't encrypted on this level (but is on the second pass)
            Object response = TransferAndEncryptOnly(SerializeInMemory(request), (Object)parameters, new ReadOnlyCollection <Recipient>(ioList.ToList <Recipient>()));

            //Convert the response
            OutputParameterData responseParameter = (OutputParameterData)response;

            //Get the sender and remove it from teh response parameter
            sender = responseParameter.Sender;
            responseParameter.Sender = null;

            //desialize the response
            byte[] timestamp;
            byte[] kmehrResponse = ParseResponse(responseParameter.ClearResponse, out timestamp);

            //clear the (internal) input and return the response
            responseParameter.ClearResponse = null;
            responseParameter.Timestamp     = timestamp;
            return(new Tuple <Stream, OutputParameterData>(new MemoryStream(kmehrResponse), responseParameter));
        }
Exemplo n.º 4
0
        protected override Tuple<Stream, Object> OnTransferEncrypted(Stream encrypted, Object parameters, ref byte[] keyId, ReadOnlyCollection<Recipient> recipients)
        {
            InputParameterData inputParameters = (InputParameterData) parameters;

            //construct the request from parameters and the encrypted message
            AskChap4MedicalAdvisorAgreementRequestType request = new AskChap4MedicalAdvisorAgreementRequestType();
            request.CommonInput = inputParameters.CommonInput;
            request.RecordCommonInput = inputParameters.RecordCommonInput;
            request.CareReceiver = inputParameters.CareReceiverId;
            request.Request = new SecuredContentType();
            request.Request.SecuredContent = ReadFully(encrypted);

            //Send the request and get the response.
            AskChap4MedicalAdvisorAgreementResponseType response;
            try
            {
                response = proxy.askChap4MedicalAdvisorAgreement(request);
            }
            catch (FaultException<SystemError> systemError)
            {
                String code = systemError.Detail.Nodes.Where(x => x.LocalName == "Code").Single().InnerText;
                String msg = systemError.Detail.Nodes.Where(x => x.LocalName == "Message").Single().InnerText;
                String id = systemError.Detail.Nodes.Where(x => x.LocalName == "Id").Single().InnerText;
                throw new InvalidOperationException(code + ": " + msg + " (" + id + ")");
            }

            //Verify the response for errors, return an exception if found.
            if (response.Status.Code != "200" || response.ReturnInfo != null)
            {
                throw new AgreementException(response.Status, response.ReturnInfo, response.CommonOutput, response.RecordCommonOutput);
            }

            //Extract the non encrypted data and the encrypted steam
            OutputParameterData outputParameters = new OutputParameterData(response.CommonOutput, response.RecordCommonOutput);
            return new Tuple<Stream, Object>(new MemoryStream(response.Response.SecuredContent), outputParameters);
        }