-
Notifications
You must be signed in to change notification settings - Fork 0
Security Extension #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
e6928a7
5c91bbf
edbec97
37ae76a
75e6ded
56281f3
74196de
bf33f0a
7a3d046
103929f
4e8f9c2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -76,3 +76,5 @@ tags | |
|
|
||
| # local buildkite run | ||
| /artifacts.out | ||
|
|
||
| .idea/* | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,7 +17,6 @@ package layers | |
| import ( | ||
| "github.com/google/gopacket" | ||
| "github.com/google/gopacket/layers" | ||
|
|
||
| "github.com/scionproto/scion/go/lib/common" | ||
| "github.com/scionproto/scion/go/lib/serrors" | ||
| "github.com/scionproto/scion/go/lib/util" | ||
|
|
@@ -49,10 +48,12 @@ var ( | |
|
|
||
| type Extension struct { | ||
| layers.BaseLayer | ||
| NextHeader common.L4ProtocolType | ||
| NumLines uint8 | ||
| Type uint8 | ||
| Data []byte | ||
| NextHeader common.L4ProtocolType | ||
| NumLines uint8 | ||
| Type uint8 | ||
| Class common.L4ProtocolType | ||
|
radwasherif marked this conversation as resolved.
|
||
| Data []byte | ||
| AuthenticatedBytes []byte | ||
| } | ||
|
|
||
| func (e *Extension) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) error { | ||
|
|
@@ -84,6 +85,22 @@ func (e *Extension) DecodeFromBytes(data []byte, df gopacket.DecodeFeedback) err | |
| } | ||
|
|
||
| func (e *Extension) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) error { | ||
| bytes, err := e.serialize(b, opts) | ||
| if err != nil { | ||
| return err | ||
| } | ||
|
|
||
| //The bytes that need to be authenticated | ||
| switch e.Class { | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why don't we have different behaviors for these? Interface
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a bit complicated because we convert common.Extension (an interface) to layers.Extension using the function |
||
| case common.HopByHopClass: | ||
| e.AuthenticatedBytes = []byte{bytes[0], bytes[2]} //HBH: only next header and type | ||
| case common.End2EndClass: //E2E: entire extension | ||
| e.AuthenticatedBytes = bytes | ||
| } | ||
|
|
||
| return nil | ||
| } | ||
| func (e *Extension) serialize(b gopacket.SerializeBuffer, opts gopacket.SerializeOptions) ([]byte, error) { | ||
| totalLength := common.ExtnSubHdrLen + len(e.Data) | ||
| paddingSize := 0 | ||
| if opts.FixLengths { | ||
|
|
@@ -93,12 +110,49 @@ func (e *Extension) SerializeTo(b gopacket.SerializeBuffer, opts gopacket.Serial | |
| } | ||
| bytes, err := b.PrependBytes(totalLength) | ||
| if err != nil { | ||
| return err | ||
| return nil, err | ||
| } | ||
| bytes[0] = uint8(e.NextHeader) | ||
| bytes[1] = e.NumLines | ||
| bytes[2] = e.Type | ||
| copy(bytes[3:], e.Data) | ||
| copy(bytes[3+len(e.Data):], zeroes[:paddingSize]) | ||
| return nil | ||
| copy(bytes[common.ExtnSubHdrLen:], e.Data) | ||
| copy(bytes[common.ExtnSubHdrLen+len(e.Data):], zeroes[:paddingSize]) | ||
|
|
||
| return bytes, nil | ||
| } | ||
|
|
||
| type SPSE struct { | ||
| Extension | ||
| //AuthenticatorBuffer is a pointer to the serialization buffer where the MAC is written | ||
| AuthenticatorBuffer []byte | ||
| //AuthStartOffset the start offset of the authenticator relative to the Data field | ||
| AuthStartOffset int | ||
| //AuthEndOffset the end offset of the authenticator relative to the Data field | ||
| AuthEndOffset int | ||
| } | ||
|
|
||
| func (e *SPSE) SetAuthenticator(b []byte) { | ||
| copy(e.AuthenticatorBuffer, b) | ||
| } | ||
|
|
||
| func (e *SPSE) Serialize() []byte { | ||
| totalLength := common.ExtnSubHdrLen + len(e.Data) | ||
| paddingSize := util.CalcPadding(totalLength, common.LineLen) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. in
Owner
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I honestly don't understand why we need this |
||
| totalLength += paddingSize | ||
| e.NumLines = uint8(totalLength / common.LineLen) | ||
| bytes := make([]byte, totalLength) | ||
| bytes[0] = uint8(e.NextHeader) | ||
| bytes[1] = e.NumLines | ||
| bytes[2] = e.Type | ||
| copy(bytes[common.ExtnSubHdrLen:], e.Data) | ||
| copy(bytes[common.ExtnSubHdrLen+len(e.Data):], zeroes[:paddingSize]) | ||
| //The bytes that need to be authenticated | ||
| e.AuthenticatedBytes = bytes | ||
|
|
||
| //Keep pointer to the buffer containing authenticator | ||
| //Initialized to zero, set later by call to SetAuthenticator after MAC computation | ||
| e.AuthenticatorBuffer = bytes[common.ExtnSubHdrLen+e.AuthStartOffset : common.ExtnSubHdrLen+e.AuthEndOffset] | ||
|
|
||
| return bytes | ||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.