A colleague sent me a python script that does asn1 encoding. It starts with:
import asn1
then after a few
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier)
It seems pyasn1 is already installed. It does not provide asn1_enc.
Then I saw a python3-asn1. I installed that and tried again (interactive mode of python). Imported asn1 and tried the above command and still
name 'asn1_enc' is not defined
Any idea which asn1 in the repo to install? Or is there a problem with multiple asn1 libraries?
thanks
On May 5, 2023, at 14:40, Robert Moskowitz rgm@htt-consult.com wrote:
A colleague sent me a python script that does asn1 encoding. It starts with:
import asn1
then after a few
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier)
It seems pyasn1 is already installed. It does not provide asn1_enc.
I am pretty sure this is just old or broken code. According to the documentation:
https://python-asn1.readthedocs.io/en/latest/usage.html
… you would just create a new asn1.Encoder() object and use that to write(). Perhaps “asn1_enc” is defined that way in the code?
I think this isn’t really a Fedora issue, unless the API changes in F38, in which case, it’s time to update the code, or pin your requirements to an older version of asn1.
-- Jonathan Billings
What my colleague said, see below.
On 5/5/23 15:35, Jonathan Billings wrote:
On May 5, 2023, at 14:40, Robert Moskowitz rgm@htt-consult.com wrote:
A colleague sent me a python script that does asn1 encoding. It starts with:
import asn1
then after a few
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier)
It seems pyasn1 is already installed. It does not provide asn1_enc.
I am pretty sure this is just old or broken code. According to the documentation:
https://python-asn1.readthedocs.io/en/latest/usage.html
… you would just create a new asn1.Encoder() object and use that to write(). Perhaps “asn1_enc” is defined that way in the code?
I think this isn’t really a Fedora issue, unless the API changes in F38, in which case, it’s time to update the code, or pin your requirements to an older version of asn1.
He is actively doing this. I believe he uses Ubuntu.
asn1 is a 3^rd party package that I installed from pip under the name pyasn1 IIRC. You would import it in your code using:
import asn1
On 5/5/23 13:01, Robert Moskowitz wrote:
What my colleague said, see below.
On 5/5/23 15:35, Jonathan Billings wrote:
On May 5, 2023, at 14:40, Robert Moskowitz rgm@htt-consult.com wrote:
A colleague sent me a python script that does asn1 encoding. It starts with:
import asn1
then after a few
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier)
There's no way that would work without something else being involved. You only imported "asn1". That can't give you something called "asn1_enc", so you're not showing enough for us to help you.
It seems pyasn1 is already installed. It does not provide asn1_enc.
python3-pyasn1 is the only Python asn1 library available. It provides a package called "pyasn1" that you can import.
I am pretty sure this is just old or broken code. According to the documentation:
https://python-asn1.readthedocs.io/en/latest/usage.html
… you would just create a new asn1.Encoder() object and use that to write(). Perhaps “asn1_enc” is defined that way in the code?
I think this isn’t really a Fedora issue, unless the API changes in F38, in which case, it’s time to update the code, or pin your requirements to an older version of asn1.
He is actively doing this. I believe he uses Ubuntu.
asn1 is a 3^rd party package that I installed from pip under the name pyasn1 IIRC. You would import it in your code using:
The README for python3-pyasn1 says that it is the one that you would get from "pip install pyasn1" so it should be the right one.
import asn1
The import is "pyasn1" in Fedora as it should be, but that still won't get you the thing you're looking for, so you need to provide some more lines of the code to see where that's coming from.
On 5/5/23 22:51, Samuel Sieb wrote:
On 5/5/23 13:01, Robert Moskowitz wrote:
What my colleague said, see below.
On 5/5/23 15:35, Jonathan Billings wrote:
On May 5, 2023, at 14:40, Robert Moskowitz rgm@htt-consult.com wrote:
A colleague sent me a python script that does asn1 encoding. It starts with:
import asn1
then after a few
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier)
There's no way that would work without something else being involved. You only imported "asn1". That can't give you something called "asn1_enc", so you're not showing enough for us to help you.
That is all my colleague has indicated he is doing. He can only generally advise me as we are working on the same IETF standard, but behind different contract setups.
asn1 encoding is a standard part of any asn1 package. That and decoding, so something like asn1_enc object has to be available.
It seems pyasn1 is already installed. It does not provide asn1_enc.
python3-pyasn1 is the only Python asn1 library available. It provides a package called "pyasn1" that you can import.
# dnf list > dnf.lst # grep asn1 dnf.lst |grep -i python python3-pyasn1.noarch 0.4.8-12.fc38 @fedora python3-pyasn1-modules.noarch 0.4.8-12.fc38 @fedora python-asn1-doc.noarch 2.6.0-2.fc38 fedora python-pyasn1-doc.noarch 0.4.8-12.fc38 fedora python3-asn1.noarch 2.6.0-2.fc38 fedora python3-asn1crypto.noarch 1.5.1-4.fc38 ----------------- python3-pyasn1 was installed already. python-asn1 was not. Don't know about python3-asn1crypto.
I am pretty sure this is just old or broken code. According to the documentation:
https://python-asn1.readthedocs.io/en/latest/usage.html
… you would just create a new asn1.Encoder() object and use that to write(). Perhaps “asn1_enc” is defined that way in the code?
I think this isn’t really a Fedora issue, unless the API changes in F38, in which case, it’s time to update the code, or pin your requirements to an older version of asn1.
He is actively doing this. I believe he uses Ubuntu.
asn1 is a 3^rd party package that I installed from pip under the name pyasn1 IIRC. You would import it in your code using:
The README for python3-pyasn1 says that it is the one that you would get from "pip install pyasn1" so it should be the right one.
thanks
import asn1
The import is "pyasn1" in Fedora as it should be, but that still won't get you the thing you're looking for, so you need to provide some more lines of the code to see where that's coming from.
asn1 is a 3rd party package that I installed from pip under the name pyasn1 IIRC. You would import it in your code using:
import asn1
I created the OID as a string ("1.3.6.1.4.1.6715.2.6.blah") and passed it into the asn1 Encoders write function like this:
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier) oid_bytes = asn1_enc.output()
Then I just combined it all together with the bytes of the Endorsement.
base64.b64encode(len(oid_bytes).to_bytes(1, 'little') + oid_bytes + endorsement_bytes).decode('ascii')
--------- That is probably all he can tell me.
So I got more research to do, as in the end, we have to interoperate.
Trying to see what help (If any) I can offer despite knowing nothing about the module in question....
(I'm not going to try to preserve the quoting as to who said what, but rather will just respond to the instructions.)
The README for python3-pyasn1 says that it is the one that you would get from "pip install pyasn1" so it should be the right one.
"pip3 install pyasn1" works for me without any apparent issue
import asn1
This fails, as there is no such module. "import pyasn1" succeeds.
But the instructions beyond this are rather incomplete. While "import pyasn1" succeeds, it doesn't appear to really import anything useful. Looks like there are submodules that need to be imported instead. Probably something along the lines of "from pyasn1.foo.bar import encoder" (names are fictitious).
asn1_enc.write(oid, asn1.Numbers.ObjectIdentifier) oid_bytes = asn1_enc.output()
These cannot work because there is no "asn1_enc" object. The object would need to be created first with something like "asn1_enc = pyasn1.foo.bar.encoder()" (again, names are fictitious). Only after the object has been created can you access methods such as "write" or "output".
So basically, the above is why it isn't working. Your colleague (or someone that knows the pyasn1 module) needs to provide more code.
On Sun, 7 May 2023 08:46:26 -0400 Robert Moskowitz rgm@htt-consult.com wrote:
from /usr/share/doc/python3-asn1/README.rst of the fedora package python3-asn1
How to use Python-asn1 ======================
.. note:: You can find more detailed documentation on the `Usage`_ page.
.. _Usage: usage.rst
Encoding --------
If you want to encode data and retrieve its DER-encoded representation, use code such as:
.. code-block:: python
import asn1
encoder = asn1.Encoder() encoder.start() encoder.write('1.2.3', asn1.Numbers.ObjectIdentifier) encoded_bytes = encoder.output()
Decoding --------
If you want to decode ASN.1 from DER or BER encoded bytes, use code such as:
.. code-block:: python
import asn1
decoder = asn1.Decoder() decoder.start(encoded_bytes) tag, value = decoder.read()
On Sun, May 7, 2023 at 10:16 AM stan via users users@lists.fedoraproject.org wrote:
On Sun, 7 May 2023 08:46:26 -0400 Robert Moskowitz rgm@htt-consult.com wrote:
from /usr/share/doc/python3-asn1/README.rst of the fedora package python3-asn1
python3-asn1 != pyasn1 which is what the OP is trying to use as per the guidance from his colleague.
On Sun, 7 May 2023 10:42:07 -0400 Go Canes letsgonhlcanes0@gmail.com wrote:
On Sun, May 7, 2023 at 10:16 AM stan via users users@lists.fedoraproject.org wrote:
On Sun, 7 May 2023 08:46:26 -0400 Robert Moskowitz rgm@htt-consult.com wrote:
from /usr/share/doc/python3-asn1/README.rst of the fedora package python3-asn1
python3-asn1 != pyasn1 which is what the OP is trying to use as per the guidance from his colleague.
I thought he had the fedora packages installed, at least that is what was in his last message. He shouldn't be messing around with 3rd party libraries if he does. Just use the fedora package.
grep asn1 dnf.lst |grep -i python python3-pyasn1.noarch 0.4.8-12.fc38 @fedora <----- looks like old compatibility version, used as pyasn1, python2? python3-pyasn1-modules.noarch 0.4.8-12.fc38 @fedora python-asn1-doc.noarch 2.6.0-2.fc38 fedora python-pyasn1-doc.noarch 0.4.8-12.fc38 fedora python3-asn1.noarch 2.6.0-2.fc38 fedora <----- current version, asn1, python3 python3-asn1crypto.noarch 1.5.1-4.fc38
The READM also had this in it: I wonder if the code he has received is actually python2, and he actually needs future installed so it doesn't break.
Dependencies ==============
Python-ASN1 relies on `Python-Future https://python-future.org`_ for Python 2 and 3 compatibility. To install Python-Future:
.. code-block:: sh
pip install future
He should install the python3-future fedora package if he doesn't have it already installed.
Or, if he has python2.7 installed, run it as python2 /usr/bin/python2 [program name]
Regardless, the code he is looking at has to have some definition of an encoder. Maybe his colleague sent him an earlier version, and he is now using a version that has this instead,
from asn1 import encoder as asn1_enc
From my colleagues on the IETF PKIX list were a lot of asn.1 oldtimers live...
from pyasn1.type import univ from pyasn1.codec.der.decoder import decode as der_decoder from pyasn1.codec.der.encoder import encode as der_encoder import binascii oid = univ.ObjectIdentifier('1.3.6.1.4.1.6715.2.6.6') s = der_encoder(oid) print(binascii.hexlify(s))
060a2b06010401b43b020606
For this I don't need the der_decoder, only the encoder.
So I am set. Actually since for my usage, the OID if fixed, only the content varies, I can just use the output above and prepend it to the value! Don't have to call asn1 for every time to just get the same value!
thanks all.
On 5/7/23 10:15, stan via users wrote:
On Sun, 7 May 2023 08:46:26 -0400 Robert Moskowitzrgm@htt-consult.com wrote:
from /usr/share/doc/python3-asn1/README.rst of the fedora package python3-asn1
How to use Python-asn1
.. note:: You can find more detailed documentation on the `Usage`_ page.
.. _Usage: usage.rst
Encoding
If you want to encode data and retrieve its DER-encoded representation, use code such as:
.. code-block:: python
import asn1
encoder = asn1.Encoder() encoder.start() encoder.write('1.2.3', asn1.Numbers.ObjectIdentifier) encoded_bytes = encoder.output()
Decoding
If you want to decode ASN.1 from DER or BER encoded bytes, use code such as:
.. code-block:: python
import asn1
decoder = asn1.Decoder() decoder.start(encoded_bytes) tag, value = decoder.read() _______________________________________________ users mailing list --users@lists.fedoraproject.org To unsubscribe send an email tousers-leave@lists.fedoraproject.org Fedora Code of Conduct:https://docs.fedoraproject.org/en-US/project/code-of-conduct/ List Guidelines:https://fedoraproject.org/wiki/Mailing_list_guidelines List Archives:https://lists.fedoraproject.org/archives/list/users@lists.fedoraproject.org Do not reply to spam, report it:https://pagure.io/fedora-infrastructure/new_issue