← Documents Documentation/security/digsig.rst GitHub 원문 ↗

Linux 6.18.37 · Security

디지털 서명 검증 API

IMA/EVM이 사용하는 디지털 서명 형식, keyid 계산, digsig_verify() 계약과 evm-utils 키링 작업을 설명합니다.

Source pathDocumentation/security/digsig.rst
Source versionLinux v6.18.37
TranslationDUJINLABS 전문 번역 + 해설

요약·해설과 원문, 전문 번역을 서로 분리했습니다. API 이름, symbol, source path는 원문 표기를 사용합니다.

1. 요약·해설

원문의 핵심 논리와 kernel programming 관점의 보충 설명입니다. 아래의 전문 번역과는 별도로 작성했습니다.

요약·해설

digsig.rst:1-101

IMA/EVM이 사용하는 디지털 서명 형식, keyid 계산, digsig_verify() 계약과 evm-utils 키링 작업을 설명합니다.

2. 영어 원문 전체

번역 기준이 된 Linux v6.18.37 원문입니다. 줄 번호는 이 버전의 파일 좌표입니다.

원문 전체 펼치기
1 ==================================
2 Digital Signature Verification API
3 ==================================
4
5 :Author: Dmitry Kasatkin
6 :Date: 06.10.2011
7
8
9 .. CONTENTS
10
11 1. Introduction
12 2. API
13 3. User-space utilities
14
15
16 Introduction
17 ============
18
19 Digital signature verification API provides a method to verify digital signature.
20 Currently digital signatures are used by the IMA/EVM integrity protection subsystem.
21
22 Digital signature verification is implemented using cut-down kernel port of
23 GnuPG multi-precision integers (MPI) library. The kernel port provides
24 memory allocation errors handling, has been refactored according to kernel
25 coding style, and checkpatch.pl reported errors and warnings have been fixed.
26
27 Public key and signature consist of header and MPIs::
28
29 struct pubkey_hdr {
30 uint8_t version; /* key format version */
31 time_t timestamp; /* key made, always 0 for now */
32 uint8_t algo;
33 uint8_t nmpi;
34 char mpi[0];
35 } __packed;
36
37 struct signature_hdr {
38 uint8_t version; /* signature format version */
39 time_t timestamp; /* signature made */
40 uint8_t algo;
41 uint8_t hash;
42 uint8_t keyid[8];
43 uint8_t nmpi;
44 char mpi[0];
45 } __packed;
46
47 keyid equals to SHA1[12-19] over the total key content.
48 Signature header is used as an input to generate a signature.
49 Such approach insures that key or signature header could not be changed.
50 It protects timestamp from been changed and can be used for rollback
51 protection.
52
53 API
54 ===
55
56 API currently includes only 1 function::
57
58 digsig_verify() - digital signature verification with public key
59
60
61 /**
62 * digsig_verify() - digital signature verification with public key
63 * @keyring: keyring to search key in
64 * @sig: digital signature
65 * @sigen: length of the signature
66 * @data: data
67 * @datalen: length of the data
68 * @return: 0 on success, -EINVAL otherwise
69 *
70 * Verifies data integrity against digital signature.
71 * Currently only RSA is supported.
72 * Normally hash of the content is used as a data for this function.
73 *
74 */
75 int digsig_verify(struct key *keyring, const char *sig, int siglen,
76 const char *data, int datalen);
77
78 User-space utilities
79 ====================
80
81 The signing and key management utilities evm-utils provide functionality
82 to generate signatures, to load keys into the kernel keyring.
83 Keys can be in PEM or converted to the kernel format.
84 When the key is added to the kernel keyring, the keyid defines the name
85 of the key: 5D2B05FC633EE3E8 in the example below.
86
87 Here is example output of the keyctl utility::
88
89 $ keyctl show
90 Session Keyring
91 -3 --alswrv 0 0 keyring: _ses
92 603976250 --alswrv 0 -1 \_ keyring: _uid.0
93 817777377 --alswrv 0 0 \_ user: kmk
94 891974900 --alswrv 0 0 \_ encrypted: evm-key
95 170323636 --alswrv 0 0 \_ keyring: _module
96 548221616 --alswrv 0 0 \_ keyring: _ima
97 128198054 --alswrv 0 0 \_ keyring: _evm
98
99 $ keyctl list 128198054
100 1 key in keyring:
101 620789745: --alswrv 0 0 user: 5D2B05FC633EE3E8
102

3. 한국어 전문 번역

영어 원문의 문단 순서와 의미를 유지한 전체 번역입니다. 코드, 함수명, symbol과 URL은 원문 표기를 유지합니다.

문서 정보와 구성

1-15

Dmitry Kasatkin이 2011년 10월 6일 작성한 디지털 서명 검증 API 문서다. 소개, 커널 API, 사용자 공간 유틸리티의 세 부분으로 구성된다.

==================================
Digital Signature Verification API
==================================

:Author: Dmitry Kasatkin
:Date: 06.10.2011


.. CONTENTS

   1. Introduction
   2. API
   3. User-space utilities

IMA/EVM용 디지털 서명 검증

16-26

디지털 서명 검증 API는 데이터에 붙은 디지털 서명을 검증하는 방법을 제공하며 현재 IMA/EVM 무결성 보호 하위 시스템이 사용한다. 구현은 GnuPG 다중 정밀도 정수(MPI) 라이브러리를 커널용으로 축소 이식한 코드를 기반으로 한다.

커널 이식판에는 메모리 할당 오류 처리가 추가됐고 Linux 커널 코딩 스타일에 맞게 리팩터링됐다. `checkpatch.pl`이 보고한 오류와 경고도 수정됐다.

Introduction
============

Digital signature verification API provides a method to verify digital signature.
Currently digital signatures are used by the IMA/EVM integrity protection subsystem.

Digital signature verification is implemented using cut-down kernel port of
GnuPG multi-precision integers (MPI) library. The kernel port provides
memory allocation errors handling, has been refactored according to kernel
coding style, and checkpatch.pl reported errors and warnings have been fixed.

공개 키·서명 헤더와 MPI

27-52

공개 키와 서명은 각각 고정 헤더 뒤에 MPI 배열이 이어지는 packed 형식이다. `struct pubkey_hdr`에는 형식 버전, 현재 항상 0인 생성 시각, 알고리즘, MPI 개수, 가변 MPI 데이터가 들어간다. `struct signature_hdr`에는 서명 형식 버전, 서명 시각, 알고리즘, 해시 종류, 8바이트 `keyid`, MPI 개수와 MPI 데이터가 들어간다.

`keyid`는 전체 키 내용에 대한 SHA-1 결과의 12~19바이트와 같다. 서명 헤더 자체도 서명 생성 입력에 포함된다. 따라서 키 또는 서명 헤더를 사후 변경할 수 없고 timestamp 변조를 막을 수 있으며 rollback 보호에도 활용할 수 있다.

키와 서명 헤더
필드pubkey_hdrsignature_hdr
version키 형식 버전서명 형식 버전
timestamp현재 0서명 생성 시각
algo포함포함
hash없음포함
keyid[8]없음포함
nmpi / mpi포함포함

두 packed 헤더가 공유하거나 추가로 갖는 필드를 비교한다.

서명 헤더 보호
키 전체 내용의 SHA-1 계산SHA1[12-19]를 keyid로 선택서명 헤더를 서명 입력에 포함헤더·timestamp 변경 검출

헤더를 서명 입력에 포함해 메타데이터 변조를 검출한다.

Public key and signature consist of header and MPIs::

        struct pubkey_hdr {
                uint8_t                version;        /* key format version */
                time_t                timestamp;        /* key made, always 0 for now */
                uint8_t                algo;
                uint8_t                nmpi;
                char                mpi[0];
        } __packed;

        struct signature_hdr {
                uint8_t                version;        /* signature format version */
                time_t                timestamp;        /* signature made */
                uint8_t                algo;
                uint8_t                hash;
                uint8_t                keyid[8];
                uint8_t                nmpi;
                char                mpi[0];
        } __packed;

keyid equals to SHA1[12-19] over the total key content.
Signature header is used as an input to generate a signature.
Such approach insures that key or signature header could not be changed.
It protects timestamp from been changed and can be used for rollback
protection.

digsig_verify() API

53-77

현재 API는 공개 키로 디지털 서명을 검증하는 `digsig_verify()` 하나만 제공한다. `keyring`은 키를 검색할 키링, `sig`와 `siglen`은 디지털 서명과 길이, `data`와 `datalen`은 검증할 데이터와 길이다. 성공하면 0, 그 밖의 경우 `-EINVAL`을 반환한다.

이 함수는 디지털 서명과 대조해 데이터 무결성을 검증한다. 현재 지원되는 공개 키 알고리즘은 RSA뿐이며, 일반적으로 파일 내용 자체가 아니라 내용의 해시를 `data`로 전달한다. 원문의 인자 설명에는 `sigen`이라고 적혀 있지만 실제 함수 원형의 인자명은 `siglen`이다.

digsig_verify() 인자
인자의미
keyring공개 키를 찾을 키링
sig / siglen디지털 서명과 길이
data / datalen검증할 데이터와 길이
return성공 0, 실패 -EINVAL

공개 키 검색 범위와 검증 입력을 전달한다.

API
===

API currently includes only 1 function::

        digsig_verify() - digital signature verification with public key


        /**
        * digsig_verify() - digital signature verification with public key
        * @keyring:        keyring to search key in
        * @sig:        digital signature
        * @sigen:        length of the signature
        * @data:        data
        * @datalen:        length of the data
        * @return:        0 on success, -EINVAL otherwise
        *
        * Verifies data integrity against digital signature.
        * Currently only RSA is supported.
        * Normally hash of the content is used as a data for this function.
        *
        */
        int digsig_verify(struct key *keyring, const char *sig, int siglen,
                          const char *data, int datalen);

evm-utils와 keyctl 예제

78-101

서명·키 관리 도구 모음인 `evm-utils`는 서명을 생성하고 키를 커널 키링에 적재하는 기능을 제공한다. 키는 PEM 형식으로 두거나 커널 형식으로 변환할 수 있다. 키가 커널 키링에 추가되면 `keyid`가 키 이름이 되며 원문 예제에서는 `5D2B05FC633EE3E8`이다.

`keyctl show` 예제는 세션 키링 아래의 사용자 키링, `kmk`, 암호화된 `evm-key`, `_module`, `_ima`, `_evm` 키링을 보여 준다. 이어서 `keyctl list 128198054`는 `_evm` 키링에 이름이 `5D2B05FC633EE3E8`인 사용자 키 하나가 있음을 보여 준다. 숫자 ID와 권한 문자열을 포함한 명령 출력은 원문 블록에 그대로 보존한다.

User-space utilities
====================

The signing and key management utilities evm-utils provide functionality
to generate signatures, to load keys into the kernel keyring.
Keys can be in PEM or converted to the kernel format.
When the key is added to the kernel keyring, the keyid defines the name
of the key: 5D2B05FC633EE3E8 in the example below.

Here is example output of the keyctl utility::

        $ keyctl show
        Session Keyring
        -3 --alswrv      0     0  keyring: _ses
        603976250 --alswrv      0    -1   \_ keyring: _uid.0
        817777377 --alswrv      0     0       \_ user: kmk
        891974900 --alswrv      0     0       \_ encrypted: evm-key
        170323636 --alswrv      0     0       \_ keyring: _module
        548221616 --alswrv      0     0       \_ keyring: _ima
        128198054 --alswrv      0     0       \_ keyring: _evm

        $ keyctl list 128198054
        1 key in keyring:
        620789745: --alswrv     0     0 user: 5D2B05FC633EE3E8