Jump to content

TrueCrypt automation


Envoi
 Share

Recommended Posts

Hello AutoIt community,

I'm working on a program for work that will automagically mount a TrueCrypt volume from a USB drive. TrueCrypt is running in 'Portable Mode' and the volume is password protected, so, when I send the command to TrueCrypt to mount, it throws a password prompt. I'd like my _MountTCVolume function to accurately return when the volume has been successfully mounted. This is where I'm stumped. Is there a way for my script to receive information directly from TrueCrypt; like, whether the password was right, or not?

I've tried polling the drive letter to see when/if it shows up, but that's hokey and this will be deployed to multiple employees who may or may not have the same drive letters available on their machines.

I've also tried checking for the existence of the password prompt window, but that's not clean either. Besides, if the password's wrong, the window blinks away, then reappears.

Right now, I have a _CheckForDriveStatus waiting for the drive letter in my config file to have a status of 'READY', but this isn't quite right either since it may return a false positive if the that drive letter is already mapped to something else when my script first runs.

As far as I could find, there's no TrueCrypt API or anything.

I hope this isn't something super simple I've over looked. Any help pointing me in the right direction would be greatly appreciated.

Thanks!

Link to comment
Share on other sites

I did briefly try reading the stream from TrueCrypt, but wasn't getting anything useful. I'm going to try again right now. I think the problem was that when I send the Run command, Truecrypt spawns a couple of child windows and I wasn't sure how to grab the output from one particular process.

Either way, thanks for the reply. You at least gave me some hope that trying the STDOUTREAD was a way to tackle it. I'll post back with results. Thanks again.

Link to comment
Share on other sites

Have a look at this It may help.

Adam

After glancing at this, it didn't look like anything that I haven't tried was being done here, but I gave it a whirl. As expected, the _TC_Mount function returns before you can even begin entering the password for the volume. Pretty much the same thing I encountered. Maybe this worked in previous versions of TrueCrypt, but not in 7.1. I appreciate your input, though, AdamUL.

I haven't looked at KaFu's function yet. Hopefully I'll have time today.

PS

I apologize for not including code. I just know it would be a pain for anyone to look at right now with its dependencies, but if someone would like to delve into this with me, I'll work on a version that doesn't require the config files I'm using (Thanks eltorro for _ConfigIO.au3), and such.

Thanks everyone.

Link to comment
Share on other sites

Here's an old function of mine for creating containers:

I took a look at your function KaFu. I appreciate your time, but I don't think there's anything I can grab from that. Thank you anyways.

I decided to quickly whip together a version that someone could run. It has the 'portable TrueCrypt' included in the zip and a very small 2MB empty volume. I password protected it so you can observe the same prompts I get. The password is '1234'.

I've stripped out all of the attempts I made to have _MountTCVolume return a true success to hopefully avoid influencing anyone method. I'm open to all kinds of suggestions at this point.

Here's the ZIP file:

http://dl.dropbox.com/u/21115339/No%20Config%20Version.zip

Thanks in advance for any more help.

Link to comment
Share on other sites

The script waited at the RunWait() until the TC PID did not exist anymore. Any for what would you need the StdOut? Just check afterwards if the drive has been mounted to the assigned letter... and the password prompt popped up because you forgot to pass the password parameter ..

Edited by KaFu
Link to comment
Share on other sites

Upsa, just re-read your request and found that my above answer does not fit at all to your question :graduated: ...

Here is another attempt:

SAGEcrypt.zip

Note the usage of the function _Number_of_mounted_TCs(), with that function you can imho solve the overall problem, maybe you need to rearrange and improve the _CheckForDriveStatus() function (which goes into an endless loop if the container is not mounted).

Link to comment
Share on other sites

Upsa, just re-read your request and found that my above answer does not fit at all to your question :graduated: ...

Here is another attempt:

SAGEcrypt.zip

Note the usage of the function _Number_of_mounted_TCs(), with that function you can imho solve the overall problem, maybe you need to rearrange and improve the _CheckForDriveStatus() function (which goes into an endless loop if the container is not mounted).

Awesome! I like it. I wish I was to the point that I could say to myself 'Oh, I'm sure this could be done with simple QueryDosDevice call.' I feel like the DLLCall() stuff is still over my head. I think this will outright do away with that ugly _CheckForDriveStatus() function all together.

Thank you very much for your time. I'm going to work today on integrating this into my script. I'll post back with an update.

Link to comment
Share on other sites

Ok. Either I'm just going nuts, or I'm back to square one.

While the WinAPI functions in your example, KaFu, are a lot more precise in checking for the existence of the TrueCrypt drive, I'm still getting a return from _MountTCVolume() too soon. Which, I think, brings me right back to an ugly While loop polling for the TrueCrypt drive's existence (or the addition of a TrueCrypt drive from what was there when the script started).

The RunWait() in the _MountTCVolume() is waiting, but only for the parent process which closes after spawning the password prompt. Thus, when I run the example in KaFu's version, and pause briefly when I get the password prompt, I see _MountTCVolume() write to the console "TrueCrypt drive not mounted" before the password's even been attempted. Arg!

I'm thinking I need to figure out how to grab handles to the processes that the first TrueCrypt process (the one that Run() is returning) spawns. However, I can foresee an issue with a wrong password being entered, the prompt disappears, a 'wrong password' dialog shows, then the password prompt is shown again with, presumably, a new process ID.

I'm sorry for beating this thing to death, but I think I need some more ideas. My next direction is to see if I can incorporate Ascend4nt's to get all of the children that the parent TrueCrypt process spawns and go from there. Any direction in the meantime is greatly appreciated.

Link to comment
Share on other sites

I guess I placed the function at the wrong place (was meant for demonstration only :graduated:). It should be part of the _CheckForDriveStatus() function. It would be even better to just query the drive letter used as the target to check. Also I would either define the as a global variable or pass it around via the function calls (I tend to do it too much the first way because of laziness ;)).

Link to comment
Share on other sites

I guess I placed the function at the wrong place (was meant for demonstration only :graduated:). It should be part of the _CheckForDriveStatus() function. It would be even better to just query the drive letter used as the target to check. Also I would either define the as a global variable or pass it around via the function calls (I tend to do it too much the first way because of laziness ;)).

Don't worry about it. I think the underlying issue still remains. Even if we move the functions around, I'm still stuck with a polling solution. I'd either have the application poll indefinitely for the existence of the drive letter, and chance hanging in limbo for eternity. Or, poll for a certain amount of time and return a failure if the password is not entered in the time allotted.

Neither seem like reasonable methods. So, I'm still looking. Unfortunately, I've hit so many dead ends (mostly due to my lack of experience) that I may just have to poll and warn the user with something like, "You will have 30 seconds to successfully enter the password before the application quits for security reasons."

Thank for all of your help so far KaFu!

Link to comment
Share on other sites

You could wait for the the login window to close before checking to see if the drive letter exist with WinWaitClose.

Here are a few example of using WinWaitClose.

WinWaitClose("Enter password for")
WinWaitClose("Enter password for", "", 30) ;Timeout after 30 seconds.
WinWaitClose("Enter password for", "Mount Opti&ons")
WinWaitClose("[CLASS:#32770]", "")
WinWaitClose("[TITLE:Enter password for; CLASS:#32770]", "")

Adam

Link to comment
Share on other sites

You could wait for the the login window to close before checking to see if the drive letter exist with WinWaitClose.

Here are a few example of using WinWaitClose.

WinWaitClose("Enter password for")
WinWaitClose("Enter password for", "", 30) ;Timeout after 30 seconds.
WinWaitClose("Enter password for", "Mount Opti&ons")
WinWaitClose("[CLASS:#32770]", "")
WinWaitClose("[TITLE:Enter password for; CLASS:#32770]", "")

Adam

Tried that. Problem is if a wrong password is entered, the window closes, does some hidden magic, then bring up the prompt again with a new PID. :-(

Thanks for the input though! I appreciate it.

Link to comment
Share on other sites

Try this loop and see if it works for you.

$sWinTitlePW = "Enter password for"
$sWinTitleIPW = "TrueCrypt"
$sWinTextIPW = "Incorrect password"
 
WinWait($sWinTitlePW)
 
While WinExists($sWinTitlePW) Or WinExists($sWinTitleIPW, $sWinTextIPW)
 
WinWaitClose($sWinTitlePW)
WinWait($sWinTitleIPW, $sWinTextIPW, 1)
WinWaitClose($sWinTitleIPW, $sWinTextIPW, 1)
 
WEnd
 
MsgBox(0, "Result", "Correct Password or Cancel Button Clicked.") ;For testing.  
;Check to see if the drive is mounted.

It checks to see if both the "Enter Password" and the "Incorrect Password" dialog boxes do not exist, then continues the script.

Edit: Update Code.

Adam

Edited by AdamUL
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...