I am not an expert of hardware manufactoring but here are my 2 cents on the topic.
Step one: set up a root PKI
On your server, you should create a custom Certification Authority (see my comment) that will be used later to sign all certificates.
Configure your server to trust only that CA
Step two: you need an extra manufacturing step to enroll the devices
You should switch your device(s) on a first time at manufacturing time, at some stage. At that stage, before the device is shipped to the final user, have the firmware generate a custom private key, which will be unique for every device, and have that keypair signed with the CA certificate.
In order to enroll devices securely, i.e. make sure that no final user alters the firmware before the first boot, this process must be done at your physical facility. Either at the place the chip is manufactured, or at an intermediate stage of delivery chain but within your (office?) boundaries.
Step three: your devices will authenticate using a TLS signed CA certificate
One of the greatest features of TLS mutual authentication is that the server must not know in advance what client certificates are authorized, but they can be just signed by the same CA.
Other tips
Hardware-based key management, e.g. a TPM device, may be helpful a lot. a TPM device can use the Endorsement Key feature to help secure the firmware.
The EK is issued by the manufacturer. I may assume that you are the manufacturer. While not a complete answer, TPM could be a good starting point to investigate.
If I have multiple devices I cannot use same keys/cert. How can I handle this without compile different image for each dev?
– Die Go May 02 '20 at 11:49Basically I need to connect to a server ( and be sure that is my server ) and the server needs to be sure that the clients that are trying to connect to it are only "my devices" or trusted.
I thought that I have to add server certs and devices cert (server's cert is the same for all of my devices, and devices certs (each one different ) to both server and each device ) in order to make this, and private/public keys for sharing data in an encrypted method.
Is also this wrong?
– Die Go May 02 '20 at 15:22server cert ( same for all ) device cert ( different for each device ) private key of the device ( different for each device)
And I will have to add these onto each device. Correct?
Does the server needs to store the device cert, before the device tries to connect to it?
– Die Go May 02 '20 at 15:58