REST API를 쿼리하려면 HMAC-SHA256으로 인증해야 합니다. 누구든지 JSL에서 이것을 수행하는 방법을 알고 있습니까? 다른 REST API 또는 웹스크레이퍼를 사용하여 이를 수행할 수도 있습니다. 예를 들어 이 웹사이트: https://www.devglan.com/online-tools/hmac-sha256-online 해시를 계산할 수 있지만 어떻게 작동합니까?
Windows에서 certutil. 맥에서 openssl. (하지만 필요하지 않을 수도 있다고 생각합니다. 아래 마지막 문장을 참조하세요.)
오래전에 트위터에 대해 알아야 할 7가지 SHA1이 필요했습니다. "certutil"은 이미 Windows에 설치되어 있으며 분명히 SHA256도 수행할 것입니다. runprogram을 사용하고 출력을 구문 분석하는 .zip AUTH.jsl 파일의 코드로 시작할 수 있습니다.
이 검색을 통해 다양한 품질의 선택 항목을 얻을 수 있습니다. https://www.google.com/search?q=windows+hmac+sha256+certutil
HMAC 부분에 대해 설명합니다. https://en.wikipedia.org/wiki/HMAC 그리고 관련 기능이있는 것 같습니다 AUTH.jsl 파일에서. 그것에 대해 생각한지 오래되었습니다.
JMP의 httpRequest/oauth2 기능에도 내장되어 있을 수 있다고 생각합니다. @폴_넬슨 @bryan_boone 그러나 나는 아직 그것들을 공부하지 않았습니다.
내장된 솔루션에 확실히 관심이 있지만 그 동안에는 솔루션도 작동합니다! auth.jsl 파일의 9행에서 SHA1을 SHA256으로 교체했고 블록 크기 = 256, 감사합니다!
@Craige_Hales 어떤 이유로 오늘 일찍 작동하게 하고 저장했는데 이제 더 이상 작동하지 않습니다. 내 실수가 보이나요? twitterpackage의 BITS.jsl 및 AUTH.jsl도 참조용으로 첨부되어 있습니다.
업데이트, 블록 크기였습니다. SHA265의 경우 64입니다. 265여야 한다고 가정했습니다.
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 기능에서 문제가 발생하는 것 같습니다.
왼쪽 테스트 값에서 대문자()를 시도합니다. 작동하는 것 같습니다.
HMAC-SHA256은 현재 HTTP Request/OAuth2에 내장되어 있지 않습니다.
Craige가 설명한 대로 수행되어야 합니다.