1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package cz.hobrasoft.pdfmu.operation.signature;
18
19 import cz.hobrasoft.pdfmu.error.ErrorType;
20 import cz.hobrasoft.pdfmu.operation.OperationException;
21 import java.io.File;
22 import java.util.AbstractMap;
23 import java.util.logging.Logger;
24 import org.apache.commons.io.FilenameUtils;
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40 public enum SslKeystore {
41
42
43
44
45
46 PRIVATE("javax.net.ssl.keyStore",
47 "javax.net.ssl.keyStorePassword",
48 "javax.net.ssl.keyStoreType",
49 "SSL KeyStore",
50 ErrorType.SSL_KEYSTORE_NOT_FOUND),
51
52
53
54
55
56 TRUSTSTORE("javax.net.ssl.trustStore",
57 "javax.net.ssl.trustStorePassword",
58 "javax.net.ssl.trustStoreType",
59 "SSL TrustStore",
60 ErrorType.SSL_TRUSTSTORE_NOT_FOUND);
61
62 private static final Logger LOGGER = Logger.getLogger(SslKeystore.class.getName());
63
64 private final String keyLocation;
65 private final String keyPassword;
66 private final String keyType;
67 private final String name;
68 private final ErrorType errorTypeNotFound;
69
70 private SslKeystore(String location,
71 String password,
72 String type,
73 String name,
74 ErrorType errorTypeNotFound) {
75 this.keyLocation = location;
76 this.keyPassword = password;
77 this.keyType = type;
78 this.name = name;
79 this.errorTypeNotFound = errorTypeNotFound;
80 }
81
82
83
84
85 public String getName() {
86 return name;
87 }
88
89
90
91
92
93
94
95
96
97 public void setSystemProperties(File file, String type, String password) throws OperationException {
98 if (file != null) {
99
100
101 String location = FilenameUtils.separatorsToUnix(file.getPath());
102 if (!file.exists()) {
103 throw new OperationException(errorTypeNotFound,
104 new AbstractMap.SimpleEntry<String, Object>("location", location));
105 }
106 LOGGER.info(String.format("%s: Configuring to use the keystore file %s.", name, location));
107 System.setProperty(keyLocation, location);
108 }
109
110 if (type != null) {
111 if (file == null) {
112 LOGGER.warning(String.format("%s: Type has been specified but location has not.", name));
113 }
114
115 System.setProperty(keyType, type);
116 }
117
118 if (password != null) {
119 if (file == null) {
120 LOGGER.warning(String.format("%s: Password has been specified but location has not.", name));
121 }
122 System.setProperty(keyPassword, password);
123 }
124 }
125 }