Created
May 12, 2014 14:36
-
-
Save cmcdevitt/b5ff79f09975824e287a to your computer and use it in GitHub Desktop.
getDate_rfc2822
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // NOT FINISHED! | |
| //getDate_rfc2822(); | |
| //var cmhash = preHash(getDate_rfc2822(),'GET','api-xxxxxxxx.duosecurity.com','/accounts/v1/account/list','username=root'); | |
| //gs.log(hashIt('fkey',cmhash)); | |
| checkDuo(); | |
| function getDate_rfc2822(){ | |
| //Raw: 2014-03-02 01:28:51 | |
| //RFC: Tue, 21 Aug 2012 17:29:18 -0000 | |
| //fin: Sun, 1 Mar 2014 02:44:33 -0000 | |
| //getDayOfWekUTC returns Monday=1, Sunday=7 (Note:NOT the same as JavaScript Sunday is 0, Monday is 1!) | |
| var dow = []; dow[1] = "Mon"; dow[2] = "Tue"; dow[3] = "Wed"; dow[4] = "Thu"; dow[5] = "Fri"; dow[6] = "Sat"; dow[7] = "Sun"; | |
| var moy=[];moy[1]="Jan";moy[2]="Feb";moy[3]="Mar";moy[4]="Apr";moy[5]="May";moy[6]="Jun";moy[7]="Jul";moy[8]="Aug";moy[9]="Sep"; | |
| moy[10]="Oct";moy[11]="Nov";moy[12]="Dec"; | |
| var timeNow = gs.nowNoTZ(); | |
| var gdt = new GlideDateTime(timeNow); | |
| var rfcTime = dow[gdt.getDayOfWeekUTC()] + ', ' + gdt.getDayOfMonth() + ' ' + moy[gdt.getMonth()] + ' ' + gdt.getYear() + ' ' + timeNow.toString().split(' ')[1] + ' ' + '-0000'; | |
| //gs.log("TaDa: " + rfcTime); | |
| return rfcTime; | |
| } | |
| function preHash(rfcTime,method,url,endPoint,account){ | |
| var mashUp = rfcTime + '\n' + method + '\n' + endPoint + '\n' + account; | |
| gs.log("M: " + mashUp); | |
| } | |
| function hashIt(fkey,data){ | |
| var MAC_ALG = "HmacSHA1"; | |
| return SncAuthentication.encode(data, fkey, MAC_ALG); | |
| } | |
| function pingDuo(){ | |
| var r = new RESTMessage('Duo Authentication', 'get'); | |
| r.setStringParameter('methods', '/auth/v2/ping'); | |
| var response = r.execute(); | |
| gs.log(response.getBody()); | |
| } | |
| function checkDuo(){ | |
| var r = new RESTMessage('Duo Authentication', 'get'); | |
| r.setStringParameter('methods', '/auth/v2/check'); | |
| var response = r.execute(); | |
| gs.log(response.getBody()); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment