« The 10 Most Important Things To Know | Main| What about Nuku'alofa? »

Is it really that hard to tell if a document is encrypted? Please help!

Tags: development

I am a bit frustrated. For a customer application I need to determine whether a document a user has selected in a view is encrypted or not. "Geez, now, that's easy", I hear you say. That's what I thought as well. Exactly for that purpose the NotesGod invented the NotesDocument.IsEncrypted method (I thought). Unfortunately either I am missing something blatantly obvious or the property just doesn't work properly.

I have tested several situations in several client versions and it seems that in one situation the NotesDocument.IsEncrypted method is not working as expected (tested in Notes 6.5.6, 7.0.2 and 8.0.1).

Scenario

A user has opened the Inbox folder of his/her mail file. The user starts a LotusScript agent (in my case using an action) which processes all selected documents and tries to determine which of the selected documents are encrypted. This is done using the UnprocessedDocuments property of the current database.

Error Description

If a document is encrypted for the current user using his/her public key (which usually is the case for encrypted mails in a user's mailbox) the NotesDocument.IsEncrypted method returns False for all documents, regardless of whether they actually are encrypted or not.

When I looked at an encrypted document in the Debugger I saw to my amazement that not only the IsEncrypted property was false but also the items $Seal and $SealData were missing from the items list of the document. When looking at the document's properties in the Inbox (or any other view) the $Seal and $SealData items are listed in the properties box.

If the agent is executed on a document which is encrypted for another user (e.g. me running the agent in the mail file of a test user) the property works as expected. If the document is open in the UI the property works as expected as well.

I have tried @IsAvailable($Seal) and that works but only in a real formula language agent. If used in an Evaluate statement in my LotusScript agent it returns false as well.

Using the IsEncrypted method of the Body item does not help either because it also returns true if a document is signed but not encrypted.

I have searched the forums, the knowledge base and the fix list database without finding any trace of somebody else having a problem with this.

If anybody has an idea what's wrong here I'd appreciate any help very much.

Sample Agents

To illustrate this here is a little sample agent which does nothing but display the value the IsEncrypted method returns for the first selected document.

Test agent to be run from a view or folder

This agent will return false when run from a view on a single encrypted document and true when run on an encrypted document which is open in the UI.

Update: This sample agent is nearly identical to the example provided in the Domino Designer 6.5 Help. So either the sample agent is incorrect or the property just doesn't work correctly.

Sub Initialize
'-- Test using the first selected document in a view
'-- Action Menu Selection - All selected documents
	Dim sess As New NotesSession
	Dim db As NotesDatabase
	Dim dc As NotesDocumentCollection
	Dim doc As NotesDocument
	
	Set db = sess.CurrentDatabase
	Set dc = db.UnprocessedDocuments
	Set doc = dc.GetFirstDocument
	Msgbox "NotesDocument.IsEncrypted: " + _
		Cstr(doc.IsEncrypted), 0, "Using First Selected Doc in View"
End Sub

Test agent for a document currently open in the UI

This agent will return the correct value when run on a document which is currently open in the UI.

Sub Initialize
'-- Test using the currently open uidocument to retrieve the NotesDocument
'-- Action Menu Selection - Target: None
	Dim uiws As New NotesUIWorkspace
	Dim uidoc As NotesUIDocument
	Dim doc As NotesDocument
	
	Set uidoc = uiws.CurrentDocument
	If Not uidoc Is Nothing Then
		Set doc = uidoc.Document
		Msgbox "NotesDocument.IsEncrypted: " + _
			Cstr(doc.IsEncrypted), 0, "Using Currently Open UIDocument"
	End If
End Sub

Comments

Gravatar Image1 - Um. When you open it as a NotesDocument, the LotusScript NOI unencrypts the document for you...

Emoticon


---* Bill

Gravatar Image2 - Well, yes, but how do I tell if is encrypted then and why is it still encrypted if I do the same when the doc is open in the UI?

Gravatar Image3 - I just tested item.IsEncrypted on 7.0.3 instead of doc.IsEncrypted and it works.

Running an agent from the Inbox folder I got:

Set item = doc.GetFirstItem( "Body" )

item.IsEncrypted = True
doc.IsEncrypted = False

Hope this helps.

Gravatar Image4 - Thanks, Vitor for testing. But I assume that 7.0.3 still also returns item.IsEncrypted=True on signed documents which are not encrypted.

Gravatar Image5 - You're right, I missed that one.

Gravatar Image6 - I found out that you can do this with the UI view... At least the most of it... Check out this NSF: { Link }
(see "using this database" for details).

Gravatar Image7 - Thanks, the uiview approach does work.
I will have to negotiate with my customer though if setting checkmarks is a viable option for the users.

Gravatar Image8 - A comment by Dick Annicchiarico in the forum confirmed what I already had assumed.
Here's an excerpt:
NotesDocument.IsEncrypted checks for both Notes encryption and SMIME encryption, by the way. For Notes encryption, it looks for the presence of a $Seal item in order to return True. In some cases, after a document is decrypted, it deletes the $Seal item, meaning another call to IsEncrypted would return False.

Post A Comment

:-D:-o:-p:-x:-(:-):-\:angry::cool::cry::emb::grin::huh::laugh::lips::rolleyes:;-)

Search

Calendar

MiscLinks

We Use Ytria Lotus Notes Tools For Faster Notes Development and Better Domino Administration

Tags

Site Info