Skip to content

Cloud IoT: device registry code on an Android device #1066

Description

@rafaelsf80

Hi,

I'm having some authentication issues when trying to execute some code of Cloud IoT examples on an Android device:

For example, this is the code as available on DeviceRegistryExample.java:

        GoogleCredential credential = GoogleCredential.getApplicationDefault().createScoped(CloudIotScopes.all());
        
        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
        HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);
        
        CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(),jsonFactory, init).setApplicationName(APP_NAME).build();

Since Default Credentials are only valid within App Engine or Compute Engine, I am using a service account for Android instead. The code now looks like this:

        AssetManager am = Main.mContext.getAssets();
        InputStream isCredentialsFile = am.open(CREDENTIALS_FILE_SERVICE_ACCOUNT_PUBSUB_AND_IOT);
        GoogleCredential credential = GoogleCredential.fromStream(isCredentialsFile).createScoped(CloudIotScopes.all());

        JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();
        HttpRequestInitializer init = new RetryHttpInitializerWrapper(credential);

        CloudIot service = new CloudIot.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, init).setApplicationName(TAG).build();

I'm having the following runtime JKS not found exception (JKS keystore not available) on CloudIot.Builder line. Any suggestions would be appreciated.

Thanks,
Rafa

03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: java.security.KeyStoreException: JKS not found
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at java.security.KeyStore.getInstance(KeyStore.java:890)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at com.google.api.client.util.SecurityUtils.getJavaKeyStore(SecurityUtils.java:53)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at com.google.api.client.googleapis.GoogleUtils.getCertificateTrustStore(GoogleUtils.java:74)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at com.google.api.client.googleapis.javanet.GoogleNetHttpTransport.newTrustedTransport(GoogleNetHttpTransport.java:55)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at com.google.cloud.iberia.IoTCoreRegisterService.onHandleIntent(IoTCoreRegisterService.java:80)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at android.app.IntentService$ServiceHandler.handleMessage(IntentService.java:76)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at android.os.Handler.dispatchMessage(Handler.java:106)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at android.os.Looper.loop(Looper.java:164)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at android.os.HandlerThread.run(HandlerThread.java:65)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: Caused by: java.security.NoSuchAlgorithmException: JKS KeyStore not available
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at sun.security.jca.GetInstance.getInstance(GetInstance.java:159)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at java.security.Security.getImpl(Security.java:627)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: at java.security.KeyStore.getInstance(KeyStore.java:887)
03-20 15:35:26.401 29410-29519/com.google.cloud.iberia I/System.out: ... 8 more

Activity

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

Metadata

Metadata

Assignees

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