1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.owasp.dependencycheck.taskdefs;
19
20 import org.apache.tools.ant.BuildException;
21 import org.owasp.dependencycheck.Engine;
22 import org.owasp.dependencycheck.data.nvdcve.DatabaseException;
23 import org.owasp.dependencycheck.utils.Settings;
24 import org.slf4j.impl.StaticLoggerBinder;
25
26
27
28
29
30
31
32 public class Update extends Purge {
33
34
35
36
37 public Update() {
38 super();
39
40
41 StaticLoggerBinder.getSingleton().setTask(this);
42 }
43
44
45
46
47 private String proxyServer;
48
49
50
51
52
53
54 public String getProxyServer() {
55 return proxyServer;
56 }
57
58
59
60
61
62
63 public void setProxyServer(String server) {
64 this.proxyServer = server;
65 }
66
67
68
69
70 private String proxyPort;
71
72
73
74
75
76
77 public String getProxyPort() {
78 return proxyPort;
79 }
80
81
82
83
84
85
86 public void setProxyPort(String proxyPort) {
87 this.proxyPort = proxyPort;
88 }
89
90
91
92 private String proxyUsername;
93
94
95
96
97
98
99 public String getProxyUsername() {
100 return proxyUsername;
101 }
102
103
104
105
106
107
108 public void setProxyUsername(String proxyUsername) {
109 this.proxyUsername = proxyUsername;
110 }
111
112
113
114 private String proxyPassword;
115
116
117
118
119
120
121 public String getProxyPassword() {
122 return proxyPassword;
123 }
124
125
126
127
128
129
130 public void setProxyPassword(String proxyPassword) {
131 this.proxyPassword = proxyPassword;
132 }
133
134
135
136 private String connectionTimeout;
137
138
139
140
141
142
143 public String getConnectionTimeout() {
144 return connectionTimeout;
145 }
146
147
148
149
150
151
152 public void setConnectionTimeout(String connectionTimeout) {
153 this.connectionTimeout = connectionTimeout;
154 }
155
156
157
158 private String databaseDriverName;
159
160
161
162
163
164
165 public String getDatabaseDriverName() {
166 return databaseDriverName;
167 }
168
169
170
171
172
173
174 public void setDatabaseDriverName(String databaseDriverName) {
175 this.databaseDriverName = databaseDriverName;
176 }
177
178
179
180
181 private String databaseDriverPath;
182
183
184
185
186
187
188 public String getDatabaseDriverPath() {
189 return databaseDriverPath;
190 }
191
192
193
194
195
196
197 public void setDatabaseDriverPath(String databaseDriverPath) {
198 this.databaseDriverPath = databaseDriverPath;
199 }
200
201
202
203 private String connectionString;
204
205
206
207
208
209
210 public String getConnectionString() {
211 return connectionString;
212 }
213
214
215
216
217
218
219 public void setConnectionString(String connectionString) {
220 this.connectionString = connectionString;
221 }
222
223
224
225 private String databaseUser;
226
227
228
229
230
231
232 public String getDatabaseUser() {
233 return databaseUser;
234 }
235
236
237
238
239
240
241 public void setDatabaseUser(String databaseUser) {
242 this.databaseUser = databaseUser;
243 }
244
245
246
247
248 private String databasePassword;
249
250
251
252
253
254
255 public String getDatabasePassword() {
256 return databasePassword;
257 }
258
259
260
261
262
263
264 public void setDatabasePassword(String databasePassword) {
265 this.databasePassword = databasePassword;
266 }
267
268
269
270
271 private String cveUrl12Modified;
272
273
274
275
276
277
278 public String getCveUrl12Modified() {
279 return cveUrl12Modified;
280 }
281
282
283
284
285
286
287 public void setCveUrl12Modified(String cveUrl12Modified) {
288 this.cveUrl12Modified = cveUrl12Modified;
289 }
290
291
292
293
294 private String cveUrl20Modified;
295
296
297
298
299
300
301 public String getCveUrl20Modified() {
302 return cveUrl20Modified;
303 }
304
305
306
307
308
309
310 public void setCveUrl20Modified(String cveUrl20Modified) {
311 this.cveUrl20Modified = cveUrl20Modified;
312 }
313
314
315
316
317 private String cveUrl12Base;
318
319
320
321
322
323
324 public String getCveUrl12Base() {
325 return cveUrl12Base;
326 }
327
328
329
330
331
332
333 public void setCveUrl12Base(String cveUrl12Base) {
334 this.cveUrl12Base = cveUrl12Base;
335 }
336
337
338
339
340 private String cveUrl20Base;
341
342
343
344
345
346
347 public String getCveUrl20Base() {
348 return cveUrl20Base;
349 }
350
351
352
353
354
355
356 public void setCveUrl20Base(String cveUrl20Base) {
357 this.cveUrl20Base = cveUrl20Base;
358 }
359
360
361
362
363
364
365
366 @Override
367 public void execute() throws BuildException {
368 populateSettings();
369 Engine engine = null;
370 try {
371 engine = new Engine(Update.class.getClassLoader());
372 engine.doUpdates();
373 } catch (DatabaseException ex) {
374 throw new BuildException("Unable to connect to the dependency-check database; unable to update the NVD data", ex);
375 } finally {
376 Settings.cleanup(true);
377 if (engine != null) {
378 engine.cleanup();
379 }
380 }
381 }
382
383
384
385
386
387 @Override
388 protected void populateSettings() {
389 super.populateSettings();
390 if (proxyServer != null && !proxyServer.isEmpty()) {
391 Settings.setString(Settings.KEYS.PROXY_SERVER, proxyServer);
392 }
393 if (proxyPort != null && !proxyPort.isEmpty()) {
394 Settings.setString(Settings.KEYS.PROXY_PORT, proxyPort);
395 }
396 if (proxyUsername != null && !proxyUsername.isEmpty()) {
397 Settings.setString(Settings.KEYS.PROXY_USERNAME, proxyUsername);
398 }
399 if (proxyPassword != null && !proxyPassword.isEmpty()) {
400 Settings.setString(Settings.KEYS.PROXY_PASSWORD, proxyPassword);
401 }
402 if (connectionTimeout != null && !connectionTimeout.isEmpty()) {
403 Settings.setString(Settings.KEYS.CONNECTION_TIMEOUT, connectionTimeout);
404 }
405 if (databaseDriverName != null && !databaseDriverName.isEmpty()) {
406 Settings.setString(Settings.KEYS.DB_DRIVER_NAME, databaseDriverName);
407 }
408 if (databaseDriverPath != null && !databaseDriverPath.isEmpty()) {
409 Settings.setString(Settings.KEYS.DB_DRIVER_PATH, databaseDriverPath);
410 }
411 if (connectionString != null && !connectionString.isEmpty()) {
412 Settings.setString(Settings.KEYS.DB_CONNECTION_STRING, connectionString);
413 }
414 if (databaseUser != null && !databaseUser.isEmpty()) {
415 Settings.setString(Settings.KEYS.DB_USER, databaseUser);
416 }
417 if (databasePassword != null && !databasePassword.isEmpty()) {
418 Settings.setString(Settings.KEYS.DB_PASSWORD, databasePassword);
419 }
420 if (cveUrl12Modified != null && !cveUrl12Modified.isEmpty()) {
421 Settings.setString(Settings.KEYS.CVE_MODIFIED_12_URL, cveUrl12Modified);
422 }
423 if (cveUrl20Modified != null && !cveUrl20Modified.isEmpty()) {
424 Settings.setString(Settings.KEYS.CVE_MODIFIED_20_URL, cveUrl20Modified);
425 }
426 if (cveUrl12Base != null && !cveUrl12Base.isEmpty()) {
427 Settings.setString(Settings.KEYS.CVE_SCHEMA_1_2, cveUrl12Base);
428 }
429 if (cveUrl20Base != null && !cveUrl20Base.isEmpty()) {
430 Settings.setString(Settings.KEYS.CVE_SCHEMA_2_0, cveUrl20Base);
431 }
432 }
433 }