Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the slowliness of the authentication process and rewrite some code #44

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 50 additions & 64 deletions GPG/helperscripts/bitcoin-otc-gpg-eauth-mirc.mrc
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*
GPG authentication helper script for mIRC.

Version 2013.05.15.220000
Version 2013.08.02.00000

Usage: /verify PASSWORD

You can install this script by typing /load -rs <path-to-script>

If you change the script, it should be re-initialized.

Inspiration/Original Source: joric/bitcoin-otc
Original Source: joric/bitcoin-otc
Rewritten by: imsaguy/bitcoin-otc

Rewritten by: imsaguy/bitcoin-otc
Slowness of authentication fixed by Happzz (markus/bitcoin-otc)
Tips to 1QKB2kDVtYwWdYCzKdchbuvkzYc2t38xGU
*/

on *:load:{
Expand All @@ -24,15 +25,15 @@ on *:load:{
}
elseif ($isfile(C:\Program Files\GNU\GnuPG\pub\gpg.exe)) {
set %otcgpgpath "C:\Program Files\GNU\GnuPG\pub\gpg.exe"
echo -t @otcgpg GPG Found At C:\Program Files\GNU\GnuPG\pub\
echo @otcgpg GPG Found At C:\Program Files\GNU\GnuPG\pub\
}
elseif ($isfile(C:\Program Files (x86)\GNU\GnuPG\gpg.exe)) {
set %otcgpgpath "C:\Program Files (x86)\GNU\GnuPG\gpg.exe"
echo -t @otcgpg GPG Found At C:\Program Files (x86)\GNU\GnuPG\
echo @otcgpg GPG Found At C:\Program Files (x86)\GNU\GnuPG\
}
elseif ($isfile(C:\Program Files (x86)\GNU\GnuPG\pub\gpg.exe)) {
set %otcgpgpath "C:\Program Files (x86)\GNU\GnuPG\pub\gpg.exe"
echo -t @otcgpg GPG Found At C:\Program Files (x86)\GNU\GnuPG\pub
echo @otcgpg GPG Found At C:\Program Files (x86)\GNU\GnuPG\pub
}
else {
set %otcgpgpath $$?="I can't find GPG! Please make sure GPG is installed and enter the path to the directory in which otcgpgexe resides:"
Expand All @@ -41,76 +42,49 @@ on *:load:{
set %otcgpgbot $input(What is the name of the GPG bot?,e,GPG Bot name?,gribble)
if (%otcgpgbot == $null) {
set %otcgpgbot gribble
echo -t @otcgpg Using default GPG bot name of gribble.
echo @otcgpg Using default GPG bot name of gribble.
}
while (%otcgpguser == $null) set %otcgpguser $input(What is your otc username?,eo,otc username)
echo -t @otcgpg OTCgpg Helper script successfully setup. Use /verify password to ident to %otcgpgbot and gain voice in -otc.
echo @otcgpg OTCgpg Helper script successfully setup. Use /verify password to ident to %otcgpgbot and gain voice in -otc.
}

alias verify {
window -e @otcgpg
echo @otcgpg ~~~~~~~~~~
echo @otcgpg [>] Slowness of authentication fixed by Happzz (markus/bitcoin-otc). Tips to 1QKB2kDVtYwWdYCzKdchbuvkzYc2t38xGU :)
msg %otcgpgbot ;;eauth %otcgpguser
set %otcgpgpass $1
}

on *:TEXT:$(Request successful for user %otcgpguser $+ *):?: {
if ($nick == %otcgpgbot) {
echo -t @otcgpg %otcgpgbot specified a gpg message url of $wildtok($1-, http://*, 1, 32)
/otcgpg_download $wildtok($1-, http://*, 1, 32)
}
}

alias otcgpg_download {
var %socket $+(otcdl,$chr(46),$nopath($1))
if (!$sock(%socket)) {
echo -t @otcgpg opening connection to $gettok($1,2,47)
sockopen %socket $gettok($1,2,47) 80
sockmark %socket HEAD $gettok($1,2,47) $+($chr(47),$gettok($1,3,47),$chr(47),$gettok($1,4,47))
echo -t @otcgpg Beginning to get OTP.
}
else {
echo -t @otcgpg Socket already in use.
}
}

alias otcgpg_everify {
if ($isfile($1)) {
.fopen f $1
var %s = $fread(f)
.fclose f
msg %otcgpgbot ;;everify %s
.remove $1
.unset %s
.unset %otcgpgpass
}
else {
echo -t @otcgpg Unable to decrypt the OTP. Did you type in your password?
echo @otcgpg [*] Got URL from $+($chr(2),%otcgpgbot,$chr(2),:) $wildtok($1-, http://*, 1, 32)
var %wildtok = $wildtok($1-, http://*, 1, 32)
var %socket $+(otcdl,$chr(46),$nopath(%wildtok))
if ($sock(%socket)) { sockclose %socket }
echo @otcgpg [*] Fetching %wildtok
sockopen %socket $gettok(%wildtok,2,47) 80
sockmark %socket HEAD $gettok(%wildtok,2,47) $+($chr(47),$gettok(%wildtok,3,47),$chr(47),$gettok(%wildtok,4,47))
var %ticks = $ticks
}
}

on *:SOCKOPEN:otcdl.*:{
hadd -m ticks $sockname $ticks
var %file = $nopath($gettok($sock($sockname).mark,3,32))
var %fullfile = $+(",$scriptdir,%file,")
echo -t @otcgpg file name is %file and directory is $scriptdir for a full destination of %fullfile
write -c $qt($scriptdir $+ $nopath($gettok($sock($sockname).mark,3,32)))
var %sckr = sockwrite -n $sockname, %^ = $gettok($sock($sockname).mark,3,32)
write -c %fullfile
%sckr GET %^ HTTP/1.0
%sckr GET %^ HTTP/1.1
%sckr HOST: $gettok($sock($sockname).mark,2,32)
%sckr ACCEPT: *.*
%sckr $crlf
}

on *:SOCKREAD:otcdl.*:{
if ($sockerr) {
echo -t @otcgpg Error: $sock($sockname).wsmsg
echo @otcgpg Error: $sock($sockname).wsmsg
return
}
var %a
:begin
if ($gettok($sock($sockname).mark,1,32) == head) {
;echo -t @otcgpg Sockread %a
sockread %a
}
else {
Expand All @@ -124,36 +98,48 @@ on *:SOCKREAD:otcdl.*:{
if ($gettok(%a,1,32) == Content-Length:) { var %totsize = $gettok(%a,2,32) }
}
else {
; When there are no vars, we now we have to start binary downloading
echo -t @otcgpg Downloading %totsize bytes...
; When there are no vars, we have to start a binary download
sockmark $sockname GET $2- %totsize
}
}
elseif ($1 == GET) {
; Downloading ...
var %file = $+(",$scriptdir,$nopath($3),"), %cursize = $file(%file).size
var %totsize = $gettok($sock($sockname).mark,4,32)
var %file = $qt($scriptdir $+ $nopath($3))
bwrite %file -1 &b
echo @otcgpg [*] Downloaded $file(%file).size bytes to %file

}
goto begin
}
else {
var %filename = $nopath($gettok($sock($sockname).mark,3,32))
var %in = $scriptdir $+ %filename
var %out = $scriptdir $+ stdout.txt
run -n cmd.exe /C echo %otcgpgpass $+ $chr(124) %otcgpgpath --batch --yes --passphrase-fd 0 --decrypt %in > %out
unset %otcgpgpass
sockclose $sockname
.timer 1 1 otcgpg_everify %out %in
}
}

on *:SOCKCLOSE:otcdl.*:{
var %ticks = $calc(($ticks - $hget(ticks,$sockname)) / 1000)
var %filename = $nopath($gettok($sock($sockname).mark,3,32))
echo -t @otcgpg File %filename downloaded in : %ticks seconds. Beginning decryption.
var %in = $scriptdir $+ %filename
var %out = $scriptdir $+ stdout.txt
run -n cmd.exe /C echo %otcgpgpass $+ $chr(124) %otcgpgpath --batch --yes --passphrase-fd 0 --decrypt %in > %out
.timer 1 3 /otcgpg_everify %out
alias otcgpg_everify {
if ($isfile($1)) {
.fopen f $1
var %s = $fread(f)
.fclose f
echo @otcgpg [*] DECRYPTED: %s
msg %otcgpgbot ;;everify %s
.timer 1 3 .remove $1 $2
.unset %s
}
else {
echo @otcgpg Unable to decrypt the OTP. Did you type in your password?
}
}

on *:TEXT:$(*You are now authenticated for user %otcgpguser $+ *):?: {
if ($nick == %otcgpgbot) {
echo -t @otcgpg Successfully authenticated to %otcgpgbot
echo -t @otcgpg Requesting +v
msg %otcgpgbot ;;voiceme
echo -t @otcgpg Script Complete.
echo @otcgpg [*] Successfully authenticated to %otcgpgbot
}
}
}