Browse Source

fix unused errors

Jonathan Turner 9 years ago
parent
commit
841e1d8332
5 changed files with 16 additions and 4 deletions
  1. 6 3
      crypto/aescts/aescts.go
  2. 3 0
      messages/Ticket.go
  3. 3 0
      pac/kerb_validation_info_test.go
  4. 3 0
      pac/s4u_delegation_info.go
  5. 1 1
      service/http.go

+ 6 - 3
crypto/aescts/aescts.go

@@ -15,7 +15,7 @@ func Encrypt(key, iv, message []byte) ([]byte, []byte, error) {
 
 	block, err := aes.NewCipher(key)
 	if err != nil {
-		return nil, nil, fmt.Errorf("Error creating cipher: %v", err)
+		return []byte{}, []byte{}, fmt.Errorf("Error creating cipher: %v", err)
 	}
 	mode := cipher.NewCBCEncrypter(block, iv)
 
@@ -43,6 +43,9 @@ func Encrypt(key, iv, message []byte) ([]byte, []byte, error) {
 	}
 	m, _ = common.ZeroPad(m, aes.BlockSize)
 	rb, pb, lb, err := tailBlocks(m, aes.BlockSize)
+	if err != nil {
+		return []byte{}, []byte{}, fmt.Errorf("Error tailing blocks: %v", err)
+	}
 	var ct []byte
 	if rb != nil {
 		// Encrpt all but the lats 2 blocks and update the rolling iv
@@ -68,7 +71,7 @@ func Decrypt(key, iv, ciphertext []byte) ([]byte, error) {
 	ct := make([]byte, len(ciphertext))
 	copy(ct, ciphertext)
 	if len(ct) < aes.BlockSize {
-		return nil, fmt.Errorf("Ciphertext is not large enough. It is less that one block size. Blocksize:%v; Ciphertext:%v", aes.BlockSize, len(ct))
+		return []byte{}, fmt.Errorf("Ciphertext is not large enough. It is less that one block size. Blocksize:%v; Ciphertext:%v", aes.BlockSize, len(ct))
 	}
 	// Configure the CBC
 	block, err := aes.NewCipher(key)
@@ -133,7 +136,7 @@ func Decrypt(key, iv, ciphertext []byte) ([]byte, error) {
 
 func tailBlocks(b []byte, c int) ([]byte, []byte, []byte, error) {
 	if len(b) <= c {
-		return nil, nil, nil, errors.New("bytes slice is not larger than one block so cannot tail")
+		return []byte{}, []byte{}, []byte{}, errors.New("bytes slice is not larger than one block so cannot tail")
 	}
 	// Get size of last block
 	var lbs int

+ 3 - 0
messages/Ticket.go

@@ -82,6 +82,9 @@ func NewTicket(cname types.PrincipalName, crealm string, sname types.PrincipalNa
 		return Ticket{}, types.EncryptionKey{}, krberror.Errorf(err, krberror.ENCRYPTING_ERROR, "Error getting encryption key for new ticket")
 	}
 	ed, err := crypto.GetEncryptedData(b, skey, keyusage.KDC_REP_TICKET, kvno)
+	if err != nil {
+		return Ticket{}, types.EncryptionKey{}, krberror.Errorf(err, krberror.ENCRYPTING_ERROR, "Error encrypting ticket encpart")
+	}
 	tkt := Ticket{
 		TktVNO:  iana.PVNO,
 		Realm:   srealm,

+ 3 - 0
pac/kerb_validation_info_test.go

@@ -126,6 +126,9 @@ func TestKerbValidationInfo_Unmarshal(t *testing.T) {
 	}
 	var k2 KerbValidationInfo
 	err = k2.Unmarshal(b)
+	if err != nil {
+		t.Fatal("Could not unmarshal KerbValidationInfo")
+	}
 
 	assert.Equal(t, time.Date(2017, 5, 6, 15, 53, 11, 825766900, time.UTC), k2.LogOnTime.Time(), "LogOnTime not as expected")
 	assert.Equal(t, time.Date(2185, 7, 21, 23, 34, 33, 709551516, time.UTC), k2.LogOffTime.Time(), "LogOffTime not as expected")

+ 3 - 0
pac/s4u_delegation_info.go

@@ -33,6 +33,9 @@ func (k *S4U_DelegationInfo) Unmarshal(b []byte) error {
 		ts := make([]mstypes.RPC_UnicodeString, k.TransitedListSize, k.TransitedListSize)
 		for i := range ts {
 			ts[i], err = mstypes.Read_RPC_UnicodeString(&b, &p, e)
+			if err != nil {
+				return err
+			}
 		}
 		for i := range ts {
 			ts[i].UnmarshalString(&b, &p, e)

+ 1 - 1
service/http.go

@@ -16,7 +16,7 @@ type ctxKey int
 const (
 	// SPNEGO_NegTokenResp_Krb_Accept_Completed - The response on successful authentication always has this header. Capturing as const so we don't have marshaling and encoding overhead.
 	SPNEGO_NegTokenResp_Krb_Accept_Completed = "Negotiate oRQwEqADCgEAoQsGCSqGSIb3EgECAg=="
-	// SPNEGO_NegTokenResp_Reject - The response on a failed authentication always has this rejection header. Capturing as const so we don't have marshaling and encoding overhead.
+	// SPNEGO_NegTokenResp_Reject - pThe response on a failed authentication always has this rejection header. Capturing as const so we don't have marshaling and encoding overhead.
 	SPNEGO_NegTokenResp_Reject        = "Negotiate oQcwBaADCgEC"
 	CTXKey_Credentials         ctxKey = 0
 	CTXKey_Authenticated       ctxKey = 1