RSA private key parser in kernel - joeyli/linux-modsign GitHub Wiki

Description

Currently the crypto/asymmetric_keys in kernel only supports RSA public key parsing but lack RSA private key. Due to we will need generate signature of S4 snapshot, means we need load RSA private key from EFI non-volatile variable to kernel.

  • Understand the logic of RSA public key parser
  • Write RSA private key parser: rsa_private_key.c
  • Write ASN.1 file for RSA private key: rsa_private_key.asn1
  • Load private key from db in UEFI OVMF BIOS for parser testing

People

Joey Lee [email protected] originated this idea.

Status

Idea looking for takers.

I plan to work on this project.

Doesn't have initial code yet, reference crypto/asymmetric_keys and maybe GunPG . Looking for takers or collaborators.

TODO:

  • Read PKCS #1 v2.2: RSA Cryptography Standard: http://www.rsa.com/rsalabs/node.asp?id=2125
  • Write RSA private key parser: rsa_private_key.c
  • Write ASN.1 file for RSA private key: rsa_private_key.asn1
  • Write In-software asymmetric private-key crypto subtype: private_key.c
  • Implement RSASP1 algorithm in rsa.c

Conceptual Model of crypto/asymmetric_keys: Conceptual Model of crypto/asymmetric_keys

Filed SLE11-SP3 bug: Bug 814999 - Could not add a X.509 certificate to keyring by keyctl

Base on PKCS#1, I developed a parser prototype of private key, this prototype can parser the private key DER file. For tesitng, we can use keyctl to add a private to keyring: e.g. keyctl padd asymmetric 1232 @u <signing_key.der

But, the pure private key lack meta information, e.g. IDENTIFIER or ALGORITHM, if we want load and identify a private key, we need also parser PKCS#8 or even PkCS#12 container format. There have another benefit for apply PKCS#8 or PKCS#12, we can embedded encrypted algorithm type in those format, used it to protect private key when shim pass private key to kernel. Setup a password of session is another idea.

[2013-05-08] Commit RSA private key parser patches to github. next: Implement RSASP1 algorithm in rsa.c

[2013-05-16] Implement RSASSA-PKCS1-v1_5-SIGN (K, M) [RFC3447 sec 8.2.1] Need implement:

  • EM = EMS-PKCS1-v1_5-ENCODE (M, k).
  • m = OS2IP (EM).
  • s = RSASP1 (K, m).

[2013-06-14]

  • EM = EMS-PKCS1-v1_5-ENCODE (M, k). [DONE]
  • m = OS2IP (EM).
  • s = RSASP1 (K, m).

[2013-06-20]

  • EM = EMS-PKCS1-v1_5-ENCODE (M, k). [DONE]
  • m = OS2IP (EM). [DONE]
  • s = RSASP1 (K, m). [DONE]

NEXT STEP: Adapt to S4 hibernate/resume

  • add interface of S4 for setting RSA key-pair.
  • generate SHA264 hash of S4 hibernate image.
  • generate signature of hibernate image from hash and attach to end of S4 image.
  • generate SHA264 hash of S4 image when resume.
  • verify signature with hash from resume image, block system resume if not match.

[2013-07-04]

  • generate SHA264 hash of S4 hibernate image. [DONE]
  • generate digest of hibernate image from hash and attach to S4 header. [DONE]
  • generate SHA264 hash of S4 image when resume. [DONE]

NEXT STEP:

Signature generation

  • Add new API for allow caller to pass hash digest.
  • Support PKCS#8.

Adapt to S4 hibernate/resume

  • Add Kernel Config: 1) Turn on S4 signature check 2) force check 3) assign hash algorithm.
  • Load PKCS#8 and X.509 from UEFI runtime variables.
  • Add interface of S4 for setting RSA key-pair.
  • verify signature with hash from resume image, block system resume if not match.
  • Support user space hibernate.
  • Avoid Private Key go to snapshot image.
  • Improve the performance of hibernate resume.

[2013-07-27]

Adapt to S4 hibernate/resume

  • Load PKCS#8 and X.509 from UEFI runtime variables. [DONE]
  • Add interface of S4 for setting RSA key-pair. [WONT]
  • Support user space hibernate. [DONE]
  • Avoid Private Key go to snapshot image. [DONE]
  • Removed S4 key data from EFI variables after loaded to kernel. [DONE]
  • verify signature with hash from resume image, block system resume if not match. [DONE]

NEXT STEP:

Adapt to S4 hibernate/resume

  • Add Kernel Config: 1) Turn on S4 signature check 2) force check 3) assign hash algorithm.

Signature generation

  • move signature generation logic to private key. Other
  • Clear up patches and porting to v3.11 and openSUSE 13.1 kernel.
  • Readme documents.

Improvement

  • Performance
    • Improve the performance of hibernate resume.
      • testing SHA256 SSE instructions improved in v3.10 kernel
    • TPM
  • Security
    • AES encrypt the private key data.
    • TPM

Categories: distribution Tags: RSA,crypto,S4,Hibernate,inprogress

Source Code

https://github.com/joeyli/linux-modsign/tree/devel-privatekey

Related material

Comments

⚠️ **GitHub.com Fallback** ⚠️