Ejemplo n.º 1
0
        public PseudonymComposite presentPseudonym(string messageParam, string verifierScopeParam, string sessionID)
        {
            // invoke the device to compute the pseudonym value and response.
            // if a scope-exclusive pseudonym is requested (when scope != null) then
            // the device-computed scope-exclusive pseudonym is used. Otherwise, the
            // device's public key and initial witness are used in lieu of the pseudonym
            // value and commitment, respectively.

            cOut.write("presentPseudonym()");
            VerifySessionId(sessionID);
            GroupElement A = null;
            GroupElement P = null;
            BigInteger   R = null;

            try
            {
                DeviceManager dManager         = sessionDB[sessionID].deviceManager;
                bool          scopeExclusive   = (verifierScopeParam != null && verifierScopeParam != "null" && verifierScopeParam.Length > 0);
                IDevicePresentationContext ctx = dManager.GetDevice().GetPresentationContext();
                byte[] proofSession            = null;
                if (!dManager.IsVirtualDevice)
                {
                    SmartCardDevice smartDevice = (SmartCardDevice)dManager.GetDevice();
                    smartDevice.ProofSession = smartDevice.Device.BeginCommitment(1);
                    proofSession             = smartDevice.ProofSession;
                }
                if (scopeExclusive)
                {
                    ctx.GetInitialWitnessesAndPseudonym(encoding.GetBytes(verifierScopeParam), out A, out P);
                }
                else
                {
                    P = dManager.GetDevice().GetDevicePublicKey();
                    A = ctx.GetInitialWitness();
                }
                if (dManager.IsVirtualDevice)
                {
                    R = ctx.GetDeviceResponse(encoding.GetBytes(messageParam), null, dManager.HashFunctionOID);
                }
                else
                {
                    R = ctx.GetDeviceResponse(proofSession, encoding.GetBytes(messageParam), dManager.HashFunctionOID);
                }
            }

            catch (Exception e)
            {
                cOut.write("Exception caught: " + e.Message);
                DebugUtils.DebugPrint(e.StackTrace.ToString());
                return(new PseudonymComposite());
            }

            return(ConvertUtils.convertPseudonym(new Pseudonym(A, P, R)));
        }
Ejemplo n.º 2
0
        public PresentationProofComposite proveToken(string[] attributesParam, int[] disclosedIndices, int[] committedIndices, string messageParam, string verifierScopeParam, IssuerParametersComposite ipc, UProveTokenComposite tokenComposite, byte[] tokenPrivateKeyParam, string sessionID)
        {
            /*
             *  token presentation
             */

            cOut.write("Presenting a U-Prove token");
            VerifySessionId(sessionID);
            try
            {
                // specify the attribute values agreed to by the Issuer and Prover
                int      numberOfAttributes = attributesParam.Length;
                byte[][] attributes         = new byte[numberOfAttributes][];
                for (int i = 0; i < numberOfAttributes; i++)
                {
                    attributes[i] = encoding.GetBytes(attributesParam[i]);
                }

                IssuerParameters ip = ConvertUtils.convertIssuerParametersComposite(ipc, sessionDB[sessionID]);
                // the application-specific message that the prover will sign. Typically this is a nonce combined
                // with any application-specific transaction data to be signed.
                byte[] message = encoding.GetBytes(messageParam);

                // the application-specific verifier scope from which a scope-exclusive pseudonym will be created
                // (if null, then a pseudonym will not be presented)
                byte[] scope = null;
                if (verifierScopeParam != null && verifierScopeParam != "null")
                {
                    scope = encoding.GetBytes(verifierScopeParam);
                }

                // generate the presentation proof
                UProveToken       uProveToken = ConvertUtils.convertUProveTokenComposite(ip, tokenComposite);
                byte[]            bigInt      = tokenPrivateKeyParam;
                DeviceManager     dManager    = sessionDB[sessionID].deviceManager;
                UProveKeyAndToken keyAndToken = new UProveKeyAndToken();
                keyAndToken.PrivateKey = new BigInteger(1, bigInt);
                keyAndToken.Token      = uProveToken;
                byte[] proofSession = null;
                if (!dManager.IsVirtualDevice)
                {
                    SmartCardDevice smartDevice = (SmartCardDevice)dManager.GetDevice();
                    smartDevice.ProofSession = smartDevice.Device.BeginCommitment(1);
                    byte[] proofSessionRaw = smartDevice.ProofSession;
                    proofSession    = new byte[1 + proofSessionRaw.Length];
                    proofSession[0] = 1;
                    Buffer.BlockCopy(proofSessionRaw, 0, proofSession, 1, proofSessionRaw.Length);
                }
                BigInteger[]      commitmentValues;
                PresentationProof p =
                    PresentationProof.Generate(ip,
                                               disclosedIndices,
                                               committedIndices,
                                               scope != null ? DevicePseudonymIndex : 0,
                                               scope,
                                               message,
                                               proofSession,
                                               dManager.GetDevice().GetPresentationContext(),
                                               keyAndToken,
                                               attributes,
                                               out commitmentValues);
#if DEBUG
                dManager.pDebug = p;
#endif

                return(ConvertUtils.convertPresentationProof(p, commitmentValues, ProtocolHelper.ComputeTokenID(ip, uProveToken), proofSession));
            }
            catch (Exception e)
            {
                cOut.write(e.ToString());
                DebugUtils.DebugPrint(e.StackTrace.ToString());
            }

            return(null);
        }