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, EET
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, EET
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 72
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, EET
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, EET
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 72
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, EET
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, EET
Avatar
Matti Siponen
Moderator
Members

Moderators
Forum Posts: 72
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, EET
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: 267

Currently Online:
9 Guest(s)

Currently Browsing this Page:
1 Guest(s)

Top Posters:

hbrackel: 103

pramanj: 86

ibrahim: 70

kapsl: 57

gjevremovic: 49

TimK: 41

Fransua33: 39

fred: 38

Rainer Versteeg: 32

Thomas Reuther: 31

Member Stats:

Guest Posters: 0

Members: 1160

Moderators: 15

Admins: 1

Forum Stats:

Groups: 3

Forums: 15

Topics: 1048

Posts: 4416

Newest Members:

jonas.rahm, sophiekohler, zqecortney, adeletoscano947, forestgenders23, auroratrumper, ericmclain04, rblu, starlowery23194, dakotadalgety82

Moderators: Jouni Aro: 853, Otso Palonen: 32, Tuomas Hiltunen: 5, janimakela: 0, Pyry: 1, Terho: 0, Petri: 0, Bjarne Boström: 579, Heikki Tahvanainen: 402, Jukka Asikainen: 1, moldzh08: 0, Teppo Uimonen: 21, Markus Johansson: 24, Matti Siponen: 72, Lusetti: 0

Administrators: admin: 1