Home > Archive > Windows CE Applications Development > May 2006 > [Urgent] Secure e-mail on pocket pc 5.0
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
[Urgent] Secure e-mail on pocket pc 5.0
|
|
| Antoine 2006-04-26, 4:09 am |
| Hi,
Like I've already explained here, I need to protect the e-mail on a
pocket pc 5.0.
My solution is like this:
Protect:
I mount the cemail.vol, enumerate all the databases and for each, I
create the same database in a personal volume, which I fill with the
same records.
So, I obtain a copy of the cemail volume.
I can, now, delete every record of every database of cemail.vol.
Release:
I make exactly the same but it is cemail.vol which is the copy of my volume.
But there is a problem. Poutlook don't see the e-mail. I believe this is
because the pim volume keep informations about the records in the
cemails databases. So after a protect action and release action, the
ceoid of each record have changed. I think that I must actualize the
pim.vol.
Is that the solution?
And if yes, how should I do to actualize pim.vol?
--
Antoine BELSOEUR
Ingénieur R&D
Everbee Networks
41, boulevard des Capucines
75002 Paris
Tel: +33 1 44 55 01 55
Fax: +33 1 44 55 01 50
Email: abelsoeur@everbee.com
Web: http://www.everbee.com
| |
| Antoine 2006-05-09, 4:34 am |
| Hi,
Like I've already explained here, I need to protect the e-mail on a
pocket pc 5.0.
My solution is like this (it has a little changed):
Protect:
I mount the cemail.vol, enumerate all the databases and for each, I
create a database in a personal volume.
This DB has the same CEDBASEINFOEX than the cemail.vol's DB.
But each record has 3 properties:
First: A ceblob which is the copy of the buffer get with
"CeReadRecordPropsEx".
Second: A DWORD (UI4) which is the number of properties that the ceblob
contains.
Third: A DWORD (UI4) which contains the ceoid of the record in the ceblob.
Now I've got all the informations needed, I can EMPTY the records of
cemail.vol's DB. I say empty and not delete because it will be easier to
restore the database in this way.
My code is:
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> // SECURE FUNCTION
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> BOOL SecureCemail()
> {
>
> /********* SECURE FUNCTION *********/
> /********* STEP 1: Mount the 2 volumes *********/
>
> CEGUID ceguidCemail;
> CEGUID ceguidBackUp;
>
> //Initialisation
> CREATE_INVALIDEDBGUID(&ceguidCemail);
> CREATE_INVALIDEDBGUID(&ceguidBackUp);
>
> //
> if(!CeMountDBVol( &ceguidCemail, L"cemail.vol", OPEN_EXISTING))
> {
> return FALSE;
> }
>
> if(!CeMountDBVol( &ceguidBackUp, L"cemailbackup.vol", CREATE_ALWAYS))
> {
> return FALSE;
> }
>
> /********* SECURE FUNCTION *********/
> /********* STEP 1 *********/
>
> /********* SECURE FUNCTION *********/
> /********* STEP 2: Enumerate and Secure each Database *********/
>
> HANDLE hDatabaseEnumHandle = INVALID_HANDLE_VALUE;
>
> if((hDatabaseEnumHandle = CeFindFirstDatabaseEx(&ceguidCemail, 0)) == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
> CEOID ceoidFind = 0;
> while(ceoidFind = CeFindNextDatabaseEx(hDatabaseEnumHandle
, NULL))
> {
>
> /** SECURE FUNCTION **/
> /** STEP 2A: Open the Database found, create its copy and open it **/
>
> // open
> HANDLE hDBOpened = INVALID_HANDLE_VALUE;
> hDBOpened = CeOpenDatabaseEx2(&ceguidCemail, &ceoidFind, NULL, NULL, CEDB_AUTOINCREMENT, NULL);
> if(hDBOpened == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
>
> // get informations
> BY_HANDLE_DB_INFORMATION hDBOpenedInfo;
> hDBOpenedInfo.wVersion = 1;
> if(!CeGetDBInformationByHandle( hDBOpened, &hDBOpenedInfo))
> {
> return FALSE;
> }
>
>
> // The three database "pmailFolders", "pmailMsgClasses" and "pmailNamedProps" doesn't be secured
> // because they doesn't seem contain significant information
> if(wcsncmp(hDBOpenedInfo.infDatabase.szDbaseName, L"pmailFolders", 12)
> &&
> wcsncmp(hDBOpenedInfo.infDatabase.szDbaseName, L"pmailMsgClasses", 15)
> &&
> wcsncmp(hDBOpenedInfo.infDatabase.szDbaseName, L"pmailNamedProps", 15))
> {
>
> // create a copy
> CEOID ceoidDBaseCopy = 0;
> if(!(ceoidDBaseCopy = CeCreateDatabaseEx2(&ceguidBackUp, &hDBOpenedInfo.infDatabase)))
> {
> return FALSE;
> }
>
> //open the copy
> HANDLE hDBaseCopyHandle = INVALID_HANDLE_VALUE;
> hDBaseCopyHandle = CeOpenDatabaseEx2(&ceguidBackUp, &ceoidDBaseCopy, hDBOpenedInfo.infDatabase.szDbaseName, NULL , CEDB_AUTOINCREMENT, NULL);
> if(hDBaseCopyHandle == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
> /** SECURE FUNCTION **/
> /** STEP 2A **/
>
> /** SECURE FUNCTION **/
> /** STEP 2B: Make a first enumeration to count the record**/
> //this solution protect us of the conflict between CeReadRecordPropsEx and CeWriteRecordProps
>
> WORD dwPropId = 0;
> BYTE* Buffer = NULL;
> DWORD dwSizeOfBuffer = 0;
> DWORD dwCpt = 0;
> CEOID ceoidFindRecord = 0;
> HANDLE hHeap = NULL;
> hHeap = GetProcessHeap();
>
> if(hHeap == NULL)
> return FALSE;
>
> while(ceoidFindRecord = CeReadRecordPropsEx(hDBOpened, CEDB_ALLOWREALLOC, &dwPropId, NULL, &Buffer, &dwSizeOfBuffer, hHeap))
> dwCpt++;
>
> if(GetLastError() != ERROR_NO_MORE_ITEMS))
> return FALSE;
>
> CeS DatabaseEx(hDBOpened, CEDB_SEEK_BEGINNING, 0, 0, NULL);
> ceoidFindRecord = 0;
>
> free(Buffer);
> Buffer = NULL;
> dwPropId = 0;
> dwSizeOfBuffer = 0;
> /** SECURE FUNCTION **/
> /** STEP 2B **/
>
> /** SECURE FUNCTION **/
> /** STEP 2C: Save all the records **/
> DWORD dwNumberOfRecordFound = 0;
> while(dwNumberOfRecordFound++ < dwCpt)
> {
> ceoidFindRecord = CeReadRecordPropsEx(hDBOpened, CEDB_ALLOWREALLOC, &dwPropId, NULL, &Buffer, &dwSizeOfBuffer, hHeap);
> if(!ceoidFindRecord)
> {
> return FALSE;
> }
>
>
> CEPROPVAL* temp;
> temp = (CEPROPVAL*) malloc(dwSizeOfBuffer);
> memcpy(temp, Buffer, dwSizeOfBuffer);
> CEOID ceoidRecordAdd = 0;
>
> CEPROPVAL props[3];
>
> props[0].propid = MAKEPROP(101,BLOB);
> props[0].val.blob.dwCount = dwSizeOfBuffer;
> props[0].val.blob.lpb = (BYTE*)malloc(dwSizeOfBuffer);
> memcpy(props[0].val.blob.lpb, Buffer, dwSizeOfBuffer);
> props[0].wFlags = 0;
>
> for(DWORD ii = 0; ii<dwPropId; ii++)
> {
> CEPROPVAL* TMP = (CEPROPVAL*)(props[0].val.blob.lpb);
> switch(LOWORD(TMP[ii].propid))
> {
> case CEVT_LPWSTR:
> wcsncpy(TMP[ii].val.lpwstr, temp[ii].val.lpwstr, wcslen(temp[ii].val.lpwstr));
> break;
> }
> }
>
> props[1].propid = MAKEPROP(102,UI4);
> props[1].val.ulVal = dwPropId;
> props[1].wFlags = 0;
>
> props[2].propid = MAKEPROP(102,UI4);
> props[2].val.ulVal = ceoidFindRecord;
> props[2].wFlags = 0;
>
> ceoidRecordAdd = CeWriteRecordProps(hDBaseCopyHandle, 0, 3, props);
>
> if(!ceoidRecordAdd)
> {
> return FALSE;
> }
>
> /** SECURE FUNCTION **/
> /** STEP 2C **/
>
> /** SECURE FUNCTION **/
> /** STEP 2D: Empty every records **/
> // We don't delete the records because we need to keep them in the database
> // with the same ceoid.
> for(DWORD ii = 0; ii<dwPropId; ii++)
> {
> temp[ii].wFlags = CEDB_PROPDELETE;
> }
>
> ceoidRecordAdd = 0;
> ceoidRecordAdd = CeWriteRecordProps(hDBOpened, ceoidFindRecord, dwPropId, temp);
> if(!ceoidRecordAdd)
> {
> return FALSE;
> }
>
>
> /** SECURE FUNCTION **/
> /** STEP 2D **/
>
> free(temp);
> temp = NULL;
> free(Buffer);
> Buffer = NULL;
> }
>
>
> }
> }
> /********* SECURE FUNCTION *********/
> /********* STEP 2 *********/
>
>
> /********* SECURE FUNCTION *********/
> /********* STEP 3: Save the modification of the volumes and unmount them *********/
>
> if(!CeFlushDBVol(&ceguidCemail))
> return FALSE;
> if(!CeFlushDBVol(&ceguidBackUp))
> return FALSE;
> if(!CeUnmountDBVol(&ceguidCemail))
> return FALSE;
> if(!CeUnmountDBVol(&ceguidBackUp))
> return FALSE;
>
> /********* SECURE FUNCTION *********/
> /********* STEP 3 *********/
>
> return TRUE;
> }
Restore:
I mount my volume, get every database and for each DB found, I restore
every record in the ceblob.
The code is:
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
> // RESTORE FUNCTION
> ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
>
> BOOL RestoreCemail()
> {
>
> /********* RESTORE FUNCTION *********/
> /********* STEP 1: Mount the 2 volumes *********/
>
> CEGUID ceguidBackUp;
> CEGUID ceguidCemail;
>
> //Initialisation
> CREATE_INVALIDEDBGUID(&ceguidBackUp);
> CREATE_INVALIDEDBGUID(&ceguidCemail);
>
>
> if(!CeMountDBVol( &ceguidBackUp, L"cemailbackup.vol", OPEN_EXISTING))
> {
> return FALSE;
> }
>
> if(!CeMountDBVol( &ceguidCemail, L"cemail.vol", OPEN_EXISTING))
> {
>
> return FALSE;
> }
>
> /********* RESTORE FUNCTION *********/
> /********* STEP 1 *********/
>
> /********* RESTORE FUNCTION *********/
> /********* STEP 2: Enumerate and Restore each Database *********/
>
> HANDLE hDatabaseEnumHandle = INVALID_HANDLE_VALUE;
>
> if((hDatabaseEnumHandle = CeFindFirstDatabaseEx(&ceguidBackUp, 0)) == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
> CEOID ceoidFind = 0;
>
> while(ceoidFind = CeFindNextDatabaseEx(hDatabaseEnumHandle
, NULL))
> {
>
> /** RESTORE FUNCTION **/
> /** STEP 2A: Open the Database found and open its original **/
>
> // open
> HANDLE hDBOpened = INVALID_HANDLE_VALUE;
> hDBOpened = CeOpenDatabaseEx2(&ceguidBackUp, &ceoidFind, NULL, NULL, CEDB_AUTOINCREMENT, NULL);
> if(hDBOpened == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
> // get informations
> BY_HANDLE_DB_INFORMATION hDBOpenedInfo;
> hDBOpenedInfo.wVersion = 1;
> if(!CeGetDBInformationByHandle( hDBOpened, &hDBOpenedInfo))
> {
> return FALSE;
> }
>
>
> //open the copy
> CEOID ceoidDBaseOriginal = 0;
> HANDLE hDBaseOriginalHandle = INVALID_HANDLE_VALUE;
> hDBaseOriginalHandle = CeOpenDatabaseEx2(&ceguidCemail, &ceoidDBaseOriginal, hDBOpenedInfo.infDatabase.szDbaseName, NULL , CEDB_AUTOINCREMENT, NULL);
> if(hDBaseOriginalHandle == INVALID_HANDLE_VALUE)
> {
> return FALSE;
> }
>
> /** RESTORE FUNCTION **/
> /** STEP 2A **/
>
> /** RESTORE FUNCTION **/
> /** STEP 2B: Read and restore the record **/
>
> WORD dwPropId = 0;
> BYTE* Buffer = NULL;
> DWORD dwSizeOfBuffer = 0;
> HANDLE hHeap = NULL;
> hHeap = GetProcessHeap();
> if(hHeap == NULL)
> return FALSE;
>
> BOOL bDBIsEmpty = FALSE;
> CEOID ceoidFindRecord = 0;
>
> while(!bDBIsEmpty)
> {
> // read
> ceoidFindRecord = CeReadRecordPropsEx(hDBOpened, CEDB_ALLOWREALLOC, &dwPropId, NULL, &Buffer, &dwSizeOfBuffer, hHeap);
> if(!ceoidFindRecord)
> {
> if(GetLastError() != ERROR_NO_MORE_ITEMS)
> return FALSE;
> else
> bDBIsEmpty = TRUE;
> }
> else
> {
> CEPROPVAL* temp;
> temp = (CEPROPVAL*) malloc(dwSizeOfBuffer);
> memcpy(temp, Buffer, dwSizeOfBuffer);
> CEOID ceoidRecordAdd = 0;
>
> // restore
> ceoidRecordAdd = CeWriteRecordProps(hDBaseOriginalHandle,
temp[2].val.ulVal, temp[1].val.uiVal, (CEPROPVAL *)(temp[0].val.blob.lpb));
>
>
>
> if(!ceoidRecordAdd)
> {
> return FALSE;
> }
>
> /** RESTORE FUNCTION **/
> /** STEP 2B **/
>
> /** RESTORE FUNCTION **/
> /** STEP 2C: Delete the record in the Back Up volume **/
> if(!CeDeleteRecord(hDBOpened,ceoidFi
ndRecord))
> return FALSE;
>
> /** RESTORE FUNCTION **/
> /** STEP 2C **/
>
> free(temp);
> temp = NULL;
> free(Buffer);
> Buffer = NULL;
> }
> }
> DebugFunctionW(L"", 1);
> }
> /********* RESTORE FUNCTION *********/
> /********* STEP 2 *********/
>
>
> /********* RESTORE FUNCTION *********/
> /********* STEP 3: Save the modification of the volumes and unmount them *********/
>
> if(!CeFlushDBVol(&ceguidBackUp))
> return FALSE;
> if(!CeFlushDBVol(&ceguidCemail))
> return FALSE;
> if(!CeUnmountDBVol(&ceguidBackUp))
> return FALSE;
> if(!CeUnmountDBVol(&ceguidCemail))
> return FALSE;
> /********* RESTORE FUNCTION *********/
> /********* STEP 3 *********/
>
> return TRUE;
> }
But I've got two problems:
First:
When I call SecureCemail() in a first time and RestoreCemail() in a
second time in the same process, it runs but the heading of each e-mail
(first e-mail except) in each folder is false.
Second:
When I call SecureCemail() in a process. Quit it and call
RestoreCemail() in an other process. It may be don't restore.
(Certainly because the records of the DBs of cemail.vol have been
clean). (This second problem is not really important because the two
functions will be called in the same dll, so. But it's strange.)
I really thanks every person who read this message until the end. f you
have any idea, suggested it me, please.
Thanks
--
Antoine BELSOEUR
Ingénieur R&D
Everbee Networks
41, boulevard des Capucines
75002 Paris
Tel: +33 1 44 55 01 55
Fax: +33 1 44 55 01 50
Email: abelsoeur@everbee.com
Web: http://www.everbee.com
|
|
|
|
|