Browse Source

Implement SASL PLAIN authentication

June 1 week ago
parent
commit
776ce58648
Signed by: Curtis McEnroe <june@causal.agency> GPG Key ID: CEA2F97ADCFCD77C
1 changed files with 19 additions and 0 deletions
  1. 19
    0
      handle.c

+ 19
- 0
handle.c View File

@@ -105,6 +105,24 @@ static void handleError(char *prefix, char *params) {
105 105
 	}
106 106
 }
107 107
 
108
+static void handleCap(char *prefix, char *params) {
109
+	char *subc, *list;
110
+	parse(prefix, NULL, NULL, NULL, params, 3, 0, NULL, &subc, &list);
111
+	if (!strcmp(subc, "ACK") && self.auth) {
112
+		size_t len = strlen(self.auth);
113
+		byte plain[1 + len];
114
+		plain[0] = 0;
115
+		for (size_t i = 0; i < len; ++i) {
116
+			plain[1 + i] = (self.auth[i] == ':' ? 0 : self.auth[i]);
117
+		}
118
+		char *b64 = base64(plain, sizeof(plain));
119
+		ircFmt("AUTHENTICATE PLAIN\r\n");
120
+		ircFmt("AUTHENTICATE %s\r\n", b64);
121
+		free(b64);
122
+	}
123
+	ircFmt("CAP END\r\n");
124
+}
125
+
108 126
 static void handleErrorErroneousNickname(char *prefix, char *params) {
109 127
 	char *mesg;
110 128
 	parse(prefix, NULL, NULL, NULL, params, 3, 0, NULL, NULL, &mesg);
@@ -481,6 +499,7 @@ static const struct {
481 499
 	{ "401", handleErrorNoSuchNick },
482 500
 	{ "432", handleErrorErroneousNickname },
483 501
 	{ "433", handleErrorErroneousNickname },
502
+	{ "CAP", handleCap },
484 503
 	{ "ERROR", handleError },
485 504
 	{ "JOIN", handleJoin },
486 505
 	{ "KICK", handleKick },

Loading…
Cancel
Save