digsig.txt 2.8 KB

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