Avatar
Please consider registering
guest
sp_LogInOut Log Insp_Registration Register
Register | Lost password?
Advanced Search
Forum Scope


Match



Forum Options



Minimum search word length is 3 characters - maximum search word length is 84 characters
sp_Feed Topic RSSsp_TopicIcon
ClassCastException with Android RSAPrivateCrtKey
December 1, 2017
14:33, EET
Avatar
David S.
New Member
Members
Forum Posts: 2
Member Since:
November 15, 2017
sp_UserOfflineSmall Offline

Hi all,
i am using the Java Client SDK in an android app. its a simple browser which also can subscribe to sensor values.
my problem is that as soon as i want to establish a connection using a security mode other then .NONE it throws a ClassCastExeption.

More specific:
java.lang.ClassCastException: com.android.org.conscrypt.OpenSSLRSAPrivateKey cannot be cast to java.security.interfaces.RSAPrivateCrtKey

What am i missing? Looking forward to hearing from you. Thanks

Responsibe Code:
ApplicationDescription appDescription = new ApplicationDescription();

appDescription.setApplicationName(new LocalizedText(“AndroidOpcuaBrowser”,
Locale.ENGLISH));

String android_id = Settings.Secure.getString(
mContext.getContentResolver(),
Settings.Secure.ANDROID_ID);

appDescription.setApplicationUri(“urn:” + android_id + “:UA:AndroidOpcuaBrowser”);
appDescription.setProductUri(“urn:hahnschickard.de:UA:AndroidOpcuaBrowser”);
appDescription.setApplicationType(ApplicationType.Client);

PkiFileBasedCertificateValidator validator = new PkiFileBasedCertificateValidator(
mContext.getFilesDir().getPath() + “/PKI/CA”);

Log.d(“PkiPath”, mContext.getFilesDir().getPath() + “/PKI/CA”);

validator.setValidationListener(new CertificateValidationListener() {
@Override
public PkiFileBasedCertificateValidator.ValidationResult onValidate(
Cert cert, ApplicationDescription applicationDescription,
EnumSet enumSet) {

return PkiFileBasedCertificateValidator.ValidationResult.AcceptPermanently;
}
});
mClient.setCertificateValidator(validator);

ApplicationIdentity identity = ApplicationIdentity
.loadOrCreateCertificate(appDescription, “Sample Organisation”,
/* Private Key Password */”opcua”,
/* Key File Path */new File(validator.getBaseDir(), “private”),
/* Enable renewing the certificate */ true);

identity.setApplicationDescription(appDescription);
mClient.setApplicationIdentity(identity);

mClient.setTimeout(60000);
mClient.setSecurityMode(SecurityMode.BASIC128RSA15_SIGN);
mClient.setUserIdentity(new UserIdentity());
mClient.connect();

Log:
E/AndroidRuntime: FATAL EXCEPTION: Thread-5
Process: de.hahn_schickard.opcuaexplorer, PID: 1640
java.lang.ClassCastException: com.android.org.conscrypt.OpenSSLRSAPrivateKey cannot be cast to java.security.interfaces.RSAPrivateCrtKey
at org.opcfoundation.ua.transport.security.ScCryptoProvider.signAsymm(Unknown Source)
at org.opcfoundation.ua.transport.tcp.impl.ChunkAsymmEncryptSigner.sign(Unknown Source)
at org.opcfoundation.ua.transport.tcp.impl.ChunkAsymmEncryptSigner.run(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.TcpConnection.sendAsymmChunk(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.TcpConnection.sendRequest(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.createSecureChannel(Unknown Source)
at org.opcfoundation.ua.transport.tcp.io.SecureChannelTcp.open(Unknown Source)
at org.opcfoundation.ua.application.Client.createSecureChannel(Unknown Source)
at com.prosysopc.ua.client.UaClient.m(Unknown Source)
at com.prosysopc.ua.client.UaClient.connect(Unknown Source)
at de.hahn_schickard.opcuaexplorer.OPCUAService$ConnectThread.run(OPCUAService.java:421)

December 1, 2017
17:42, EET
Avatar
Ismo Leszczynski
Member
Members
Forum Posts: 4
Member Since:
February 18, 2015
sp_UserOfflineSmall Offline

Hi David,

Your problem is most likely caused by a wrong crypto provider. When developing for Android, you need to use SpongyCastle instead of the default BouncyCastle. Typically the SDK takes care of this, but the current version has a known issue where the selection isn’t made and will be fixed in a future release. Please add the following line before making any OPC UA connections:

CryptoUtil.setCryptoProvider(new ScJceCryptoProvider());

Please note that you have to include the SpongyCastle libraries delivered with the SDK in your project.

Let us know if you have any further issues!

December 4, 2017
10:32, EET
Avatar
David S.
New Member
Members
Forum Posts: 2
Member Since:
November 15, 2017
sp_UserOfflineSmall Offline

Great, that solved it! Thank you.

June 8, 2019
11:22, EEST
Avatar
Rakshan
Member
Members
Forum Posts: 30
Member Since:
June 2, 2019
sp_UserOfflineSmall Offline

hey! just a small query.

I am using the Prosys SDK for Java. And i am kinda stuck at figuring out the following issue.
CODE:
PkiFileBasedCertificateValidator validator = new PkiFileBasedCertificateValidator(
getFilesDir().getPath() + “/PKI/CA”);
validator.setValidationListener(new CertificateValidationListener() {
@Override
public PkiFileBasedCertificateValidator.ValidationResult onValidate(
Cert cert, ApplicationDescription applicationDescription,
EnumSet enumSet) {
return PkiFileBasedCertificateValidator.ValidationResult.AcceptPermanently;
}
});
client.setCertificateValidator(validator);

The “PkiFileBasedCertificateValidator” and “CertificateValidationListener” are not recognised in Android Studio.

Any library file i am missing on?

June 8, 2019
11:23, EEST
Avatar
Rakshan
Member
Members
Forum Posts: 30
Member Since:
June 2, 2019
sp_UserOfflineSmall Offline

hey! just a small query.

I am using the Prosys SDK for Java. And i am kinda stuck at figuring out the following issue.
CODE:
PkiFileBasedCertificateValidator validator = new PkiFileBasedCertificateValidator(
getFilesDir().getPath() + “/PKI/CA”);
validator.setValidationListener(new CertificateValidationListener() {
@Override
public PkiFileBasedCertificateValidator.ValidationResult onValidate(
Cert cert, ApplicationDescription applicationDescription,
EnumSet enumSet) {
return PkiFileBasedCertificateValidator.ValidationResult.AcceptPermanently;
}
});
client.setCertificateValidator(validator);

The “PkiFileBasedCertificateValidator” and “CertificateValidationListener” are not recognised in Android Studio.

Any library file i am missing on?

June 10, 2019
12:26, EEST
Avatar
Bjarne Boström
Moderator
Moderators
Forum Posts: 1047
Member Since:
April 3, 2012
sp_UserOfflineSmall Offline

When you make a post please do not post it to multiple forums. Additionally unless you had the same exact problem, do not post on old threads. If you have a new problem, start a new thread. I now answered this in https://forum.prosysopc.com/fo…..ndroid-ui/.

Forum Timezone: Europe/Helsinki
Most Users Ever Online: 1919
Currently Online:
Guest(s) 32
Currently Browsing this Page:
1 Guest(s)
Top Posters:
Heikki Tahvanainen: 402
hbrackel: 144
rocket science: 90
pramanj: 86
Francesco Zambon: 83
Ibrahim: 78
Sabari: 62
kapsl: 57
gjevremovic: 49
Xavier: 43
Member Stats:
Guest Posters: 0
Members: 735
Moderators: 7
Admins: 1
Forum Stats:
Groups: 3
Forums: 15
Topics: 1545
Posts: 6521
Newest Members:
Jorsiz, wilfredoforeman, ptdenriqueta, basilpullman, Richardmip, mood edibles, LouieWreve, daniellabdx, janessan21, sammiebeak359
Moderators: Jouni Aro: 1029, Pyry: 1, Petri: 1, Bjarne Boström: 1047, Jimmy Ni: 26, Matti Siponen: 353, Lusetti: 0
Administrators: admin: 1