KMIP协议/TTLV格式解码

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)));
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值