Skip to content

Commit 7cf27d2

Browse files
JavaJoeSjukzi
authored andcommitted
Add checks for PKI properties
1 parent f732132 commit 7cf27d2

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed

team/bundles/org.eclipse.core.pki/src/org/eclipse/core/pki/auth/SecurityFileSnapshot.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import java.util.Properties;
3535
import java.util.Set;
3636

37+
import org.eclipse.core.pki.util.DotPkiPropertiesRequired;
3738
import org.eclipse.core.pki.util.LogUtil;
3839
import org.eclipse.core.pki.util.NormalizeGCM;
3940
import org.eclipse.core.pki.util.SecureGCM;
@@ -64,6 +65,10 @@ public boolean image() {
6465
FileSystems.getDefault().getSeparator()+DotEclipse+
6566
FileSystems.getDefault().getSeparator()+
6667
".pki");
68+
if (!DotPkiPropertiesRequired.CHECKER.testFile(userDotEclipseHome)) {
69+
TemplateForPKIfile.CREATION.setup();
70+
return false;
71+
}
6772
} else {
6873
LogUtil.logWarning("NO PKI file detected");
6974
/*
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.eclipse.core.pki.util;
2+
3+
import java.nio.channels.Channels;
4+
import java.nio.channels.FileChannel;
5+
import java.nio.channels.FileLock;
6+
import java.nio.file.Files;
7+
import java.nio.file.Path;
8+
import java.nio.file.StandardOpenOption;
9+
import java.util.ArrayList;
10+
import java.util.Arrays;
11+
import java.util.LinkedList;
12+
import java.util.List;
13+
import java.util.Properties;
14+
import java.util.Set;
15+
16+
public enum DotPkiPropertiesRequired {
17+
CHECKER;
18+
List<String> list = get();
19+
public boolean testFile(Path path) {
20+
Properties properties=new Properties();
21+
System.out.println("DotPkiPropertiesRequired testFile:"+path.toString());
22+
try {
23+
if (Files.exists(path)) {
24+
final FileChannel channel = FileChannel.open(path, StandardOpenOption.READ);
25+
final FileLock lock = channel.lock(0L, Long.MAX_VALUE, true);
26+
properties.load(Channels.newInputStream(channel));
27+
Set<Object> keys=properties.keySet();
28+
lock.close();
29+
for ( Object key: keys ) {
30+
isProperty((String)key);
31+
}
32+
if ( list.isEmpty()) {
33+
//System.out.println("DotPkiPropertiesRequired All proeprties exist:"+list.size());
34+
return true;
35+
} else {
36+
//System.out.println("DotPkiPropertiesRequired missing preoperties");
37+
LogUtil.logWarning("Missing properies;"+ list.toString());
38+
}
39+
} else {
40+
LogUtil.logWarning("DotPkiPropertiesRequired- NO PKI file detected");
41+
}
42+
43+
} catch (Exception e) {
44+
// TODO Auto-generated catch block
45+
e.printStackTrace();
46+
}
47+
48+
return false;
49+
}
50+
private void isProperty(String s) {
51+
if ( list.contains(s)) {
52+
list.remove(s);
53+
}
54+
55+
}
56+
private List<String> get() {
57+
List<String> l = new LinkedList<String>();
58+
l = Arrays.asList("javax.net.ssl.trustStore","javax.net.ssl.trustStoreType",
59+
"javax.net.ssl.trustStorePassword","javax.net.ssl.keyStoreType",
60+
"javax.net.ssl.keyStoreProvider","javax.net.ssl.cfgFileLocation",
61+
"javax.net.ssl.keyStorePassword", "javax.net.ssl.keyStore");
62+
List<String> list = new ArrayList(l);
63+
return list;
64+
}
65+
}

0 commit comments

Comments
 (0)