Logo Search packages:      
Sourcecode: g2ipmsg version File versions  Download package

int pcrypt_crypt_generate_anspubkey_string ( ipmsg_cap_t  peer_cap,
const char **  message_p 
)

IPMSG_ANSPUBKEYパケットの生成を行う

Parameters:
[in] peer_cap ピアの暗号化能力
[out] message_p 生成したIPMSG_ANSPUBKEYパケットを指し示すポインタ変数の アドレス.
Return values:
0 正常終了
-EINVAL 引数異常 以下のいずれかまたは両方が発生した.
  • 不正な暗号化能力IDをpeer_capに指定した
  • message_pがNULL).
-ENOMEM メモリ不足

Definition at line 1049 of file pubcrypt.c.

References _MSG_BUF_SIZE, pcrypt_crypt_refer_rsa_key(), RSA_CAPS, select_rsa_key_for_answer(), select_signature(), and select_symmetric_key().

Referenced by ipmsg_proc_get_public_key().

                                                                                     {
      char            *buffer = NULL;
      char            *string = NULL;
      char             *hex_e = NULL;
      char             *hex_n = NULL;
      RSA                *rsa = NULL;
      int                rc = 0;
      ipmsg_cap_t skey_type = 0;
      ipmsg_cap_t akey_type = 0;
      ipmsg_cap_t sign_type = 0;
      size_t      total_len = 0;
      int                 i = 0;

      if ( (message_p == NULL) && (!(peer_cap & RSA_CAPS)) )
            return -EINVAL;

      rc = select_rsa_key_for_answer(peer_cap, &akey_type,
          hostinfo_refer_ipmsg_crypt_policy_is_speed());

      if (rc != 0)
            return rc;

      dbg_out("RSA key:%x\n", akey_type);

      rc = select_symmetric_key(peer_cap, &skey_type,
          hostinfo_refer_ipmsg_crypt_policy_is_speed());

      if (rc != 0)
            return rc;

      dbg_out("sym key:%x\n", skey_type);

      rc = select_signature(peer_cap, &sign_type, 
          hostinfo_refer_ipmsg_crypt_policy_is_speed());

      if (rc != 0)
            dbg_out("No sign:%x\n", sign_type);
      else
            dbg_out("Sign type:%x\n", sign_type);

      rc = pcrypt_crypt_refer_rsa_key(akey_type, &rsa);
      if (rc != 0){
            dbg_out("Can not find rsa key:%d\n", rc);
            return -EINVAL;
      }

      buffer = g_malloc(_MSG_BUF_SIZE);
      if (buffer == NULL)
            return -ENOMEM;
  
      memset(buffer, 0, _MSG_BUF_SIZE);
      rc = -ENOMEM;

      hex_e = BN_bn2hex(rsa->e);
      if (hex_e == NULL)
            goto free_buffer_out;

      hex_n = BN_bn2hex(rsa->n);
      if (hex_n == NULL)
            goto free_hex_n_out;

      dbg_out("hex-e:%s hex-n:%s\n", hex_e, hex_n);

      snprintf(buffer, _MSG_BUF_SIZE, "%x:%s-%s", 
          (akey_type|skey_type|sign_type), hex_e, hex_n);

      dbg_out("Generated:%s\n", buffer);
      string = g_strdup(buffer);
      total_len = strlen(buffer);

      /*
       * 小文字に変換
       */
      for(i = 0; i < total_len; ++i) {
        string[i] = tolower((int)string[i]);
      }

      *message_p = string;

      rc = 0;

 free_hex_n_out:
      if (hex_n != NULL)
            OPENSSL_free(hex_n);
 free_hex_e_out:
      if (hex_e != NULL)
            OPENSSL_free(hex_e);
 free_buffer_out:
      if (buffer != NULL)
            g_free(buffer);

  return rc;
}


Generated by  Doxygen 1.6.0   Back to index