Avatar

Please consider registering
guest

sp_LogInOut Log In sp_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 RSS sp_TopicIcon
ClassCastException with Android RSAPrivateCrtKey
December 1, 2017
14:33, EEST
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, EEST
Avatar
Ismo Leszczynski
Member
Members
Forum Posts: 3
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, EEST
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: 10
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: 10
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: 365
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/forum/prosys-opc-ua-client-for-android/how-to-get-the-nodeids-of-a-server-coded-in-c-on-the-android-ui/.

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 78

Currently Online:
16 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 89

pramanj: 86

ibrahim: 68

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 36

Rainer Versteeg: 32

peterrob45: 25

Member Stats:

Guest Posters: 0

Members: 841

Moderators: 11

Admins: 1

Forum Stats:

Groups: 3

Forums: 14

Topics: 860

Posts: 3632

Newest Members:

augusthanks, jackbryan, jansmithsmth, uiuida, johnjorge, Ramraj, dimad, aku, Rakshan, claradsouza

Moderators: Jouni Aro: 824, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 365, Heikki Tahvanainen: 402, Jukka Asikainen: 1, Teppo Uimonen: 14

Administrators: admin: 0