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

int pcrypt_crypt_init_keys ( void   ) 

RSA鍵を初期化する.

Return values:
0 正常終了
Attention:
鍵格納用パスフレーズが不正だった場合は, 強制終了する.

Definition at line 1260 of file pubcrypt.c.

References generate_rsa_key(), ipmsg_pem_passwd_dialog(), key2ipmsg_key_type, pcrypt_crypt_set_rsa_key(), pcrypt_get_rsa_key_length(), pcrypt_load_rsa_key(), pcrypt_store_rsa_key(), and rsa_keys.

                             {
      int          rc = 0;
      int           i = 0;
      int      keylen = 0;
      RSA        *rsa = NULL;
      gchar   *passwd = NULL;
      size_t pass_len = 0;

      OpenSSL_add_all_algorithms();
      ERR_load_crypto_strings();

      if (hostinfo_refer_ipmsg_encrypt_public_key()) {
            rc = ipmsg_pem_passwd_dialog(&passwd);
            if (rc == -EPERM) {
                  ipmsg_err_dialog_mordal("%s", 
                      _("Can not load RSA key due to invalid passphrase."));
                  exit(1);
            }
            g_assert( (passwd == NULL) || (rc == 0) );
      }

      for(i = 0;key2ipmsg_key_type[i] >= 0; ++i) {
            rc = pcrypt_load_rsa_key(key2ipmsg_key_type[i], passwd);
            if (rc == 0)
                  continue; /* 鍵をロードした  */
            dbg_out("Can not load key:rc=%d\n", rc);
            rc = generate_rsa_key(&rsa, key2ipmsg_key_type[i]);
            if (rc != 0) {
                  rc = pcrypt_get_rsa_key_length(key2ipmsg_key_type[i], &keylen);
                  if (rc != 0)
                        err_out("Can not generate key length:%d\n", 
                            keylen);
                  else
                        err_out("Can not generate key length invalid key index:%d\n", i);
                  rsa_keys[i] = NULL;
                  continue;
            }

            rc = pcrypt_crypt_set_rsa_key(key2ipmsg_key_type[i], rsa);
            if (rc != 0) {
                  err_out("Can not set key length:%d\n", keylen);
            } else {
                  /*
                   * 生成した鍵を保存する
                   */
                  rc = pcrypt_store_rsa_key(key2ipmsg_key_type[i], passwd);
                  if (rc != 0)
                        err_out("Can not store key: length: %d\n", keylen);
            }
      }

passwd_free_out:
      if (passwd != NULL) {
            pass_len = strlen(passwd);
            memset(passwd, 0xdd, pass_len);  /*  パスワード格納領域を廃棄  */
            g_free(passwd);
      }

      return 0;
}


Generated by  Doxygen 1.6.0   Back to index