コード例 #1
0
        public OperationResult DigitalSignatureVote(ClientPetitionVote vote)
        {
            OperationResult result;

            try
            {
                if (vote.PetitionID == 0)
                {
                    result = OperationResult.Fail(-2, "PetitionID was not provided.");
                    return(result);
                }

                // verify:
                IVerificationRepository verificationRepository;
                switch (vote.CertificateType)
                {
                case EntityDictionary.Certificate.Type.DPA:
                {
                    verificationRepository = new DpaVerificationRepository();
                    break;
                }

                case EntityDictionary.Certificate.Type.UACrypto:
                {
                    verificationRepository = new UaCryptoVerificationRepository();
                    break;
                }

                default:
                {
                    verificationRepository = new UaCryptoVerificationRepository();
                    break;
                }
                }

                var verificationResult       = verificationRepository.Verify(vote.SignedData);
                var isVerficationSuccessfull =
                    verificationResult.Descendants("Result").SingleOrDefault() != null &&
                    verificationResult.Descendants("Result").SingleOrDefault().Value == "Success" &&
                    verificationResult.Descendants("Serial").SingleOrDefault() != null &&
                    verificationResult.Descendants("Serial").SingleOrDefault().Value.Length > 0;

                if (!isVerficationSuccessfull)
                {
                    result = OperationResult.Fail(-3, "Certificate verification failed.");
                    return(result);
                }

                result = this.petitionVoteRepository.Vote(vote, verificationResult.Descendants("Serial").SingleOrDefault().Value);
            }
            catch (Exception exc)
            {
                result = OperationResult.ExceptionResult(exc);
            }

            return(result);
        }
コード例 #2
0
        public OperationResult Post(ClientAgreementVote vote)
        {
            OperationResult result;

            try
            {
                if (vote.AgreementID == 0)
                {
                    result = OperationResult.Fail(-2, "AgreementID was not provided.");
                    return(result);
                }

                // verify:
                IVerificationRepository verificationRepository;
                switch (vote.CertificateType)
                {
                case EntityDictionary.Certificate.Type.DPA:
                {
                    verificationRepository =
                        // BUG: DPA verification server doesn't work properly
                        //new DpaVerificationRepository();
                        new UaCryptoVerificationRepository();
                    break;
                }

                case EntityDictionary.Certificate.Type.UACrypto:
                {
                    verificationRepository = new UaCryptoVerificationRepository();
                    break;
                }

                default:
                {
                    verificationRepository = new UaCryptoVerificationRepository();
                    break;
                }
                }

                var verificationResult       = verificationRepository.Verify(vote.SignedData);
                var isVerficationSuccessfull =
                    verificationResult.Descendants("Result").SingleOrDefault() != null &&
                    verificationResult.Descendants("Result").SingleOrDefault().Value == "Success" &&
                    verificationResult.Descendants("Serial").SingleOrDefault() != null &&
                    verificationResult.Descendants("Serial").SingleOrDefault().Value.Length > 0;

                if (!isVerficationSuccessfull)
                {
                    result = OperationResult.Fail(-3, "Certificate verification failed.");
                    return(result);
                }

                var agreementVote = new AgreementVote
                {
                    AgreementID = vote.AgreementID,
                    Certificate = new Certificate()
                    {
                        SerialNumber = verificationResult.Descendants("Serial").SingleOrDefault().Value
                    },
                    SignedData = vote.SignedData,
                    SignedHash = vote.Signature
                };
                result = this.agreementRepository.Vote(agreementVote);
            }
            catch (Exception exc)
            {
                result = OperationResult.ExceptionResult(exc);
            }

            return(result);
        }