[Dshield] Requiring a key-pair to mount a volume

Stephane Grobety security at admin.fulgan.com
Tue Dec 20 08:59:47 GMT 2005

Hello Adam,

No problem. discussion is the reason I'm hear and, when I'm wrong,
it's far better that I get corrected ;)

But let's have a look at your points.

1/ Yes, you can import and export EFS private keys. The procedure
isn't what you can expect Joe Average to do (in particular if he has
more than one key) but it's doable. It doesn't make it easily
portable, though: in order to use the key in a different account, you
have to link that account with that private key and THAT's complex.
otherwise, you can use the key to read the file but not encrypt them
(at least, not without manual operation).

2/ The recovery agent feature is nice, but unfortunately the default
mode for that is simply not to work (try making a KRA work in an
enterprise environment: it is a very delicate process that is likely
to fail silently. Additionally, on windows XP, the KRA isn't necessary
in order to use encryption and creating one isn't exactly a 1-2-3
process either.

3/ EFS does NOT support multiple users. When one user creates an
encrypted file, only that user and the KRA can decrypt the file until
other users are manually added, regardless of the permissions.
Additionally, there is NO way to add a user to multiple files from the
GUI: you have to do it for each file you ever created. This means that
for all practical uses, EFS is single user only.

4/ I never said it isn't work on USB key. It's just that the process
of having the key moved to a different machine is not trivial and
having the other machine (and user account) make use of that key isn't
trivial either.

The result of all the above is that while it's very easy for a user to
create an encrypted container (or file), the likelihood of him losing
all his data in a very short time is extremely high. In order to
reduce that probability, the number and complexities of the steps are
far higher and require much more knowledge. This is extremely bad

Good luck,

Monday, December 19, 2005, 5:49:50 PM, you wrote:

SA> Stephane,

SA> Not to start a flame war, I just want clear up some Windows FUD.  

SA> 1. EFS is as portable as any other PKI product listed here.  You can
SA> export/import your EFS key (and those of others) from the certificate
SA> manager (Start | Run | certmgr.msc).
SA> 2. Just like with every other PKI implementation, if you don't backup
SA> your key you will loss your data.  But EFS has the ability to specify a
SA> Recovery Agent.  Basically a Recovery Agent allows you to specify a
SA> certificate that when any file is EFS encrypted to an end user
SA> certification it is also encrypted to the recovery agent's certificate.
SA> This way if the user losses his key, the recovery agent can use his key
SA> to decrypt the file.  The setting for this can be found in a GPO under
SA> Computer Configuration | Windows Settings | Security Settings | Public
SA> Key Policies | Encrypting File System.  To my knowledge, the only other
SA> products that support such a mandatory secondary key are fairly
SA> expensive (products made by RSA, Verisign, PGP come to mind).
SA> 3. EFS does support multiple users.  Just like every other PKI product,
SA> you need to get the target person's certificate on your computer
SA> (certmgr.msc).  Then from the target file's properties menu, select
SA> Advanced | Details | Add | Select other user's certificate.
SA> 4. EFS does work on USB keys, as long as you format it with NTFS.

SA> Regards,
SA> Adam Stasiniewicz 
SA> Computer and Communication Services Department 
SA> Milwaukee School of Engineering 
SA> MSCE: Messaging & Security 2003 

SA> -----Original Message-----
SA> From: list-bounces at lists.dshield.org
SA> [mailto:list-bounces at lists.dshield.org] On Behalf Of Stephane Grobety
SA> Sent: Monday, December 19, 2005 9:31 AM
SA> To: General DShield Discussion List
SA> Subject: Re: [Dshield] Requiring a key-pair to mount a volume

SA> Hello Anthony,

SA> Excuse me is this message is a bit large: I included a couple of
SA> sample scripts that should help you solve your problem.

SA> First, I would suggest you avoid using EFS. It's a pretty sure way of
SA> losing all your data is a short time. This feature is really a gadget
SA> more than anything else as it has numerous problems (no support for
SA> multiple accounts, extremely poor portability between systems, etc).
SA> It's really only useful if you want to encrypt a folder on a personal
SA> computer (not on removable media).

SA> Now, there are numerous tools that will allow you to create a virtual
SA> drive (as a file) and mount it as a new partition. Most use password
SA> protection but some will also allow for PKI. I would advise against
SA> PGPDisk, though: it has a tendency to corrupt files (mostly these that
SA> use record-locking and concurrent access) and it's extremely
SA> expensive.

SA> I would suggest you have a look at TrueCrypt which is pretty good but
SA> requires you to enter a password (and, optionally, provide a keyfile)
SA> to mount a volume. It has a traveller mode designed for USB drives and
SA> other removable devices. It's also free and open source.

SA> You could also have a look at DriveCrypt. It is not freeware but
SA> includes support for PKI protection. It's made by the company that
SA> wrote E4M on which TrueCrypt is also based so their feature set are
SA> pretty close. It can, however, make use of keys stored on USB tokens,
SA> smart card, fingerprint readers or any PKCS#11 compatible containers.
SA> It will not, however, work with key pairs from the certificate store.
SA> price is around 50$ IIRC.

SA> Finally, you could use some scripting to achieve your exact goal. Here
SA> is how:

SA> 1/ Get an encryption product that can create encrypted volumes
SA> protected by a passphrase.
SA> 2/ Get a X509 certificate and matching key pair. You do not need to
SA> sign it with a CA if you don't want to (you're not going to use this
SA> for digital signing, just for encryption). Make
SA> 3/ Generate an encrypted volme protected by a long and complex
SA> passphrase (just don't use space: it'll be easier).
SA> 4/ Download and register CAPICOM.dll from Microsoft. This dll allows
SA> easy access to the CryptoAPI functions and the system's secure store.
SA> 5/ Create a script file that will decrypt the passphrase (see exemple
SA> below).

SA> The advantage of this method is that you can keep a copy of the
SA> passphrase on a secure system or simply printed out on a piece of
SA> paper stored in a safe. You can also make that passphrase as long as
SA> you want since you won't have to type it in. The exemple I give is
SA> more or less transparent: you can put the call to decryptfile.vbs into
SA> an autorun batch file and it'll be executed whenever you plug de
SA> device in (e.g "cscript decrypt.vbs keyfile.txt"). Please note that
SA> the certificate is protected by your windows logon account. You can
SA> make variations that use the current system account to allow anyone
SA> using the same machine as you to mount the encrypted volume. If you
SA> lose your USB key, no one will be able to decrypt the keyfile to
SA> retreive the passphrase. Total cost: 0$ if you use TrueCrypt.

SA> If you want the sample script in a more convenient format (i.e. zipped
SA> and attached), please contact me off list.

SA> First file called "Encrypt.vbs". You'll use it to create a key file
SA> that contains your passphrase:
SA> ---- Encrpyt.vbs ----
SA> ' Retreive the argument list
SA> Set objArgs = WScript.Arguments
SA> if objArgs.Count <> 2 then
SA>   Wscript.Echo "This script takes 2 parameters: first one is the name of
SA> the target file, second is the data to encrypt"
SA> else
SA>   KeyFileName = objArgs(0)
SA>   ClearText = objArgs(1)
SA>   ' This part deals with the encryption
SA>   ' Some useful constants for CAPICOM
SA>   ' Create the CAPICOM store object
SA>   Set store = CreateObject("CAPICOM.Store")
SA>   ' Open the store containing the certificate you want to use.
SA>   ' The current parameters only displays the certificates that have been
SA> loaded in the current user's personal store
SA>   ' Optionally, you could use the machine store (Make sure it has the
SA> proper certificate loaded)
SA>   ' The certificate does not need to be valid to be used and you do not
SA> need to have access to the
SA>   ' private key here. It will, however, be necessary to have access to
SA> that private key to decrypt the message
SA>   ' Trigger the certificate selection dialog
SA>   Set certificates = store.certificates.Select
SA>   If certificates.Count >= 1 Then
SA>     ' Pick the first certificate of the list
SA>     Set certificate = certificates.Item(1)
SA>     ' Create an envelopped data object. It's the easier way to encrypt
SA> the file
SA>     Set EnvelopedData = CreateObject("CAPICOM.EnvelopedData")
SA>     ' Assigne the input data to the certificate store
SA>     EnvelopedData.Content = ClearText
SA>     ' Indicates what key pair we should use for encryption.
SA>     EnvelopedData.Recipients.Add certificate
SA>     ' Do the actual encryption
SA>     CipherText = EnvelopedData.Encrypt(CAPICOM_ENCODE_BASE64)
SA>         ' Create the key file
SA>         Set objFSO = CreateObject("Scripting.FileSystemObject")
SA>         Set objTextFile = objFSO.CreateTextFile(KeyFileName, true)
SA>     objTextFile.Write CipherText
SA>   End If
SA> end if
SA> ---- end Encrpyt.vbs ----

SA> The second file is simpler. It will decrypt the key file and pass the
SA> argument to your application. You'll need to change the list maked
SA> "CHANGE THIS LINE" at the end with a call to your application.

SA> ---- Decrpyt.vbs ----
SA> Set objArgs = WScript.Arguments
SA> if  objArgs.Count <> 1 then
SA>   Wscript.Echo "This script takes 1 parameter: the name of the key file"
SA> else
SA>   KeyFileName = objArgs(0)
SA>   ' Read the key file
SA>   set objFSO = CreateObject("Scripting.FileSystemObject")
SA>   Const ForReading = 1
SA>   Set objTextFile = objFSO.OpenTextFile(KeyFileName, forReading)
SA>   cipherText = objTextFile.ReadAll

SA>   Set EnvelopedData = CreateObject("CAPICOM.EnvelopedData")

SA>   ' Decryption is really easy: just call decrypt with the ciphertext as
SA> parameter
SA>   ' The library will automatically locate the proper private key is you
SA> have accees to it
SA>   ' and, optionally, ask for the related password
SA>   EnvelopedData.Decrypt cipherText
SA>   ClearText = EnvelopedData.Content
SA>   ' This part calls TrueCrypt with some sample parameters to mount an
SA> encrypted file as a volume
SA>   ' Change it to fit your needs
SA>   Set WshShell = CreateObject("WScript.Shell")
SA>   WshShell.Exec "trueCrypt.exe /P """ + ClearText + """ /v myvolume.dat
SA> /l U /m rm" ' <-------- CHANGE THIS LINE
SA>  end if
SA> ---- end Decrpyt.vbs ----

SA> Note that some lines might get wrapped by your mailer so you might
SA> need reformatting.

SA> Good luck,
SA> Stephane

SA> Friday, December 16, 2005, 6:46:41 PM, you wrote:

AR>> Greetings,

AR>> Like many folks, I use a USB thumb drive and was wondering if there

AR>> was a way of allowing it to mount only on machines that had the  
AR>> appropriate half of a PKI pair, or requiring a passphrase to unlock
SA> a  
AR>> keypair in order to mount the drive.

AR>> The object would be to prevent someone mounting the drive on their  
AR>> machine if I lost it.

SA> _________________________________________
SA> Learn about Intrusion Detection in Depth from the comfort of your own
SA> couch:
SA> https://www.sans.org/athome/details.php?id=1341&d=1

SA> _______________________________________________
SA> send all posts to list at lists.dshield.org
SA> To change your subscription options (or unsubscribe), see:
SA> http://www.dshield.org/mailman/listinfo/list

SA> _________________________________________
SA> Learn about Intrusion Detection in Depth from the comfort of your own couch:
SA> https://www.sans.org/athome/details.php?id=1341&d=1

SA> _______________________________________________
SA> send all posts to list at lists.dshield.org
SA> To change your subscription options (or unsubscribe), see: http://www.dshield.org/mailman/listinfo/list

Best regards,
 Stephane                            mailto:security at admin.fulgan.com

More information about the list mailing list