Per eseguire query su un'API REST devo autenticarmi con HMAC-SHA256. Qualcuno sa di un modo per farlo in JSL? Potremmo anche utilizzare un'altra API REST o webscraper per farlo. Ad esempio questo sito web: https://www.devglan.com/online-tools/hmac-sha256-online posso calcolare l'hash ma come faccio a farlo funzionare?
certutil su Windows. openssl su mac. (Ma penso che potresti non averne bisogno, vedi la frase finale di seguito.)
Tanto tempo fa dentro 7 cose da sapere su Twitter Avevo bisogno di un SHA1. "certutil" è già installato su Windows e apparentemente farà anche SHA256. Potresti iniziare con il codice nel file .zip AUTH.jsl che utilizza runprogram e analizza l'output.
Otterrai un sacco di scelte di qualità variabile con questa ricerca https://www.google.com/search?q=windows+hmac+sha256+certutil
Viene descritta la parte HMAC https://en.wikipedia.org/wiki/HMAC e sembra esserci una funzione correlata nel file AUTH.jsl. È passato molto tempo da quando ci ho pensato.
Penso che questo possa essere integrato anche nelle funzioni httpRequest/oauth2 di JMP @Paul_Nelson @bryan_boone ma non li ho ancora studiati.
Sicuramente interessato alla soluzione integrata ma nel frattempo funziona anche la tua soluzione! Ho sostituito SHA1 con SHA256 nella riga 9 del tuo file auth.jsl e blocksize = 256, grazie!
@Craige_Hales per qualche motivo l'ho fatto funzionare prima oggi, poi l'ho salvato e ora non funzionerà più. Riesci a vedere il mio errore? BITS.jsl e AUTH.jsl dal tuo twitterpackage sono anche allegati come riferimento.
Aggiornamento, era la dimensione del blocco, è 64 per SHA265 avevo pensato che dovrebbe essere 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"));Ho controllato la funzione certutil SHA256 e che genera hash corretti. Sembra che HMACSHA256 o nelle funzioni BITS che chiama, dove va storto.
prova uppercase() sul valore del test di sinistra. Sembra che funzioni.
HMAC-SHA256 non è attualmente integrato in HTTP Request/OAuth2.
Dovrebbe essere fatto nel modo descritto da Craige.