Skip to content

AttributeError: 'bytearray' object has no attribute 'public_key' #1533

Open

Description

@eduardofrafre

Hi there,

I'm struggling to get my client/server running with secure policies, cryptography, and authentication, I understand this project is deprecated, but I use it for a project at work. Before refactoring and migrating to the new tools, I want to establish secure SSL communication to satisfy client needs.

Here is a simple server I instantiated to develop the PKI and learn how to set this up before adapting it to production.

image

Here is a simple client I instantiated to communicate with the server and get my certification and private key authenticated.

image

And here is the error, when I try to connect the client with the server using not just SignAndEncrypt, but Sign as well, only Anonymous access is currently working.

image

My initial understanding was that my certification was missing a public key, I went in and studied a little more on openssl and upon debugging, I could easily see my Subject Public Key Info pointing out that a rsaEncryption had generated a 2048bit public key, and the modulus after it, if the debugging command helps confirm it, here is the command I wrote:

openssl x509 -in cert/server_cert.pem -pubkey -noout -text

@AndreasHeine I searched the repo's issues and discussions as well as others and saw you as an active moderator at least whenever this used to be more active, I understand this error might be a misuse of some features, but I ask for some help nonetheless as this topic is hard to research upon, and I couldn't find any more info on it.

When using the client UAExpert, same thing happens in any type of Basic256Sha256 secure policy, I don't know what to do anymore. If you decide to help and need any more info on it, I'll gladly provide.

Thanks in advance!

Activity

  1. eduardofrafre commented on Dec 6, 2023

    @eduardofrafre
    Author

    I forgot to add that but this is how I structured my PKI, my server_cert is my CA.

    #Create server key and certification
    openssl req -x509 -newkey rsa:2048 -config x509v3/ssl.conf -keyout cert/server_private_key.pem -sha256 -nodes -days 1095 -out cert/server_cert.pem
    
    #Create client key and certification signing request
    openssl req -new -config client/client.conf -nodes -keyout client/client_private_key.pem -out client/client_csr.pem
    
    # Authenticate client certification signing request with CA as server certification
    openssl x509 -req -in client/client_csr.pem -days 1095 -CA cert/server_cert.pem -CAkey cert/server_private_key.pem -CAcreateserial -out client/client_cert.pem -extensions req_ext -extfile client/client.conf
    
  2. AndreasHeine commented on Dec 7, 2023

    @AndreasHeine
    Member

    this library is DEPRICATED so dont use it with regards to security!

    your issue however is you are mixing transport security with authorization...

    your client use the cert and key for auth aswell which the server do not support in the old version!

  3. eduardofrafre commented on Dec 7, 2023

    @eduardofrafre
    Author

    Thank you Andreas, this brings some clarity to my problem, I intend to use it momentarily just to get the feel for it, thinking about migrating the actual solution to the asyncio-opcua or node-opcua

  4. eduardofrafre commented on Dec 7, 2023

    @eduardofrafre
    Author

    I created another cert to separate transport security from auth, but I still get the same error, is the cert and key for transport meant to be handled differently?

    image

  5. eduardofrafre commented on Dec 18, 2023

    @eduardofrafre
    Author

    I'm still struggling with this approach.

  6. schroeder- commented on Dec 19, 2023

    @schroeder-
    Contributor

    From the callstack the server certificate is not set correctly. This should be done when the server starts.
    Does only setting encrypted communication help?

    server.set_security_policy([ua.SecurityPolicyType.Basic256Sha256_SignAndEncrypt])

  7. eduardofrafre commented on Dec 19, 2023

    @eduardofrafre
    Author

    Hey, this helped, I had a little more debugging to do but it seems to be working fine now, I'll do some testing tomorrow and if it works out I'll consider it solved and close this discussion! Thank you so much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions