<div dir="ltr"><div dir="ltr">On Sun, Nov 24, 2019, at 12:12 AM Hal Murray via devel <<a href="mailto:devel@ntpsec.org">devel@ntpsec.org</a>> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><br>
Mark Atwood said:<br>
> On the other other other hand, can we have a Python binding on the C crypto<br>
> routines that ntpd uses? <br></blockquote><div><br></div><div>I'd probably prefer a generic FFI module with a ctypes wrapper<br>but yes probably.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
The ntpd code gets crypto from OpenSSL's libcrypto.<br>
<br>
We could write a wrapper for libcrypto.  The API is reasonably clean.  (or at <br>
least the parts we use.)  I'm a bit surprised that one doesn't already exist <br>
but I didn't find one with more than a little poking around.<br>
<br>
The code we use is in: libntp/macencrypt.c<br>
<br>
There are separate routines for old digest mode and new CMAC mode using AES.<br>
<br>
Looks like the current python code gets crypto from hashlib which is part of <br>
python libs.  It doesn't include AES.  Since AES has been out for ages, I <br>
assume that lack of support is an indication that hashlib is (somewhat?) <br>
deprecated.<br>
<br>
----------<br>
<br>
pyca/pyopenssl seems like the python way to get to OpenSSL<br>
  <a href="https://github.com/pyca/pyopenssl" rel="noreferrer" target="_blank">https://github.com/pyca/pyopenssl</a><br>
  <a href="https://www.pyopenssl.org/en/stable/" rel="noreferrer" target="_blank">https://www.pyopenssl.org/en/stable/</a><br>
<br>
That suggests pyca/crytography<br>
  <a href="https://github.com/pyca/cryptography" rel="noreferrer" target="_blank">https://github.com/pyca/cryptography</a><br>
  <a href="https://cryptography.io/en/latest/" rel="noreferrer" target="_blank">https://cryptography.io/en/latest/</a><br>
<br>
I looked a little, but didn't see exactly what I was looking for.  I'm pretty <br>
sure I could make it work.<br></blockquote><div> </div><div>I think I might be able to if that is the direction I should<br>have been going in the first place. Cryptography at least has<br>CMAC support unlike pycrypto, ssl, and pyopenssl.<br></div><div> </div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">
----------<br>
<br>
pycryptodome seems like a reasonable choice.  It's a bit more complicated that <br>
a simple pip install.  We should be able to write the code so that AES doesn't <br>
work if not installed.<br>
<br>
From<br>
  <a href="https://pycryptodome.readthedocs.io/en/latest/src/installation.html" rel="noreferrer" target="_blank">https://pycryptodome.readthedocs.io/en/latest/src/installation.html</a><br>
One must avoid having both PyCrypto and PyCryptodome installed at the same <br>
time, as they will interfere with each other.<br>
<br>
Then it goes on with the alternate recipe.<br>
<br>
I think this is will be the first/only use of pip in buildprep.  Somebody <br>
smarter than me will have to sort that out.<br></blockquote><div><br></div><div>There is an alternative pycryptodomex which installs the module<br>cryptodome, I just did not use it. I am pretty sure it is, the<br>only things that might have been installable via pip would be<br>gps, curses, and argparse(?). All three options dropped scripts<br>rather than resort to pip. In that case, it will have to be<br>someone else.<br></div></div></div>