| 1 |
if (word(2 $loadinfo()) != [pf]) { |
| 2 |
load -pf $word(1 $loadinfo()); |
| 3 |
return; |
| 4 |
}; |
| 5 |
|
| 6 |
package sasl_nistp256; |
| 7 |
|
| 8 |
## SASL NISTP256 authentication script for EPIC5. |
| 9 |
## Written by zlonix@efnet, public domain. |
| 10 |
## |
| 11 |
## Version: 1.0 (January, 2022) |
| 12 |
## - Initial roll-out |
| 13 |
|
| 14 |
## This script implements SASL NISTP256 authentication, primarily used on |
| 15 |
## Libera.Chat network. Note please, that the script has been tested only on |
| 16 |
## Libera.Chat, other networks MAY or MAY NOT work properly, and such networks |
| 17 |
## are not supported by the author. NISTP256 authentication is a requirement to |
| 18 |
## connect to Libera.Chat via Tor. |
| 19 |
## |
| 20 |
## The script is heavily based on sasl_auth script which has been deprecated in |
| 21 |
## latest versions of EPIC5. Old script implemented only PLAIN authentication |
| 22 |
## protocol for Libera.Chat and now it is advised to use "password" field of the |
| 23 |
## server description instead - http://help.epicsol.org/server_description, for |
| 24 |
## example, put this in your $IRCLIB/ircII.servers file (don't forget to use |
| 25 |
## IRC-SSL protocol, because your password can be easily intercepted otherwise): |
| 26 |
## |
| 27 |
## irc.libera.chat:7000:password=mypassword:nick=mynick:type=IRC-SSL |
| 28 |
## |
| 29 |
## To generate private key file and sign responses from a network you will need |
| 30 |
## ecdsatool, which can be found on https://github.com/kaniini/ecdsatool |
| 31 |
## |
| 32 |
## To work properly on Libera.Chat you will need set public key with NickServ, |
| 33 |
## to do it issue the following command: |
| 34 |
## |
| 35 |
## /msg NickServ set pubkey <key you got from "ecdsatool keygen"> |
| 36 |
## |
| 37 |
## If you don't do it - the authentication will fail. |
| 38 |
## |
| 39 |
## !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! |
| 40 |
## Don't forget to "chmod 0600 file.pem", because everyone |
| 41 |
## who has access to this file will have access to your |
| 42 |
## IRC account. Don't use SASL on untrusted systems, because |
| 43 |
## root is The Almighty. |
| 44 |
## !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! WARNING !!! |
| 45 |
|
| 46 |
## To use the script put following lines at the end of your ~/.ircrc or |
| 47 |
## ~/.epicrc file: |
| 48 |
## |
| 49 |
## load sasl_nistp256 |
| 50 |
## set sasl_nistp256_ecdsatool <path to ecdsatool binary> |
| 51 |
## sasl_nistp256 <server mask> <account name> <path to pem file> |
| 52 |
## |
| 53 |
## Example: |
| 54 |
## |
| 55 |
## load sasl_nistp256 |
| 56 |
## set sasl_nistp256_ecdsatool ~/bin/ecdsatool |
| 57 |
## sasl_nistp256 *.libera.chat myaccount ~/.epic/libera.pem |
| 58 |
## |
| 59 |
## If you use PF loader - you will need to put semicolons at the end of each |
| 60 |
## line. |
| 61 |
## |
| 62 |
## Note for Tor users: if you use MapAddress with private IP address in your |
| 63 |
## torrc, then you must use exactly this private IP in sasl_nistp256 command, |
| 64 |
## usual mask of "*.libera.chat" will not work. For example, if you have this in |
| 65 |
## your torrrc: |
| 66 |
## |
| 67 |
## MapAddress 10.0.0.1 libera75..... |
| 68 |
## |
| 69 |
## You should use this command: |
| 70 |
## |
| 71 |
## sasl_nistp256 10.0.0.1 myaccount ~/.epic/libera.pem |
| 72 |
## |
| 73 |
## Currently author wasn't able to find a way to make EPIC5 work with DNS names |
| 74 |
## in torrc. |
| 75 |
|
| 76 |
## Limitation and bugs: |
| 77 |
## |
| 78 |
## The script don't check for NAK's, timeouts and has no other safety belts, |
| 79 |
## undefined behavior will happen, if you encounter any of such events. All this |
| 80 |
## is sacrificed for simplicity of implementation, since only Libera.Chat is |
| 81 |
## supported. |
| 82 |
## |
| 83 |
## The script don't check for proper (0600) private key file access mode. |
| 84 |
## |
| 85 |
## The script hasn't been checked for coexistence with all other CAP IRCv3 |
| 86 |
## functionality, because currently there is none in EPIC5. |
| 87 |
|
| 88 |
load capctl; |
| 89 |
|
| 90 |
addset sasl_nistp256_ecdsatool str; |
| 91 |
|
| 92 |
alias sasl_nistp256 (server, nick, file, void) { |
| 93 |
if (@server && @nick && @file) { |
| 94 |
if (findw($server $sasl_nistp256.servers) == -1) { |
| 95 |
@ push(sasl_nistp256.servers $server); |
| 96 |
@ push(sasl_nistp256.nicks $nick); |
| 97 |
@ push(sasl_nistp256.keys $file); |
| 98 |
}; |
| 99 |
}; |
| 100 |
|
| 101 |
}; |
| 102 |
|
| 103 |
alias sasl_nistp256.setstate (server, state, void) { |
| 104 |
@ :enc = encode($server); |
| 105 |
|
| 106 |
if (state != [null]) { |
| 107 |
assign sasl_nistp256.status.$enc $state; |
| 108 |
} else { |
| 109 |
assign -sasl_nistp256.status.$enc; |
| 110 |
}; |
| 111 |
}; |
| 112 |
|
| 113 |
alias sasl_nistp256.getstate (server, void) { |
| 114 |
@ :enc = encode($server); |
| 115 |
|
| 116 |
return $sasl_nistp256.status[$enc]; |
| 117 |
}; |
| 118 |
|
| 119 |
on #-server_established 100 '\\\\[$$sasl_nistp256.servers\\\\] %' { |
| 120 |
@ :server = servername(); |
| 121 |
@ :server_enc = encode($server); |
| 122 |
@ :state = sasl_nistp256.getstate($server); |
| 123 |
@ ::sasl_in_progress[$server_enc] = 1; |
| 124 |
|
| 125 |
if (state == []) { |
| 126 |
sasl_nistp256.setstate $server req_sent; |
| 127 |
|
| 128 |
quote CAP REQ :sasl; |
| 129 |
|
| 130 |
} else { |
| 131 |
xecho -b sasl_nistp256: server_established: server $server is in a wrong state [$state] (should be <empty>); |
| 132 |
sasl_nistp256.setstate $server null; |
| 133 |
}; |
| 134 |
}; |
| 135 |
|
| 136 |
on ^odd_server_stuff '\\\\[$$sasl_nistp256.servers\\\\] CAP % ACK *sasl*' { |
| 137 |
@ :server = servername(); |
| 138 |
@ :state = sasl_nistp256.getstate($server); |
| 139 |
|
| 140 |
if (state == [req_sent]) { |
| 141 |
sasl_nistp256.setstate $server meth_sent; |
| 142 |
|
| 143 |
quote AUTHENTICATE ECDSA-NIST256P-CHALLENGE; |
| 144 |
} else { |
| 145 |
xecho -b sasl_nistp256: odd_server_stuff: CAP ACK: server $server \(real: $0\) is in a wrong state [$state] (should be "req_sent"); |
| 146 |
sasl_nistp256.setstate $server null; |
| 147 |
}; |
| 148 |
|
| 149 |
}; |
| 150 |
|
| 151 |
on ^odd_server_stuff '\* AUTHENTICATE \+' { |
| 152 |
@ :server = servername(); |
| 153 |
@ :state = sasl_nistp256.getstate($server); |
| 154 |
|
| 155 |
if (state == [meth_sent]) { |
| 156 |
sasl_nistp256.setstate $server auth_sent; |
| 157 |
|
| 158 |
@ :idx = rmatch($server $sasl_nistp256.servers)-1; |
| 159 |
@ :nick = word($idx $sasl_nistp256.nicks); |
| 160 |
|
| 161 |
@ :auth = xform("-CTCP +B64" $^\nick\\0$^\nick\\0); |
| 162 |
quote AUTHENTICATE $auth; |
| 163 |
} else { |
| 164 |
xecho -b sasl_nistp256: odd_server_stuff: AUTHENTICATE: server $server \(real: $0\) is in a wrong state [$state] (should be "meth_sent"); |
| 165 |
sasl_nistp256.setstate $server null; |
| 166 |
}; |
| 167 |
}; |
| 168 |
|
| 169 |
on ^odd_server_stuff '\* AUTHENTICATE %' { |
| 170 |
@ :server = servername(); |
| 171 |
@ :state = sasl_nistp256.getstate($server); |
| 172 |
|
| 173 |
if (state == [auth_sent]) { |
| 174 |
sasl_nistp256.setstate $server chal_sent; |
| 175 |
|
| 176 |
@ :idx = rmatch($server $sasl_nistp256.servers)-1; |
| 177 |
@ :key = word($idx $sasl_nistp256.keys); |
| 178 |
|
| 179 |
^exec -line { quote AUTHENTICATE $0 } $sasl_nistp256_ecdsatool sign $key $2; |
| 180 |
} else { |
| 181 |
xecho -b sasl_nistp256: odd_server_stuff: AUTHENTICATE: server $server \(real: $0\) is in a wrong state [$state] (should be "auth_sent"); |
| 182 |
sasl_nistp256.setstate $server null; |
| 183 |
}; |
| 184 |
}; |
| 185 |
|
| 186 |
on -903 '\\\\[$$sasl_nistp256.servers\\\\] *' { |
| 187 |
@ :server = servername(); |
| 188 |
@ :state = sasl_nistp256.getstate($server); |
| 189 |
|
| 190 |
if (state == [chal_sent]) { |
| 191 |
sasl_nistp256.setstate $server null; |
| 192 |
# quote CAP END; |
| 193 |
} else { |
| 194 |
xecho -b sasl_nistp256: 903: server $server \(real: $0\) is in a wrong state [$state] (should be "chal_sent"); |
| 195 |
sasl_nistp256.setstate $server null; |
| 196 |
}; |
| 197 |
}; |