public static void VerifySmartCard(SmartCardDevice smartCardDevice, byte[] com, byte[] response, string hashFunctionName, byte[] proofSession, byte[] challangeMgs) { BigInteger resp = new BigInteger(1, response); //BigInteger comBig = new BigInteger(1, com); HashFunction hash = new HashFunction(hashFunctionName); //hash.Hash(new byte[1] {0x1}); //hash.Hash(1); byte[] proofSessionFoo = new byte[1 + proofSession.Length]; proofSessionFoo[0] = 1; Buffer.BlockCopy(proofSession, 0, proofSessionFoo, 1, proofSession.Length); hash.Hash(proofSessionFoo); hash.Hash(challangeMgs); byte[] cByte = hash.Digest; BigInteger c = new BigInteger(1, cByte); byte[] devicePubKeyByte = smartCardDevice.Device.GetDevicePublicKey(true); //BigInteger devicePubKey = new BigInteger(1, devicePubKeyByte); SubgroupGroupDescription subGq = (SubgroupGroupDescription)smartCardDevice.getGroupDescription(); SubgroupGroupElement leftSide = (SubgroupGroupElement)smartCardDevice.getGroupElement().Exponentiate(resp); SubgroupGroupElement pk = (SubgroupGroupElement)subGq.CreateGroupElement(devicePubKeyByte); SubgroupGroupElement pkc = (SubgroupGroupElement)pk.Exponentiate(c.Negate()); SubgroupGroupElement rightSide = (SubgroupGroupElement)pkc.Multiply(smartCardDevice.getGroupDescription().CreateGroupElement(com)); Console.Out.WriteLine("Printing left and right side"); Utils.PrintByteArrayToConsole(leftSide.GetEncoded()); Utils.PrintByteArrayToConsole(rightSide.GetEncoded()); }
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))); }
internal byte[] SetIssueCredential() { this.EnsureDeviceInit(); SmartCardDevice d = (SmartCardDevice)device; SmartCard s = d.Device; byte[] proofSession = s.BeginCommitment(this.smartCardParam.proverID); s.GetIssuanceCommitment((byte)this.smartCardParam.credID); s.GetIssuanceResponse((byte)this.smartCardParam.credID); return(proofSession); }
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); }
public void Dispose() { this.device = null; }
/// <summary> /// Initializes a new instance of the <see cref="DevicePresentationContext"/> class. /// </summary> /// <param name="device">The device.</param> public DevicePresentationContext(SmartCardDevice device) { this.device = device; }