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
Application Identity:LoadOrCreateCertificate IO Exception
April 7, 2020
9:35, EEST
Avatar
swaj
Member
Members
Forum Posts: 6
Member Since:
December 12, 2018
sp_UserOfflineSmall Offline

I am trying to create a Application Identity to connect to a OPC server using Basis254SignandEncrypt with a username and password Authentication. I get this IO Exception

java.io.IOException: The filename, directory name, or volume label syntax is incorrect
at java.io.WinNTFileSystem.createFileExclusively(Native Method)
at java.io.File.createNewFile(Unknown Source)
at com.prosysopc.ua.stack.utils.FileUtil.writeFile(SourceFile:116)
at com.prosysopc.ua.stack.transport.security.Cert.save(SourceFile:194)
at com.prosysopc.ua.ApplicationIdentity.loadOrCreateKeyPair(SourceFile:632)
at com.prosysopc.ua.ApplicationIdentity.loadOrCreateCertificate(SourceFile:466)
at com.prosysopc.ua.ApplicationIdentity.loadOrCreateCertificate(SourceFile:358)

My code looks like this

certStore = new PkiDirectoryCertificateStore();
validator = new DefaultCertificateValidator(certStore);
client.setCertificateValidator(validator);
validator.setValidationListener(validationListener);

// *** Certificates
privatePath = new File(certStore.getBaseDir(),”privatefile”);
privatePath.canWrite(); // return a true to show that the directory is writable
privatePath.getAbsolutePath();// returns the correct path to the file
int[] keySizes = new int[] {0,4096};
Set supportedHttpsModes = new HashSet();
supportedHttpsModes.addAll(HttpsSecurityPolicy.ALL_102);
supportedHttpsModes.addAll(HttpsSecurityPolicy.ALL_103);
supportedHttpsModes.addAll(HttpsSecurityPolicy.ALL_104);
client.getHttpsSettings().setHttpsSecurityPolicies(supportedHttpsModes);
client.getHttpsSettings().setCertificateValidator(validator);
// Define a custom certificate validator for the HTTPS certificates
applicationDescription = new ApplicationDescription();
applicationDescription.setApplicationName(new LocalizedText(Applicationidentity + “GKNAerospace”));
applicationDescription.setApplicationUri(“urn:” + APPLICATIONURI + Applicationidentity);
applicationDescription.setProductUri(“urn:” + PRODUCTURI);
applicationDescription.setApplicationType(ApplicationType.Client);
try {
ApplicationIdentity.loadOrCreateCertificate(applicationDescription, “opcclient”, “opcclient”, privatePath, null, keySizes,true);
} catch (SecureIdentityException | IOException e) {
e.printStackTrace(); // I get error at this point
}

What is the problem ?

April 7, 2020
14:37, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 349
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello swaj!

The certificates are stored to PKI\CA folder of your working directory by default. Could you verify that your working directory allows you to write files into it? Alternatively, you can try to initialize PkiDirectoryCertificateStore with an absolute path, e.g. “C:\\Folder1\\Folder2\\PKI”, of a folder that allows writing files into it.

BR,

Matti

April 7, 2020
18:07, EEST
Avatar
swaj
Member
Members
Forum Posts: 6
Member Since:
December 12, 2018
sp_UserOfflineSmall Offline

Matti Siponen said
Hello swaj!

The certificates are stored to PKI\CA folder of your working directory by default. Could you verify that your working directory allows you to write files into it? Alternatively, you can try to initialize PkiDirectoryCertificateStore with an absolute path, e.g. “C:\\Folder1\\Folder2\\PKI”, of a folder that allows writing files into it.

BR,

Matti  

Hello Matti Siponen
I tried to verify that I have user rights by actually writing a file using a another Java program into the same folder. The error I get still exists.

April 8, 2020
9:18, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 349
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

Hello swaj!

This exception could also be caused by attempting to write a file with filename containing invalid characters. In Windows based systems these invalid characters are , :, “, /, \, |, ? and *. Please verify that your Applicationidentity used to set application name doesn’t contain any of these characters.

BR,

Matti

April 8, 2020
11:07, EEST
Avatar
swaj
Member
Members
Forum Posts: 6
Member Since:
December 12, 2018
sp_UserOfflineSmall Offline

Matti Siponen said
Hello swaj!

This exception could also be caused by attempting to write a file with filename containing invalid characters. In Windows based systems these invalid characters are , :, “, /, \, |, ? and *. Please verify that your Applicationidentity used to set application name doesn’t contain any of these characters.

BR,

Matti  

This is the path I use

File privatePath = new File(“C:\\Users\\Admin\\Desktop\\certs\\privatefile”);

I can write to a file using the same path by using the java.io.fileWritter. Problem still exists !!!!!

Thank you

April 8, 2020
12:11, EEST
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 349
Member Since:
February 11, 2020
sp_UserOfflineSmall Offline

There should be no problem with your path. However, if your Applicationidentity contains invalid characters, it will cause this exception. Please specify the value of Applicationidentity used in the following line of the code:

applicationDescription.setApplicationName(new LocalizedText(Applicationidentity + “GKNAerospace”));

April 8, 2020
12:36, EEST
Avatar
swaj
Member
Members
Forum Posts: 6
Member Since:
December 12, 2018
sp_UserOfflineSmall Offline

Yes , my application Identity contained special characters, after removing those the error is resolved.

Thanks for answers Matti Siponen.Laugh

Forum Timezone: Europe/Helsinki

Most Users Ever Online: 1919

Currently Online:
21 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

Heikki Tahvanainen: 402

hbrackel: 144

rocket science: 88

pramanj: 86

Francesco Zambon: 83

Ibrahim: 78

Sabari: 62

kapsl: 57

gjevremovic: 49

Xavier: 43

Member Stats:

Guest Posters: 0

Members: 727

Moderators: 7

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1529

Posts: 6471

Newest Members:

kourtneyquisenbe, ellis87832073466, zkxwilliemae, gabriellabachus, Deakin, KTP25Zof, Wojciech Kubala, efrennowell431, wilfredostuart, caitlynfajardo

Moderators: Jouni Aro: 1026, Pyry: 1, Petri: 0, Bjarne Boström: 1032, Jimmy Ni: 26, Matti Siponen: 349, Lusetti: 0

Administrators: admin: 1