USBError: b'No error when capture()'ing with CWNANO

Hi!

I’m trying to follow along with the Lab 2_1B - Power Analysis for Password Bypass (HARDWARE) tutorial with a CWNANO (NAE-CW1101-04).

Communication with board works perfectly fine, as well as programming the target, however - when trying to capture a trace (following along exactly with the same code in the tutorial) a USBError is being raised during capture():

Traceback (most recent call last):
  File "/home/vagrant/work/projects/chipwhisperer/software/chipwhisperer/hardware/naeusb/naeusb.py", line 290, in txrx
    response = self.cmdReadMem(addr, dlen)
  File "/home/vagrant/work/projects/chipwhisperer/software/chipwhisperer/hardware/naeusb/naeusb.py", line 473, in cmdReadMem
    data = self.usbdev().read(self.rep, dlen, timeout=self._timeout)
  File "/home/vagrant/.pyenv/versions/3.6.7/envs/cw/lib/python3.6/site-packages/pyusb-1.0.2-py3.6.egg/usb/core.py", line 988, in read
    self.__get_timeout(timeout))
  File "/home/vagrant/.pyenv/versions/3.6.7/envs/cw/lib/python3.6/site-packages/pyusb-1.0.2-py3.6.egg/usb/backend/libusb0.py", line 542, in bulk_read
    timeout)
  File "/home/vagrant/.pyenv/versions/3.6.7/envs/cw/lib/python3.6/site-packages/pyusb-1.0.2-py3.6.egg/usb/backend/libusb0.py", line 627, in __read
    timeout
  File "/home/vagrant/.pyenv/versions/3.6.7/envs/cw/lib/python3.6/site-packages/pyusb-1.0.2-py3.6.egg/usb/backend/libusb0.py", line 431, in _check
    raise USBError(errmsg, ret)
usb.core.USBError: [Errno None] b'No error'
---------------------------------------------------------------------------
USBError                                  Traceback (most recent call last)
<ipython-input-5-f4bac772fbe6> in <module>
----> 1 x = cap_pass_trace("h\n")
      2 print(x)

<ipython-input-3-addfe96922f3> in cap_pass_trace(pass_guess)
      9     scope.arm()
     10     target.write(pass_guess)
---> 11     ret = scope.capture()
     12     if ret:
     13         print('Timeout happened during acquisition')

~/work/projects/chipwhisperer/software/chipwhisperer/capture/scopes/cwnano.py in capture(self)
    633                 return True
    634 
--> 635         self._lasttrace = self._cwusb.cmdReadMem(0, self.adc.samples)
    636 
    637         self._lasttrace = np.array(self._lasttrace) / 256.0 - 0.5

~/work/projects/chipwhisperer/software/chipwhisperer/hardware/naeusb/naeusb.py in cmdReadMem(self, addr, dlen)
    646         """
    647 
--> 648         return self.usbseralizer.cmdReadMem(addr, dlen)
    649 
    650     def cmdWriteMem(self, addr, data):

~/work/projects/chipwhisperer/software/chipwhisperer/hardware/naeusb/naeusb.py in cmdReadMem(self, addr, dlen)
    199         cmdpacket = self.make_cmd(self.CMD_READ_MEM, payload)
    200 
--> 201         return self.process_rx(self.txrx(tx=cmdpacket))
    202 
    203     def cmdWriteMem(self, addr, data):

~/work/projects/chipwhisperer/software/chipwhisperer/hardware/naeusb/naeusb.py in process_rx(self, inp)
    152             print(resp)
    153             print(payload)
--> 154             raise payload
    155 
    156         return payload

USBError: [Errno None] None

I’m using the example code given in the documentation:
https://chipwhisperer.readthedocs.io/en/latest/api.html?highlight=simpleserial_wait_ack#chipwhisperer.capture_trace

Yet it says nothing about a USB Error.

I’ve made sure that the scope is configured as CWNANO rather than anything else, and also - this only happens when I send a plaintext with terminating \n.
So I have a reason to believe that in fact there is some trace to get, but something in the processing is gone awry.

What am I missing?

Thanks in advance

Hi,

Yeah, that’s an interesting one. The USBError is from PyUSB, which I think is reporting that something failed in libusb. That beng said, we really should document that these functions can throw this error. I’ll make sure this gets updated.

A few quick questions about your setup:

  1. Are you running ChipWhisperer in a VM, or natively?
  2. Are you running this off a USB-2/3 port or is it USB-C?
  3. If you’re running natively, what operating system are you using?
  4. Have you noticed anything else strange about the device, like that programming the target takes a long time (should only take a few seconds at most)?

Alex

Hi, thank you for your response!

  1. I’m using the latest VM release posted on GitHub using VirtualBox 6.0.14 (with the expansion pack)
  2. The CWNANO is plugged via a USB3 port and is used by the VM (verified)
  3. Running OS X 10.15.6 if that matters
  4. The programming takes around 10 seconds to complete, I’ve also tried changing the C code and indeed I see that the program is working and communicating well with the CWNANO.

I have also:

  1. Switched a USB cable and the port I was using
  2. Tried a different (out of the box) CWNANO)

Still getting the same error

My code:

import chipwhisperer as cw
scope = cw.scope(scope_type=cw.scopes.CWNano)

target = cw.target(scope)
scope.default_setup()

cw.program_target(scope, cw.programmers.STM32FProgrammer,
                  "../hardware/victims/firmware/simpleserial-base/simpleserial-base-CWNANO.hex",
                  baud=38400)


msg = bytearray([1]*16)
target.simpleserial_write('p', msg)

# This does print a sequence of 16 bytes of 0x01
print(target.simpleserial_read('r', 16))

scope.arm()
target.simpleserial_write('p', msg)

print(scope.capture())   # <---- USBError
print(scope.get_last_trace())

We have had issues with the Nano in particular in the VM, which we’re still looking at the root cause for. The VM makes installation a lot easier, especially on Windows, but unfortunately adds an extra layer of complexity. If you can, try installing ChipWhisperer natively. I’ll try replicating the issue and seeing if I can fix it. I can at least get the long programming time, but I haven’t been able to get any errors.

Alex

Potential fix:

  1. The VM settings, go to USB and select USB2.0 and hit OK
  2. Repeat, selecting USB3.0 this time

Alex

Switched to running natively, installed the library from PyPi, and everything works fine now - I guess it really is the VM.

Random question - would making a docker image instead of a VM would make things easier?

Also, please let me know if I can share any data about that error that would maybe assist with debugging.
Thank you again for your help

Hi,

Really, the major reason we’re using the VM is to make installing all the required software on Windows in particular easier. IIRC, Docker doesn’t support Windows 7, which is why we ended up doing VM builds instead. As time goes on, that reason for not just doing a docker image will become less and less relevant, so we may eventually switch over :slight_smile:

Probably the most helpful thing you can do is to try the USB fix out, since that will let me know if this issue is fixed.

Alex

Switching from USB 3.0 to 2.0 and vice versa (also tried switching and restarting VirtualBox) didn’t work for me.

As of now I’m just using it directly without a VM

Sounds like this is a weird edge case then. As a last check, do you think you can upload your ChipWhisperer Jupyter.vbox file?

Alex

Couldn’t upload the file via here so here’s a link to it:

https://drive.google.com/file/d/1k5TggzQd8DRfBuLtSlnGV50KMtWVqOcW/view?usp=sharing