声明:
下述协议内容略去了一些在编写程序过程中没有用到协议内容,最初的Ipmsg协议是用日文写的,
下面协议内容基于cugb_cat翻译自Mr.Kanazawa的英文文档。我(赵崇日)做一些补充说明:)。本翻
译文档可任意传播和使用。
----------------------------------------------------------------------
IP信使传输协议(第9版草案) 1996/02/21
2003/01/14 修订
H.Shirouzu
[email protected]
YLT64-MKFFG-8A1DY-4M8ZK OR LCT4T-24GFE-A816V-4MTQQ
----------------------------------------------------------------------
关于IP信使:
IP信使使用TCP/UDP协议提供收发消息及文件(目录)。
特性:
IP信使能够安装在任何一个安装了TCP/IP协议栈的操作系统上,使用在线用户的动态识别机制,
可以和在线所有用户进行信息交换。
运行机制介绍:
使用TCP/UDP端口(默认端口为2425),消息的收发使用UDP协议,文件(文件夹)的收发使用TCP协议。
1、 命令字:
1) 基本命令字(32位命令字的低8位)
IPMSG_NOOPERATION 不进行任何操作
IPMSG_BR_ENTRY 用户上线(以广播方式登陆)
IPMSG_BR_EXIT 用户下线(以广播方式退出)
IPMSG_ANSENTRY 应答用户上线
IPMSG_BR_ABSENCE 改为缺席模式
IPMSG_BR_ISGETLIST 寻找有效的可以发送用户列表的成员
IPMSG_OKGETLIST 通知用户列表已经获得
IPMSG_GETLIST 用户列表发送请求
IPMSG_ANSLIST 应答用户列表发送请求
IPMSG_SENDMSG 发送消息
IPMSG_RECVMSG 消息接受验证
IPMSG_READMSG 消息打开通知
IPMSG_DELMSG 消息丢弃通知
IPMSG_ANSREADMSG 消息打开确认通知(version-8中添加)
IPMSG_GETFILEDATA 文件传输请求
IPMSG_RELEASEFILES 丢弃附加文件
IPMSG_GETDIRFILES 附着同级文件请求
IPMSG_GETINFO 获得IPMSG版本信息
IPMSG_SENDINFO 发送IPMSG版本信息
IPMSG_GETABSENCEINFO 获得缺席信息
IPMSG_SENDABSENCEINFO 发送缺席信息
IPMSG_GETPUBKEY 获得RSA公钥
IPMSG_ANSPUBKEY 应答RSA公钥
2) 选项位(32位命令字的高24位)
IPMSG_ABSENCEOPT 缺席模式(Member recognition command)
IPMSG_SERVEROPT 服务器(保留)
IPMSG_DIALUPOPT 发送给个人 Send individual member recognition command
IPMSG_SENDCHECKOPT 传送验证
IPMSG_SECRETOPT 密封的消息
IPMSG_READCHECKOPT 密封消息验证(ver8中添加 )
IPMSG_PASSWORDOPT 密码
IPMSG_BROADCASTOPT 广播
IPMSG_MULTICASTOPT 多播
IPMSG_NEWMUTIOPT 新版本的多播(保留)
IPMSG_AUTORETOPT 自动应答(Ping-pong protection)
IPMSG_NOLOGOPT 没有日志文件
IPMSG_NOADDLISTOPT 不添加用户列表Notice to the members outside of BR_ENTRY
IPMSG_FILEATTACHOPT 附加文件
IPMSG_ENCRYPTOPT 加密
IPMSG_NOPOPUPOPT (不再有效)
IPMSG_RETRYOPT 重发标志(用于请求用户列表时)
3) Extended code flag (hex format combination)
IPMSG_RSA_512
IPMSG_RSA_1024
IPMSG_RSA_2048
IPMSG_RC2_40
IPMSG_RC2_128
IPMSG_RC2_256
IPMSG_BLOWFISH_128
IPMSG_BLOWFISH_256
IPMSG_SIGN_MD5
4) Extended files for attachment (fileattr low 8 bits)
IPMSG_FILE_REGULAR
IPMSG_FILE_DIR
IPMSG_FILE_RETPARENT
IPMSG_FILE_SYMLINK
IPMSG_FILE_CDEV
IPMSG_FILE_BDEV
IPMSG_FILE_FIFO
IPMSG_FILE_RESFORK
5) Attachment file extended attribute(fileattr high 24 bits)
IPMSG_FILE_RONLYOPT
IPMSG_FILE_HIDDENOPT
IPMSG_FILE_EXHIDDENOPT
IPMSG_FILE_ARCHIVEOPT
IPMSG_FILE_SYSTEMOPT
6) Extended file attribute for attachment file
IPMSG_FILE_UID
IPMSG_FILE_USERNAME
IPMSG_FILE_GID
IPMSG_FILE_GROUPNAME
IPMSG_FILE_PERM
IPMSG_FILE_MAJORNO
IPMSG_FILE_MINORNO
IPMSG_FILE_CTIME
IPMSG_FILE_MTIME
IPMSG_FILE_ATIME
IPMSG_FILE_CREATETIME
IPMSG_FILE_CREATOR
IPMSG_FILE_FILETYPE
IPMSG_FILE_FINDERINFO
IPMSG_FILE_ACL
IPMSG_FILE_ALIASFNAME
IPMSG_FILE_UNICODEFNAME
2、 数据包格式(使用字符串):
1) 数据包格式(版本1的格式)
版本号(1):包编号:发送者姓名:发送者主机名:命令字:附加信息
2) 举例如下
“1:100:shirouzu:Jupiter:32:Hello”
3、 数据包处理总述:
1) 用户识别
当IPMSG 启动时,命令IPMSG_BR_ENTRY被广播到网络中,向所有在线的用户提示一个新用户的到达
(即表示“我来了”)。
所有在线用户将把该新上线用户添加到自己的用户列表中,并向该新上线用户发送IPMSG_ANSENTRY
命令(即表示“我在线”)。
该新上线用户接收到IPMSG_ANSENTRY命令后即将在线用户添加到自己的用户列表中。只要IP包存在
所有用户可以相互交流。
当缺席模式或者昵称改变时,PMSG_BR_ABSENCE命令向所有用户广播。然而,IPMSG_ANSENTRY 命令
不同于IPMSG_BR_ENTRY命令,它不需要一个返回消息。
IPMSG_BR_ENTRY, IPMSG_ANSENTRY, 和 IPMSG_BR_ABSENCE命令在缺席模式下需要使用IPMSG_ABSENCEOPT标志,在附加命令里添加一个昵称。 IPMSG_DIALUPOPT标志用于直连那些不能靠广播来联系的用户。有这个选项时,成员识别命令需要被单独发送给这些用户。
(Extended group)IPMSG_BR_ENTRY 和IPMSG_BR_ABSENCE命令发送一个组名是通过在现有的格式化的字符串后面加上这个新组名来实现的。(在现有命令和扩展名之间加入'\0')
2) 收发消息
使用IPMSG_SENDMSG命令发送消息,消息内容添加在附加信息中;在接收消息时,如果对方要求回
信确认(IPMSG_SENDCHECKOPT位打开),则需发送IPMSG_RECVMSG命令并将对方发送的数据包的编号放
在附加信息中一同发送至发送消息方。
发送广播消息需要使用IPMSG_BOADCASTOPT标志和IPMSG_SENDMSG命令。自动发送包(缺席通知)还
需要加上IPMSG_AUTORETOPT标志以得到请求-应答保护(for ping-pong protection)。如果没有任何
一个包应答,那么确认/自动发送包就没有返回。
(附加的IPMSG_NOADDLISTOPT)
当从一台主机得到一个没有在你的发送/接受列表中的IPMSG_SENDMSG包,IPMsg或者发送一个
IPMSG_BR_ENTRY命令或者把他的的主机名添加到发送/接受列表中。然而,需要避免single-shot消息的
发送/接受行为。它需要在IPMSG_SENDMSG命令上添加一个IPMSG_NOADDLISTOPT标志。
(version8 中附加的IPMSG_READCHECKOPT)
当一个IPMSG_READMSG命令包含一个IPMSG_READCHECKOPT标志时;IPMsg处理IPMSG_SENDMSG同样需要一个 IPMSG_SENDCHECKOPT选项。但是,发送消息使用IPMSG_ANSREADMSG命令,而不是IPMSG_RECVMSG。
3) 收发消息|加密扩展(添加于第9版)
使用Public-key(RSA)和common key(RC2/Blowfish)双重加密。(加密区使用十六进制)
(Public-key获得)发送IPMSG_GETPUBKEY 命令来得到。得到的消息中有IPMSG_ANSPUBKEY,意味着得到了RSA的Public-key。
IPMSG_GETPUBKEY/IPMSG_ANSPUBKEY都需要加密长度值(例如IPMSG_RSA_1024)在扩展的第一部分使用‘OR’标志。
另外,在IPMSG_ANSPUBKEY时,public key需要以这种格式来写:EE-NNNNNN E=Exponent丄N=method使用':'分隔,在E和N之间输入分隔符Fdelimiter '-'
在第二次收发处理记住了public key和加密数据后,这个顺序可以略过。
(加密消息)发送者创建了一个common key后,它可以加密一个消息。另外,接受者的public key加密common key
(加密消息传输)IPMSG_SENDMSG要使用IPMSG_ENCRYPTOPT。在扩展的第一部分,输入值
which is 'or' resoult from Convination of public key and common key type。接着使用被common key which encrypt with public key devide by ':',接着再输入消息which is eccrypted by public key devide by ':'. If both supports IPMSG_SIGN_XXX, then add ':' and signeture.
Also, In the method of encode padding, PKCS#1ECB key is used for RSA,PKCS#5 CBC common key is used for RC2/blowfish.
Also, The Packet related to Entry manifestation the capability of ecryption support using IPMSG_ENCRYPTOPT
4) 附加文件的扩充(添加于第9版)
带有IPMSG_FILEATTACHOPT位的IPMSG_SENDMSG命令可用来传输文件,文件属性及内容添加在附加
信息中,文件内容添加在消息内容后并以’\0’与之分隔开。
传输文件时以下信息将被添加到消息内容之后(包括格式):
文件序号:文件名:大小(单位:字节):最后修改时间:文件属性[: 附加属性=val1[,val2…][:附加
信息=…]]:\a:文件序号…(文件大小、最后修改时间和文件属性为十六进制数,如果文件名中包含’:’
则使用“::”代替)。
接收端开始接收文件时,请求传输文件命令IPMSG_GETFILEDATA将发送到发送端的TCP端口(和UDP的
发送端口相同),并将发送端发送的包编号:文件序号:偏移量(全为十六进制格式)写到附加信息区一同发送,
文件发送端接收到该请求信息并进行校验正确后即开始发送文件(不使用任何格式,亦不进行加密)。
当接收端接收到目录文件时,将发送附加信息区为发送端发送的包编号:文件序号:偏移量(全为十六
进制格式)的 IPMSG_GETDIRFILES命令,以用来请求传输目录文件。
发送端则将头信息长度:文件名:文件大小:文件属性:文件内容添加到附加信息区(除了文件名和文件内容
外,其余皆为十六进制)。
头信息长度是从头信息长度开始到文件内容前的‘:’分割符为止的字符个数。扩展属性被忽略并且使用
多个扩展属性。内容输入使用'='。
当文件属性为IPMSG_FILE_DIR时,IPMsg能够自动识别其为目录,下一个文件的数据在该目录之后。
当文件属性为IPMSG_FILE_RETPARENT时,IPMsg识别其动作为返回上一级目录,在这种情况下,文件名为‘.’其属性为当前目录的值。
发送处理直接开始于附加文件且返回IPMSG_FILE_RETPARENT命令来附加目录。
给Entry包添加一个IPMSG_FILEATTACHOPT标志来支持附加文件。
5) 其他命令
当需要不同版本信息时,发送IPMSG_GETINFO命令。接受方在扩展信息区加上版本信息来回应。
发送IPMSG_GETABSENCEINFO命令来得到缺席模式时的信息。如果接受方是在缺席模式下,则发送
IPMSG_SENDABSENCEINFO;如果不是,则发送字符串"Not absence mode"。
6) 确认/重发
如果IPMSG_SENDMSG 和 IPMSG_RECVMSG的确认包在一个设定的时间内没有返回,那就需要重发。重发次数和时间间隔依赖于当前条件。
4、其他
1)换行
发送消息中换行符是UNIX的类型('0x0a'),如果需要可以改变。
2)分隔符':'
你不能在用户名和主机名中使用分隔符':'。如果用户名/主机名包含了':',请用其他的符号替换,
比如';'。使用分隔符不是问题所在,可以创建一个escape sequence。
//水平有限,仅作参考,有什么问题或建议请联系:[email protected]
附IPMSG协议英文版:
QUOTE:
Original ipmsg protocol specification is written in Japanese.
This document was translated by Mr.Kanazawa.
This document is not verified yet.
----------------------------------------------------------------------
IP Messenger communication protocol (Draft-9) 1996/02/21
Modified 2003/01/14
H.Shirouzu
[email protected]
----------------------------------------------------------------------
About IP Messenger
This is a Send/Receive message service using the TCP/UDP Port.
Characteristics
IP Messenger can be installed in any OS if TCP/IP is used on your machine.
Dynamic member recognition can be done within your network or specified network.
You can exchange messages between all IPMsg members.
Function description
Use TCP/UDP port(default:2425). See the following descriptions
(Message Send/Receive: UDP, File Send/Receive: TCP)
1. Command
1) Command functions (Low 8 bits from command number 32 bits)
IPMSG_NOOPERATION No Operation
IPMSG_BR_ENTRY Entry to service (Start-up with a Broadcast command)
IPMSG_BR_EXIT Exit from service (End with a Broadcast command)
IPMSG_ANSENTRY Notify a new entry
IPMSG_BR_ABSENCE Change absence mode
IPMSG_BR_ISGETLIST Search valid sending host members
IPMSG_OKGETLIST Host list sending notice
IPMSG_GETLIST Host list sending request
IPMSG_ANSLIST Host list sending
IPMSG_SENDMSG Message transmission
IPMSG_RECVMSG Message receiving check
IPMSG_READMSG Message open notice
IPMSG_DELMSG Message discarded notice
IPMSG_ANSREADMSG Message open confirmation notice(added from version-8 )
IPMSG_GETFILEDATA File Transfer request by TCP
IPMSG_RELEASEFILES Discard attachment file
IPMSG_GETDIRFILES Attachment hierarchical file request
IPMSG_GETINFO Get IPMSG version info.
IPMSG_SENDINFO Send IPMSG version info.
IPMSG_GETABSENCEINFO Get absence sentence
IPMSG_SENDABSENCEINFO Send absence sentence
IPMSG_GETPUBKEY RSA Public Key Acquisition
IPMSG_ANSPUBKEY RSA Public Key Response
2) Option flag (High 24 bits from command number 32 bits)
IPMSG_ABSENCEOPT Absence mode(Member recognition command)
IPMSG_SERVEROPT Server(Reserved)
IPMSG_DIALUPOPT Send individual member recognition command
IPMSG_SENDCHECKOPT Transmission check
IPMSG_SECRETOPT Sealed message
IPMSG_READCHECKOPT Sealed message check(added from ver8 )
IPMSG_PASSWORDOPT Lock
IPMSG_BROADCASTOPT Broadcast message
IPMSG_MULTICASTOPT Multi-cast(Multiple casts selection)
IPMSG_NEWMUTIOPT New version multi-cast(reserved)
IPMSG_AUTORETOPT Automatic response(Ping-pong protection)
IPMSG_NOLOGOPT No log files
IPMSG_NOADDLISTOPT Notice to the members outside of BR_ENTRY
IPMSG_FILEATTACHOPT File attachment
IPMSG_ENCRYPTOPT Code
IPMSG_NOPOPUPOPT (No longer valid)
IPMSG_RETRYOPT Re-send flag(Use when acquiring HOSTLIST)
3) Extended code flag (hex format combination)
IPMSG_RSA_512
IPMSG_RSA_1024
IPMSG_RSA_2048
IPMSG_RC2_40
IPMSG_RC2_128
IPMSG_RC2_256
IPMSG_BLOWFISH_128
IPMSG_BLOWFISH_256
IPMSG_SIGN_MD5
4) Extended files for attachment (fileattr low 8 bits)
IPMSG_FILE_REGULAR
IPMSG_FILE_DIR
IPMSG_FILE_RETPARENT
IPMSG_FILE_SYMLINK
IPMSG_FILE_CDEV
IPMSG_FILE_BDEV
IPMSG_FILE_FIFO
IPMSG_FILE_RESFORK
5) Attachment file extended attribute(fileattr high 24 bits)
IPMSG_FILE_RONLYOPT
IPMSG_FILE_HIDDENOPT
IPMSG_FILE_EXHIDDENOPT
IPMSG_FILE_ARCHIVEOPT
IPMSG_FILE_SYSTEMOPT
6) Extended file attribute for attachment file
IPMSG_FILE_UID
IPMSG_FILE_USERNAME
IPMSG_FILE_GID
IPMSG_FILE_GROUPNAME
IPMSG_FILE_PERM
IPMSG_FILE_MAJORNO
IPMSG_FILE_MINORNO
IPMSG_FILE_CTIME
IPMSG_FILE_MTIME
IPMSG_FILE_ATIME
IPMSG_FILE_CREATETIME
IPMSG_FILE_CREATOR
IPMSG_FILE_FILETYPE
IPMSG_FILE_FINDERINFO
IPMSG_FILE_ACL
IPMSG_FILE_ALIASFNAME
IPMSG_FILE_UNICODEFNAME
2.Command format(Use all character strings)
1) Command(Format version-1)
Ver(1) : PacketNo : SenderName : SenderHost : CommandNo : AdditionalSection
2) An example for Message Send/Receive by using the current command format
"1:100:shirouzu:jupiter:32:Hello"
3.Command process overview
1) Member recognition
An IPMSG_BR_ENTRY command notifies a new entry to the current
members at start-up.
All members add the new member to their list after getting a notification message.
An IPMSG_ANSENTRY command sends a message back to the new member.
The new member gets the current member data by a
IPMSG_ANSENTRY command. All members can communicate as long as an
IP packet exists.
An IPMSG_BR_ABSENCE command broadcasts absence mode cancel or
nickname change to all members. However, an IPMSG_ANSENTRY command
does not send a message back, which is different from an IPMSG_BR_ENTRY
command.
IPMSG_BR_ENTRY, IPMSG_ANSENTRY, and IPMSG_BR_ABSENCE commands
use an IPMSG_ABSENCEOPT flag for absence mode. Input a nickname to
additional command.
Add an IPMSG_DIALUPOPT flag for dial-up users who can't be reached by
a broadcast command. A member recognition command needs to be
sent individually to the members with this optional flag.
(Extended group)IPMSG_BR_ENTRY and IPMSG_BR_ABSENCE commands
sends a group name by adding the new group name after the current
command format character strings (Input '\0' between the current
command and extended name).
2) Send/Receive Message
Send Message uses an IPMSG_SENDMSG command that can input a message
in the extended area.
Receive Message sends back an IPMSG_RECVMSG command only
if an IPMSG_SENDCHECKOPT flag is ON. Input the original packet number
to the extended area.
Broadcast Message Send uses an IPMSG_BOADCASTOPT command
and an IPMSG_SENDMSG flag should be ON.
Auto-Send packet(absence notice) needs to be added to IPMSG_AUTORETOPT
for ping-pong protection. If either one or another packet is ON, then
confirmation/auto-send packet is not sent back.
Send Message Sealing needs to be an IPMSG_SECRETOPT packet ON.
In this case, Receive Message sends an IPMSG_READMSG command.
Input the original packet number to the extended area.
(Additional IPMSG_NOADDLISTOPT)
When receiving an IPMSG_SENDMSG packet from a host that is
not on your Send/Receive list, IPMsg will either confirm a host by
sending an IPMSG_BR_ENTRY command or add a host name to
the Send/Receive list.
However, single-shot Message Send/Receive action needs to be avoided.
Add an IPMSG_NOADDLISTOPT flag to an IPMSG_SENDMSG command.
(Additional IPMSG_READCHECKOPT from version-8 )
When an IPMSG_READMSG command contains an IPMSG_READCHECKOPT flag,
IPMsg process is the same as IPMSG_SENDMSG with an
IPMSG_SENDCHECKOPT flag.
However, Send Message uses an IPMSG_ANSREADMSG command,
not IPMSG_RECVMSG.
3) Message Send/Receive 亅encrypted extension (Added in the version-9 )
Use the combination of Public-key(RSA) and common key(RC2/Blowfish).
(Encrypted extension area is used in hex format.)
(Public key acquisition)Send an IPMSG_GETPUBKEY command to Receive
Message. Receive Message gets an IPMSG_ANSPUBKEY that
means receiving RSA public key from Send Message.
IPMSG_GETPUBKEY/IPMSG_ANSPUBKEY both require the value which is
encryption capability (Exp. IPMSG_RSA_1024) flag uses "OR" at first
part of extension
In addition, In IPMSG_ANSPUBKEY, public key written as EE-NNNNNN
E=Exponent丄N=method)devide by ':'. and Input the Fdelimiter '-'
between E and N.
This sequence can be skipped after the 2nd Send/Receive process by
memorizing public key and encrypted data.
(Encrypted message)After a sender creates a common key that is
supported both sender and receiver, a common key can encrypt a message.
In addition, a receiver's public key encrypts the common key.
(Encrypted message transmission) IPMSG_ENCRYPTOPT is used in
IPMSG_SENDMSG. At the first part of extension, input the value which
is 'or' resoult from Convination of public key and common key type .
Then use common key which encrypt with public key devide by ':'.
Then input message which is eccrypted by public key devide by ':'.
If both supports IPMSG_SIGN_XXX, then add ':' and signeture.
Also, In the method of encode padding, PKCS#1ECB key is used for RSA,
PKCS#5 CBC common key is used for RC2/blowfish.
Also, The Packet related to Entry manifestation the capability of
ecryption support using IPMSG_ENCRYPTOPT
4) Extension with file attachment(Available from version-9 )
An IPMSG_SENDMSG command with an IPMSG_FILEATTACHOPT flag for
File transfer (download permission)notification sends a message
with attachment.
Input '\0' after the message and attachment file data.
fileID:filename:size:mtime:fileattr[:extend-attr=val1
[,val2...][:extend-attr2=...]]:\a:fileID...
(size, mtime, and fileattr describe hex format.
If a filename contains ':', please replace with "::".)
When Receive Message downloads an attachment file, an IPMSG_GETFILEDATA
command requests a data transmission packet to the TCP port that is the same number
as the UDP sending port number. Input packetID:fileID: offset to the extended area.
(Use all hex format.)
File Transfer side receives the request. After recognizing that it's a correct request,
then send the specified data (no format)
When the data receiving side downloads a hierarchical attachment file,
use an IPMSG_GETDIRFILES command and input a packetID:fileID
to the extended area and send a data transmission request packet.
(all hex format)
Data sending side sends the following hierarchical data format.
header-size:filename:file-size:fileattr[:extend-attr=val1
[,val2...][:extend-attr2=...]]:contents-data
Next headersize: Next filename...
(All hex format except for filename and contetns-data)
header-size is from the beginning of header-size to the delimiter ':'
that is before contents-data. extend-attr can be omitted and used multiple
extended attributes. Use '=' for data input.
When fileattr is IPMSG_FILE_DIR, IPMsg recognizes that it is automatically
in the directory, the next file data is after the directory.
When fileattr is IPMSG_FILE_RETPARENT, IMPsg recognizes that it returns
to the parent directory. In this case, File name is always "." and the attribute
value is the current directory data.
Sending process starts from the attachment directly and returns the
IPMSG_FILE_RETPARENT command to the attachment directory.
Add an IPMSG_FILEATTACHOPT flag for an Entry packet to support the
attachment file.
5) Other commands
When acquiring different versions, send an IPMSG_GETINFO command.
Receiving side sends the version information character string to
extended area.
Send an IPMSG_GETABSENCEINFO command for acquiring an absence message.
Receiving side sends an IPMSG_SENDABSENCEINFO back if the status is absence mode.
If the status is not absence mode, a character string "Not absence mode" will be sent back.
6) Confirmation/Retry
If a confirmation packet for IPMSG_SENDMSG or IPMSG_RECVMSG is not delivered
within a specified time, then it will be sent again.
A number of retry actions or interval period is depended on the current condition.
4. Other
1) Linefeed
Linefeed characters in Send Message is standardized with UNIX type ('0x0a').
Please change if needed.
2) Delimiter ':'
':' is used as a delimiter. You can't use this delimiter for user name
and host name.
If the use/host names contain a ':', please replace with another sign,
for an example ';'.
Although using this delimiter isn't problem as yet, I may create an
escape sequence.
3) Kanji codes
SJIS
5. Contact e-mail address
E-Mail [email protected]
Note
See ipmsg.h for command codes.
Please e-mail me your comments and suggestions.