public SecondIssuanceMessageComposite getSecondMessage(string[] attributesParam, IssuerParametersComposite ipc, int numberOfTokensParam, FirstIssuanceMessageComposite firstMessage, string sessionID)
    {
      /*
       *  token issuance - generate second message
       */

      cOut.write("Issuing U-Prove tokens - generate second message, prover side");
      VerifySessionId(sessionID);

      try
      {
        string tokenInformationParam = null;
        string proverInformationParam = null;

        // 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]);
        }

        // specify the special field values
        byte[] tokenInformation = (tokenInformationParam == null) ? new byte[] { } : encoding.GetBytes(tokenInformationParam);
        byte[] proverInformation = (proverInformationParam == null) ? new byte[] { } : encoding.GetBytes(proverInformationParam);

        // specify the number of tokens to issue
        int numberOfTokens = numberOfTokensParam;

        IssuerParameters ip = ConvertUtils.convertIssuerParametersComposite(ipc, sessionDB[sessionID]);

        // Convert serializable FirstIssuanceMessageComposite members to FirstIssuanceMessage
        FirstIssuanceMessage fi = ConvertUtils.convertFirstIssuanceMessageComposite(firstMessage, ip);

        // setup the prover and generate the second issuance message
        Prover prover = new Prover(ip, numberOfTokens, attributes, tokenInformation, proverInformation, sessionDB[sessionID].deviceManager.GetDevice());

        // Store the prover in proversDictionary using the sessionKey as key
        sessionDB[sessionID].prover = prover;

        SecondIssuanceMessage sm = prover.GenerateSecondMessage(fi);

        // Convert SecondIssuanceMessage members to serializable SecondIssuanceMessageComposite
        SecondIssuanceMessageComposite smc = ConvertUtils.convertSecondIssuanceMessage(sm);

        // Add the sessionKey to SecondIssuanceMessageComposite
        smc.SessionKey = sessionID;

        return smc;

      }
      catch (Exception e)
      {
        cOut.write(e.ToString());
        DebugUtils.DebugPrint(e.StackTrace.ToString());
      }

      return null;
    }
示例#2
0
        public void TestProver()
        {
            byte[][] A = new byte[][] { };
            byte[] TI = null;
            byte[] PI = null;
            IssuerSetupParameters isp = new IssuerSetupParameters();
            isp.UidP = new byte[] { 0 };
            isp.E = new byte[] { 0 };
            IssuerKeyAndParameters ikap = isp.Generate();
            IssuerProtocolParameters ipp = new IssuerProtocolParameters(ikap);
            ipp.Attributes = A;
            ipp.NumberOfTokens = 1;
            ipp.TokenInformation = TI;
            Issuer issuer = ipp.CreateIssuer();

            FirstIssuanceMessage msg1 = null;
            SecondIssuanceMessage msg2 = null;
            ThirdIssuanceMessage msg3 = null;
    
            msg1 = issuer.GenerateFirstMessage();
            try { new Prover(null, 1, A, TI, PI, null); Assert.Fail(); } catch (ArgumentNullException) { }
            try { new Prover(ikap.IssuerParameters, -1, A, TI, PI, null); Assert.Fail(); } catch (ArgumentException) { }
            try { new Prover(ikap.IssuerParameters, 0, A, TI, PI, null); Assert.Fail(); } catch (ArgumentException) { }
            Prover prover = new Prover(ikap.IssuerParameters, 1, A, TI, PI, null);
            try { prover.GenerateTokens(msg3); Assert.Fail(); } catch (InvalidOperationException) { }
            msg2 = prover.GenerateSecondMessage(msg1);
            try { msg2 = prover.GenerateSecondMessage(msg1); Assert.Fail(); } catch (InvalidOperationException) { }
            msg3 = issuer.GenerateThirdMessage(msg2);
            prover.GenerateTokens(msg3);
            try { prover.GenerateTokens(msg3); Assert.Fail(); } catch (InvalidOperationException) { }
        }