1 /*
2  * Dropbear - a SSH2 server
3  *
4  * Copyright (c) 2002,2003 Matt Johnston
5  * All rights reserved.
6  *
7  * Permission is hereby granted, free of charge, to any person obtaining a copy
8  * of this software and associated documentation files (the "Software"), to deal
9  * in the Software without restriction, including without limitation the rights
10  * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11  * copies of the Software, and to permit persons to whom the Software is
12  * furnished to do so, subject to the following conditions:
13  *
14  * The above copyright notice and this permission notice shall be included in
15  * all copies or substantial portions of the Software.
16  *
17  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20  * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23  * SOFTWARE. */
24 
25 #include "includes.h"
26 #include "runopts.h"
27 #include "signkey.h"
28 #include "buffer.h"
29 #include "dbutil.h"
30 #include "auth.h"
31 #include "algo.h"
32 #include "dbrandom.h"
33 
34 runopts opts; /* GLOBAL */
35 
36 /* returns success or failure, and the keytype in *type. If we want
37  * to restrict the type, type can contain a type to return */
readhostkey(const char * filename,sign_key * hostkey,enum signkey_type * type)38 int readhostkey(const char * filename, sign_key * hostkey,
39 	enum signkey_type *type) {
40 
41 	int ret = DROPBEAR_FAILURE;
42 	buffer *buf;
43 
44 	buf = buf_new(MAX_PRIVKEY_SIZE);
45 
46 	if (buf_readfile(buf, filename) == DROPBEAR_FAILURE) {
47 		goto out;
48 	}
49 	buf_setpos(buf, 0);
50 
51 	addrandom(buf_getptr(buf, buf->len), buf->len);
52 
53 	if (buf_get_priv_key(buf, hostkey, type) == DROPBEAR_FAILURE) {
54 		goto out;
55 	}
56 
57 	ret = DROPBEAR_SUCCESS;
58 out:
59 
60 	buf_burn(buf);
61 	buf_free(buf);
62 	return ret;
63 }
64 
65 #if DROPBEAR_USER_ALGO_LIST
66 void
parse_ciphers_macs()67 parse_ciphers_macs() {
68 	int printed_help = 0;
69 	if (opts.cipher_list) {
70 		if (strcmp(opts.cipher_list, "help") == 0) {
71 			char *ciphers = algolist_string(sshciphers);
72 			dropbear_log(LOG_INFO, "Available ciphers: %s", ciphers);
73 			m_free(ciphers);
74 			printed_help = 1;
75 		} else {
76 			if (check_user_algos(opts.cipher_list, sshciphers, "cipher") == 0) {
77 				dropbear_exit("No valid ciphers specified for '-c'");
78 			}
79 		}
80 	}
81 
82 	if (opts.mac_list) {
83 		if (strcmp(opts.mac_list, "help") == 0) {
84 			char *macs = algolist_string(sshhashes);
85 			dropbear_log(LOG_INFO, "Available MACs: %s", macs);
86 			m_free(macs);
87 			printed_help = 1;
88 		} else {
89 			if (check_user_algos(opts.mac_list, sshhashes, "MAC") == 0) {
90 				dropbear_exit("No valid MACs specified for '-m'");
91 			}
92 		}
93 	}
94 	if (printed_help) {
95 		dropbear_exit(".");
96 	}
97 }
98 #endif
99 
print_version()100 void print_version() {
101 	fprintf(stderr, "Dropbear v%s\n", DROPBEAR_VERSION);
102 }
103 
104 
105