KMIP协议官方文档
KMIP协议官方文档:http://docs.oasis-open.org/kmip/spec/
打开是这样的,在我写这篇文章的时候 KMIP更新到了1.4版本
以下KIMIP1.0协议为例:
手动解析TTLV格式
请求
官方文档有解析ttlv的例子(见文档 9.Message Encoding),但是比较简单
这里我截取的mysql发送ttlv请求,并解码
大体就是遵循
T 项目标识
T 项目数据类型
L 项目长度(十六进制)
V{ 项目值
T
T
L
V {
.......
}
}
{
"420078" Request Message
"01"
"000000F8"
{
"420077" Request Header
"01"
"00000048"
{
"420069" Protocol Version
"01"
"00000020"
{
"42006A" Protocol Version Major
"02"
"00000004"
"00000001" 1
"00000000"
"42006B" Protocol Version Minor
"02"
"00000004"
"00000001" 1
"00000000"
}
"420050" Maximum Response Size
"02"
"00000004"
"000445C0"
"00000000"
"42000D" Batch Count
"02"
"00000004"
"00000001" 1
"00000000"
}
"42000F" Batch Item
"01"
"000000A0"
{
"42005C" Operation
"05" Enumeration
"00000004"
"00000008" Locate
"00000000"
"420079" Request Payload
"01"
"00000088"
{
"42004F" Maximum Items
"02"
"00000004"
"000186A0"
"00000000"
"42008E" Storage Status Mask
"02"
"00000004"
"00000001"
"00000000"
"420008" Attribute
"01"
"00000028"
{
"42000A" Attribute Name
"07" Text string
"0000000B" 11
"782D6B65792D7265616479" x-key-ready
"0000000000"
"42000B"
"07"
"00000003"
"796573" yes
"0000000000"
}
"420008" Attribute
"01"
"00000030"
{
"42000A" Attribute Name
"07"
"00000005"
"5374617465" State
"000000"
"420009" Attribute Index
"02" int
"00000004"
"00000000" 0
"00000000"
"42000B" Attribute Value
"05" enum
"00000004"
"00000002" Active
"00000000"
}
}
}
}
}
响应
"42007B" Response Message
"01"
"000000B0"
{
"42007A" Response Header
"01"
"00000048"
{
"420069" Protocol Version
"01"
"00000020"
{
"42006A" Protocol Version Major
"02"
"00000004"
"00000001"
"00000000"
"42006B" Protocol Version Minor
"02"
"00000004"
"00000000"
"00000000"
}
"420092" Time Stamp
"09" Date-Time
"00000008"
"000000004B742476"
"42000D" Batch Count
"02"
"00000004"
"00000001" 1
"00000000"
}
"42000F" Batch Item
"01"
"00000058"
{
"42005C" Operation
"05"
"00000004"
"00000008"
"00000000"
"42007F" Result Status
"05"
"00000004"
"00000000"
"00000000"
"42007C" Response Payload
"01"
"00000030"
{
"420094" Unique Identifier
"07" Text String
"00000024"
"66303334323539302D663738612D346433342D613266342D346436666338356135366566" f0342590-f78a-4d34-a2f4-4d6fc85a56ef
"00000000"
}
}
}
自动解析
这里要借助一个开源项目的工具类:KMIP4j
解析请求和响应
KMIPDecoder kmipDecoder = new KMIPDecoder();
System.out.println(kmipDecoder.decodeRequest(KMIPUtils.convertByteArrayToArrayList(buffer)));
System.out.println(kmipDecoder.decodeResponse(KMIPUtils.convertHexStringToArrayList(response)));