private static CommitmentPrivateValues PresentUProveToken(IssuerParameters ip, UProveKeyAndToken upkt, byte[][] attributes, int[] disclosed, int[] committed, byte[] message, byte[] scope, IDevice device, byte[] deviceMessage)
        {
            WriteLine("Presenting one token");
            // the returned commitment randomizer (to be used by an external proof module)
            CommitmentPrivateValues cpv;

            // generate the presentation proof
            string token = ip.Serialize <UProveToken>(upkt.Token);
            ProverPresentationProtocolParameters pppp = new ProverPresentationProtocolParameters(ip, disclosed, message, upkt, attributes);

            pppp.Committed = committed;
            // if a scope is defined, we use the first attribute to derive a scope exclusive pseudonym
            pppp.PseudonymAttributeIndex = (scope == null ? 0 : 1);
            pppp.PseudonymScope          = scope;
            if (device != null)
            {
                pppp.SetDeviceData(deviceMessage, device.GetPresentationContext());
            }
            pppp.KeyAndToken = upkt;
            pppp.Attributes  = attributes;
            string proof = ip.Serialize <PresentationProof>(PresentationProof.Generate(pppp, out cpv));

            // verify the presentation proof
            VerifierPresentationProtocolParameters vppp = new VerifierPresentationProtocolParameters(ip, disclosed, message, ip.Deserialize <UProveToken>(token));

            vppp.Committed = committed;
            // if a scope is defined, we use the first attribute to derive a scope exclusive pseudonym
            vppp.PseudonymAttributeIndex = (scope == null ? 0 : 1);
            vppp.PseudonymScope          = scope;
            vppp.DeviceMessage           = deviceMessage;
            ip.Deserialize <PresentationProof>(proof).Verify(vppp);

            return(cpv);
        }
Exemple #2
0
        /// <summary>
        /// first method to call - Initializes the ProverProof by generating the PresentationProof
        /// </summary>
        /// <param name="ip">IssuerParameter from the Issuer of the given token</param>
        /// <param name="attributes">Attributes which are included in the given token</param>
        /// <param name="proofRequirements">Necessary informations for creating the proofs (e.g. disclosedAttributes)</param>
        /// <param name="tokenWithKey">Token for which the proof will be done</param>
        /// <param name="supportedDateAttributes">If there is a RangeProof done, all date attributes where treated and formated especially</param>
        /// <param name="devicePresentationContext">If there was a device involved during the token generation, the context from the device is needed to generate the
        /// PresentationProof as well</param>
        /// <returns>returns the proof for the given token as json object or an error</returns>
        public string Init(IssuerParameters ip, List <BasicClaim> attributes, ProofRequirements proofRequirements,
                           UProveKeyAndToken tokenWithKey, List <string> supportedDateAttributes,
                           IDevicePresentationContext devicePresentationContext)
        {
            try
            {
                LogService.Log(LogService.LogType.Info, "ProverProof - init called");
                this.ip = ip;
                this.proofRequirements = proofRequirements;
                ci.CreateBase64ForAttributeList(attributes, supportedDateAttributes, out rangeProofProperties);
                attributesToInclude = ci.ConvertAttributeListToBase64ByteArray(attributes);

                pppp = new ProverPresentationProtocolParameters(this.ip, proofRequirements.disclosedAttributes,
                                                                proofRequirements.message, tokenWithKey, attributesToInclude);
                pppp.Committed = proofRequirements.committedAttributes;

                //// TODO
                //// if a scope is defined, we use the first attribute to derive a scope exclusive pseudonym
                //pppp.PseudonymAttributeIndex = (proofRequirements.scope == null ? 0 : 1);
                //pppp.PseudonymScope = proofRequirements.scope;

                // add device presentation context to the provers presentation context
                if (this.ip.IsDeviceSupported && devicePresentationContext != null)
                {
                    pppp.SetDeviceData(proofRequirements.deviceMessage, devicePresentationContext);
                }

                // generate proof
                PresentationProof pProof = PresentationProof.Generate(pppp, out cpv);
                LogService.Log(LogService.LogType.Info, "ProverProof - init presentation proof generated");

                proof = parser.ParseJsonToObject <Proof>(this.ip.Serialize <PresentationProof>(pProof));
                proof.requirements = proofRequirements;

                string proofJson = parser.ParseObjectToJson(proof);
                LogService.Log(LogService.LogType.Info, "ProverProof - proof created: " + proofJson);

                return(proofJson);
            }
            catch (Exception e)
            {
                LogService.Log(LogService.LogType.FatalError, "ProverProof - Error during prover setup.", e);
                throw new CommunicationException("ProverProof - Error during ProverProof init; " + e);
            }
        }