성태의 닷넷 이야기
홈 주인
모아 놓은 자료
프로그래밍
질문/답변
사용자 관리
사용자
메뉴
아티클
외부 아티클
유용한 코드
온라인 기능
MathJax 입력기
최근 덧글
[정성태] Linux의 경우 Shell Script에서도 exec 명령어를...
[정성태] 본문의 CheckTokenMembership의 래퍼로 제공하는 ...
[정성태] Build your own Shell ; https://app...
[SuperAnt] 답변 정말 감사합니다. 1,2번내용은 EXE를 띄우는게 아니...
[정성태] 우선, C# DLL에서 VB6 withevents로 받는 것은 ...
[정성태] WinForm DLL에 했던 것을 WinForm EXE 측에 하...
[미디블루] 안녕하세요. WinForm 앱을 만들면서 OCX 등록하지 않고...
[정성태] 4.7.2로 굳이 해야 할 필요가 없다면 .NET 8을 대상으로...
[정성태] Creating dotnet tool and publishing...
[정성태] Why do we have header files <pshpac...
글쓰기
제목
이름
암호
전자우편
HTML
홈페이지
유형
제니퍼 .NET
닷넷
COM 개체 관련
스크립트
VC++
VS.NET IDE
Windows
Team Foundation Server
디버깅 기술
오류 유형
개발 환경 구성
웹
기타
Linux
Java
DDK
Math
Phone
Graphics
사물인터넷
부모글 보이기/감추기
내용
<div style='display: inline'> <h1 style='font-family: Malgun Gothic, Consolas; font-size: 20pt; color: #006699; text-align: center; font-weight: bold'>Linux - 커널 이미지 파일 서명 (Ubuntu 환경)</h1> <p> 직접 빌드한 커널 이미지를,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > Ubuntu 22.04 - 리눅스 커널 빌드 및 업그레이드 ; <a target='tab' href='https://www.sysnet.pe.kr/2/0/13790'>https://www.sysnet.pe.kr/2/0/13790</a> </pre> <br /> (대표적으로) Secure Boot 환경에서 사용하고 싶다면 서명을 해야 합니다. 이에 대해서는 문서가 많이 있으니 쉽게 적용할 수 있는데요,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > How to sign things for Secure Boot ; <a target='tab' href='https://ubuntu.com/blog/how-to-sign-things-for-secure-boot'>https://ubuntu.com/blog/how-to-sign-things-for-secure-boot</a> Chapter 3. Signing a kernel and modules for Secure Boot ; <a target='tab' href='https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/signing-a-kernel-and-modules-for-secure-boot_managing-monitoring-and-updating-the-kernel'>https://docs.redhat.com/en/documentation/red_hat_enterprise_linux/8/html/managing_monitoring_and_updating_the_kernel/signing-a-kernel-and-modules-for-secure-boot_managing-monitoring-and-updating-the-kernel</a> </pre> <br /> 이번 글에서는 위의 내용을 간단하게 정리해 보겠습니다. ^^<br /> <br /> <hr style='width: 50%' /><br /> <br /> 우선, <a target='tab' href='https://www.sysnet.pe.kr/2/0/12570#cnf'>openssl</a>로 커널 서명 용도를 만족하는 키를 생성하기 위해 cnf 파일을 만들고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>cat kernel_key.cnf</span> HOME = . RANDFILE = $ENV::HOME/.rnd [ req ] distinguished_name = req_distinguished_name x509_extensions = v3 string_mask = utf8only prompt = no [ req_distinguished_name ] commonName = Secure Boot Signing Key [ v3 ] subjectKeyIdentifier = hash authorityKeyIdentifier = keyid:always,issuer basicConstraints = critical,CA:FALSE extendedKeyUsage = codeSigning,1.3.6.1.4.1.311.10.3.6 nsComment = "OpenSSL Generated Certificate" </pre> <br /> 이 설정을 반영해 키를 생성합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>openssl req -config ./kernel_key.cnf -new -x509 -newkey rsa:2048 -nodes -days 36500 -outform DER -keyout "kernel_key.priv" -out "kernel_key.der"</span> $ <span style='color: blue; font-weight: bold'>sudo openssl x509 -in kernel_key.der -inform DER -outform PEM -out kernel_key.pem</span> $ <span style='color: blue; font-weight: bold'>ls kernel_*</span> kernel_key.cnf kernel_key.der kernel_key.pem kernel_key.priv </pre> <br /> 그다음, 해당 커널이 로드될 시스템에 위에서 생성한 키의 공개키 파트를 등록합니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > // 암호는 임의로 설정합니다. (나중에 쓸 것이니 기억해 두세요.) $ <span style='color: blue; font-weight: bold'>sudo mokutil --import kernel_key.der</span> input password: input password again: </pre> <br /> 이후 "reboot"을 하면 다음 화면과 같이 잠시 "Shim UEFI key management" 화면이 나타납니다. (이 화면을 보여주는 프로그램의 이름이 "MOKManager" 라는군요. ^^)<br /> <br /> <img width='500px' alt='sign_linux_kernel_1.png' src='/SysWebRes/bbs/sign_linux_kernel_1.png' /><br /> <br /> 그럼 아무 키나 누르면 화면이 넘어가는데요,<br /> <br /> <img width='300px' alt='sign_linux_kernel_2.png' src='/SysWebRes/bbs/sign_linux_kernel_2.png' /><br /> <br /> "Enroll MOK"을 선택하고 Enter를 누르면 다음 메뉴로 넘어가는데 (등록 키의 개수에 따라 다를 수 있는) "View key 0"와 "Continue"에서 "View key 0"를 선택해 Enter를 누릅니다. 그럼, 방금 전에 "mokutil"로 등록한 키에 해당하는 내용이 나올 것입니다. 해당 키가 맞는다면 Enter를 눌러 이전 메뉴로 돌아와 이번엔 "Continue"를 선택, 이어서 "Yes"를 선택합니다.<br /> <br /> 그럼 (역시 위에서 mokutil 실행 시 입력했던) 암호를 묻는 단계가 나오고, 통과하면 "Reboot"을 선택해 재부팅하면 됩니다.<br /> <br /> 이후, 정상적으로 등록됐는지는 이렇게 확인할 수 있습니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>sudo mokutil --list-enrolled</span> [key 1] SHA1 Fingerprint: 76:a0:92:06:58:00:bf:37:69:01:c3:72:cd:55:a9:0e:1f:de:d2:e0 Certificate: Data: Version: 3 (0x2) Serial Number: b9:41:24:a0:18:2c:92:67 Signature Algorithm: sha256WithRSAEncryption Issuer: C=GB, ST=Isle of Man, L=Douglas, O=Canonical Ltd., CN=Canonical Ltd. Master Certificate Authority ...[생략]... [key 2] SHA1 Fingerprint: 06:1d:0c:9f:d6:b5:cb:35:3f:82:ea:c7:ae:15:c2:4a:c1:df:8c:46 Certificate: Data: Version: 3 (0x2) Serial Number: 64:2c:10:08:10:ce:f6:53:77:e3:92:ed:d1:97:1c:45:53:d8:11:aa Signature Algorithm: sha256WithRSAEncryption <span style='color: blue; font-weight: bold'>Issuer: CN=Secure Boot Signing Key</span> ...[생략]... </pre> <br /> <hr style='width: 50%' /><br /> <br /> 자, 이제 마지막으로 빌드된 커널 이미지 파일을 서명해 주면 됩니다. <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>ll /boot/vmlinuz-6.*</span> -rw-r--r-- 1 root root 13382144 Nov 8 05:39 /boot/vmlinuz-6.11.5 -rw------- 1 root root 14952840 Sep 27 12:26 /boot/vmlinuz-6.8.0-48-generic </pre> <br /> 제 경우에 6.8.0-48-generic이 최초 Ubuntu 24.04에 사용된 것이고, 새롭게 6.11.5 버전을 빌드한 것인데요, 이것을 다음과 같은 식으로 서명하시면 됩니다. <br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>sudo sbsign --key kernel_key.priv --cert kernel_key.pem /boot/vmlinuz-6.11.5 --output /boot/vmlinuz-6.11.5.signed</span> Signing Unsigned original image $ <span style='color: blue; font-weight: bold'>ls /boot/vmlinuz-6.*</span> /boot/vmlinuz-6.11.5 /boot/vmlinuz-6.11.5.old <span style='color: blue; font-weight: bold'>/boot/vmlinuz-6.11.5.signed</span> /boot/vmlinuz-6.8.0-48-generic </pre> <br /> 그다음 서명되지 않은 initrd.img-* 파일이 있을 텐데요, (위의 경우 initrd.img-6.11.5) 이것을 위에서 만든 signed 이름 규칙을 따라 또 하나 만들어 줍니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>sudo cp /boot/initrd.img-6.11.5{,.signed}</span> $ <span style='color: blue; font-weight: bold'>ls /boot/initrd.img-6.*</span> /boot/initrd.img-6.11.5 <span style='color: blue; font-weight: bold'>/boot/initrd.img-6.11.5.signed</span> /boot/initrd.img-6.8.0-48-generic </pre> <br /> 끝입니다. 이제 GRUB 설정을 업데이트하고,<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>sudo update-grub</span> Sourcing file `/etc/default/grub' Generating grub configuration file ... Found linux image: <span style='color: blue; font-weight: bold'>/boot/vmlinuz-6.11.5.signed</span> Found initrd image: <span style='color: blue; font-weight: bold'>/boot/initrd.img-6.11.5.signed</span> Found linux image: /boot/vmlinuz-6.11.5 Found initrd image: /boot/initrd.img-6.11.5 Found linux image: /boot/vmlinuz-6.11.5.old Found initrd image: /boot/initrd.img-6.11.5 Found linux image: /boot/vmlinuz-6.8.0-48-generic Found initrd image: /boot/initrd.img-6.8.0-48-generic Warning: os-prober will not be executed to detect other bootable partitions. Systems on them will not be added to the GRUB boot configuration. Check GRUB_DISABLE_OS_PROBER documentation entry. Adding boot menu entry for UEFI Firmware Settings ... done </pre> <br /> 재부팅하면 새로운 버전의 커널이 부팅될 것입니다.<br /> <br /> <pre style='margin: 10px 0px 10px 10px; padding: 10px 0px 10px 10px; background-color: #fbedbb; overflow: auto; font-family: Consolas, Verdana;' > $ <span style='color: blue; font-weight: bold'>uname -r</span> 6.11.5 </pre> </p><br /> <br /> <br /><hr /><span style='color: Maroon'>[이 글에 대해서 여러분들과 의견을 공유하고 싶습니다. 틀리거나 미흡한 부분 또는 의문 사항이 있으시면 언제든 댓글 남겨주십시오.]</span> </div>
첨부파일
스팸 방지용 인증 번호
1440
(왼쪽의 숫자를 입력해야 합니다.)