2

システムでサポートされているハッシュアルゴリズム(パスワードのハッシュ用)を返すコマンドまたはスクリプトが必要です。つまり、アルゴリズムはpam.d構成ファイルまたはlogin.defsで使用できます。

通常、md5、bigcrypt、sha256、sha512、blowfishがサポートされていますが、新しいアルゴリズムがサポートされているかどうかをプログラムで確認し、スクリプトで判断する必要があります。/proc/cryptoを確認しましたが、前に述べたものよりも少なすぎました。

ありがとう

4

1 に答える 1

2

/proc/cryptoカーネルが知っているアルゴリズムの単なるリストです。これはPAMとは何の関係もありません。

PAMに直接クエリを実行して、サポートできるハッシュを見つける方法はありません。もちろん、これは内部的に認識されていますが、パブリックAPIによって公開されることはありません。

実行できることの1つはcrypt、さまざまなIDタイプでパスをハッシュして、基本的にPAMをプローブすることです(より正確には、PAMがシャドウパスワードに使用するlibcの暗号をプローブします)。簡単な例:

#include <unistd.h>
#include <stdio.h>
#include <string>

bool test_crypt_method(const char* id)
   {
   const std::string salt =
      std::string("$") + id + "$" + "testsalt$";

   std::string crypt_result = ::crypt("password", salt.c_str());

   /*
   * If the hash ID is not supported, glibc unfortunately
   * then treats it as a old-style DES crypt rather than
   * failing; find this situation.
   */
   if(crypt_result.size() == 13 &&
      crypt_result[0] == '$' &&
      crypt_result.find('$', 1) == std::string::npos)
      return false;

   return true;
   }

int main()
   {
   if(test_crypt_method("1"))
      printf("md5 ");
   if(test_crypt_method("2a"))
      printf("blowfish ");
   if(test_crypt_method("4")) // test for false positives
      printf("undefined ");
   if(test_crypt_method("5"))
      printf("sha256 ");
   if(test_crypt_method("6"))
      printf("sha512 ");
   printf("\n");
   }
于 2010-10-12T14:00:35.847 に答える