source: other-projects/trunk/gs3-release-maker/tasks/sshtaskdef/src/mindbright/application/MindTunnel.java@ 14627

Last change on this file since 14627 was 14627, checked in by oranfry, 17 years ago

initial import of the gs3-release-maker

File size: 4.3 KB
Line 
1/******************************************************************************
2 *
3 * Copyright (c) 1998,99 by Mindbright Technology AB, Stockholm, Sweden.
4 * www.mindbright.se, [email protected]
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 *****************************************************************************
17 * $Author: mats $
18 * $Date: 1999/10/31 13:19:39 $
19 * $Name: rel1-2-1 $
20 *****************************************************************************/
21package mindbright.application;
22
23import java.io.*;
24
25import java.awt.*;
26import java.awt.event.*;
27
28import mindbright.ssh.*;
29import mindbright.security.*;
30import mindbright.terminal.*;
31
32public class MindTunnel {
33
34 public static void main(String[] argv) {
35 MindTunnel controller = new MindTunnel();
36 controller.startup(argv);
37 }
38
39 public void startup(String[] argv) {
40 try {
41 String hostKeyFile = null;
42 String authKeysDir = null;
43 boolean doGenerateId = false;
44 int port = SSH.DEFAULTPORT;
45 int bits = 0;
46 int i;
47
48 for(i = 0; i < argv.length; i++) {
49 String arg = argv[i];
50 if(arg.charAt(0) != '-')
51 break;
52 switch(arg.charAt(1)) {
53 case 'a':
54 authKeysDir = argv[++i] + File.separatorChar;
55 break;
56 case 'b':
57 bits = Integer.parseInt(argv[++i]);
58 break;
59 case 'g':
60 doGenerateId = true;
61 break;
62 case 'v':
63 System.out.println("verbose mode selected...");
64 SSH.DEBUG = true;
65 break;
66 case 'V':
67 System.out.println(SSH.VER_MINDTUNL);
68 System.out.println("SSH protocol version " + SSH.SSH_VER_MAJOR + "." + SSH.SSH_VER_MINOR);
69 System.exit(0);
70 break;
71 case 'p':
72 port = Integer.parseInt(argv[++i]);
73 break;
74 default:
75 throw new Exception();
76 }
77 }
78
79 if(bits == 0)
80 bits = (doGenerateId ? SSH.HOST_KEY_LENGTH : SSH.SERVER_KEY_LENGTH);
81
82 if(doGenerateId) {
83 BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
84 String fileName, comment, passwd;
85 System.out.print("filename: ");
86 fileName = br.readLine();
87 System.out.print("password (return for none): ");
88 passwd = br.readLine();
89 System.out.print("comment: ");
90 comment = br.readLine();
91
92 System.out.print("Generating " + (passwd.length() == 0 ? "(unencrypted) " : "") +
93 "identity of length " + bits + "...");
94 KeyPair kp = SSH.generateRSAKeyPair(bits, SSH.secureRandom());
95 System.out.println("done");
96
97 SSH.generateKeyFiles(kp, fileName, passwd, comment);
98 System.exit(0);
99 }
100
101 hostKeyFile = argv[i];
102
103 if(authKeysDir == null) {
104 i = hostKeyFile.lastIndexOf(File.separatorChar);
105 if(i != -1)
106 authKeysDir = hostKeyFile.substring(0, i + 1);
107 else
108 authKeysDir = "";
109 }
110
111 SSHServer.setAuthKeysDir(authKeysDir);
112 SSHServer.setHostKeyFile(hostKeyFile);
113 SSHServer.setServerKeyBits(bits);
114
115 SSHServer.sshd(port);
116
117 } catch(FileNotFoundException e) {
118 System.out.println("File not found: " + e.getMessage());
119 } catch(IOException e) {
120 System.out.println("Error starting MindTunnel sshd: " + e.getMessage());
121 } catch(Exception e) {
122 System.out.println("usage: MindTunnel [options] <host_key_file>");
123 System.out.println("Options:");
124 System.out.println(" -a <dir> Directory where the users authorized_keys files are located");
125 System.out.println(" (default same dir as host-key).");
126 System.out.println(" -b <bits> Specifies the number of bits in the server key (default 768).");
127 System.out.println(" OR length of key to generate with option -g.");
128 System.out.println(" -g Generate authentication key pair files (default 1024 bits).");
129 System.out.println(" -v Verbose; display verbose debugging messages.");
130 System.out.println(" -V Display version number only.");
131 System.out.println(" -p <port> Port to listen for connections on (default is 22).");
132 }
133
134 System.exit(0);
135 }
136
137
138}
Note: See TracBrowser for help on using the repository browser.