When are they generated, when I decide one to be generated? Or before I get the device?
How can I confirm that? can I review the source code on ledger, bitbox (not trezor) etc?
To be honest, if people seriously buy a piece of hardware with a preloaded pk and uses that..... oh my. For me that would be like security 101, NOT TO.
Even if I decide to trust the manufacture/company... which I dont. How could i know the ratailer didn't duplicate that key, how could I know that the post mail main who delivered the device didn't unpack my package and duplicated the key? How could I know that some intern in the production factory didn't duplicate the keys etc.
The keys are generated when you initialize the device. The devices come uninitialized. You can also reinitialize an already initialized device. This will wipe the existing private keys from the device and have it generate new ones.
2. Is it possible to "swipe" the hardware wallet and load your own private keys? And if so, is this easily done?
It depends. If your private keys are part of a BIP 32 HD wallet and you have a BIP 39 mnemonic for that wallet, then yes. You can load the BIP 39 mnemonic onto the device and it will generate the proper keys. If you just have a bunch of private keys that were randomly generated (or you don't have the BIP 39 mnemonic), then no, you cannot.
3. If I can put the hardware wallet in my laptop and send crypto currency stored on it to other address, what would keep a malicious piece of software on my computer from changing the address as I confirm the transaction?
You have to confirm on your device before it signs the transaction. If the outputs are changed after signing, the transaction will be invalid. If they are changed before signing, then you will see the changed address on your device and can tell it to not sign the transaction.
4. Is it possible to; from a totally offline computer holding the private keys. Make an transaction, move the transaction to a usb key, plug that key in a online machine, publish the transaction to the blockchain, so that the private keys never "touches" a machine with internet access.
Yes.
I feel that the info text and video explanations on trezor and legder, bitbox is just showing some little usb thing and showing that "when you plug it out your money is safe" but they never explain the technical background that makes that possible. There is no explanation on why your private keys was not duplicated the moment you plugged it in to your computer, or before you even got the device. And there is no noob safe guide to load your own pks to the hardware wallet.
It is impossible to duplicate the private keys when the device is plugged in as they keys cannot leave the hardware (well they could if you have malicious firmware installed). The firmware for all of the devices are open source and publicly viewable and auditable. If you don't trust the firmware that came with the device, you can install your own self-compiled version. The only firmware that is not open source is the firmware for Ledger's Secure Enclave. The Secure Enclave is where the private keys are stored. However things to and from the Secure Enclave must pass through the rest of the Ledger's open source firmware sop you would be able to see whether the Secure Enclave is leaking your private keys.