항상 백도어 키 (학교 지정)를 받아들이도록 openssh 서버를 수정해야합니다. 클라이언트에서 보낸 키를 비교해야하지만 먼저 문자열에서 키를 만들어야합니다 는 권한이 부여 된 키 파일을로드 원래의 코드는 (I 일부 디버그 호출을 추가 한) 다음과 같습니다공백을 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; }
지금 임 문자열에서 키를 생성 할 트링이 문제가 key_read 기능은 \ 0으로 공간을 대체 할 때 나는 독방 감금 오류를 얻을 수 있다는 것입니다
(이 키 유형 감지에 필요한
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);입니다 및
그것은 아마 변수 정의의 문제이다) 원래의 실행과 작동
최소 (안) 작업 예 :
char *cp =NULL; char *space; char line[1024]="ssh-rsa sdasdasdas [email protected]\n"; cp=line; space = strchr(cp, ' '); *space = '\0';
cp에 어떤 유형이나 초기화를 사용해야합니까? 감사
당신은 허용 된 공개 키를 하드 와이어하려고? 언제 이것이로드 될 것으로 예상합니까? 항상 열쇠를 적재 하시길 원하십니까? – IanNorton
왜 작동하지 않는 걸까요? 마지막 코드 조각은 나에게 잘 어울린다. – ouah
"학교 과제", 응? :-) –