PKI/HSM

์˜คํ”ˆ์†Œ์Šค SoftHSM ์‚ฌ์šฉ๋ฒ• ( Windows ํ™˜๊ฒฝ )

JayKim๐Ÿ™‚ 2023. 5. 12. 10:16

SoftHSM์€ PKCS#11 ๊ธฐ๋Šฅ์„ ์†Œํ”„ํŠธ์›จ์–ด๋กœ ๊ตฌํ˜„ํ•œ ์˜คํ”ˆ์†Œ์Šค ํ”„๋กœ๊ทธ๋žจ์ด๋‹ค.

์ผ๋ฐ˜์ ์œผ๋กœ๋Š” HSM์€ ํ•˜๋“œ์›จ์–ด ์žฅ์น˜ ์ด๊ตฌ ์ด๊ฒƒ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด PKCS#11 API๋ฅผ ์ œ๊ณตํ•œ๋‹ค.
๊ทธ๋ž˜์„œ ํ•ด๋‹น ํ•˜๋“œ์›จ์–ด ์žฅ์น˜๊ฐ€ ํ•„์š”ํ•˜๋‹ค.
ํ•˜์ง€๋งŒ SoftHSM์€ ๋ณ„๋„์˜ ํ•˜๋“œ์›จ์–ด ์—†์ด ์†Œํ”„ํŠธ์›จ์–ด๋งŒ์œผ๋กœ ๊ตฌํ˜„๋˜์–ด์„œ ์‰ฝ๊ฒŒ PKCS#11 ์„ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋‹ค.

๋ฌผ๋ก  ๋ณ„๋„์˜ ํ•˜๋“œ์›จ์–ด๋กœ ์ œ๊ณตํ•˜์ง€ ์•Š์œผ๋ฏ€๋กœ ์•ˆ์ „์„ฑ์— ๋Œ€ํ•ด์„œ๋Š” ์•ฝํ•˜์ง€๋งŒ ํ”„๋กœ๊ทธ๋žจ ๊ฐœ๋ฐœ์—์„œ๋Š” ์•„์ฃผ ์œ ์šฉํ•˜๋‹ค.
https://www.opendnssec.org/softhsm/ ์—ฌ๊ธฐ์„œ ๊ด€๋ จ ์†Œํ”„ํŠธ์›จ์–ด์— ๋Œ€ํ•œ ์ •๋ณด๋ฅผ ์–ป์„ ์ˆ˜ ์žˆ๋‹ค.

๊ทธ๋Ÿผ ์œˆ๋„์šฐ ํ™˜๊ฒฝ์—์„œ ์„ค์น˜ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด์„œ ์•Œ์•„๋ณด์ž

์œˆ๋„์šฐ ์„ค์น˜ ํŒŒ์ผ ์œ„์น˜
https://sourceforge.net/projects/softhsm4windows/
๋จผ์ € ์„ค์น˜ ํŒŒ์ผ์„ ๊ฐ€์ง€๊ณ  ์„ค์น˜ ํ•ด ์ฃผ์–ด์•ผ ํ•œ๋‹ค.

SoftHSM ํ™˜๊ฒฝ ์„ค์ •

๋จผ์ € SoftHSM ์„ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด์„œ๋Š” ์„ค์ • ํŒŒ์ผ ๊ฒฝ๋กœ๋ฅผ ๊ทธ๋ฆผ ์ฒ˜๋Ÿผ ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์žก์•„์ฃผ์–ด์•ผ ํ•œ๋‹ค.

์ฐธ๊ณ ๋กœ ์„ค์น˜ ๊ฒฝ๋กœ softhsm2.conf ํŒŒ์ผ์€ ๋‹ค์Œ ์ฒ˜๋Ÿผ ๊ธฐ๋ก ๋œ๋‹ค.
์—ฌ๊ธฐ์„œ๋Š” D:\SoftHSM2 ๊ฒฝ๋กœ์— ์„ค์น˜ ํ•˜์˜€๋‹ค.

# SoftHSM v2 configuration file
directories.tokendir = D:\SoftHSM2\var\softhsm2\tokens\
objectstore.backend = file
log.level = INFO
slots.removable = false
  • direcories.tokendir : ๊ด€๋ จ ๋ฐ์ดํƒ€๊ฐ€ ์ €์žฅ ๋˜๋Š” ์œ„์น˜
    ์ฒ˜์Œ ์„ค์น˜ ํ•˜๋ฉด tokendir ํด๋”์— ๋ฐ์ดํƒ€๊ฐ€ ์—†๋‹ค.
    ๋งŒ์•ฝ ๋‹ค์‹œ ์„ค์น˜ ํ•˜๊ฑฐ๋‚˜ ํ• ๋•Œ ์ด ํด๋”๋ฅผ ๋ฐฑ์—…ํ•ด์„œ ๋‹ค์‹œ ๋ณต์‚ฌํ•ด์ฃผ๋ฉด ๊ธฐ์กด ๋ฐ์ดํƒ€๋ฅผ ์‚ฌ์šฉ ๊ฐ€๋Šฅ ํ•˜๋‹ค.

SoftHSM ์ฒ˜์Œ ์ƒํƒœ ํ™•์ธ

softhsm2-util.exe --show-slots

Available slots:
Slot 0
    Slot info:
        Description:      SoftHSM slot ID 0x0
        Manufacturer ID:  SoftHSM project
        Hardware version: 2.5
        Firmware version: 2.5
        Token present:    yes
    Token info:
        Manufacturer ID:  SoftHSM project
        Model:            SoftHSM v2
        Hardware version: 2.5
        Firmware version: 2.5
        Serial number:
        Initialized:      no
        User PIN init.:   no
        Label:

์ด๋ ‡๊ฒŒ ์ดˆ๊ธฐํ™”๊ฐ€ ์—†๋Š” ์ƒํƒœ๋กœ ๋‚˜์˜จ๋‹ค.

SoftHSM ์ดˆ๊ธฐํ™”

softhsm2-util.exe --init-token --slot 0 --label "jykim74 token"

๋ช…๋ น์–ด๋กœ ์ดˆ๊ธฐํ™” ํ™”๋ฉด

=== SO PIN (4-255 characters) ===
Please enter SO PIN: ****
Please reenter SO PIN: ****
=== User PIN (4-255 characters) ===
Please enter user PIN: ****
Please reenter user PIN: ****
The token has been initialized and is reassigned to slot 1804819021

SO๋ž‘ User ์— PIN ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•œ๋‹ค. ( ์ด PIN ๋ฒˆํ˜ธ๋Š” ๋กœ๊ทธ์ธ์— ์‚ฌ์šฉ ๋˜๋‹ˆ ๊ธฐ์–ต ํ•ด ๋‘์–ด์•ผ ํ•œ๋‹ค )
์ฐธ๊ณ ๋กœ SO ๋Š” User PIN ์„ค์ •๋“ฑ ๊ด€๋ฆฌ์ž ๊ณ„์ •์œผ๋กœ ๋ณด๋ฉด ๋˜๊ณ  User๋Š” ์ผ๋ฐ˜ HSM์„ ์‚ฌ์šฉํ•˜๋Š” ์‚ฌ์šฉ์ž ์ด๋‹ค.

์ด๋ ‡๊ฒŒ ์ดˆ๊ธฐํ™”๋ฅผ ํ•˜๊ณ  ์ƒํƒœ ํ™•์ธ์„ ํ•ด๋ณด์ž

softhsm2-util.exe --show-slots
Available slots:
Slot 1804819021
    Slot info:
        Description:      SoftHSM slot ID 0x6b935a4d
        Manufacturer ID:  SoftHSM project
        Hardware version: 2.5
        Firmware version: 2.5
        Token present:    yes
    Token info:
        Manufacturer ID:  SoftHSM project
        Model:            SoftHSM v2
        Hardware version: 2.5
        Firmware version: 2.5
        Serial number:    b70e9af7eb935a4d
        Initialized:      yes
        User PIN init.:   yes
        Label:            jykim74 token
Slot 1
    Slot info:
        Description:      SoftHSM slot ID 0x1
        Manufacturer ID:  SoftHSM project
        Hardware version: 2.5
        Firmware version: 2.5
        Token present:    yes
    Token info:
        Manufacturer ID:  SoftHSM project
        Model:            SoftHSM v2
        Hardware version: 2.5
        Firmware version: 2.5
        Serial number:
        Initialized:      no
        User PIN init.:   no
        Label:

์ด๋ ‡๊ฒŒ Slot 0 ๋ฒˆ์— ์ดˆ๊ธฐํ™” ๋ฐ PIN ์„ค์ •์ด ๋œ๊ฑธ๋ฃจ ๋‚˜์˜จ๋‹ค.
ํ˜„์žฌ SoftHSM2 ๊ฒฝ์šฐ slot์„ ์ดˆ๊ธฐํ™” ํ•˜๊ณ  ๋‚˜๋ฉด ์ถ”๊ฐ€๋กœ ํ•  ์ˆ˜ ์žˆ๋„๋ก ์ž๋™์œผ๋กœ slot ์ด ์ƒˆ๋กœ ์ถ”๊ฐ€ ๋œ๋‹ค.(์ด๊ฑด SoftHSM2 ์˜ ํŠน์„ฑ์ด๋‹ค)

slot 1๋ฒˆ๋„ ์ดˆ๊ธฐํ™”๋ฅผ ํ•˜๋ ค๋ฉด --slot 0 ์„ --slot 1 ๋กœ ๋ฐ”๊พธ์–ด์„œ ์„ค์ • ํ•˜๋ฉด slot 1 ๋„ ์‚ฌ์šฉ ํ•  ์ˆ˜ ์žˆ๋‹ค.
slot ์˜ ๊ฒฝ์šฐ ๋…๋ฆฝ๋œ ์˜์—ญ์œผ๋กœ ๋ถ„๋ฆฌ ๋˜์–ด ์žˆ๋Š” ๋…ผ๋ฆฌ์  ๊ฐœ๋…์œผ๋กœ ๋ณด๋ฉด ๋œ๋‹ค.

Linux ํ™˜๊ฒฝ ์„ค์ •

ํ™˜๊ฒฝ ๋ณ€์ˆ˜๋กœ
export SOFTHSM2_CONF="$HOME/SoftHSM2/softhsm2.conf"
์„ค์ • ํ•˜๊ณ  softhsm2.conf ๋ฅผ ์•„๋ž˜ ์ฒ˜๋Ÿผ ์žก์•˜๋‹ค.

# SoftHSM v2 configuration file
directories.tokendir = /home/jykim/SoftHSM2/tokens
objectstore.backend = file
log.level = INFO
slots.removable = false

์ด๋•Œ /home/jykim/SoftHSM2/tokens ํด๋”๋ฅผ ์ƒ์„ฑ ํ•ด ๋†“์•„์•ผ ํ•œ๋‹ค.

SoftHSM ์‚ฌ์šฉ

์ด๋ ‡๊ฒŒ ์ดˆ๊ธฐํ™”๋ฅผ ํ•˜๊ณ  ๋‚˜๋ฉด ๋™์  ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ํ˜ธ์ถœํ•ด์„œ PKCS#11 API์— ์ •์˜ ๋œ ํ•จ์ˆ˜๋ฅผ ์ด์šฉํ•ด์„œ ์‚ฌ์šฉํ•˜๋ฉด ๋œ๋‹ค.
์„ค์น˜ ํด๋”์˜ lib ์— ๋ณด๋ฉด 32 ๋น„ํŠธ์™€ 64 ๋น„ํŠธ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๊ฐ€ ์žˆ๋‹ค.

  • softhsm2.dll : 32bit crytoki library
  • softhsm2-x64.dll : 64bit cryptoki library

์‹คํ–‰ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ softhsm2 dll ์„ ๋™์  ํ˜ธ์ถœ ํ•ด์„œ ์‚ฌ์šฉ ํ•˜๋ฉด ๋œ๋‹ค.
CryptokiMan ์„ ์ด์šฉํ•ด PKCS#11 API๋ฅผ ์ด์šฉํ•œ ๋ชจ์Šต์ด๋‹ค.

์ด ํ™”๋ฉด์—์„œ๋Š” softhsm2-x64.dll ์„ ๋กœ๋“œ ํ•˜์—ฌ์„œ C_Initialize ํ•œ์ˆ˜ C_GetTokenInfo ํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜์—ฌ ๋ณด์—ฌ์ฃผ๋Š” ํ™”๋ฉด์ด๋‹ค.

์‚ฌ์‹ค SoftHSM ์—์„œ๋Š” ์ดˆ๊ธฐํ™” ๊ธฐ๋Šฅ์„ softhsm2-util ๋ช…๋ น์–ด๋ฅผ ์ œ๊ณตํ•˜์ง€๋งŒ
PKCS#11 API๋ฅผ ์ด์šฉํ•ด์„œ ์ดˆ๊ธฐํ™”๋„ ๊ฐ€๋Šฅํ•˜๋‹ค.
๋‹ค์Œ์— CryptokiMan ์„ ์‚ฌ์šฉ ํ•ด PKCS#11 API๋ฅผ ํ†ตํ•ด์„œ ์ดˆ๊ธฐํ™” ํ•˜๋Š” ๋ฒ•์„ ๋ณ„๋„๋กœ ๋‹ค๋ฃจ์–ด ๋ณด๊ฒ ๋‹ค.

๋ฐ˜์‘ํ˜•