simao / ota-lith

Mozilla Public License 2.0
7 stars 3 forks source link

Server alway return 403 #10

Closed chen-sh-io closed 1 year ago

chen-sh-io commented 1 year ago

I use docker compose to run the server and use aktualizr as client. I followed the instruction of read me. But when I run the aktualizr with following command, I always got an http 403 error. do you have some hint? it seems there is no problem of the mutual TLS.

simao commented 1 year ago

Hi,

Which commands are you running? Can you show what commands are you running to create a device and the output of those commands?

What is the exact output of aktualizr when you try to run it?

chen-sh-io commented 1 year ago

I ran the script ./scripts/gen-device.sh to generate the device certificate and key. below is the output

cning@uptane2:~/ota-community-edition$ ./scripts/gen-server-certs.sh.original read EC key writing EC key read EC key writing EC key Certificate request self-signature ok subject=CN = ota-gateway read EC key writing EC key cning@uptane2:~/ota-community-edition$ ./scripts/gen-device.sh read EC key writing EC key Certificate request self-signature ok subject=CN = 733b2183-1a2f-44da-bd8e-dad31ff8d5d5 Certificate: Data: Version: 3 (0x2) Serial Number: 4f:ad:70:db:43:0a:14:8d:ac:06:67:4c:1a:99:41:27:da:82:01:0c Signature Algorithm: ecdsa-with-SHA256 Issuer: CN = ota-devices-CA Validity Not Before: Aug 10 13:23:41 2023 GMT Not After : Aug 9 13:23:41 2024 GMT Subject: CN = 733b2183-1a2f-44da-bd8e-dad31ff8d5d5 Subject Public Key Info: Public Key Algorithm: id-ecPublicKey Public-Key: (256 bit) pub: 04:fb:52:d1:76:a2:f4:c0:aa:2a:dc:b7:96:b7:97: 6c:9d:ec:74:3d:09:ef:2a:cf:d2:0f:9d:81:e8:0f: cc:ae:10:65:fb:43:0c:9c:c7:49:28:18:12:be:99: 5a:f4:3e:20:e9:f8:0e:44:a4:e5:2f:9f:fe:3e:bd: df:86:49:ef:e6 ASN1 OID: prime256v1 NIST CURVE: P-256 X509v3 extensions: X509v3 Key Usage: critical Digital Signature X509v3 Extended Key Usage: critical TLS Web Client Authentication X509v3 Subject Key Identifier: 96:DC:3A:D7:EA:59:4F:51:A5:F5:79:56:5E:F3:C2:01:FD:B2:86:12 X509v3 Authority Key Identifier: 42:BD:48:74:86:AC:CF:16:8E:ED:EB:0A:36:10:A8:65:20:E7:FB:66 Signature Algorithm: ecdsa-with-SHA256 Signature Value: 30:44:02:20:42:b0:2b:bd:ec:ab:15:b6:ce:0a:97:d6:94:ed: f3:bc:e6:ff:cd:1a:3b:32:f0:a6:79:77:ec:ac:82:f1:5c:fe: 02:20:66:55:0a:b1:3f:71:df:ef:12:80:b2:d6:88:22:ef:94: 89:b7:2c:e7:54:99:1f:85:5c:32:f6:3f:58:ec:14:14

[p11] module = "" pass = "" uptane_key_id = "" tls_ca_id = "" tls_pkey_id = "" tls_clientcert_id = ""

[tls] server = "https://ota.ce:30443" server_url_path = "gateway.url" ca_source = "file" pkey_source = "file" cert_source = "file"

[provision] server = "https://ota.ce:30443" p12_password = "" expiry_days = "36000" provision_path = "" device_id = "" primary_ecu_serial = "" primary_ecu_hardware_id = "ota-ce-device" ecu_registration_endpoint = "https://ota.ce:30443/director/ecus" mode = "DeviceCred"

[uptane] polling_sec = 10 director_server = "https://ota.ce:30443/director" repo_server = "https://ota.ce:30443/repo" key_source = "file" key_type = "RSA2048" force_install_completion = false secondary_config_file = "" secondary_preinstall_wait_sec = 600

[pacman] type = "none" os = "" sysroot = "" ostree_server = "https://ota.ce:30443/treehub" images_path = "storage/images" packages_file = "/usr/package.manifest" fake_need_reboot = false booted = "booted"

[storage] type = "sqlite" path = "storage" sqldb_path = "sql.db" uptane_metadata_path = "metadata" uptane_private_key_path = "ecukey.der" uptane_public_key_path = "ecukey.pub" tls_cacert_path = "root.crt" tls_pkey_path = "pkey.pem" tls_clientcert_path = "client.pem"

[import] base_path = "." uptane_private_key_path = "" uptane_public_key_path = "" tls_cacert_path = "ca.pem" tls_pkey_path = "pkey.pem" tls_clientcert_path = "client.pem"

[telemetry] report_network = true report_config = true

[bootloader] rollback_mode = "none" reboot_sentinel_dir = "/var/run/aktualizr-session" reboot_sentinel_name = "need_reboot" reboot_command = "/sbin/reboot"

Current directory: /home/cning/ota-community-edition/ota-ce-gen/devices/733b2183-1a2f-44da-bd8e-dad31ff8d5d5 Bootstrap empty SQL storage created: storage Bootstraping DB to version 25 Couldn`t import data: empty path received Client certificate not found in database Device ID key not found in database Unable to load previous device ID. Successfully imported client certificate from "./client.pem" Successfully imported server CA certificate from "./ca.pem" Successfully imported client TLS key from "./pkey.pem" No serial found in database for this ECU, defaulting to empty serial Root metadata not found in database Not importing "./repo/root.json" because it doesn't exist Root metadata not found in database Not importing "./director/root.json" because it doesn't exist Uptane public key not found in database No pending updates, continuing with initialization post request body:{ "ecus" : [ { "clientKey" : { "keytype" : "RSA", "keyval" : { "public" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqPHJ2SiIH0yNScbLDbRU\nD0gji3MVMYf5oNTkT7Csjc81tACMl0PhqFxzsjH9PcITTSQ8hVXrFQYvCTI7cgv9\nwOO+LE2VyMheboWTZX320aWqgbE2vGnyNNvHzbexCrsZC+J/2tEwgXlInVL8CDWQ\ncQdAiGXf25VW1vZP4RpVRuS8E1tkxxOughXiarqh5ViftcyhJMYEMC+LhhoTD/qD\ncWrQyg/Cd7DqukLsBAscFY3U9YXeE5OrcEU87xfKYPN5ozuuerAB+TMUey/E9XTT\n+iUVpSWu8XXwgBuHLWTrgKIUUjxFU2idU7Lb0BJ6twAm+VF9lOzA7xqWeYbjHfyq\nIQIDAQAB\n-----END PUBLIC KEY-----\n" } }, "ecu_serial" : "ae7f4c46e70fa9c4e1410dac7753e3feadc0811e98c6d348791de68c2a1afa75", "hardware_identifier" : "ota-ce-device" } ], "primary_ecu_serial" : "ae7f4c46e70fa9c4e1410dac7753e3feadc0811e98c6d348791de68c2a1afa75" }

to "https://ota.ce:30443/director/ecus"

I don't know which part of code in director processes this request.

simao commented 1 year ago

Did you also run get-credentials.sh ? Could you show the output please.

chen-sh-io commented 1 year ago

hi Simao, I didn't run it before. below is the output of get-credentials.sh


After I ran the get-credentials.sh, seems it is working now, below is the output. What is functionality of ge-credentials.sh? [sudo] password for cning: Aktualizr version 2020.10-288-gb2ee72ebf starting Reading config: "config.toml" Final configuration that will be used: [logger] loglevel = 0

[p11] module = "" pass = "" uptane_key_id = "" tls_ca_id = "" tls_pkey_id = "" tls_clientcert_id = ""

[tls] server = "https://ota.ce:30443" server_url_path = "gateway.url" ca_source = "file" pkey_source = "file" cert_source = "file"

[provision] server = "https://ota.ce:30443" p12_password = "" expiry_days = "36000" provision_path = "" device_id = "" primary_ecu_serial = "" primary_ecu_hardware_id = "ota-ce-device" ecu_registration_endpoint = "https://ota.ce:30443/director/ecus" mode = "DeviceCred"

[uptane] polling_sec = 10 director_server = "https://ota.ce:30443/director" repo_server = "https://ota.ce:30443/repo" key_source = "file" key_type = "RSA2048" force_install_completion = false secondary_config_file = "" secondary_preinstall_wait_sec = 600

[pacman] type = "none" os = "" sysroot = "" ostree_server = "https://ota.ce:30443/treehub" images_path = "storage/images" packages_file = "/usr/package.manifest" fake_need_reboot = false booted = "booted"

[storage] type = "sqlite" path = "storage" sqldb_path = "sql.db" uptane_metadata_path = "metadata" uptane_private_key_path = "ecukey.der" uptane_public_key_path = "ecukey.pub" tls_cacert_path = "root.crt" tls_pkey_path = "pkey.pem" tls_clientcert_path = "client.pem"

[import] base_path = "." uptane_private_key_path = "" uptane_public_key_path = "" tls_cacert_path = "ca.pem" tls_pkey_path = "pkey.pem" tls_clientcert_path = "client.pem"

[telemetry] report_network = true report_config = true

[bootloader] rollback_mode = "none" reboot_sentinel_dir = "/var/run/aktualizr-session" reboot_sentinel_name = "need_reboot" reboot_command = "/sbin/reboot"

Current directory: /home/cning/ota-community-edition/ota-ce-gen/devices/733b2183-1a2f-44da-bd8e-dad31ff8d5d5 Use existing SQL storage: "storage/sql.db" Couldn`t import data: empty path received No serial found in database for this ECU, defaulting to empty serial Root metadata not found in database Not importing "./repo/root.json" because it doesn't exist Root metadata not found in database Not importing "./director/root.json" because it doesn't exist No pending updates, continuing with initialization post request body:{ "ecus" : [ { "clientKey" : { "keytype" : "RSA", "keyval" : { "public" : "-----BEGIN PUBLIC KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqPHJ2SiIH0yNScbLDbRU\nD0gji3MVMYf5oNTkT7Csjc81tACMl0PhqFxzsjH9PcITTSQ8hVXrFQYvCTI7cgv9\nwOO+LE2VyMheboWTZX320aWqgbE2vGnyNNvHzbexCrsZC+J/2tEwgXlInVL8CDWQ\ncQdAiGXf25VW1vZP4RpVRuS8E1tkxxOughXiarqh5ViftcyhJMYEMC+LhhoTD/qD\ncWrQyg/Cd7DqukLsBAscFY3U9YXeE5OrcEU87xfKYPN5ozuuerAB+TMUey/E9XTT\n+iUVpSWu8XXwgBuHLWTrgKIUUjxFU2idU7Lb0BJ6twAm+VF9lOzA7xqWeYbjHfyq\nIQIDAQAB\n-----END PUBLIC KEY-----\n" } }, "ecu_serial" : "ae7f4c46e70fa9c4e1410dac7753e3feadc0811e98c6d348791de68c2a1afa75", "hardware_identifier" : "ota-ce-device" } ], "primary_ecu_serial" : "ae7f4c46e70fa9c4e1410dac7753e3feadc0811e98c6d348791de68c2a1afa75" }

simao commented 1 year ago

get-credentials will create some required resources on the server side (uptane repo, image repo, keys, etc) and will build a credentials.zip file with your root.json and targets keys.