signature_data.go 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package pac
  2. import (
  3. "bytes"
  4. "github.com/jcmturner/gokrb5/v8/iana/chksumtype"
  5. "github.com/jcmturner/rpc/v2/mstypes"
  6. )
  7. /*
  8. https://msdn.microsoft.com/en-us/library/cc237955.aspx
  9. The Key Usage Value MUST be KERB_NON_KERB_CKSUM_SALT (17) [MS-KILE] (section 3.1.5.9).
  10. Server Signature (SignatureType = 0x00000006)
  11. https://msdn.microsoft.com/en-us/library/cc237957.aspx
  12. KDC Signature (SignatureType = 0x00000007)
  13. https://msdn.microsoft.com/en-us/library/dd357117.aspx
  14. */
  15. // SignatureData implements https://msdn.microsoft.com/en-us/library/cc237955.aspx
  16. type SignatureData struct {
  17. SignatureType uint32 // A 32-bit unsigned integer value in little-endian format that defines the cryptographic system used to calculate the checksum. This MUST be one of the following checksum types: KERB_CHECKSUM_HMAC_MD5 (signature size = 16), HMAC_SHA1_96_AES128 (signature size = 12), HMAC_SHA1_96_AES256 (signature size = 12).
  18. Signature []byte // Size depends on the type. See comment above.
  19. RODCIdentifier uint16 // A 16-bit unsigned integer value in little-endian format that contains the first 16 bits of the key version number ([MS-KILE] section 3.1.5.8) when the KDC is an RODC. When the KDC is not an RODC, this field does not exist.
  20. }
  21. // Unmarshal bytes into the SignatureData struct
  22. func (k *SignatureData) Unmarshal(b []byte) (rb []byte, err error) {
  23. r := mstypes.NewReader(bytes.NewReader(b))
  24. k.SignatureType, err = r.Uint32()
  25. if err != nil {
  26. return
  27. }
  28. var c int
  29. switch k.SignatureType {
  30. case chksumtype.KERB_CHECKSUM_HMAC_MD5_UNSIGNED:
  31. c = 16
  32. case uint32(chksumtype.HMAC_SHA1_96_AES128):
  33. c = 12
  34. case uint32(chksumtype.HMAC_SHA1_96_AES256):
  35. c = 12
  36. }
  37. k.Signature, err = r.ReadBytes(c)
  38. if err != nil {
  39. return
  40. }
  41. // When the KDC is not an Read Only Domain Controller (RODC), this field does not exist.
  42. if len(b) >= 4+c+2 {
  43. k.RODCIdentifier, err = r.Uint16()
  44. if err != nil {
  45. return
  46. }
  47. }
  48. // Create bytes with zeroed signature needed for checksum verification
  49. rb = make([]byte, len(b), len(b))
  50. copy(rb, b)
  51. z := make([]byte, len(b), len(b))
  52. copy(rb[4:4+c], z)
  53. return
  54. }