REST APIをクエリするには、HMAC-SHA256で認証する必要があります。 JSLでこれを行う方法を知っている人はいますか? 別のRESTAPIまたはWebscraperを使用してそれを行うこともできます。 たとえば、このWebサイト: https://www.devglan.com/online-tools/hmac-sha256-onlineハッシュを計算できますが、どうすればそれを機能させることができますか?
Windows上のcertutil。 Macのopenssl。 (しかし、私はあなたがそうする必要はないかもしれないと思います、以下の最後の文を見てください。)
ずっと前にTwitterについて知っておくべき7つのことSHA1が必要でした。 「certutil」はすでにWindowsにインストールされており、SHA256も実行するようです。 runprogramを使用して出力を解析する.zipAUTH.jslファイルのコードから始めることができます。
この検索では、さまざまな品質の選択肢がたくさんありますhttps://www.google.com/search?q=windows+hmac+sha256+certutil
HMAC部分について説明しますhttps://en.wikipedia.org/wiki/HMACと関連する機能があるようですAUTH.jslファイル内。 考えてから久しぶりです。
これはJMPのhttpRequest / oauth2関数にも組み込まれていると思います@Paul_Nelson @bryan_booneしかし、私はまだそれらを研究していません。
組み込みのソリューションに間違いなく興味がありますが、それまでの間、ソリューションも機能します。 auth.jslファイルの9行目でSHA1をSHA256に置き換えました。ブロックサイズは256です。ありがとうございます。
@Craige_Halesなんらかの理由で、今日早く動作させてから保存したところ、動作しなくなりました。 私の間違いが見えますか? 参照用に、twitterpackageのBITS.jslとAUTH.jslも添付されています。
更新、それはブロックサイズでした、それは私が265であるべきだと思っていたSHA265の場合は64です
include("BITS.jsl");
SHA256 = Function( {txt},
{hash, rc, hexdata,temppath},
try(deleteFile("$temp/deleteme.txt"));
temppath = Save Text File( "$temp/deleteme.txt", txt );
If( Host is( "windows" ),
hash = RunProgram( executable( "certutil" ), options( "-hashfile "|| temppath|| " SHA256" ), readfunction( "text" ) ); // win jmp 11
//hash = RunProgram( executable( "certutil" ), options( {"-hashfile", temppath, "SHA1"} ), readfunction( "text" ) );
rc = Pat Match(
hash,
Pat Regex( "\[^.+?:\s+]\" ) + Pat Span( "0123456789abcdefABCDEF " ) >> hexdata + Pat Regex(
"\[\s*CertUtil: -hashfile command completed successfully.\s*$]\"
)
);
If( rc != 1,
Throw( "bad hash:" || hash )
);
hexdata = Regex( hexdata, " ", "", GLOBALREPLACE );
, // else MAC
hash = RunProgram( executable( "/usr/bin/openssl" ), options( {"dgst", "-sha1", temppath} ), readfunction( "text" ) );
hexdata =regex(hash,"=\s*([0-9a-fA-F]{40})\s*","\1");
if( length(hexdata) != 40, throw("bad hash:" || hash));
);
try(deleteFile("$temp/deleteme.txt"),show("did not delete temp file??"));
Return( Hex To Blob( hexdata ) );
);
HMACSHA256 = Function( {key, message},
{blocksize = 64}, // Where blocksize is that of the underlying hash function
//show(length(key));
If(
Length( key ) > blocksize, // keys longer than blocksize are shortened
//print("shorten:");
key = SHA256( key );
//show(key,length(key));
);
if(
Length( key ) < blocksize, // keys shorter than blocksize are zero-padded
key = key || Matrix To Blob( J( (blocksize - Length( key )), 1, 0 ), "uint", 1, "big" )
);
//show(length(key));
o_key_pad = BITS:XORBLOB( Matrix To Blob( J( blocksize, 1, Hex To Number( "5c" ) ), "uint", 1, "big" ), key );
i_key_pad = BITS:XORBLOB( Matrix To Blob( J( blocksize, 1, Hex To Number( "36" ) ), "uint", 1, "big" ), key );
Return( SHA256( o_key_pad || SHA256( i_key_pad || message ) ) );
);
//from https://www.devglan.com/online-tools/hmac-sha256-online
if("090a613de1a32c513f5477019dbd395fe4c6727708e945277d6af6c5cf7a6778" != hex(HMACSHA256( Char To Blob( "dbc62ec300b2624c580611858d94f2332ac63" ), Char To Blob( "Why don't we test this" ) )), throw("hmac busted"));certutil SHA256関数を確認しましたが、正しいハッシュが生成されます。 HMACSHA256またはそれが呼び出すBITS関数で、問題が発生しているようです。
左側のテスト値でuppercase()を試してください。 動作しているようです。
HMAC-SHA256は現在、HTTP Request/OAuth2に組み込まれていません。
それはクレイジが説明した方法で行われなければならないでしょう。