Yesterday we introduced the need to sign program modules for AutoCAD 2016. Today we’re going to see how AutoCAD behaves when loading signed and unsigned modules, as well as what the innards of a signed LISP module look like.
Here’s a simple piece of AutoLISP code that I’ve placed in a file called c:/temp/MyModule.lsp:
(princ "\nThis is a test command.")
Here’s what AutoCAD displays when we try to load this module:
We can use AcSignApply.exe to sign this module with our digital certificate, as we discussed yesterday:
Here are the contents of the file once it has been signed:
(princ "\nThis is a test command.")
The digital signature has essentially been encoded in plain text and appended to the file's contents. Now let’s see what AutoCAD says when we attempt to load this newly signed module:
As this module was not found in one of our “trusted locations”, we do still get a message, despite its being signed. So there are a couple of important things, here…
Firstly, we need to consider whether the module should be in a trusted location. The locations that are trusted implicitly by AutoCAD are:
- C:\Program Files\Autodesk\ApplicationPlugins
- C:\Program Files (x86)\Autodesk\ApplicationPlugins
- C:\Program Files\Autodesk\AutoCAD 2016 (or wherever AutoCAD is installed to)
This is a change from prior versions, where an ApplicationPlugins folder under the current user’s (and all users’) application data was also trusted. We realised this was actually a bad idea and so removed automatic trust for such folders in 2016.
It has previously been suggested that applications should append their installation folder to the TRUSTEDPATHS system variable (or the Registry entry in which it is stored), but this is actually not such a good idea: this setting is really intended for users and CAD managers to control what is considered trusted. If applications start writing to it, behind the scenes, then bad things could happen. So you should expect access to this system variable to become more controlled, over time.
This means that to trust an application based on its location, you can either place your application in AutoCAD’s install folder – its sub-directories are also trusted, by the way – or in a trusted ApplicationPlugins folder/sub-folder. This latter option is fine for applications in the Autoloader bundle format but not for applications that don’t yet use it.
The good news is that if an application module was signed using a trusted digital certificate, then it doesn’t matter if it’s in a trusted location or not*. Which takes us to our next point…
[* It’s also worth noting that the inverse is true: modules found in trusted locations don’t have their digital signatures checked by AutoCAD, as they get trusted automatically.]
Secondly, it’s possible for modules signed with a particular digital certificate to be trusted. If the “Always trust applications from” option is selected, that’s what happens: the user won’t be asked the question for any other application modules, or when the module is loaded in future. Checking this option results in the digital certificate being added to the Windows certificate store.
If you launch certmgr.msc, you’ll see the contents of this store on your system:
It’s possible to add this certificate to the store at install time, even though MSI doesn’t support it directly. Over on the ADN DevBlog, Madhukar has described a number of options for achieving this using a custom action, from calling the certutil.exe to using the Microsoft CryptoAPI from C# or C++. I haven’t yet had to do this, myself, but it seems that adding this certificate on installation isn’t unreasonable.
Now is a really good time to start signing your program modules. This will allow AutoCAD to inform your users in case your application gets tampered with by a malicious process (or person!). Once you’ve signed your modules, you can either have your digital certificate added to the certificate store at install time or the first time one of your modules is loaded (documenting this manual step is clearly an option, if you’d rather make the trusting of your application an explicit user action).
You might also rely on the trusted locations mechanism, by installing to AutoCAD’s program files folder or to ApplicationPlugins (if your application is in Autoloader format). Signing modules is a good idea, irrespective of where they get installed to, so my own preference would be to follow that path.
That’s it for this series, unless someone raises some concerns that haven’t been addressed by these two posts. On Monday I’m planning to unveil a new look for this blog, so get your mobile devices ready… :-)
I’ve been told (thanks, George!) of the existence of a command-line tool for signing AutoLISP modules. This is clearly helpful when integrating digital signing into your build process.
- Product documentation
- About Digitally Signing Custom Program Files
- About Digital Signatures for Executable Files
- About Loading A Digitally Signed Custom Program File
- To Make a Digital Certificate
- To Create A Personal Information Exchange (PFX) File
- To Import a Digital Certificate
- To Digitally Sign an AutoLISP File
- To Digitally Sign a Binary (ObjectARX or Managed .NET) File
- To Digitally Sign a Binary (ObjectARX or Managed .NET) File with a Post-Build Event in Microsoft Visual Studio
- ADN DevBlog
- Dieter Schlaepfer’s posts on Lynn Allen’s blog