Skip to content

Commit

Permalink
Encrypt nil Ike payload (#12)
Browse files Browse the repository at this point in the history
* Encrypt nil Ike payload

* Add nil ike payload encryption in UT

* Add random padding in encrypt procedure

* Add encr aes_cbc UT

* Modify Algo name to global parameter

* Modify Encr NewCrypto parameter

* Modify algo struct name

* Fix UT fail due to naming issue

---------

Co-authored-by: Allen00991 <[email protected]>
  • Loading branch information
allen0091 and Allen00991 authored Oct 14, 2024
1 parent 7474f6e commit 083f897
Show file tree
Hide file tree
Showing 20 changed files with 927 additions and 310 deletions.
14 changes: 9 additions & 5 deletions ike.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,10 +237,7 @@ func encryptMsg(
return errors.Errorf("encryptMsg(): IKE SA is nil")
}
ikePayloads := ikeMsg.Payloads
// Check parameters
if len(ikePayloads) == 0 {
return errors.Errorf("encryptMsg(): No IKE payload to be encrypted")
}

// Check if the context contain needed data
if ikesaKey.IntegInfo == nil {
return errors.Errorf("encryptMsg(): No integrity algorithm specified")
Expand Down Expand Up @@ -271,7 +268,14 @@ func encryptMsg(

encryptedData = append(encryptedData, make([]byte, checksumLength)...)
ikeMsg.Payloads.Reset()
sk := ikeMsg.Payloads.BuildEncrypted(ikePayloads[0].Type(), encryptedData)

var encrNextPayloadType message.IKEPayloadType
if len(ikePayloads) == 0 {
encrNextPayloadType = message.NoNext
} else {
encrNextPayloadType = ikePayloads[0].Type()
}
sk := ikeMsg.Payloads.BuildEncrypted(encrNextPayloadType, encryptedData)

// Calculate checksum
ikeMsgData, err := ikeMsg.Encode()
Expand Down
Loading

0 comments on commit 083f897

Please sign in to comment.