测试 aws-sdk-android-samples/AndroidPubSub 但连接被拒绝
Test aws-sdk-android-samples/AndroidPubSub but connection is refused
我试图从 https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSub
测试 aws-sdk-android-samples/AndroidPubSub/
,但在我点击连接后,总是收到错误消息
a2k94wsqkar4rm-ats.iot.us-west-2.amazonaws.com/52.13.183.162 (port
8883) after 30000ms: isConnected failed: ECONNREFUSED (Connection
refused)
我在 AWS IoT 控制台上创建了我的设备证书并激活了它,还附上了如下所述的策略,
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Subscribe",
"iot:Receive"
],
"Resource": "*"
}
]
}
并且我尝试了两种方法将证书和密钥安装到本地密钥库,并且都有效。
方法一,源代码
AssetManager assetManager = getAssets();
// read cert and private key from pem file
InputStream input = assetManager.open("4ed2c76117-private.pem");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
String privateKeyPem = new String(buffer);
System.out.println(privateKeyPem);
input = assetManager.open("4ed2c76117-certificate.pem");
size = input.available();
byte[] buffer2 = new byte[size];
input.read(buffer2);
input.close();
String certPem = new String(buffer2);
System.out.println(certPem);
// store in keystore for use in MQTT client
// saved as alias "default" so a new certificate isn't
// generated each run of this application
AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId,
certPem,
privateKeyPem,
keystorePath, keystoreName, keystorePassword);
// load keystore from file into memory to pass on
// connection
clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(certificateId,
keystorePath, keystoreName, keystorePassword);
方法二,通过终端命令,
openssl pkcs12 -export -out iot_keystore.p12 -inkey 4ed2c76117-private.pem -in 4ed2c76117-certificate.pem -name default
keytool -importkeystore -srckeystore iot_keystore.p12 -srcstoretype pkcs12 -destkeystore iot_keystore.bks -deststoretype bks --provider org.bouncycastle.jce.provider.BouncyCastleProvider -–providerpath bcprov-jdk15on-164.jar
adb push iot_keystore.bks /data/user/0/com.amazonaws.demo.androidpubsub/files/iot_keystore
谁能帮忙解决这个问题?
抱歉,我认为这是模拟器网络问题。正确连接网络后,这个问题就没有了。
我试图从 https://github.com/awslabs/aws-sdk-android-samples/tree/master/AndroidPubSub
测试 aws-sdk-android-samples/AndroidPubSub/
,但在我点击连接后,总是收到错误消息
a2k94wsqkar4rm-ats.iot.us-west-2.amazonaws.com/52.13.183.162 (port 8883) after 30000ms: isConnected failed: ECONNREFUSED (Connection refused)
我在 AWS IoT 控制台上创建了我的设备证书并激活了它,还附上了如下所述的策略,
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Action": "iot:Connect",
"Resource": "*"
},
{
"Effect": "Allow",
"Action": [
"iot:Publish",
"iot:Subscribe",
"iot:Receive"
],
"Resource": "*"
}
]
}
并且我尝试了两种方法将证书和密钥安装到本地密钥库,并且都有效。
方法一,源代码
AssetManager assetManager = getAssets();
// read cert and private key from pem file
InputStream input = assetManager.open("4ed2c76117-private.pem");
int size = input.available();
byte[] buffer = new byte[size];
input.read(buffer);
input.close();
String privateKeyPem = new String(buffer);
System.out.println(privateKeyPem);
input = assetManager.open("4ed2c76117-certificate.pem");
size = input.available();
byte[] buffer2 = new byte[size];
input.read(buffer2);
input.close();
String certPem = new String(buffer2);
System.out.println(certPem);
// store in keystore for use in MQTT client
// saved as alias "default" so a new certificate isn't
// generated each run of this application
AWSIotKeystoreHelper.saveCertificateAndPrivateKey(certificateId,
certPem,
privateKeyPem,
keystorePath, keystoreName, keystorePassword);
// load keystore from file into memory to pass on
// connection
clientKeyStore = AWSIotKeystoreHelper.getIotKeystore(certificateId,
keystorePath, keystoreName, keystorePassword);
方法二,通过终端命令,
openssl pkcs12 -export -out iot_keystore.p12 -inkey 4ed2c76117-private.pem -in 4ed2c76117-certificate.pem -name default
keytool -importkeystore -srckeystore iot_keystore.p12 -srcstoretype pkcs12 -destkeystore iot_keystore.bks -deststoretype bks --provider org.bouncycastle.jce.provider.BouncyCastleProvider -–providerpath bcprov-jdk15on-164.jar
adb push iot_keystore.bks /data/user/0/com.amazonaws.demo.androidpubsub/files/iot_keystore
谁能帮忙解决这个问题?
抱歉,我认为这是模拟器网络问题。正确连接网络后,这个问题就没有了。