Skip to content

Commit

Permalink
feat(Jt808MsgBuilder): Jt808MsgBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
hylexus committed Jun 8, 2024
1 parent 4e86eb9 commit 5f749f2
Show file tree
Hide file tree
Showing 34 changed files with 1,198 additions and 187 deletions.
3 changes: 2 additions & 1 deletion .github/FUNDING.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ issuehunt: # Replace with a single IssueHunt username
otechie: # Replace with a single Otechie username
lfx_crowdfunding: # Replace with a single LFX Crowdfunding project-name e.g., cloud-foundry
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']
- https://img.dferic.com/img/pay.png
- https://hylexus.github.io/jt-framework/img/pay.png

22 changes: 22 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,25 @@
## 2.1.4(2024-06-08)

### ⭐ New Features

- 完善 `Jt808MsgBuilder`
- 新增 `RebuildableByteBufJt808MsgBuilder`

### 🔨 Dependency Upgrades

- `Gradle` : **8.6** 升级到 **8.8**
- `spring-boot-dependencies`
- **2.7.14** 升级到 **2.7.18**
- **3.1.2** 升级到 **3.3.0**
- `spring-cloud-dependencies`
- **2021.0.8** 升级到 **2021.0.9**
- **2022.0.4** 升级到 **2023.0.2**

### 📔 Documentation

- 新增消息加解密相关文档
- 新增 `RebuildableByteBufJt808MsgBuilder` 相关文档

## 2.1.4-rc.4(2024-06-02)

### ⭐ New Features
Expand Down
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ Jt-808协议服务端。

## Compatibility

支持 **spring-boot-2.x** [![spring-boot-2.x](https://img.shields.io/maven-central/v/io.github.hylexus.jt/jt-808-server-spring-boot-starter-boot2.svg?label=spring-boot-2.x)](https://search.maven.org/search?q=g:%22io.github.hylexus.jt%22%20AND%20a:%22jt-808-server-spring-boot-starter-boot2%22)
**spring-boot-3.x** [![spring-boot-3.x](https://img.shields.io/maven-central/v/io.github.hylexus.jt/jt-808-server-spring-boot-starter.svg?label=spring-boot-3.x)](https://search.maven.org/search?q=g:%22io.github.hylexus.jt%22%20AND%20a:%22jt-808-server-spring-boot-starter%22)
支持 **spring-boot-2.x
** [![spring-boot-2.x](https://img.shields.io/maven-central/v/io.github.hylexus.jt/jt-808-server-spring-boot-starter-boot2.svg?label=spring-boot-2.x)](https://search.maven.org/search?q=g:%22io.github.hylexus.jt%22%20AND%20a:%22jt-808-server-spring-boot-starter-boot2%22)
**spring-boot-3.x
** [![spring-boot-3.x](https://img.shields.io/maven-central/v/io.github.hylexus.jt/jt-808-server-spring-boot-starter.svg?label=spring-boot-3.x)](https://search.maven.org/search?q=g:%22io.github.hylexus.jt%22%20AND%20a:%22jt-808-server-spring-boot-starter%22)

更多有关版本兼容性的信息,请移步: [入门--兼容性](https://hylexus.github.io/jt-framework/v2/jt-808/guide/quick-start/compatibility.html)

Expand All @@ -28,14 +30,14 @@ Jt-808协议服务端。

`starter`**JDK** 版本、**spring-boot** 版本限制如下:

| Module | JDK | spring-boot | Desc |
|--------------------------------------------|-------|------------------|--------------------------------------------|
| `jt-808-server-spring-boot-starter-boot2` | `11+` | `[2.2.x, 2.7.x]` |**spring-boot-2.x** 提供的 starter |
| `jt-808-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` |**spring-boot-3.x** 提供的 starter |
| `jt-1078-server-spring-boot-starter-boot2` | `11+` | `[2.2.x, 2.7.x]` |**spring-boot-2.x** 提供的 starter; `beta版` |
| `jt-1078-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` |**spring-boot-3.x** 提供的 starter; `beta版` |
| `jt-dashboard-client-spring-boot-starter` | `17+` | `[3.0.0, ...]` | 暂时只支持 `jdk17+/spring-boot-3.x`; `beta版` |
| `jt-dashboard-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` | 暂时只支持 `jdk17+/spring-boot-3.x`; `beta版` |
| Module | JDK | spring-boot | Desc |
|--------------------------------------------|-------|-------------------|--------------------------------------------|
| `jt-808-server-spring-boot-starter-boot2` | `11+` | `[2.2.x, 2.7.18]` |**spring-boot-2.x** 提供的 starter |
| `jt-808-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` |**spring-boot-3.x** 提供的 starter |
| `jt-1078-server-spring-boot-starter-boot2` | `11+` | `[2.2.x, 2.7.18]` |**spring-boot-2.x** 提供的 starter; `beta版` |
| `jt-1078-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` |**spring-boot-3.x** 提供的 starter; `beta版` |
| `jt-dashboard-client-spring-boot-starter` | `17+` | `[3.0.0, ...]` | 暂时只支持 `jdk17+/spring-boot-3.x`; `beta版` |
| `jt-dashboard-server-spring-boot-starter` | `17+` | `[3.0.0, ...]` | 暂时只支持 `jdk17+/spring-boot-3.x`; `beta版` |

## Modules

Expand All @@ -44,15 +46,15 @@ Jt-808协议服务端。
| Module | JDK | CompileLevel | .class | spring-boot | Desc |
|------------------------------------------|-----|--------------|-------------|-------------|-------------------------------------------|
| jt-core | 17 | JDK-11 | 55 (JDK-11) | -- | |
| jt-808-server-spring-boot-starter | 17 | _**JDK-17**_ | 61 (JDK-17) | _**3.1.2**_ | |
| jt-808-server-spring-boot-starter-boot2 | 17 | JDK-11 | 55 (JDK-11) | 2.7.14 | |
| jt-808-server-spring-boot-autoconfigure | 17 | JDK-11 | 55 (JDK-11) | 2.7.14 | |
| jt-808-server-spring-boot-starter | 17 | _**JDK-17**_ | 61 (JDK-17) | _**3.3.0**_ | |
| jt-808-server-spring-boot-starter-boot2 | 17 | JDK-11 | 55 (JDK-11) | 2.7.18 | |
| jt-808-server-spring-boot-autoconfigure | 17 | JDK-11 | 55 (JDK-11) | 2.7.18 | |
| jt-808-server-support | 17 | JDK-11 | 55 (JDK-11) | -- | |
| jt-1078-server-spring-boot-starter | 17 | _**JDK-17**_ | 61 (JDK-17) | _**3.1.2**_ | |
| jt-1078-server-spring-boot-starter-boot2 | 17 | JDK-11 | 55 (JDK-11) | 2.7.14 | |
| jt-1078-server-spring-boot-autoconfigure | 17 | JDK-11 | 55 (JDK-11) | 2.7.14 | |
| jt-1078-server-spring-boot-starter | 17 | _**JDK-17**_ | 61 (JDK-17) | _**3.3.0**_ | |
| jt-1078-server-spring-boot-starter-boot2 | 17 | JDK-11 | 55 (JDK-11) | 2.7.18 | |
| jt-1078-server-spring-boot-autoconfigure | 17 | JDK-11 | 55 (JDK-11) | 2.7.18 | |
| jt-1078-server-support | 17 | JDK-11 | 55 (JDK-11) | -- | |
| `dashboard/**` | 17 | _**JDK-17**_ | 61 (JDK-11) | _**3.1.2**_ | dashboard 模块暂时只支持 `spring-boot-3.x/jdk17` |
| `dashboard/**` | 17 | _**JDK-17**_ | 61 (JDK-11) | _**3.3.0**_ | dashboard 模块暂时只支持 `spring-boot-3.x/jdk17` |

- 模块介绍

Expand Down Expand Up @@ -139,7 +141,7 @@ Jt-808协议服务端。
- gradle

```groovy
implementation group: 'io.github.hylexus.jt', name: 'jt-808-server-spring-boot-starter-boot2', version: "2.1.4-rc.3"
implementation group: 'io.github.hylexus.jt', name: 'jt-808-server-spring-boot-starter-boot2', version: "2.1.4"
```

- maven
Expand All @@ -149,7 +151,7 @@ implementation group: 'io.github.hylexus.jt', name: 'jt-808-server-spring-boot-s
<dependency>
<groupId>io.github.hylexus.jt</groupId>
<artifactId>jt-808-server-spring-boot-starter-boot2</artifactId>
<version>2.1.4-rc.3</version>
<version>2.1.4</version>
</dependency>
```

Expand Down Expand Up @@ -219,4 +221,5 @@ Maven版示例项目

项目的发展离不开你的支持,请作者喝一杯🍺吧!

![有钱的捧个钱场 没钱的捧个人场](https://img.dferic.com/img/pay.png)
![有钱的捧个钱场 没钱的捧个人场](https://hylexus.github.io/jt-framework/img/pay.png)

Binary file added docs/src/.vuepress/public/img/pay.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions docs/src/.vuepress/sidebar/zh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ export const zhSidebar = sidebar({
'/v2/jt-808/guide/customization/sub-package-config.md',
'/v2/jt-808/guide/customization/request-lifecycle-listener.md',
'/v2/jt-808/guide/customization/jt-808-request-filter.md',
'/v2/jt-808/guide/customization/msg-encryption.md',
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion docs/src/about.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@

项目的发展离不开你的支持,请作者喝一杯🍺吧!

![有钱的捧个钱场 没钱的捧个人场](https://img.dferic.com/img/pay.png)
![有钱的捧个钱场 没钱的捧个人场](https://hylexus.github.io/jt-framework/img/pay.png)
7 changes: 6 additions & 1 deletion docs/src/frequently-asked-questions/package-parsing.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,9 @@

## 报文加密解密

暂时不支持
`2.1.4` 开始支持。

报文加解密参考资料:

- [消息加密](../v2/jt-808/guide/customization/msg-encryption.md)
- [issues-82](https://github.com/hylexus/jt-framework/issues/82)
104 changes: 104 additions & 0 deletions docs/src/v2/jt-808/guide/customization/msg-encryption.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
---
icon: lock
---

# 消息加密(v2.1.4)

## 相关资料

- [#issues-82](https://github.com/hylexus/jt-framework/issues/82)

## 加密方式的判断

收到消息,解析之后,消息体**可能**是密文。具体通过消息头中的消息体属性字段判断。

消息体属性格式如下:

- v2011/v2013

```
消息体属性 word(16)
bit[0-10) 消息体长度
bit[10-13) 数据加密方式
此三位都为 0,表示消息体不加密
第 10 位为 1,表示消息体经过 RSA 算法加密
其它保留
bit[13] 分包
1: 消息体卫长消息,进行分包发送处理,具体分包信息由消息包封装项决定
0: 则消息头中无消息包封装项字段
bit[14-15] 保留
```

- v2019

```
消息体属性 word(16)
bit[0-10) 消息体长度
bit[10-13) 数据加密方式
此三位都为 0,表示消息体不加密
第 10 位为 1,表示消息体经过 RSA 算法加密
其它保留
bit[13] 分包
1: 消息体卫长消息,进行分包发送处理,具体分包信息由消息包封装项决定
0: 则消息头中无消息包封装项字段
bit[14] 版本标识
bit[15] 保留
```

尽管消息体属性有所不同,但是其中的 `数据加密方式位` 都是相同的:消息体属性中的 `bit10`, `bit11``bit12` 三个位。

这三个二进制位具体含义,应该和具体的硬件实现相关。

## 加密/解密报文

可以通过自定义 `Jt808MsgEncryptionHandler` 实现报文的加密/解密。也就是给 **spring** 容器中加入一个 `Jt808MsgEncryptionHandler` 实现类即可。

```java

@Component
public class Jt808MsgEncryptionHandlerDemo01 implements Jt808MsgEncryptionHandler {

@Override
public ByteBuf decryptRequestBody(Jt808RequestHeader header, ByteBuf body) {
final int encryptionType = header.msgBodyProps().encryptionType();
if (encryptionType == 0) {
return body;
}
// @see https://github.com/hylexus/jt-framework/issues/82
// 消息属性中的 第10位,11位,12位 为 010 时,表示消息体经过SM4算法加密
if (encryptionType == 0b010) {
try {
return JtCryptoUtil.SM4.ecbDecrypt(getSecretKey(), body);
} finally {
JtProtocolUtils.release(body);
}
}
throw new NotImplementedException("不支持的加密类型: 0b" + FormatUtils.toBinaryString(encryptionType, 3));
}

@Override
public ByteBuf encryptResponseBody(Jt808Response response, ByteBuf plaintextBody) {
// response.encryptionType(010);
final int encryptionType = response.encryptionType();
if (encryptionType == 0) {
return plaintextBody;
}

// @see https://github.com/hylexus/jt-framework/issues/82
// 消息属性中的 第10位,11位,12位 为 010 时,表示消息体经过SM4算法加密
if (encryptionType == 0b010) {
try {
return JtCryptoUtil.SM4.ecbEncrypt(getSecretKey(), plaintextBody);
} finally {
JtProtocolUtils.release(plaintextBody);
}
}
throw new NotImplementedException("不支持的加密类型: 0b" + FormatUtils.toBinaryString(encryptionType, 3));
}

private byte[] getSecretKey() {
// 从其他配置中获取密钥
return HexStringUtils.hexString2Bytes("8e47374be6b8d114cb47be6a9a128a37");
}
}
```
8 changes: 4 additions & 4 deletions docs/src/v2/jt-808/guide/quick-start/quick-start.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,14 @@ icon: launch
<dependency>
<groupId>io.github.hylexus.jt</groupId>
<artifactId>jt-808-server-spring-boot-starter-boot2</artifactId>
<version>2.1.4-rc.3</version>
<version>2.1.4</version>
</dependency>
```

@tab:active gradle

```groovy
implementation 'io.github.hylexus.jt:jt-808-server-spring-boot-starter-boot2:2.1.4-rc.3'
implementation 'io.github.hylexus.jt:jt-808-server-spring-boot-starter-boot2:2.1.4'
```

:::
Expand All @@ -62,14 +62,14 @@ implementation 'io.github.hylexus.jt:jt-808-server-spring-boot-starter-boot2:2.1
<dependency>
<groupId>io.github.hylexus.jt</groupId>
<artifactId>jt-808-server-spring-boot-starter</artifactId>
<version>2.1.4-rc.3</version>
<version>2.1.4</version>
</dependency>
```

@tab:active gradle

```groovy
implementation 'io.github.hylexus.jt:jt-808-server-spring-boot-starter:2.1.4-rc.3'
implementation 'io.github.hylexus.jt:jt-808-server-spring-boot-starter:2.1.4'
```

:::
Expand Down
Loading

0 comments on commit 5f749f2

Please sign in to comment.