Skip to content

Commit

Permalink
fix comments
Browse files Browse the repository at this point in the history
* fix comments
* update to test with 1.14
  • Loading branch information
jcmturner authored Feb 29, 2020
1 parent f1c93a8 commit 1a5195b
Show file tree
Hide file tree
Showing 76 changed files with 95 additions and 1,400 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/testing.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.11.x', '1.12.x', '1.13.x' ]
go: [ '1.12.x', '1.13.x', '1.14.x' ]
env:
TEST_KDC_ADDR: 127.0.0.1
TEST_HTTP_URL: http://cname.test.gokrb5
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/testingv8.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.11.x', '1.12.x', '1.13.x' ]
go: [ '1.12.x', '1.13.x', '1.14.x' ]
env:
TEST_KDC_ADDR: 127.0.0.1
TEST_HTTP_URL: http://cname.test.gokrb5
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ Development will be focused on the latest major version. New features will only


#### Go Version Support
![Go version](https://img.shields.io/badge/Go-1.14-brightgreen.svg)
![Go version](https://img.shields.io/badge/Go-1.13-brightgreen.svg)
![Go version](https://img.shields.io/badge/Go-1.12-brightgreen.svg)
![Go version](https://img.shields.io/badge/Go-1.11-brightgreen.svg)

gokrb5 may work with other versions of Go but they are not tested.

Expand Down
10 changes: 1 addition & 9 deletions client/ASExchange.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,15 +145,7 @@ func setPAData(cl *Client, krberr *messages.KRBError, ASReq *messages.ASReq) err

// preAuthEType establishes what encryption type to use for pre-authentication from the KRBError returned from the KDC.
func preAuthEType(krberr *messages.KRBError) (etype etype.EType, err error) {
//The preferred ordering of the "hint" pre-authentication data that
//affect client key selection is: ETYPE-INFO2, followed by ETYPE-INFO,
//followed by PW-SALT.
//A KDC SHOULD NOT send PA-PW-SALT when issuing a KRB-ERROR message
//that requests additional pre-authentication. Implementation note:
//Some KDC implementations issue an erroneous PA-PW-SALT when issuing a
//KRB-ERROR message that requests additional pre-authentication.
//Therefore, clients SHOULD ignore a PA-PW-SALT accompanying a
//KRB-ERROR message that requests additional pre-authentication.
//RFC 4120 5.2.7.5 covers the preference order of ETYPE-INFO2 and ETYPE-INFO.
var etypeID int32
var pas types.PADataSequence
e := pas.Unmarshal(krberr.EData)
Expand Down
13 changes: 1 addition & 12 deletions client/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,18 +172,7 @@ func (cl *Client) sendUDP(conn *net.UDPConn, b []byte) ([]byte, error) {
func (cl *Client) sendTCP(conn *net.TCPConn, b []byte) ([]byte, error) {
defer conn.Close()
var r []byte
/*
RFC https://tools.ietf.org/html/rfc4120#section-7.2.2
Each request (KRB_KDC_REQ) and response (KRB_KDC_REP or KRB_ERROR)
sent over the TCP stream is preceded by the length of the request as
4 octets in network byte order. The high bit of the length is
reserved for future expansion and MUST currently be set to zero. If
a KDC that does not understand how to interpret a set high bit of the
length encoding receives a request with the high order bit of the
length set, it MUST return a KRB-ERROR message with the error
KRB_ERR_FIELD_TOOLONG and MUST close the TCP stream.
NB: network byte order == big endian
*/
// RFC 4120 7.2.2 specifies the first 4 bytes indicate the length of the message in big endian order.
var buf bytes.Buffer
err := binary.Write(&buf, binary.BigEndian, uint32(len(b)))
if err != nil {
Expand Down
17 changes: 1 addition & 16 deletions credentials/ccache.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,6 @@ const (
headerFieldTagKDCOffset = 1
)

// The first byte of the file always has the value 5.
// The value of the second byte contains the version number (1 through 4)
// Versions 1 and 2 of the file format use native byte order for integer representations.
// Versions 3 and 4 always use big-endian byte order
// After the two-byte version indicator, the file has three parts:
// 1) the header (in version 4 only)
// 2) the default principal name
// 3) a sequence of credentials

// CCache is the file credentials cache as define here: https://web.mit.edu/kerberos/krb5-latest/doc/formats/ccache_file_format.html
type CCache struct {
Version uint8
Expand Down Expand Up @@ -257,13 +248,7 @@ func (c *CCache) GetEntries() []*Credential {
}

func (h *headerField) valid() bool {
// At this time there is only one defined header field.
// Its tag value is 1, its length is always 8.
// Its contents are two 32-bit integers giving the seconds and microseconds
// of the time offset of the KDC relative to the client.
// Adding this offset to the current time on the client should give the current time on the KDC, if that offset has not changed since the initial authentication.

// Done as a switch in case other tag values are added in the future.
// See https://web.mit.edu/kerberos/krb5-latest/doc/formats/ccache_file_format.html - Header format
switch h.tag {
case headerFieldTagKDCOffset:
if h.length != 8 || len(h.value) != 8 {
Expand Down
44 changes: 0 additions & 44 deletions crypto/aes128-cts-hmac-sha1-96.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,6 @@ import (
)

// RFC 3962
//+--------------------------------------------------------------------+
//| protocol key format 128- or 256-bit string |
//| |
//| string-to-key function PBKDF2+DK with variable |
//| iteration count (see |
//| above) |
//| |
//| default string-to-key parameters 00 00 10 00 |
//| |
//| key-generation seed length key size |
//| |
//| random-to-key function identity function |
//| |
//| hash function, H SHA-1 |
//| |
//| HMAC output size, h 12 octets (96 bits) |
//| |
//| message block size, m 1 octet |
//| |
//| encryption/decryption functions, AES in CBC-CTS mode |
//| E and D (cipher block size 16 |
//| octets), with next-to- |
//| last block (last block |
//| if only one) as CBC-style |
//| ivec |
//+--------------------------------------------------------------------+
//
//+--------------------------------------------------------------------+
//| encryption types |
//+--------------------------------------------------------------------+
//| type name etype value key size |
//+--------------------------------------------------------------------+
//| aes128-cts-hmac-sha1-96 17 128 |
//| aes256-cts-hmac-sha1-96 18 256 |
//+--------------------------------------------------------------------+
//
//+--------------------------------------------------------------------+
//| checksum types |
//+--------------------------------------------------------------------+
//| type name sumtype value length |
//+--------------------------------------------------------------------+
//| hmac-sha1-96-aes128 15 96 |
//| hmac-sha1-96-aes256 16 96 |
//+--------------------------------------------------------------------+

// Aes128CtsHmacSha96 implements Kerberos encryption type aes128-cts-hmac-sha1-96
type Aes128CtsHmacSha96 struct {
Expand Down
7 changes: 2 additions & 5 deletions crypto/aes128-cts-hmac-sha256-128.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,8 @@ func (e Aes128CtsHmacSha256128) DeriveRandom(protocolKey, usage []byte) ([]byte,
}

// VerifyIntegrity checks the integrity of the ciphertext message.
// The HMAC is calculated over the cipher state concatenated with the
// AES output, instead of being calculated over the confounder and
// plaintext. This allows the message receiver to verify the
// integrity of the message before decrypting the message.
// Therefore the pt value to this interface method is not use. Pass any []byte.
// As the hash is calculated over the iv concatenated with the AES cipher output not the plaintext the pt value to this
// interface method is not use. Pass any []byte.
func (e Aes128CtsHmacSha256128) VerifyIntegrity(protocolKey, ct, pt []byte, usage uint32) bool {
// We don't need ib just there for the interface
return rfc8009.VerifyIntegrity(protocolKey, ct, usage, e)
Expand Down
44 changes: 0 additions & 44 deletions crypto/aes256-cts-hmac-sha1-96.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,6 @@ import (
)

// RFC 3962
//+--------------------------------------------------------------------+
//| protocol key format 128- or 256-bit string |
//| |
//| string-to-key function PBKDF2+DK with variable |
//| iteration count (see |
//| above) |
//| |
//| default string-to-key parameters 00 00 10 00 |
//| |
//| key-generation seed length key size |
//| |
//| random-to-key function identity function |
//| |
//| hash function, H SHA-1 |
//| |
//| HMAC output size, h 12 octets (96 bits) |
//| |
//| message block size, m 1 octet |
//| |
//| encryption/decryption functions, AES in CBC-CTS mode |
//| E and D (cipher block size 16 |
//| octets), with next-to- |
//| last block (last block |
//| if only one) as CBC-style |
//| ivec |
//+--------------------------------------------------------------------+
//
//+--------------------------------------------------------------------+
//| encryption types |
//+--------------------------------------------------------------------+
//| type name etype value key size |
//+--------------------------------------------------------------------+
//| aes128-cts-hmac-sha1-96 17 128 |
//| aes256-cts-hmac-sha1-96 18 256 |
//+--------------------------------------------------------------------+
//
//+--------------------------------------------------------------------+
//| checksum types |
//+--------------------------------------------------------------------+
//| type name sumtype value length |
//+--------------------------------------------------------------------+
//| hmac-sha1-96-aes128 15 96 |
//| hmac-sha1-96-aes256 16 96 |
//+--------------------------------------------------------------------+

// Aes256CtsHmacSha96 implements Kerberos encryption type aes256-cts-hmac-sha1-96
type Aes256CtsHmacSha96 struct {
Expand Down
7 changes: 2 additions & 5 deletions crypto/aes256-cts-hmac-sha384-192.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,8 @@ func (e Aes256CtsHmacSha384192) DeriveRandom(protocolKey, usage []byte) ([]byte,
}

// VerifyIntegrity checks the integrity of the ciphertext message.
// The HMAC is calculated over the cipher state concatenated with the
// AES output, instead of being calculated over the confounder and
// plaintext. This allows the message receiver to verify the
// integrity of the message before decrypting the message.
// Therefore the pt value to this interface method is not use. Pass any []byte.
// As the hash is calculated over the iv concatenated with the AES cipher output not the plaintext the pt value to this
// interface method is not use. Pass any []byte.
func (e Aes256CtsHmacSha384192) VerifyIntegrity(protocolKey, ct, pt []byte, usage uint32) bool {
// We don't need ib just there for the interface
return rfc8009.VerifyIntegrity(protocolKey, ct, usage, e)
Expand Down
19 changes: 4 additions & 15 deletions crypto/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,39 +92,28 @@ func GetIntegrityHash(b, key []byte, usage uint32, etype etype.EType) ([]byte, e

// VerifyChecksum compares the checksum of the msg bytes is the same as the checksum provided.
func VerifyChecksum(key, chksum, msg []byte, usage uint32, etype etype.EType) bool {
//The ciphertext output is the concatenation of the output of the basic
//encryption function E and a (possibly truncated) HMAC using the
//specified hash function H, both applied to the plaintext with a
//random confounder prefix and sufficient padding to bring it to a
//multiple of the message block size. When the HMAC is computed, the
//key is used in the protocol key form.
//The encrypted message is a concatenation of the encrypted output and the hash HMAC.
expectedMAC, _ := GetChecksumHash(msg, key, usage, etype)
return hmac.Equal(chksum, expectedMAC)
}

// GetUsageKc returns the checksum key usage value for the usage number un.
//
// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
//
// Kc = DK(base-key, usage | 0x99);
// See RFC 3961 5.3 key-derivation function definition.
func GetUsageKc(un uint32) []byte {
return getUsage(un, 0x99)
}

// GetUsageKe returns the encryption key usage value for the usage number un
//
// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
//
// Ke = DK(base-key, usage | 0xAA);
// See RFC 3961 5.3 key-derivation function definition.
func GetUsageKe(un uint32) []byte {
return getUsage(un, 0xAA)
}

// GetUsageKi returns the integrity key usage value for the usage number un
//
// RFC 3961: The "well-known constant" used for the DK function is the key usage number, expressed as four octets in big-endian order, followed by one octet indicated below.
//
// Ki = DK(base-key, usage | 0x55);
// See RFC 3961 5.3 key-derivation function definition.
func GetUsageKi(un uint32) []byte {
return getUsage(un, 0x55)
}
Expand Down
35 changes: 0 additions & 35 deletions crypto/des3-cbc-sha1-kd.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,41 +15,6 @@ import (

//RFC: 3961 Section 6.3

/*
des3-cbc-hmac-sha1-kd, hmac-sha1-des3-kd
------------------------------------------------
protocol key format 24 bytes, parity in low
bit of each
key-generation seed 21 bytes
length
hash function SHA-1
HMAC output size 160 bits
message block size 8 bytes
default string-to-key empty string
params
encryption and triple-DES encrypt and
decryption functions decrypt, in outer-CBC
mode (cipher block size
8 octets)
key generation functions:
random-to-key DES3random-to-key (see
below)
string-to-key DES3string-to-key (see
below)
The des3-cbc-hmac-sha1-kd encryption type is assigned the value
sixteen (16). The hmac-sha1-des3-kd checksum algorithm is assigned a
checksum type number of twelve (12)*/

// Des3CbcSha1Kd implements Kerberos encryption type des3-cbc-hmac-sha1-kd
type Des3CbcSha1Kd struct {
}
Expand Down
24 changes: 12 additions & 12 deletions crypto/etype/etype.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@ type EType interface {
GetETypeID() int32
GetHashID() int32
GetKeyByteSize() int
GetKeySeedBitLength() int // key-generation seed length, k
GetDefaultStringToKeyParams() string // default string-to-key parameters (s2kparams)
StringToKey(string, salt, s2kparams string) ([]byte, error) // string-to-key (UTF-8 string, UTF-8 string, opaque)->(protocol-key)
RandomToKey(b []byte) []byte // random-to-key (bitstring[K])->(protocol-key)
GetHMACBitLength() int // HMAC output size, h
GetMessageBlockByteSize() int // message block size, m
EncryptData(key, data []byte) ([]byte, []byte, error) // E function - encrypt (specific-key, state, octet string)->(state, octet string)
GetKeySeedBitLength() int
GetDefaultStringToKeyParams() string
StringToKey(string, salt, s2kparams string) ([]byte, error)
RandomToKey(b []byte) []byte
GetHMACBitLength() int
GetMessageBlockByteSize() int
EncryptData(key, data []byte) ([]byte, []byte, error)
EncryptMessage(key, message []byte, usage uint32) ([]byte, []byte, error)
DecryptData(key, data []byte) ([]byte, error) // D function
DecryptData(key, data []byte) ([]byte, error)
DecryptMessage(key, ciphertext []byte, usage uint32) ([]byte, error)
GetCypherBlockBitLength() int // cipher block size, c
GetConfounderByteSize() int // This is the same as the cipher block size but in bytes.
DeriveKey(protocolKey, usage []byte) ([]byte, error) // DK key-derivation (protocol-key, integer)->(specific-key)
DeriveRandom(protocolKey, usage []byte) ([]byte, error) // DR pseudo-random (protocol-key, octet-string)->(octet-string)
GetCypherBlockBitLength() int
GetConfounderByteSize() int
DeriveKey(protocolKey, usage []byte) ([]byte, error)
DeriveRandom(protocolKey, usage []byte) ([]byte, error)
VerifyIntegrity(protocolKey, ct, pt []byte, usage uint32) bool
GetChecksumHash(protocolKey, data []byte, usage uint32) ([]byte, error)
VerifyChecksum(protocolKey, data, chksum []byte, usage uint32) bool
Expand Down
4 changes: 1 addition & 3 deletions crypto/rc4-hmac.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@ import (
"gopkg.in/jcmturner/gokrb5.v7/iana/etypeID"
)

//http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/8u40-b25/sun/security/krb5/internal/crypto/dk/ArcFourCrypto.java#ArcFourCrypto.encrypt%28byte%5B%5D%2Cint%2Cbyte%5B%5D%2Cbyte%5B%5D%2Cbyte%5B%5D%2Cint%2Cint%29

// RC4HMAC implements Kerberos encryption type aes256-cts-hmac-sha1-96
// RC4HMAC implements Kerberos encryption type rc4-hmac
type RC4HMAC struct {
}

Expand Down
6 changes: 0 additions & 6 deletions crypto/rfc3961/encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,12 +112,6 @@ func DES3DecryptMessage(key, ciphertext []byte, usage uint32, e etype.EType) ([]

// VerifyIntegrity verifies the integrity of cipertext bytes ct.
func VerifyIntegrity(key, ct, pt []byte, usage uint32, etype etype.EType) bool {
//The ciphertext output is the concatenation of the output of the basic
//encryption function E and a (possibly truncated) HMAC using the
//specified hash function H, both applied to the plaintext with a
//random confounder prefix and sufficient padding to bring it to a
//multiple of the message block size. When the HMAC is computed, the
//key is used in the protocol key form.
h := make([]byte, etype.GetHMACBitLength()/8)
copy(h, ct[len(ct)-etype.GetHMACBitLength()/8:])
expectedMAC, _ := common.GetIntegrityHash(pt, key, usage, etype)
Expand Down
Loading

0 comments on commit 1a5195b

Please sign in to comment.