InitializeBinding Method

Summary
Enables a context management component ("bindee") to initiate the process of establishing a secure binding with another context management component ("binder").
Syntax
C#
VB
C++
public string InitializeBinding( 
   int binderCoupon, 
   object propertyNames, 
   object propertyValues, 
   ref string binderPublicKey 
) 
Function InitializeBinding( _ 
   ByVal binderCoupon As Integer, _ 
   ByVal propertyNames As Object, _ 
   ByVal propertyValues As Object, _ 
   ByRef binderPublicKey As String _ 
) As String 
String^ InitializeBinding(  
   int binderCoupon, 
   Object^ propertyNames, 
   Object^ propertyValues, 
   String^% binderPublicKey 
)  

Parameters

binderCoupon
The binder coupon.

propertyNames
The property names of the technology-specific secure binding-related properties for which the bindee wishes to establish agreement.

propertyValues
The property values.

binderPublicKey
The binder public key.

Return Value

When a passcode-based secure binding is to be established, the value of the output mac is a message authentication code. This code shall be used by the bindee to prove the identity of the binder, and to ensure that the value of binderPublicKey has not been tampered with. When a PKI-based secure binding is to be established, the value of the output mac is a digital signature.

Remarks

A secure binding shall be established by the bindee before it attempts to interact with the binder via methods that entail the use of either the bindee's or the binder's digital signature. For example, an application or user mapping agent shall establish a secure binding with the context manager before it attempts to access the context manager in order to set or get context item values that require the bindee's digital signature.

Example

Joins a common context and set patient information.

C#
VB
using Leadtools; 
using Leadtools.Ccow; 
using Leadtools.Ccow.UI; 
 
 
public void SecureBinding() 
{ 
	IContextManager contextManager = Utils.COMCreateObject<IContextManager>(CcowProgId); 
	SecureParticipant participant = new SecureParticipant(); 
	ISecureBinding secure = contextManager as ISecureBinding; 
	int coupon = 0; 
 
	try 
	{ 
		string binderPublicKey = string.Empty; 
		string mac = string.Empty, hash; 
		object access; 
 
		coupon = contextManager.JoinCommonContext(participant, ApplicationName, true, false); 
 
		// 
		// Bind securely context manager 
		// 
		mac = secure.InitializeBinding(coupon, Constants.PassCodeNames, Constants.PassCodeValues, ref binderPublicKey); 
		hash = Utils.BinaryEncode(Utils.Hash(binderPublicKey + SecureParticipant.Passcode)); 
		Debug.Assert(mac.ToLower() == hash.ToLower()); 
 
		// 
		// Create participant mac and finalize binding 
		// 
		mac = Utils.BinaryEncode(Utils.Hash(participant.PublicKey + SecureParticipant.Passcode)); 
		access = secure.FinalizeBinding(coupon, participant.PublicKey, mac); 
 
		// 
		// Display access 
		// 
		if (access != null) 
		{ 
			string[] a = (string[])access; 
 
			for (int i = 0; i < a.Length; i += 2) 
			{ 
				Debug.WriteLine(string.Format("     {0}\t{1}", a[i], a[i + 1])); 
			} 
		} 
		SetUserContext(contextManager, participant, coupon); 
		contextManager.LeaveCommonContext(coupon); 
	} 
	catch (Exception e) 
	{ 
		Debug.WriteLine(e.Message); 
	} 
} 
 
private void SetUserContext(IContextManager contextManager, SecureParticipant participant, int coupon) 
{ 
	ISecureContextData secure = contextManager as ISecureContextData; 
	Subject userSubject = new Subject("User"); 
	int transactionCoupon = 0; 
	bool noContinue = true, disconnect = false; 
	object reasons; 
	string decision = "accept"; 
 
	userSubject.Items.Add(new ContextItem("User.id.logon")); 
	userSubject.Items[0].Value = "test"; 
	userSubject.Items.Add(new ContextItem("User.co.Name")); 
	userSubject.Items[1].Value = "Test User"; 
 
	try 
	{ 
		string messageDigest, appSignature; 
		List<string> values = new List<string>(); 
 
		foreach (object v in userSubject.ToItemValueArray()) 
		{ 
			values.Add(v.ToString()); 
		} 
 
		transactionCoupon = contextManager.StartContextChanges(coupon); 
 
		// 
		// Create digital signature 
		// 
		messageDigest = coupon.ToString() + string.Join("", userSubject.ToItemNameArray()) + 
						string.Join("", values.ToArray()) + transactionCoupon.ToString(); 
		appSignature = participant.CreateSignature(messageDigest); 
 
		secure.SetItemValues(coupon, userSubject.ToItemNameArray(), userSubject.ToItemValueArray(), 
							 transactionCoupon, appSignature); 
		reasons = contextManager.EndContextChanges(transactionCoupon, ref noContinue); 
 
		// 
		// If any application responded that they cannot apply the change we need to display 
		// a dialog that displays the reasons for the problems. 
		// 
		if ((reasons != null && ((string[])reasons).Length > 0) || noContinue) 
		{ 
			ProblemDialog pd = new ProblemDialog((string[])reasons, noContinue); 
			DialogResult result; 
 
			result = pd.ShowDialog(); 
			if (noContinue) 
				decision = "cancel"; 
			if (result == DialogResult.OK) 
				decision = "accept"; 
			else if (result == DialogResult.Cancel) 
				decision = "cancel"; 
			else 
			{ 
				decision = "cancel"; 
				disconnect = true; 
			} 
		} 
 
		// 
		// If user decided to break context we must leave 
		// 
		contextManager.PublishChangesDecision(transactionCoupon, decision); 
		if (disconnect) 
		{ 
			contextManager.LeaveCommonContext(coupon); 
		} 
 
	} 
	catch (Exception e) 
	{ 
		Debug.WriteLine(e.Message); 
	} 
 
} 
 
[ComVisible(true)] 
public class SecureParticipant : IContextParticipant 
{ 
	public const string Passcode = "A2C053FC-182C-4167-BB56-EE394BC5DB05"; 
	public const string ApplicationName = "LEADTOOLS CCOW App"; 
 
	private KeyContainer _KeyContainer = null; 
 
	public string PublicKey 
	{ 
		get 
		{ 
			if (_KeyContainer != null) 
				return Utils.BinaryEncode(_KeyContainer.GetPublicKey()); 
			return string.Empty; 
		} 
	} 
 
	public SecureParticipant() 
	{ 
		_KeyContainer = new KeyContainer(ApplicationName); 
	} 
 
	public string CreateSignature(string messageDigest) 
	{ 
		byte[] signature = _KeyContainer.Sign(messageDigest); 
 
		return Utils.BinaryEncode(signature); 
	} 
 
	#region IContextParticipant Members 
 
	public void CommonContextTerminated() 
	{ 
		Console.WriteLine("CommonContextTerminated"); 
	} 
 
	public void ContextChangesAccepted(int contextCoupon) 
	{ 
		Console.WriteLine("ContextChangesAccepted"); 
	} 
 
	public void ContextChangesCanceled(int contextCoupon) 
	{ 
		Console.WriteLine("ContextChangesCanceled"); 
	} 
 
	public string ContextChangesPending(int contextCoupon, ref string reason) 
	{ 
		reason = string.Empty; 
		Console.WriteLine("ContextChangesPending"); 
		return "accept"; 
	} 
 
	public void Ping() 
	{ 
	} 
 
	#endregion 
} 
Imports Leadtools 
Imports Leadtools.Ccow 
Imports Leadtools.Ccow.UI 
 
Public Sub SecureBinding() 
   Dim contextManager As IContextManager = Utils.COMCreateObject(Of IContextManager)(CcowProgId) 
   Dim participant As SecureParticipant = New SecureParticipant() 
   Dim secure As ISecureBinding = TryCast(contextManager, ISecureBinding) 
   Dim coupon As Integer = 0 
 
   Try 
      Dim binderPublicKey As String = String.Empty 
      Dim mac As String = String.Empty, hash As String 
      Dim access As Object 
 
      coupon = contextManager.JoinCommonContext(participant, ApplicationName, True, False) 
 
      ' 
      ' Bind securely context manager 
      ' 
      mac = secure.InitializeBinding(coupon, Leadtools.Ccow.Constants.PassCodeNames, Leadtools.Ccow.Constants.PassCodeValues, binderPublicKey) 
      hash = Utils.BinaryEncode(Utils.Hash(binderPublicKey & SecureParticipant.Passcode)) 
      Debug.Assert(mac.ToLower() = hash.ToLower()) 
 
      ' 
      ' Create participant mac and finalize binding 
      ' 
      mac = Utils.BinaryEncode(Utils.Hash(participant.PublicKey + SecureParticipant.Passcode)) 
      access = secure.FinalizeBinding(coupon, participant.PublicKey, mac) 
 
      ' 
      ' Display access 
      ' 
      If Not access Is Nothing Then 
         Dim a As String() = CType(access, String()) 
 
         Dim i As Integer = 0 
         Do While i < a.Length 
            Debug.WriteLine(String.Format("     {0}" & Microsoft.VisualBasic.Constants.vbTab & "{1}", a(i), a(i + 1))) 
            i += 2 
         Loop 
      End If 
      SetUserContext(contextManager, participant, coupon) 
      contextManager.LeaveCommonContext(coupon) 
   Catch e As Exception 
      Debug.WriteLine(e.Message) 
   End Try 
End Sub 
 
Private Sub SetUserContext(ByVal contextManager As IContextManager, ByVal participant As SecureParticipant, ByVal coupon As Integer) 
   Dim secure As ISecureContextData = TryCast(contextManager, ISecureContextData) 
   Dim userSubject As Subject = New Subject("User") 
   Dim transactionCoupon As Integer = 0 
   Dim noContinue As Boolean = True, disconnect As Boolean = False 
   Dim reasons As Object 
   Dim decision As String = "accept" 
 
   userSubject.Items.Add(New ContextItem("User.id.logon")) 
   userSubject.Items(0).Value = "test" 
   userSubject.Items.Add(New ContextItem("User.co.Name")) 
   userSubject.Items(1).Value = "Test User" 
 
   Try 
      Dim messageDigest, appSignature As String 
      Dim values As List(Of String) = New List(Of String)() 
 
      For Each v As Object In userSubject.ToItemValueArray() 
         values.Add(v.ToString()) 
      Next v 
 
      transactionCoupon = contextManager.StartContextChanges(coupon) 
 
      ' 
      ' Create digital signature 
      ' 
      messageDigest = coupon.ToString() & String.Join("", userSubject.ToItemNameArray()) + String.Join("", values.ToArray()) + transactionCoupon.ToString() 
      appSignature = participant.CreateSignature(messageDigest) 
 
      secure.SetItemValues(coupon, userSubject.ToItemNameArray(), userSubject.ToItemValueArray(), transactionCoupon, appSignature) 
      reasons = contextManager.EndContextChanges(transactionCoupon, noContinue) 
 
      ' 
      ' If any application responded that they cannot apply the change we need to display 
      ' a dialog that displays the reasons for the problems. 
      ' 
      If (Not reasons Is Nothing AndAlso (CType(reasons, String())).Length > 0) OrElse noContinue Then 
         Dim pd As ProblemDialog = New ProblemDialog(CType(reasons, String()), noContinue) 
         Dim result As DialogResult 
 
         result = pd.ShowDialog() 
         If noContinue Then 
            decision = "cancel" 
         End If 
         If result = System.Windows.Forms.DialogResult.OK Then 
            decision = "accept" 
         ElseIf result = DialogResult.Cancel Then 
            decision = "cancel" 
         Else 
            decision = "cancel" 
            disconnect = True 
         End If 
      End If 
 
      ' 
      ' If user decided to break context we must leave 
      ' 
      contextManager.PublishChangesDecision(transactionCoupon, decision) 
      If disconnect Then 
         contextManager.LeaveCommonContext(coupon) 
      End If 
 
   Catch e As Exception 
      Debug.WriteLine(e.Message) 
   End Try 
 
End Sub 
 
<ComVisible(True)> 
Public Class SecureParticipant 
   Implements IContextParticipant 
 
   Public Const Passcode As String = "A2C053FC-182C-4167-BB56-EE394BC5DB05" 
   Public Const ApplicationName As String = "LEADTOOLS CCOW App" 
 
   Private _KeyContainer As KeyContainer = Nothing 
 
   Public ReadOnly Property PublicKey() As String 
      Get 
         If Not _KeyContainer Is Nothing Then 
            Return Utils.BinaryEncode(_KeyContainer.GetPublicKey()) 
         End If 
         Return String.Empty 
      End Get 
   End Property 
 
   Public Sub New() 
      _KeyContainer = New KeyContainer(ApplicationName) 
   End Sub 
 
   Public Function CreateSignature(ByVal messageDigest As String) As String 
      Dim signature As Byte() = _KeyContainer.Sign(messageDigest) 
 
      Return Utils.BinaryEncode(signature) 
   End Function 
 
   Public Sub CommonContextTerminated() Implements IContextParticipant.CommonContextTerminated 
      Console.WriteLine("CommonContextTerminated") 
   End Sub 
 
   Public Sub ContextChangesAccepted(ByVal contextCoupon As Integer) Implements IContextParticipant.ContextChangesAccepted 
      Console.WriteLine("ContextChangesAccepted") 
   End Sub 
 
   Public Sub ContextChangesCanceled(ByVal contextCoupon As Integer) Implements IContextParticipant.ContextChangesCanceled 
      Console.WriteLine("ContextChangesCanceled") 
   End Sub 
 
   Public Function ContextChangesPending(ByVal contextCoupon As Integer, ByRef reason As String) As String Implements IContextParticipant.ContextChangesPending 
      reason = String.Empty 
      Console.WriteLine("ContextChangesPending") 
      Return "accept" 
   End Function 
 
   Public Sub Ping() Implements IContextParticipant.Ping 
   End Sub 
 
 
End Class 
Requirements

Target Platforms

Help Version 21.0.2021.3.3
Products | Support | Contact Us | Intellectual Property Notices
© 1991-2021 LEAD Technologies, Inc. All Rights Reserved.

Leadtools.Ccow Assembly