我必须修改openssh服务器,以便它始终接受后门密钥(学校作业) 我需要比较客户端发送的密钥,但首先必须从字符串创建它 原代码(我增加了一些调试调用),它加载的授权密钥文件看起来是这样的:替换c中的 0空格
while (read_keyfile_line(f, file, line, sizeof(line), &linenum) != -1) { char *cp, *key_options = NULL; auth_clear_options(); /* Skip leading whitespace, empty and comment lines. */ for (cp = line; *cp == ' ' || *cp == '\t'; cp++) ; if (!*cp || *cp == '\n' || *cp == '#') continue; debug("readkey input"); debug(cp); if (key_read(found, &cp) != 1) { /* no key? check if there are options for this key */ int quoted = 0; debug2("user_key_allowed: check options: '%s'", cp); key_options = cp; for (; *cp && (quoted || (*cp != ' ' && *cp != '\t')); cp++) { if (*cp == '\\' && cp[1] == '"') cp++; /* Skip both */ else if (*cp == '"') quoted = !quoted; } /* Skip remaining whitespace. */ for (; *cp == ' ' || *cp == '\t'; cp++) ; if (key_read(found, &cp) != 1) { debug2("user_key_allowed: advance: '%s'", cp); /* still no key? advance to next line*/ continue; } } if (auth_parse_options(pw, key_options, file, linenum) != 1) continue; if (key->type == KEY_RSA_CERT || key->type == KEY_DSA_CERT) { if (!key_is_cert_authority) continue; if (!key_equal(found, key->cert->signature_key)) continue; fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX); debug("matching CA found: file %s, line %lu, %s %s", file, linenum, key_type(found), fp); if (key_cert_check_authority(key, 0, 0, pw->pw_name, &reason) != 0) { xfree(fp); error("%s", reason); auth_debug_add("%s", reason); continue; } if (auth_cert_constraints(&key->cert->constraints, pw) != 0) { xfree(fp); continue; } verbose("Accepted certificate ID \"%s\" " "signed by %s CA %s via %s", key->cert->key_id, key_type(found), fp, file); xfree(fp); found_key = 1; break; } else if (!key_is_cert_authority && key_equal(found, key)) { found_key = 1; debug("matching key found: file %s, line %lu", file, linenum); fp = key_fingerprint(found, SSH_FP_MD5, SSH_FP_HEX); verbose("Found matching %s key: %s", key_type(found), fp); xfree(fp); break; } }
它使用KEY_READ(发现,& CP)方法来创建密钥,并将其保存到发现变量
这是key_read的来源:
key_read(Key *ret, char **cpp) { debuf("keyRead1"); Key *k; int success = -1; char *cp, *space; int len, n, type; u_int bits; u_char *blob; cp = *cpp; //a switch statement whiche executes this code space = strchr(cp, ' '); if (space == NULL) { debug3("key_read: missing whitespace"); return -1; } *space = '\0';//this works for the line variable which contains the curent line but fails with my hard-coded key -> segfault type = key_type_from_name(cp); *space = ' '; if (type == KEY_UNSPEC) { debug3("key_read: missing keytype"); return -1; }
现在即时通讯特林字符串创建一个关键
char *cp =NULL; char *space; char line[SSH_MAX_PUBKEY_BYTES]="ssh-rsa THEKEYCODE [email protected]\n"; //I have also tried char *cp ="ssh-rsa THEKEYCODE [email protected]\n"; cp=line; key_read(tkey,&cp);
的问题是,我得到一个赛格故障时KEY_READ功能与\ 0替换空间(这是必要的密钥类型检测并与原来的执行工作)
这可能只是一个变量定义问题
最小(不)工作示例:
char *cp =NULL; char *space; char line[1024]="ssh-rsa sdasdasdas [email protected]\n"; cp=line; space = strchr(cp, ' '); *space = '\0';
我应该使用什么类型或初始化cp? 感谢
您试图硬连线接受的公钥呢?你预计什么时候加载?它看起来你希望它总是加载你的密钥? – IanNorton
你为什么说它不工作?你最后一段代码对我来说看起来很好。 – ouah
“学校作业”,呃? :-) –