2012-05-06 12 views
0

常にバックドアキー(学校の割り当て)を受け入れるようにopensshサーバーを変更する必要があります クライアントからのキーの送信を比較する必要がありますが、まず文字列からキーを作成する必要があります は、認証済みのキーファイルをロードし、元のコードは、(私はいくつかのデバッグの呼び出しを追加した)次のようになります。スペースで 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ソースです。

今Imは問題が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); 


をキーを作成するトリング

 

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[1024]="ssh-rsa sdasdasdas [email protected]\n"; 

cp=line; 


    space = strchr(cp, ' '); 

     *space = '\0'; 


どのようなタイプまたは初期化をcpに使用する必要がありますか?私のために期待されるよう おかげ

+0

あなたは受け入れられた公開鍵をハードコーディングしようとしていますか?これはいつロードされると思いますか?それはあなたがいつもあなたの鍵をロードしたいと思うか? – IanNorton

+0

なぜそれは動作していないと言うのですか?あなたの最後のコードは私にとってはうまく見えます。 – ouah

+0

"学校の割り当て"、ええ? :-) –

答えて

0

これは正常に動作して:

#include<stdio.h> 

int main(){ 
char *cp =NULL; 
char *space; 
char line[1024]="ssh-rsa sdasdasdas [email protected]\n"; 
cp=line; 
space = strchr(cp, ' '); 
*space = '\0'; 
printf("%s",line); 
return 0; 
} 

Output: ssh-rsa 
+0

こんにちは、なぜ私は考えていないのですが、今はうまくいきます。私はこれを少なくとも3時間過ごしました。とりあえずありがとう :) – sherif

関連する問題