时间:2009-04-23 17:47
人气:
作者:admin
void generate_type1_msg(type1msg *t1_msg, char *user); void generate_type3_msg(type2msg *t2_msg, type3msg *t3_msg, char *user, char *pass);These routines allow NTLM authentication to be added easily to any client application by abstracting the NTLM internals from the user. Refer to the Additional Information section below for detailed descriptions of the NTLM protocol.
AUTHThe server responds with a "success" message, followed by the list of supported mechanisms. This list should include "NTLM," and is terminated by a line containing a single period ("."):
+OK The operation completed successfully. NTLM .The client initiates NTLM authentication by sending an AUTH command that specifies NTLM as the authentication mechanism:
AUTH NTLMThe server responds with a success message:
+ OKThe client sends the Type 1 message (Base-64 encoded):
TlRMTVNTUAABAAAAB7IAAAUABQAgAAAABQAFACUAAABzZWVuaXNlZW5pThe server replies with the Type 2 challenge message (Base-64 encoded). The challenge format is specified by RFC 1734 ("+", followed by a space, followed by the challenge message), as shown below:
+TlRMTVNTUAACAAAADwAPADAAAAAHAgIAbYIeZCZESTMAAAAAAAAAAAAAAAAAAAAAbWFpbC5kb21haW4uY29tThe client calculates and sends the Base-64 encoded Type 3 message:
TlRMTVNTUAADAAAAGAAYAEAAAAAYABgAWAAAAA8ADwBwAAAACgAKAH8AAAAKAAoAiQAAAAUABQCTAAAABwICAFinally, the server validates the response and indicates the result of authentication process:
FadILoghkFeli66HycIYmjpnmm6XToht7yzrLzrNb8CV7gLSwRScY1FQQ86d+hWnm1haWwuZG9tYWluLmNvbX
MAZQBlAG4AaQBzAGUAZQBuAGkAZHVtbXJ
+OK User successfully logged onAfter successful authentication, the POP3 session enters the "transaction" state, allowing messages to be retrieved by the client.
int ntlm_authentication(pop3_session *pop3_handle)
{
char buf[MAX_LINE_SIZE];
char *mimebuf;
int size;
sprintf(buf, "AUTH NTLM\r\n");
//request NTLM authentication mechanism to choose for authentication with server
if(send(pop3_handle->handle, buf, strlen(buf),0)!=0)
{
return POP3_SOCKET_ERROR;
}
if((size=recv(pop3_handle->handle,buf,MAX_LINE_SIZE,0))==0x0FFFF)
{
return POP3_SOCKET_ERROR;
}
buf[size]='\0';
//if server doesn't support NTLM, return with error
if(strncmp(buf,"+",1)!=0)
{
return POP3_RECEIVEMAIL_ERROR;
}
//generate type1 ntlm message, give user name as input
generate_type1_msg(&t1_msg, pop3_handle->user);
//encode type1 message in base64 format
mimebuf=mime_encode((unsigned char
*)&t1_msg,(sizeof(type1msghdr)+t1_msg.buf_index), BASE64);
strcpy(buf,mimebuf);
strcat(buf,"\r\n");
//send type1 message to server
if(send(pop3_handle->handle, buf, strlen(buf),0)!=0)
return POP3_SOCKET_ERROR;
//receive server response
if((size=recv(pop3_handle->handle,buf,MAX_LINE_SIZE,0))==0x0FFFF)
return POP3_SOCKET_ERROR;
//ignore server response status mark and extract server type2 message response
if(buf[0]=='+' && buf[1] == ' ')
mimebuf=mime_decode((char far*)(buf+2), BASE64);
else
mimebuf=mime_decode((char far*)buf, BASE64);
memcpy((char *)&t2_msg,mimebuf,mem_sizeof(mimebuf));
//generate type3 ntlm message
generate_type3_msg(&t2_msg, &t3_msg, pop3_handle->user,pop3_handle->pass);
//encode type3 message in base64 format
mimebuf=mime_encode((unsigned char
*)&t3_msg,(sizeof(type3msghdr)+t3_msg.buf_index), BASE64);
strcpy(buf,mimebuf);
strcat(buf,"\r\n");
//send type3 message to server
if(send(pop3_handle->handle, buf, strlen(buf),0)!=0)
return POP3_SOCKET_ERROR;
if((size=recv(pop3_handle->handle,buf,MAX_LINE_SIZE,0))==0x0FFFF)
return POP3_SOCKET_ERROR;
buf[size]='\0';
//check server response to see whether authentication is successful or not.
//if authentication is not successful, send error code to POP3 library
if(strncmp(buf,"+",1)!=0)
{
return POP3_INVALID_USER_PASSWORD;
}
//we have gone through authentication successfully, return success status code
return POP3_STATUS_SUCCESS;
}
Dallas Semiconductor is a registered trademark of Dallas Semiconductor Corp.
Maxim is a registered trademark of Maxim Integrated Products, Inc.
Windows is a registered trademark of Microsoft Corp.
Dallas Semiconductor is a wholly owned subsidiary of Maxim Integrated Products, Inc.
上一篇:利用DS5250产生RSA密钥
下一篇:构建网络使陈旧的电脑外设重焕生机