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

Create PEM for Android Things: Invalid authentication key. Check the format. #3

Open
li2 opened this issue Dec 25, 2018 · 0 comments
Open

Comments

@li2
Copy link

li2 commented Dec 25, 2018

Finally, fixed this issue by almost one day:

image

Firstly, execute the follow command to create a pem file, I use EC in this command:

adb shell am start -e project_id <PROJECT_ID> -e cloud_region <REGION> -e registry_id <REGISTRY_ID> -e device_id <DEVICE_ID> [-e key_algorithm <one of RSA,EC>] com.example.androidthings.sensorhub/.SensorHubActivity

the key point is -e key_algorithm, which allows RSA and EC, and EC is actually ES256:

ES256 key pair using the Eliptic Curve algorithm
See Google Cloud Internet of Things Core - Creating Public/Private Key Pairs

Lastly, upload the pem to GCP console, and select ES256_X509:

image

This function in AuthKeyGenerator.class is actually for _X509

public void initialize() throws GeneralSecurityException, IOException {
    if (certificate instanceof X509Certificate) { // is true

private void writeCertificatePEM(OutputStream os) throws GeneralSecurityException, IOException {
    os.write("-----BEGIN CERTIFICATE-----\n".getBytes());
    os.write(Base64.encode(certificate.getEncoded(), Base64.DEFAULT));
    os.write("-----END CERTIFICATE-----\n".getBytes());
}

Done

image

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

1 participant