Copy/Paste only to same application instance

Hi,
We want to control paste operation such a way that it only works if copy is done from same application instance. If I am running two instances 1 and 2 of an application, If I do copy from instance 1, I should not be able to past it on instance 2. This is done for stick IP protection reasons, not allowing user with access to two different systems, copy from one to another system.

Well, I’m not a security expert, but I can see at least two ways of doing this.

First, adding some tag to the clipboard (e.g. a GUID) on a Copy and only allowing a Paste if the application recognizes the GUID.

Second, doing some form of encryption on the data in the clipboard that only the source app can decode.

The first would prevent Paste as long as all the apps were being friendly. It wouldn’t prevent an app from ignoring the GUID and doing a paste.

The second would in theory even prevent malicious apps from stealing data.

Which are we talking about here?

We are talking about putting GUID type of approach here. We use _GoView.EditCopy(); and _GoView.EditCut(); _GoView.EditPaste();commands for copy/cut/paste.Can you suggest how I can overwrite these to say putting some identifier in the buffer in addition to what is being done by default EditCopy() command and extract that during paste command.

Can you please provide some example code on how I can overwrite EditCopy() and EditPaste() methods of goview to just add an additional guid during copy and check that during the paste() operation?

I suggest overriding GoView.CopyToClipboard and GoView.PasteFromClipboard so that they do not operate with the Windows Clipboard, but just with a global variable in memory.

Declare this global variable to act as the in-memory clipboard:

    private static Dictionary<String, GoDocument> myClipboard = new Dictionary<String, GoDocument>();  // simulate Clipboard

Override GoView.CopyToClipboard:

  public override void CopyToClipboard(IGoCollection coll) {
    if (coll == null || coll.IsEmpty) {
      myClipboard.Clear();
    } else {
      GoDocument thisdoc = this.Document;
      if (thisdoc != null) {
        Type doctype = thisdoc.GetType();
        GoDocument clipdoc = (GoDocument)Activator.CreateInstance(doctype);
        // don't need to worry about undo/redo
        clipdoc.UndoManager = null;
        // make sure the clipdoc has the same layers as the view's document,
        // but not the same document objects in those layers
        clipdoc.MergeLayersFrom(thisdoc);
        // now copy selected objects, making sure they go in Z-order
        GoCollection sorted = new GoCollection();
        sorted.InternalChecksForDuplicates = false;
        sorted.AddRange(coll);
        thisdoc.Layers.SortByZOrder(sorted);
        clipdoc.CopyFromCollection(sorted, true, true, new SizeF(), null);
        // and set up the clipboard
        myClipboard.Clear();
        myClipboard[clipdoc.DataFormat] = clipdoc;
      }
    }
  }

Override GoView.PasteFromClipboard:

    public override GoCopyDictionary PasteFromClipboard() {
      GoDocument thisdoc = this.Document;
      if (thisdoc == null)
        return null;
      GoDocument clipdoc = null;
      myClipboard.TryGetValue(thisdoc.DataFormat, out clipdoc);
      if (clipdoc != null) {
        return thisdoc.CopyFromCollection(clipdoc, false, false, new SizeF(1, 1), null);
      }
      return null;
    }

Oh, also:

    public override bool CanEditPaste() {
      if (!CanInsertObjects()) return false;
      GoDocument thisdoc = this.Document;
      if (thisdoc == null) return false;
      return myClipboard.ContainsKey(thisdoc.DataFormat);
    }