├── .gitignore
├── CHANGELOG.md
├── LICENSE
├── README.md
├── pom.xml
└── src
├── main
├── java
│ ├── com
│ │ └── m11n
│ │ │ └── jdbc
│ │ │ └── ssh
│ │ │ ├── SshConfiguration.java
│ │ │ ├── SshDriver.java
│ │ │ └── SshTunnel.java
│ └── overview.ad
└── resources
│ ├── META-INF
│ └── services
│ │ └── java.sql.Driver
│ └── PROPERTIES
├── site
├── asciidoc
│ ├── configuration.adoc
│ ├── contribute.adoc
│ └── index.adoc
├── resources
│ ├── css
│ │ └── site.css
│ └── images
│ │ └── bg.png
└── site.xml
└── test
├── java
└── com
│ └── m11n
│ └── jdbc
│ └── ssh
│ ├── DerbySshDriverTest.java
│ ├── H2SshDriverTest.java
│ ├── JdbcSshDriverTest.java
│ └── util
│ ├── BogusPasswordAuthenticator.java
│ ├── Slf4jDerbyBridge.java
│ ├── Slf4jOutputStream.java
│ └── TestCachingPublicKeyAuthenticator.java
└── resources
├── logback.xml
└── ssh.properties
/.gitignore:
--------------------------------------------------------------------------------
1 | target/
2 | pom.xml.tag
3 | pom.xml.releaseBackup
4 | pom.xml.versionsBackup
5 | pom.xml.next
6 | release.config
7 | atlassian-ide-plugin.xml
8 | .idea
9 | *.iml
10 | build.sh
11 | release.sh
12 | trace.db
13 | derby.log
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | 1.0.10
2 |
3 | - bug fix: avoid wrong local port increment (@emac)
4 | - Update dependencies
5 |
6 | 1.0.9
7 |
8 | - pass original connect properties to real driver and 1 bug fix (@emac)
9 |
10 | 1.0.8
11 |
12 | - Osgi compatible package structure
13 | - Constistent naming of classes (should be final now)
14 |
15 | 1.0.7
16 |
17 | - release promoted to Maven central
18 | - fixed GPG signing for releases
19 |
20 | 1.0.6
21 |
22 | - project configuration improvements
23 |
24 | 1.0.5
25 |
26 | - project configuration improvements
27 |
28 | 1.0.4
29 |
30 | - project configuration improvements
31 |
32 | 1.0.3
33 |
34 | - check for valid configuration properties
35 | - refactored all packages to "com.m11n.jdbc"
36 | - project configuration improvements
37 |
38 | 1.0.2
39 |
40 | - passwordless logins
41 | - Derby logging over Slf4j
42 | - GPG signing for Maven Central
43 | - use Asciidoclet
44 | - minor improvements and bugfixes
45 |
46 | 1.0.1
47 |
48 | - Initial release
49 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "{}"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright {yyyy} {name of copyright owner}
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
203 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # jdbc-ssh
2 |
3 | JDBC driver over SSH tunnel. 
4 |
5 |
6 | ## Build
7 |
8 | If you just want to compile the project without running the tests:
9 |
10 | ```
11 | mvn -DskipTests clean install
12 | ```
13 |
14 | If you want to run the tests (Derby and H2 in server mode):
15 |
16 | ```
17 | mvn -Djdbc.ssh.username="xxx" -Djdbc.ssh.password="xxx" clean install
18 | ```
19 |
20 | NOTE:
21 |
22 | If your SSH server is not running on the default port 22 and/or localhost then you can change those parameters:
23 |
24 | ```
25 | mvn -Djdbc.ssh.username="xxx" -Djdbc.ssh.password="xxx" -Djdbc.ssh.host="192.168.0.1" -Djdbc.ssh.port="2222" clean install
26 | ```
27 |
28 | At the moment a locally running SSH server is needed for the tests. The embedded SSH server in the unit tests is not yet
29 | ready (authentication works, but port forwarding fails at the moment).
30 |
31 | ## Maven dependencies
32 |
33 | You can find the latest releases here:
34 |
35 | [  ](https://bintray.com/cheetah/monkeysintown/jdbc-ssh/_latestVersion)
36 |
37 | ... or setup your Maven dependencies:
38 |
39 | ```xml
40 |
41 | com.github.monkeysintown
42 | jdbc-ssh
43 | 1.0.9
44 |
45 | ```
46 |
47 | ... and configure Bintray's JCenter repository in your pom.xml:
48 |
49 | ```xml
50 | ...
51 |
52 |
53 |
54 | false
55 |
56 | central
57 | bintray
58 | http://jcenter.bintray.com
59 |
60 |
61 | ...
62 | ```
63 |
64 | Get automatic notifications about new releases here:
65 |
66 | [  ](https://bintray.com/cheetah/monkeysintown/jdbc-ssh/view?source=watch)
67 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | com.github.monkeysintown
6 | jdbc-ssh
7 | 1.0.11-SNAPSHOT
8 |
9 | jar
10 | JDBC SSH
11 | JDBC over SSH
12 | https://monkeysintown.github.io/jdbc-ssh
13 |
14 |
15 |
16 | Apache 2.0
17 | http://www.apache.org/licenses/LICENSE-2.0.txt
18 | repo
19 |
20 |
21 |
22 |
23 | Monkeys in Town Lda.
24 | https://github.com/monkeysintown
25 |
26 |
27 |
28 | scm:git:https://github.com/monkeysintown/jdbc-ssh.git
29 | scm:git:https://github.com/monkeysintown/jdbc-ssh.git
30 | scm:git:https://github.com/monkeysintown/jdbc-ssh.git
31 |
32 |
33 |
34 |
35 | vidakovic
36 | Aleksandar Vidakovic
37 |
38 | https://github.com/vidakovic
39 | Monkeys in Town Lda.
40 | https://github.com/monkeysintown
41 |
42 | developer
43 |
44 | 0
45 |
46 |
47 |
48 |
49 | 3.2.3
50 |
51 |
52 |
53 | 1.7.12
54 | 1.1.3
55 | 0.1.53
56 | 1.1.3
57 | UTF-8
58 | UTF-8
59 | 1.7
60 | github
61 |
62 |
63 |
64 |
65 | bintray
66 | https://api.bintray.com/maven/cheetah/monkeysintown/jdbc-ssh
67 |
68 |
69 |
70 |
71 |
72 | rubygems-release
73 | http://rubygems-proxy.torquebox.org/releases
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 | com.jcraft
82 | jsch
83 | ${jsch.version}
84 |
85 |
86 | com.jcraft
87 | jzlib
88 | ${jzlib.version}
89 |
90 |
91 |
92 |
93 | org.slf4j
94 | slf4j-api
95 | ${slf4j.version}
96 |
97 |
98 | ch.qos.logback
99 | logback-core
100 | ${logback.version}
101 | true
102 |
103 |
104 | ch.qos.logback
105 | logback-classic
106 | ${logback.version}
107 | true
108 |
109 |
110 | org.slf4j
111 | slf4j-api
112 |
113 |
114 |
115 |
116 |
117 | mysql
118 | mysql-connector-java
119 | 5.1.34
120 | test
121 |
122 |
123 |
124 | com.h2database
125 | h2
126 | 1.4.183
127 | test
128 |
129 |
130 |
131 | org.apache.derby
132 | derby
133 | 10.11.1.1
134 | test
135 |
136 |
137 |
138 | org.apache.derby
139 | derbynet
140 | 10.11.1.1
141 | test
142 |
143 |
144 |
145 | org.apache.derby
146 | derbyclient
147 | 10.11.1.1
148 | test
149 |
150 |
151 |
152 | org.apache.sshd
153 | sshd-core
154 | 0.14.0
155 | test
156 |
157 |
158 | org.slf4j
159 | slf4j-api
160 |
161 |
162 |
163 |
164 |
165 | org.bouncycastle
166 | bcpg-jdk15on
167 | 1.52
168 | test
169 |
170 |
171 | org.bouncycastle
172 | bcpkix-jdk15on
173 | 1.52
174 | test
175 |
176 |
177 |
178 | junit
179 | junit
180 | 4.12
181 | test
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 | src/main/resources
191 | true
192 |
193 |
194 |
195 |
196 |
197 |
198 | org.apache.maven.plugins
199 | maven-source-plugin
200 | 2.2.1
201 |
202 |
203 | attach-sources
204 |
205 | jar-no-fork
206 |
207 |
208 |
209 |
210 |
211 |
212 | org.apache.maven.plugins
213 | maven-compiler-plugin
214 | 3.2
215 |
216 | ${java.version}
217 | ${java.version}
218 |
219 |
220 |
221 |
222 | org.apache.maven.plugins
223 | maven-deploy-plugin
224 | 2.8.2
225 |
226 |
227 |
228 | org.apache.maven.plugins
229 | maven-project-info-reports-plugin
230 | 2.7
231 |
232 |
233 |
234 | org.asciidoctor
235 | asciidoctor-maven-plugin
236 | 1.5.2
237 |
238 | ${project.build.directory}/generated-docs/asciidoc
239 | ${project.build.directory}/generated-docs/asciidoc
240 | index.ad
241 | ${project.build.directory}/gems-provided
242 |
243 |
244 | true
245 | true
246 | UTF-8
247 | images
248 |
249 |
250 | true
251 | left
252 | font
253 | true
254 |
255 | -
256 | true
257 | ${project.url}
258 | ${project.build.sourceDirectory}
259 |
260 | coderay
261 |
262 |
263 |
264 |
265 | asciidoc-to-docbook
266 | generate-resources
267 |
268 | process-asciidoc
269 |
270 |
271 | ${project.build.directory}/generated-docs/docbook/en-US
272 | docbook5
273 | book
274 | slim
275 | true
276 | false
277 |
278 |
279 |
280 | asciidoc-to-html5
281 | generate-resources
282 |
283 | process-asciidoc
284 |
285 |
286 | ${project.build.directory}/generated-docs/html5
287 | html5
288 |
289 |
290 |
291 | asciidoc-to-pdf
292 | generate-resources
293 |
294 | process-asciidoc
295 |
296 |
297 | ${project.build.directory}/gems
298 |
299 | asciidoctor-pdf
300 |
301 | pdf
302 |
303 |
304 |
305 |
306 |
307 | org.asciidoctor
308 | asciidoctorj
309 | 1.5.2
310 |
311 |
312 | org.jruby
313 | jruby-complete
314 | 1.7.18
315 |
316 |
317 |
318 |
319 |
320 | com.github.github
321 | site-maven-plugin
322 | 0.10
323 |
324 | Creating site for ${project.version}
325 |
326 |
327 |
328 |
329 | site
330 |
331 | site
332 |
333 |
334 |
335 |
336 |
337 | org.apache.maven.plugins
338 | maven-site-plugin
339 | 3.4
340 |
341 |
342 | lt.velykis.maven.skins
343 | reflow-velocity-tools
344 | 1.1.1
345 |
346 |
347 |
348 | org.apache.velocity
349 | velocity
350 | 1.7
351 |
352 |
353 | org.asciidoctor
354 | asciidoctor-maven-plugin
355 | 1.5.2
356 |
357 |
358 |
359 |
360 | external.atlassian.jgitflow
361 | jgitflow-maven-plugin
362 | 1.0-m4.3
363 |
364 | ${github.username}
365 | ${github.password}
366 | true
367 | true
368 | true
369 | false
370 | false
371 | false
372 | false
373 | true
374 |
375 |
376 |
377 |
378 | org.apache.maven.plugins
379 | maven-javadoc-plugin
380 | 2.10.1
381 |
382 |
383 | attach-javadocs
384 |
385 | test-jar
386 | jar
387 |
388 |
389 |
390 |
391 | ${java.version}
392 | org.asciidoctor.Asciidoclet
393 |
394 | org.asciidoctor
395 | asciidoclet
396 | 1.5.1
397 |
398 | src/main/java/overview.ad
399 |
400 | --base-dir ${project.basedir}
401 | --attribute "name=${project.name}"
402 | --attribute "version=${project.version}"
403 | --attribute "title-link=${project.url}[${project.name} ${project.version}]"
404 |
405 | true
406 |
407 |
408 |
409 |
410 | org.owasp
411 | dependency-check-maven
412 | 1.2.8
413 |
414 |
415 |
416 | check
417 |
418 |
419 |
420 |
421 |
422 |
423 | org.apache.maven.plugins
424 | maven-gpg-plugin
425 | 1.5
426 |
427 |
428 | sign-artifacts
429 | verify
430 |
431 | sign
432 |
433 |
434 |
435 |
436 |
437 |
438 |
439 |
440 |
441 | org.apache.maven.plugins
442 | maven-compiler-plugin
443 |
444 |
445 |
446 | external.atlassian.jgitflow
447 | jgitflow-maven-plugin
448 |
449 |
450 |
451 |
452 |
453 |
454 |
455 | org.owasp
456 | dependency-check-maven
457 |
458 |
459 |
460 | aggregate
461 |
462 |
463 |
464 |
465 |
466 |
467 |
468 |
469 |
470 | release-profile
471 |
472 |
473 | performRelease
474 | true
475 |
476 |
477 |
478 |
479 |
480 | org.apache.maven.plugins
481 | maven-javadoc-plugin
482 |
483 |
484 |
485 | org.apache.maven.plugins
486 | maven-gpg-plugin
487 |
488 |
489 |
490 | com.github.github
491 | site-maven-plugin
492 |
493 |
494 |
495 |
496 |
497 |
498 |
499 |
--------------------------------------------------------------------------------
/src/main/java/com/m11n/jdbc/ssh/SshConfiguration.java:
--------------------------------------------------------------------------------
1 | package com.m11n.jdbc.ssh;
2 |
3 | import org.slf4j.Logger;
4 | import org.slf4j.LoggerFactory;
5 |
6 | import java.io.*;
7 | import java.util.*;
8 |
9 | /**
10 | * = JdbcSshConfiguration
11 | *
12 | * A think wrapper around `java.util.Properties`.
13 | *
14 | * @author https://github.com/vidakovic[Aleksandar Vidakovic]
15 | */
16 | public class SshConfiguration {
17 | private static final Logger logger = LoggerFactory.getLogger(SshConfiguration.class);
18 |
19 | public static final String CONFIG = "jdbc.ssh.config";
20 | public static final String DRIVER_PREFIX = "jdbc:ssh:";
21 | public static final String CONFIG_HOST = "jdbc.ssh.host";
22 | public static final String CONFIG_PORT = "jdbc.ssh.port";
23 | public static final String CONFIG_USERNAME = "jdbc.ssh.username";
24 | public static final String CONFIG_PASSWORD = "jdbc.ssh.password";
25 | public static final String CONFIG_KEY_PRIVATE = "jdbc.ssh.key.private";
26 | public static final String CONFIG_KEY_PUBLIC = "jdbc.ssh.key.public";
27 | public static final String CONFIG_PASSPHRASE = "jdbc.ssh.passphrase";
28 | public static final String CONFIG_KNOWN_HOSTS = "jdbc.ssh.known.hosts";
29 | public static final String CONFIG_HOST_REMOTE = "jdbc.ssh.host.remote";
30 | public static final String CONFIG_PORT_REMOTE = "jdbc.ssh.port.remote";
31 | public static final String CONFIG_PORT_AUTO = "jdbc.ssh.port.auto";
32 |
33 | private Properties config;
34 |
35 | private final Set allowed = new HashSet<>();
36 |
37 | public SshConfiguration() {
38 | importAllowedPropertyNames();
39 |
40 | config = new Properties();
41 |
42 | try {
43 | InputStream is;
44 |
45 | String path = System.getProperty(CONFIG)==null ? "ssh.properties" : System.getProperty(CONFIG);
46 |
47 | File f = new File(path);
48 |
49 | if(f.exists()) {
50 | is = new FileInputStream(f);
51 | } else {
52 | is = SshConfiguration.class.getClassLoader().getResourceAsStream(path);
53 | }
54 |
55 | if(is!=null) {
56 | config.load(is);
57 | }
58 |
59 | check(config);
60 |
61 | config = setDefaults(config);
62 | } catch(Exception e) {
63 | logger.warn(e.toString(), e);
64 | }
65 | }
66 |
67 | public SshConfiguration(Properties c) {
68 | this();
69 |
70 | // NOTE: assume same username and password for SSH connection and database if not set explicitly
71 | if(c.getProperty("user")!=null && config.getProperty(CONFIG_USERNAME) == null) {
72 | config.setProperty(CONFIG_USERNAME, c.getProperty("user"));
73 | }
74 | if(c.getProperty("password")!=null && config.getProperty(CONFIG_PASSWORD) == null) {
75 | config.setProperty(CONFIG_PASSWORD, c.getProperty("password"));
76 | }
77 |
78 | for(String key : allowed) {
79 | if(c.getProperty(key)!=null && !"".equals(c.getProperty(key).trim())) {
80 | config.setProperty(key, c.getProperty(key));
81 | }
82 | }
83 |
84 | if(logger.isDebugEnabled()) {
85 | logger.debug("Configuration: {}", config);
86 | }
87 | }
88 |
89 | private void importAllowedPropertyNames() {
90 | try {
91 | allowed.clear();
92 |
93 | BufferedReader reader = new BufferedReader(new InputStreamReader(SshConfiguration.class.getClassLoader().getResourceAsStream("PROPERTIES")));
94 |
95 | String line;
96 |
97 | while((line=reader.readLine())!=null) {
98 | allowed.add(line);
99 | }
100 | } catch(Exception e) {
101 | throw new RuntimeException(e);
102 | }
103 | }
104 |
105 | private Properties setDefaults(Properties c) {
106 | if(c.getProperty("Compression")==null) {
107 | c.put("Compression", getSystemPropertyOrDefault("Compression", "no"));
108 | }
109 | if(c.getProperty("ConnectionAttempts") == null) {
110 | c.put("ConnectionAttempts", getSystemPropertyOrDefault("ConnectionAttempts", "2"));
111 | }
112 | if(c.getProperty("StrictHostKeyChecking")==null) {
113 | c.put("StrictHostKeyChecking", getSystemPropertyOrDefault("StrictHostKeyChecking", "no"));
114 | }
115 | if(c.getProperty(CONFIG_HOST)==null) {
116 | c.put(CONFIG_HOST, getSystemPropertyOrDefault(CONFIG_HOST, "localhost"));
117 | }
118 | if(c.getProperty(CONFIG_PORT)==null) {
119 | c.put(CONFIG_PORT, getSystemPropertyOrDefault(CONFIG_PORT, "22"));
120 | }
121 | if(c.getProperty(CONFIG_PORT_AUTO)==null) {
122 | c.put(CONFIG_PORT_AUTO, getSystemPropertyOrDefault(CONFIG_PORT_AUTO, "20000"));
123 | }
124 | if(c.getProperty(CONFIG_USERNAME)==null) {
125 | c.put(CONFIG_USERNAME, System.getProperty(CONFIG_USERNAME));
126 | }
127 | if(c.getProperty(CONFIG_PASSWORD)==null) {
128 | c.put(CONFIG_PASSWORD, System.getProperty(CONFIG_PASSWORD));
129 | }
130 | if(c.getProperty(CONFIG_KEY_PRIVATE)==null) {
131 | c.put(CONFIG_KEY_PRIVATE, getSystemPropertyOrDefault(CONFIG_KEY_PRIVATE, ""));
132 | }
133 | if(c.getProperty(CONFIG_KEY_PUBLIC)==null) {
134 | c.put(CONFIG_KEY_PUBLIC, getSystemPropertyOrDefault(CONFIG_KEY_PUBLIC, c.getProperty(CONFIG_KEY_PRIVATE) + ".pub"));
135 | }
136 | if(c.getProperty(CONFIG_PASSPHRASE)==null) {
137 | c.put(CONFIG_PASSPHRASE, getSystemPropertyOrDefault(CONFIG_PASSPHRASE, ""));
138 | }
139 | if(c.getProperty(CONFIG_KNOWN_HOSTS)==null) {
140 | c.put(CONFIG_KNOWN_HOSTS, getSystemPropertyOrDefault(CONFIG_KNOWN_HOSTS, "~/.ssh/known_hosts"));
141 | }
142 |
143 | return c;
144 | }
145 |
146 | private void check(Properties c) {
147 | Enumeration