|
|
@ -245,6 +245,11 @@ func (w *AuthenticationWriter) seal(b *buf.Buffer) (*buf.Buffer, error) { |
|
|
|
paddingSize = int(w.padding.NextPaddingLen()) |
|
|
|
paddingSize = int(w.padding.NextPaddingLen()) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
totalSize := encryptedSize + paddingSize |
|
|
|
|
|
|
|
if totalSize > buf.Size { |
|
|
|
|
|
|
|
return nil, newError("size too large: ", totalSize) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eb := buf.New() |
|
|
|
eb := buf.New() |
|
|
|
common.Must(eb.Reset(func(bb []byte) (int, error) { |
|
|
|
common.Must(eb.Reset(func(bb []byte) (int, error) { |
|
|
|
w.sizeParser.Encode(uint16(encryptedSize+paddingSize), bb[:0]) |
|
|
|
w.sizeParser.Encode(uint16(encryptedSize+paddingSize), bb[:0]) |
|
|
@ -301,17 +306,17 @@ func (w *AuthenticationWriter) writePacket(mb buf.MultiBuffer) error { |
|
|
|
|
|
|
|
|
|
|
|
mb2Write := buf.NewMultiBufferCap(int32(len(mb)) + 1) |
|
|
|
mb2Write := buf.NewMultiBufferCap(int32(len(mb)) + 1) |
|
|
|
|
|
|
|
|
|
|
|
for !mb.IsEmpty() { |
|
|
|
for _, b := range mb { |
|
|
|
b := mb.SplitFirst() |
|
|
|
|
|
|
|
if b.IsEmpty() { |
|
|
|
if b.IsEmpty() { |
|
|
|
continue |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
eb, err := w.seal(b) |
|
|
|
eb, err := w.seal(b) |
|
|
|
b.Release() |
|
|
|
|
|
|
|
if err != nil { |
|
|
|
if err != nil { |
|
|
|
mb2Write.Release() |
|
|
|
newError("failed to encrypt packet").Base(err).AtWarning().WriteToLog() |
|
|
|
return err |
|
|
|
continue |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
mb2Write.Append(eb) |
|
|
|
mb2Write.Append(eb) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -324,7 +329,8 @@ func (w *AuthenticationWriter) WriteMultiBuffer(mb buf.MultiBuffer) error { |
|
|
|
b := buf.New() |
|
|
|
b := buf.New() |
|
|
|
defer b.Release() |
|
|
|
defer b.Release() |
|
|
|
|
|
|
|
|
|
|
|
eb, _ := w.seal(b) |
|
|
|
eb, err := w.seal(b) |
|
|
|
|
|
|
|
common.Must(err) |
|
|
|
return w.writer.WriteMultiBuffer(buf.NewMultiBufferValue(eb)) |
|
|
|
return w.writer.WriteMultiBuffer(buf.NewMultiBufferValue(eb)) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|