63#define SEND(X) debug("sending '%s' to squid\n",X); printf(X "\n");
65#define SEND2(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
66#define SEND3(X,Y...) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
69#define SEND2(X,Y) debug("sending '" X "' to squid\n",Y); printf(X "\n",Y);
70#define SEND3(X,Y,Z) debug("sending '" X "' to squid\n",Y,Z); printf(X "\n",Y,Z);
86 "Usage: %s [-d] [-v] [-h]\n"
87 " -d enable debugging.\n"
88 " -v enable verbose Negotiate packet debugging.\n"
89 " -h this message\n\n",
96 int opt, had_error = 0;
99 while (-1 != (opt =
getopt(argc, argv,
"hdv"))) {
115 fprintf(stderr,
"ERROR: unknown option: -%c. Exiting\n", opt);
131 SEND(
"BH base64 decode failed");
132 fprintf(stderr,
"ERROR: base64 decoding failed for: '%s'\n", buf);
143 size_t decodedLen = 0;
144 char helper_command[3];
159 SEND(
"BH illegal request received");
160 fprintf(stderr,
"ERROR: Illegal request received: '%s'\n", buf);
165 fprintf(stderr,
"No newline in '%s'\n", buf);
173 strncpy(helper_command, buf, 2);
174 debug(
"Got '%s' from Squid with data:\n", helper_command);
175 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
177 debug(
"Got '%s' from Squid\n", buf);
179 if (memcmp(buf,
"YR ", 3) == 0) {
181 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
183 if (decodedLen <
sizeof(
ntlmhdr)) {
184 SEND(
"NA * Packet format error");
188 c = (
char *) SSP_MakeNegotiateBlob(decoded, decodedLen, &Done, &status, cred);
198 debug(
"sending 'AF' %s to squid with data:\n", cred);
200 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
202 fprintf(stderr,
"No data available.\n");
203 printf(
"AF %s %s\n", c, cred);
205 SEND3(
"AF %s %s", c, cred);
210 debug(
"sending 'TT' to squid with data:\n");
211 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
212 printf(
"TT %s\n", c);
219 SEND(
"BH can't obtain server blob");
222 if (memcmp(buf,
"KK ", 3) == 0) {
224 SEND(
"BH invalid server blob");
228 if (!decodedLen && !
token_decode(&decodedLen, decoded, buf+3))
230 if (decodedLen <
sizeof(
ntlmhdr)) {
231 SEND(
"NA * Packet format error");
235 c = (
char *) SSP_ValidateNegotiateCredentials(decoded, decodedLen, &Done, &status, cred);
238 FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM |
239 FORMAT_MESSAGE_IGNORE_INSERTS,
242 MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
243 (LPTSTR) & ErrorMessage,
246 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\n')
247 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
248 if (ErrorMessage[strlen(ErrorMessage) - 1] ==
'\r')
249 ErrorMessage[strlen(ErrorMessage) - 1] =
'\0';
250 SEND2(
"NA * %s", ErrorMessage);
251 LocalFree(ErrorMessage);
261 debug(
"sending 'AF' %s to squid with data:\n", cred);
263 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
265 fprintf(stderr,
"No data available.\n");
266 printf(
"AF %s %s\n", c, cred);
268 SEND3(
"AF %s %s", c, cred);
275 debug(
"sending 'TT' to squid with data:\n");
276 hex_dump(
reinterpret_cast<unsigned char*
>(decoded), decodedLen);
277 printf(
"TT %s\n", c);
284 SEND(
"BH illegal request received");
285 fprintf(stderr,
"Illegal request received: '%s'\n", buf);
288 SEND(
"BH detected protocol error");
303 fprintf(stderr,
"FATAL: %s: can't initialize SSPI, exiting.\n", argv[0]);
306 debug(
"SSPI initialized OK\n");
311 setbuf(stdout,
nullptr);
312 setbuf(stderr,
nullptr);
void base64_decode_init(struct base64_decode_ctx *ctx)
int base64_decode_update(struct base64_decode_ctx *ctx, size_t *dst_length, uint8_t *dst, size_t src_length, const char *src)
int base64_decode_final(struct base64_decode_ctx *ctx)
#define HELPER_INPUT_BUFFER
void debug(const char *format,...)
int getopt(int nargc, char *const *nargv, const char *ostr)
static bool token_decode(size_t *decodedLen, uint8_t decoded[], const char *buf)
int main(int argc, char *argv[])
void process_options(int argc, char *argv[])
char * negotiate_check_auth(SSP_blobP auth, int auth_length)
static int have_serverblob
int Negotiate_packet_debug_enabled
void UnloadSecurityDll(void)
HMODULE LoadSecurityDll(int mode, const char *SSP_Package)
#define NEGOTIATE_PACKAGE_NAME
void hex_dump(unsigned char *data, int size)