boho 1.1.1 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,76 +1,113 @@
1
- [ en | [kr](./docs/README-kr.md) ]
2
1
 
3
2
  # Boho
4
3
 
5
- **Secure Lightweight Encryption & Authentication Library for Node.js, Browsers, and Arduino**
4
+ **Node.js, 브라우저, Arduino를 위한 안전하고 가벼운 암호화 및 인증 라이브러리**
6
5
 
7
- Boho is a lightweight JavaScript library for robust encryption, authentication, and secure communication. Designed for Node.js, browsers, and embedded systems (such as Arduino), Boho provides simple APIs for random value generation, SHA256 hashing, HMAC, and secure message packing. It is ideal for IoT, embedded, and web applications that require strong security with minimal overhead.
6
+ Boho는 강력한 암호화, 인증 및 보안 통신을 위한 경량 JavaScript 라이브러리입니다. Node.js, 브라우저, 그리고 Arduino와 같은 임베디드 시스템을 위해 설계되었으며, 최소한의 오버헤드로 강력한 보안이 필요한 IoT, 임베디드 및 웹 애플리케이션에 이상적입니다.
8
7
 
9
- - `boho` means Protection
8
+ - `boho`는 **보호**를 의미합니다.
10
9
 
11
10
  ---
12
11
 
13
- ## Features
14
- - General-purpose encryption and decryption
15
- - Mutual authentication protocol (see below)
16
- - Secure communication after authentication
17
- - End-to-End symmetric encryption
18
- - TypeScript type definitions included
19
- - Supports JavaScript (Node.js, Browser) and C/C++ (Arduino)
12
+ ## 주요 기능
13
+ - 범용 암호화 및 복호화
14
+ - 상호 인증 프로토콜 (아래 참조)
15
+ - 인증 후 보안 통신
16
+ - 종단간(End-to-End) 대칭 암호화
17
+ - TypeScript 타입 정의 포함
18
+ - JavaScript (Node.js, 브라우저) 및 C/C++ (Arduino) 지원
20
19
 
21
20
  ---
22
21
 
23
- ## Libraries
24
- - **JavaScript:** Node.js, Web Browser ([GitHub](https://github.com/remocons/boho))
22
+ ## 라이브러리
25
23
  - **C/C++:** Arduino ([GitHub](https://github.com/remocons/boho-arduino))
26
24
 
27
25
  ---
28
26
 
29
- ## Typical Applications
30
- - WebSocket authentication and secure messaging
31
- - Secure TCP/Serial/Stream communication
32
- - Secure MQTT payloads
33
- - Local file encryption
27
+ ## 대표적인 사용 사례
28
+ - WebSocket 인증 및 보안 메시징
29
+ - 보안 TCP/직렬/스트림 통신
30
+ - 보안 MQTT 페이로드
31
+ - 로컬 파일 암호화
34
32
 
35
33
  ---
36
34
 
37
- ## Core Concepts
38
- - **SHA256** for hashing
39
- - **xotp**: XOR-based one-time pad
40
- - **generateOTP**: OTP generation
41
- - **generateHMAC**: HMAC for authentication
35
+ ## 주요 API
36
+ - `encryptPack`, `decryptPack`: 범용 암호화/복호화
37
+ - `encrypt_488`, `decrypt_488`: 인증 후 보안 통신
38
+ - `encrypt_e2e`, `decrypt_e2e`: 종단간 암호화
39
+ - `RAND(size)`: 안전한 랜덤 버퍼 생성
40
+ - `sha256.hash`, `sha256.hex`, `sha256.base64`, `sha256.hmac`: 해싱 유틸리티
42
41
 
43
42
  ---
44
43
 
45
- ## Main APIs
46
- - `encryptPack`, `decryptPack`: General-purpose encryption/decryption
47
- - `encrypt_488`, `decrypt_488`: Secure communication after authentication
48
- - `encrypt_e2e`, `decrypt_e2e`: End-to-end encryption
49
- - `RAND(size)`: Secure random buffer generation
50
- - `sha256.hash`, `sha256.hex`, `sha256.base64`, `sha256.hmac`: Hashing utilities
44
+ ## 인증 프로토콜 (요약)
45
+
46
+ boho 라이브러리의 서버-클라이언트 인증(AUTH) 프로세스는 다음과 같은 단계로 이루어집니다.
51
47
 
52
48
  ---
53
49
 
54
- ## Authentication Protocol (Summary)
55
- Boho uses a mutual authentication protocol based on random nonces and HMAC:
50
+ ### 1. 서버 → 클라이언트: SERVER_TIME_NONCE
51
+ - 서버는 현재 시각(초/밀리초)과 랜덤 nonce를 포함한 `SERVER_TIME_NONCE` 메시지를 클라이언트에 보냅니다.
52
+ - 메시지 타입: `BohoMsg.SERVER_TIME_NONCE`
53
+ - 내용: unixTime, milTime, nonce
54
+
55
+ ### 2. 클라이언트 → 서버: AUTH_REQ
56
+ - 클라이언트는 서버로부터 받은 nonce와 시각 정보를 바탕으로 salt12를 생성하고, 자신의 랜덤 nonce를 새로 만듭니다.
57
+ - salt12와 자신의 nonce를 합쳐 HMAC을 생성한 뒤, `AUTH_REQ` 메시지로 서버에 전송합니다.
58
+ - 메시지 타입: `BohoMsg.AUTH_REQ`
59
+ - 내용: id8, clientNonce, hmac32
60
+
61
+ ### 3. 서버: AUTH_REQ 검증 및 응답
62
+ - 서버는 클라이언트의 HMAC이 올바른지 검증합니다.
63
+ - 검증 성공 시, 서버는 자신의 HMAC을 생성하여 `AUTH_RES` 메시지로 클라이언트에 응답합니다.
64
+ - 실패 시, `AUTH_FAIL` 메시지를 보낼 수 있습니다.
56
65
 
57
- 1. **AUTH_REQ**: Client initiates authentication
58
- 2. **AUTH_NONCE**: Server responds with time and random nonce
59
- 3. **AUTH_HMAC**: Client sends HMAC using server's nonce and its own
60
- 4. **AUTH_ACK**: Server verifies and responds with its own HMAC
61
- 5. **AUTH_FAIL**: Sent by server if authentication fails
66
+ ### 4. 클라이언트: AUTH_RES 검증
67
+ - 클라이언트는 서버의 `AUTH_RES` 메시지에 포함된 HMAC이 올바른지 검증합니다.
68
+ - 검증이 성공하면, 양쪽 모두 `isAuthorized = true` 상태가 되어 이후 암호화 통신이 가능합니다.
69
+
70
+ ---
62
71
 
63
- See [`AUTH_PROCESS.md`](./docs/AUTH_PROCESS.md) for a detailed protocol description.
72
+ ### 메시지 플로우 요약
64
73
 
65
- ### Authentication Message Flow Diagram
74
+ ```mermaid
75
+ sequenceDiagram
76
+ participant Client
77
+ participant Server
78
+
79
+ Server->>Client: SERVER_TIME_NONCE (unixTime, milTime, nonce)
80
+ Client->>Server: AUTH_REQ (id8, clientNonce, hmac32)
81
+ Server->>Client: AUTH_RES (hmac32) / AUTH_FAIL
82
+ Client->>Client: AUTH_RES verification
83
+ ```
84
+
85
+ ---
86
+
87
+ ### 각 단계의 목적
88
+
89
+ - **SERVER_TIME_NONCE**: 서버가 시간/nonce를 제공하여 리플레이 공격 방지
90
+ - **AUTH_REQ**: 클라이언트가 서버의 정보를 바탕으로 HMAC 생성(서버가 검증)
91
+ - **AUTH_RES**: 서버가 클라이언트의 인증 성공을 알리고, 클라이언트는 서버의 HMAC 검증 상호 인증
92
+ - **AUTH_FAIL**: 인증 실패 시 서버가 전송
93
+
94
+ ---
95
+
96
+ ### 특징 및 보안성
97
+
98
+ - 서버와 클라이언트 모두 랜덤 nonce와 시각 정보를 사용하여, 리플레이 공격에 강함
99
+ - HMAC 기반 상호 인증으로, 키를 노출하지 않고 인증 가능
100
+ - 인증이 완료되어야만 이후 암호화 통신(ENC_488, ENC_PACK, E2E )이 가능
101
+
102
+ ---
66
103
 
67
- ![Boho Auth Message Flow](./docs/auth_process_flow.svg)
104
+ boho의 인증 프로토콜은 서버와 클라이언트가 nonce와 시각 정보를 교환하고, HMAC을 통해 상호 인증하는 구조입니다. 이 과정을 통해 안전하게 세션을 설정하고, 이후 암호화된 데이터 통신이 가능합니다.
68
105
 
69
106
  ---
70
107
 
71
- ## Example Usage
108
+ ## 사용 예제
72
109
 
73
- ### general data encryption & decryption
110
+ ### 일반 데이터 암호화 및 복호화
74
111
  ```js
75
112
  import Boho from 'boho'
76
113
 
@@ -93,21 +130,22 @@ import Boho from 'boho'
93
130
 
94
131
  function printMessage(data){
95
132
  let dataStr = new TextDecoder().decode( data )
96
- console.log('\n result string:',dataStr)
133
+ console.log('
134
+ result string:',dataStr)
97
135
  }
98
136
 
99
137
  ```
100
138
 
101
- ### For examples of authentication and secure communication using Boho, please refer to `IOSignal`.
102
- - `iosignal` ([GitHub](https://github.com/remocons/iosignal))
139
+ ### Boho를 사용한 인증 및 보안 통신 예제는 `IOSignal`을 참고하세요.
140
+ - `iosignal` ([GitHub](https://github.com/remocons/iosignal/packages/iosignal))
103
141
  - test/AUTH_process.js
104
142
 
105
143
  ---
106
144
 
107
- ## TypeScript Support
108
- Boho provides full TypeScript type definitions. Simply install and import to get autocompletion and type checking in your TypeScript projects.
145
+ ## TypeScript 지원
146
+ Boho는 완전한 TypeScript 타입 정의를 제공합니다. 간단히 설치하고 가져오기만 하면 TypeScript 프로젝트에서 자동 완성 및 타입 검사를 받을 수 있습니다.
109
147
 
110
148
  ---
111
149
 
112
- ## License
150
+ ## 라이선스
113
151
  MIT
package/dist/boho.d.ts CHANGED
@@ -1,37 +1,32 @@
1
1
  // TypeScript type definitions for boho
2
+ // Project: https://github.com/remocons/boho
3
+ // Definitions by: Taeo Lee (sixgen@gmail.com)
4
+
2
5
  import { Buffer } from 'buffer';
6
+ import MBP from 'meta-buffer-pack';
3
7
 
4
8
  export function RAND(size: number): Buffer;
5
9
 
10
+ // Interfaces based on src/constants.js and usage in boho.js
6
11
  export interface BohoMsgType {
12
+ SERVER_TIME_NONCE: number;
7
13
  AUTH_REQ: number;
8
- AUTH_NONCE: number;
9
- AUTH_HMAC: number;
10
- AUTH_ACK: number;
11
- AUTH_FAIL: number;
12
- AUTH_EXT: number;
14
+ AUTH_RES: number;
13
15
  ENC_PACK: number;
14
- ENC_E2E: number;
15
16
  ENC_488: number;
16
17
  [key: string]: number | string;
17
18
  }
18
19
 
19
20
  export interface MetaType {
21
+ SERVER_TIME_NONCE: any;
20
22
  AUTH_REQ: any;
21
- AUTH_NONCE: any;
22
- AUTH_HMAC: any;
23
- AUTH_ACK: any;
23
+ AUTH_RES: any;
24
24
  ENC_PACK: any;
25
25
  ENC_488: any;
26
26
  }
27
27
 
28
28
  export interface MetaSizeType {
29
- AUTH_REQ: number;
30
- AUTH_NONCE: number;
31
- AUTH_HMAC: number;
32
- AUTH_ACK: number;
33
29
  ENC_PACK: number;
34
- ENC_488: number;
35
30
  }
36
31
 
37
32
  export interface Sha256 {
@@ -42,59 +37,187 @@ export interface Sha256 {
42
37
  }
43
38
 
44
39
  export class Boho {
45
- _id8: Buffer;
46
- _otpSrc44: Buffer;
47
- _otp36: Buffer;
48
- _hmac: Buffer;
40
+ protected _id8: Buffer;
41
+ protected _otpSrc44: Buffer;
42
+ protected _otp36: Buffer;
43
+ protected _hmac: Buffer;
44
+
49
45
  auth_salt12: Buffer;
50
46
  localNonce: Buffer;
51
47
  remoteNonce: Buffer;
52
48
  isAuthorized: boolean;
49
+ counter: number;
53
50
 
54
51
  constructor();
52
+
53
+ /**
54
+ * Initializes authentication state.
55
+ */
55
56
  clearAuth(): void;
57
+
58
+ /**
59
+ * Sets id8 by hashing the input data.
60
+ * @param data
61
+ */
56
62
  set_hash_id8(data: any): void;
63
+
64
+ /**
65
+ * Sets the id8 value.
66
+ * @param data
67
+ */
57
68
  set_id8(data: any): void;
69
+
70
+ /**
71
+ * Sets the key value by hashing and storing in otpSrc44.
72
+ * @param data
73
+ */
58
74
  set_key(data: any): void;
75
+
76
+ /**
77
+ * Splits 'id.key' string and sets id8 and key.
78
+ * @param id_key
79
+ */
59
80
  set_id_key(id_key: string): void;
81
+
82
+ /**
83
+ * Copies id8 value from external buffer.
84
+ * @param data
85
+ */
60
86
  copy_id8(data: Buffer): void;
87
+
88
+ /**
89
+ * Copies key value from external buffer.
90
+ * @param data
91
+ */
61
92
  copy_key(data: Buffer): void;
93
+
94
+ /**
95
+ * Applies sha256 hash n times.
96
+ * @param srcData
97
+ * @param n
98
+ */
62
99
  sha256_n(srcData: any, n: number): Uint8Array;
100
+
101
+ /**
102
+ * Sets random clock value (salt12) in otpSrc44.
103
+ */
63
104
  set_clock_rand(): void;
105
+
106
+ /**
107
+ * Sets otpSrc44 with given nonce and clock value.
108
+ * @param nonce
109
+ */
64
110
  set_clock_nonce(nonce: Buffer): void;
65
- set_salt12(salt12: Buffer): void;
111
+
112
+ /**
113
+ * Sets salt12 value in otpSrc44.
114
+ * @param salt12
115
+ * @param caller - for debug
116
+ */
117
+ set_salt12(salt12: Buffer, caller?: string): void;
118
+
119
+ /**
120
+ * Initializes OTP value.
121
+ */
66
122
  resetOTP(): void;
123
+
124
+ /**
125
+ * Returns OTP value for the given index.
126
+ * @param otpIndex
127
+ */
67
128
  getIndexOTP(otpIndex: number): Uint8Array;
129
+
130
+ /**
131
+ * Generates HMAC value.
132
+ * @param data
133
+ */
68
134
  generateHMAC(data: Buffer): void;
135
+
136
+ /**
137
+ * Returns 8-byte HMAC value.
138
+ * @param data
139
+ */
69
140
  getHMAC8(data: Buffer): Buffer;
141
+
142
+ /**
143
+ * OTP-based XOR encryption/decryption
144
+ * @param data
145
+ * @param otpStartIndex
146
+ * @param shareDataBuffer
147
+ */
70
148
  xotp(data: Buffer, otpStartIndex?: number, shareDataBuffer?: boolean): Buffer;
71
- auth_req(): Buffer;
72
- auth_nonce(): Buffer;
73
- auth_hmac(buffer: Buffer): Buffer | boolean;
74
- check_auth_hmac(data: Buffer | object): boolean;
75
- check_auth_ack_hmac(buffer: Buffer): boolean;
149
+
150
+ // B. AUTH process
151
+
152
+ /**
153
+ * Generates server time and nonce signal
154
+ */
155
+ server_time_nonce(): Buffer;
156
+
157
+ /**
158
+ * Generates AUTH_REQ message
159
+ * @param buffer server's time nonce
160
+ */
161
+ auth_req(buffer: Buffer): Buffer | boolean;
162
+
163
+ /**
164
+ * Verify client's AUTH_REQ.
165
+ * @param data
166
+ * @returns auth_res packet or false
167
+ */
168
+ verify_auth_req(data: Buffer | object): Buffer | false;
169
+
170
+ /**
171
+ * Verifies server's AUTH_RES HMAC.
172
+ * @param buffer
173
+ */
174
+ verify_auth_res(buffer: Buffer): boolean | undefined;
175
+
176
+ // C. Secure Communication
177
+
178
+ /**
179
+ * Generates encrypted 488 packet after authentication
180
+ * @param data
181
+ */
76
182
  encrypt_488(data: Buffer): Buffer | undefined;
183
+
184
+ /**
185
+ * Decrypts 488 packet after authentication
186
+ * @param data
187
+ */
77
188
  decrypt_488(data: Buffer): Buffer | undefined;
189
+
190
+ /**
191
+ * Generates encrypted packet for up to 2^32-1 bytes
192
+ * @param data
193
+ */
78
194
  encryptPack(data: Buffer): Buffer;
79
- decryptPack(data: Buffer): Buffer;
80
- encrypt_e2e(data: Buffer, key: Buffer): Buffer;
81
- decrypt_e2e(data: Buffer, key: Buffer): Buffer;
195
+
196
+ /**
197
+ * Decrypts encrypted packet
198
+ * @param data
199
+ * @returns The decrypted data buffer inside a pack object, or undefined.
200
+ */
201
+ decryptPack(data: Buffer): { data: Buffer, [key: string]: any } | undefined;
202
+
203
+ /**
204
+ * End-to-end encryption
205
+ * @param data
206
+ * @param key
207
+ */
208
+ encrypt_e2e(data: Buffer, key: any): Buffer;
209
+
210
+ /**
211
+ * End-to-end decryption
212
+ * @param data
213
+ * @param key
214
+ */
215
+ decrypt_e2e(data: Buffer, key: any): { data: Buffer, [key: string]: any } | undefined;
82
216
  }
83
217
 
84
218
  export const BohoMsg: BohoMsgType;
85
219
  export const Meta: MetaType;
86
220
  export const MetaSize: MetaSizeType;
87
221
  export const sha256: Sha256;
88
- export const MBP: any;
89
- export { Buffer };
90
-
91
- declare const _default: typeof Boho & {
92
- RAND: typeof RAND;
93
- BohoMsg: typeof BohoMsg;
94
- Meta: typeof Meta;
95
- MetaSize: typeof MetaSize;
96
- sha256: typeof sha256;
97
- MBP: typeof MBP;
98
- Buffer: typeof Buffer;
99
- };
100
- export default _default;
222
+
223
+ export { MBP, Buffer };