Jump to content
C4 Forums | Control4

c4z driver encryption


Nick2021

Recommended Posts

I was wondering if anybody can point me to some resources that outline the exact steps to encrypt a c4z driver.

I am in the process of learning to write my first driver and this part of the process isn't clear to me. I have read the help files in driver editor 3.0.1 and also in the SDK but I am still getting stuck.

Here is the example text given in the driver editor help file

<Driver type="c4z" name="sample" squishLua="true" manualsquish="false”>

<Items>

<Item type="dir" name="www" c4zDir="www" recurse="true" />

<Item type="dir" name="common" c4zDir="Common" />

<Item type="dir" name="tests" exclude="true" />

<Item type="file" name="driver.xml"/>

<Item type="file" name="squish.lua" />

<Item type="file" name="foo1.lua" />

<Item type="file" name="foo2.lua" />

<Item type="file" name="library.lua" c4zDir="Common" />

<Item type="file" name="readme.txt" exclude="true" />

</Items>

 

As an example, lets say I want to encrypt the stock standard TV proxy template driver that comes with driver editor.

What lines do I need to add to the XML, and what are the next steps.

If someone is willing to break it down for me step by step that would be greatly appreciated.

Thanks

Nick

Link to comment
Share on other sites


The Github link (driverpackager) is definitely where you want to look. That said, I had a hard time getting things going until I figured a few things out with driverpackager.

YMMV, but here's the steps I had to take in order to get driverpackager to work correctly on any of my projects.

1. In the manifest file, you don't need to point to every lua file that you use, since they'll be squished into one file before encryption. You'll also need to include the encryption option in the Driver tag. Ex.

<Driver type="c4z" name="sample" squishLua="true" Encryption="True">
  <Items>
    <Item type="dir" name="www" recurse="true"/>
    <Item type="file" name="driver.xml"/>
    <Item type="file" name="squish.lua"/>
  </Items>
</Driver>

2. You'll need to create a file called 'Squishy' that details how lua should squish your source files. That follows the basic format of
 

Main "../driver.lua"
Module "common.c4_command" "../common/c4_command.lua"
Module "common.c4_common" "../common/c4_common.lua"
Output "squish.lua"

For each module, the first option is the module name. The second is the file path so that the squish utility can find it. Each lua file that you intend to be packaged into your driver should be listed as a module. In my experience, I have to have two copies of the 'squishy' file. One goes in the main project directory, and one goes in a folder inside the main directory with the same name as the project directory. It seems that the one inside the subfolder is the one that gets referenced, but both have to be there to squish (this is why I have all source files prepended with '../' : the output seems to know where to go). I can't explain why this is as I didn't bother to look too far into the driverpackager utility and debug what was going on, but I was never able to get my lua to squish without including both. No squish, no encrypted driver.

3. You need to amend your script tag in your document.xml file to point to the output of your squishy file and to include 'encryption=2' to use the newer c4 encryption method. ex.

<script file="squish.lua" encryption="2">

 

4. Run the driverpackager utility specifying the project directory, manifest file name, and output directory. I always run with the verbose option to get some more useful information on output.

Link to comment
Share on other sites

Thanks Andrew H,

I have just looked at the driver packager GitHub link. My first hurdle will be how to install and use the utility. I am a complete beginner. I have managed to learn lua enough to actually make it do what I want to as far as the driver is concerned. However I haven't used python before.

From what I can gather, I need to install python, add M2Crypto to python, and I must also have lua installed. 

I have a MacBook Pro with a windows 10 VM and an Ubuntu VM. Would I be correct in thinking that the easiest way for me to do all this is with the Ubuntu VM?

So once I have python installed, whats the next step? Heres my best guess below.

I also need to install lua onto the Ubuntu VM. Not sure how this all ties in with the driverpackager python script. Does squish need installing?

Modify the script tag in my driver.xml file.

Im planning to use driverpackager dp3.

Do I then just copy the following to the Ubuntu VM

build_c4z.py
driverpackager.py
encrypt_c4z.py
squish

The project directory for my driver.

Then create a manifest file saved as xml on the ubuntu vm

Then create a squishy file with no extension on the ubuntu vm

Then just run the driverpackager.py in the command line with all the correct arguments? 

........................

On a side note. I noticed in driver editor 3.0.1 in the drop down menus that there is a feature. Project>Build>Squishy Dependancies.

Where does this fit into the puzzle?

......................

Sorry for the huge amount of questions. 

Edited by Nick2021
Link to comment
Share on other sites

Hey Nick,

You are correct in thinking that you'll need to have both Python3 and Lua installed. I would recommend using your Ubuntu machine for this if you're comfortable with it and/or willing to learn. I do all my driver development on Ubuntu and have had good luck so far.

First, start with installing Python3. It's important to be sure that you're using Python3 (not Python2, often referred to simply as Python) to be able to use dp3. After you've installed/updated Python3, install pip3. You can use the command 'pip3 --version' from the terminal to check if it exists on your machine already. If it does, you can skip install. Pip3 is the package manager for Python3.  You are also correct that you will need to install M2Crypto to encrypt your drivers.

You should be able to install lua using the command 'sudo apt install lua5.3' . Squish does not need installed apart from installing lua.

As for getting the driverpackager tool: open a terminal session where you wish to store the utilities. I'd go somewhere close to where you will be writing your drivers for ease of use. You can use the command 'git clone --recurse-submodules https://github.com/control4/drivers-driverpackager.git driverpackager'. This will pull everything from the driverpackager github module.

 

Here's how I've found helpful to structure my development folders.

DriverDev
	driverpackager
		createc4z
			...
		dp
			...
		dp3
			build_c4z.py
			driverpackager.py
			encrypt_c4z.py	
			squish
		dplite
			...
		dplite3
			...
		gosquish
			...
		....
	MyDriver1
		driver.lua
		driver.xml
		others.lua
		manifest.xml
		squishy
		MyDriver1 
			squishy
		...
	MyDriver2
		driver.lua
		driver.xml
		others.lua
		squishy
		manifest.xml
		MyDriver2
			squishy
		...

Then, from the terminal, inside the folder DriverDev, I can call 'python3 driverpackager/dp3/driverpackager.py MyDriver1 DestinationLocation manifest.xml'

 

Quote

On a side note. I noticed in driver editor 3.0.1 in the drop down menus that there is a feature. Project>Build>Squishy Dependancies.

DriverEditor and driverpackager are two different tools for doing the same thing. DriverEditor is a Windows-only tool that will build your c4z file for you, and will encrypt it if you mark your <script> tag with 'encryption=2'. If you choose to go this way, you'll have no need for driverpakager. The reason that I and others suggest to use driverpackager over DriverEditor is that the latter is slow and buggy. I found it to be helpful in learning the anatomy of a C4 driver, but it quickly became the biggest hurdle to me in writing drivers. I also prefer to work in Linux as much as possible, and driverpackager gives me the freedom to do that much easier than using DriverEditor.

 

I hope this helps. Let me know if I can clarify anything.

Link to comment
Share on other sites


Keep in mind you can also just specify the certificate and use OpenSSL to encrypt the source directly. At which point you don't need driverpackager at all and can just create an archive.

openssl smime -encrypt -binary -aes-256-cbc -in driver.lua -out driver.lua.encrypted -outform DER certificate.pem

// certificate.pem containing the contents of the public key located here:
// https://github.com/control4/drivers-driverpackager/blob/master/dp/encrypt_c4z.py
Link to comment
Share on other sites

On 11/22/2021 at 9:40 AM, Andrew H said:

Hey Nick,

You are correct in thinking that you'll need to have both Python3 and Lua installed. I would recommend using your Ubuntu machine for this if you're comfortable with it and/or willing to learn. I do all my driver development on Ubuntu and have had good luck so far.

This may be heresy to "true" Linux people but Windows Services for Linux (WSL) has become pretty good and you can run pretty much a fully functional version of Ubuntu (and a few other distros) under Windows 10 without having to have a full-on VM or dual boot system.  This allows you to do some things on Windows and some on Linux at the same time.  For Windows users this is a good way to become more familiar with using Linux.

Here is one (of many) tutorials on how to do this.

d'oh - forgot to provide the link:  https://www.itechguides.com/how-to-install-ubuntu-on-windows-10/

Link to comment
Share on other sites

This thread is quite old. Please consider starting a new thread rather than reviving this one.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.