Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AttributeError: 'NoneType' object has no attribute 'private_bytes' #74

Open
bhavya1213 opened this issue Jul 30, 2024 · 1 comment
Open

Comments

@bhavya1213
Copy link

bhavya1213 commented Jul 30, 2024

I am trying to run this send.py from given example files,


  import asyncio
  import xml.etree.ElementTree as ET
  
  from configparser import ConfigParser
  
  import pytak
  
  
  class MySerializer(pytak.QueueWorker):
      """
      Defines how you process or generate your Cursor on Target Events.
      From there it adds the CoT Events to a queue for TX to a COT_URL.
      """
  
      async def handle_data(self, data):
          """Handle pre-CoT data, serialize to CoT Event, then puts on queue."""
          event = data
          await self.put_queue(event)
  
      async def run(self, number_of_iterations=-1):
          """Run the loop for processing or generating pre-CoT data."""
          while 1:
              data = tak_pong()
              await self.handle_data(data)
              await asyncio.sleep(20)
  
  
  def tak_pong():
      """Generate a simple takPong CoT Event."""
      root = ET.Element("event")
      root.set("version", "2.0")
      root.set("type", "t-x-d-d")
      root.set("uid", "takPong")
      root.set("how", "m-g")
      root.set("time", pytak.cot_time())
      root.set("start", pytak.cot_time())
      root.set("stale", pytak.cot_time(3600))
      return ET.tostring(root)
  
  
  async def main():
      """Main definition of your program, sets config params and
      adds your serializer to the asyncio task list.
      """
      config = ConfigParser()
      config["mycottool"] = {"COT_URL": "tls://SERVER_ADDRESS:8089", "PYTAK_TLS_CLIENT_CERT": "CERT_PATH.p12", "PYTAK_TLS_CLIENT_PASSWORD": "atakatak"}
      config = config["mycottool"]
  
      
      # Initializes worker queues and tasks.s
      clitool = pytak.CLITool(config)
      await clitool.setup()
  
      # Add your serializer to the asyncio task list.
      clitool.add_tasks(set([MySerializer(clitool.tx_queue, config)]))
  
      # Start all tasks.
      await clitool.run()
  
  
  if __name__ == "__main__":
      asyncio.run(main())

but when i run this i get this error:

`/Users/admin/anaconda3/lib/python3.11/site-packages/takproto/__init__.py:43: UserWarning: COMPAT Python 3.6. Ignoring Exception: cannot import name 'builder' from 'google.protobuf.internal' (/Users/admin/anaconda3/lib/python3.11/site-packages/google/protobuf/internal/__init__.py)
  warnings.warn(f"COMPAT Python 3.6. Ignoring Exception: {str(exc)}")
atakatak
Traceback (most recent call last):
  File "/Users/admin/Downloads/pytak-main/examples/send.py", line 64, in <module>
    asyncio.run(main())
  File "/Users/admin/anaconda3/lib/python3.11/asyncio/runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/admin/Downloads/pytak-main/examples/send.py", line 54, in main
    await clitool.setup()
  File "/Users/admin/anaconda3/lib/python3.11/site-packages/pytak/classes.py", line 363, in setup
    reader, writer = await pytak.protocol_factory(self.config)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/site-packages/pytak/client_functions.py", line 100, in protocol_factory
    reader, writer = await create_tls_client(config, cot_url)
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/site-packages/pytak/client_functions.py", line 278, in create_tls_client
    ssl_ctx = get_ssl_ctx(tls_config)
              ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/site-packages/pytak/client_functions.py", line 342, in get_ssl_ctx
    cert_paths = convert_cert(client_cert, client_password)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/admin/anaconda3/lib/python3.11/site-packages/pytak/crypto_functions.py", line 88, in convert_cert
    pk_pem = private_key.private_bytes(
             ^^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'private_bytes'`

how do i solve this?

@inteq
Copy link

inteq commented Aug 15, 2024

From the traceback and your initial setup of the clitool object, you need to specify your SERVER ADDRESS:
config["mycottool"] = {"COT_URL": "tls://SERVER_ADDRESS:8089", "PYTAK_TLS_CLIENT_CERT": "CERT_PATH.p12", "PYTAK_TLS_CLIENT_PASSWORD": "atakatak"}
right now it is not set to anything that would resolve to an ip.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants