4
0
mirror of https://github.com/cwinfo/matterbridge.git synced 2025-06-27 13:29:25 +00:00

Add dependencies/vendor (whatsapp)

This commit is contained in:
Wim
2022-01-31 00:27:37 +01:00
parent e7b193788a
commit e3cafeaf92
1074 changed files with 3091569 additions and 26075 deletions

View File

@ -0,0 +1,245 @@
// From https://github.com/signalapp/libsignal-protocol-c/blob/master/protobuf/FingerprintProtocol.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.12.4
// source: serialize/FingerprintProtocol.proto
package serialize
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type LogicalFingerprint struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Content []byte `protobuf:"bytes,1,opt,name=content" json:"content,omitempty"`
Identifier []byte `protobuf:"bytes,2,opt,name=identifier" json:"identifier,omitempty"` // Version 0
}
func (x *LogicalFingerprint) Reset() {
*x = LogicalFingerprint{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_FingerprintProtocol_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *LogicalFingerprint) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*LogicalFingerprint) ProtoMessage() {}
func (x *LogicalFingerprint) ProtoReflect() protoreflect.Message {
mi := &file_serialize_FingerprintProtocol_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use LogicalFingerprint.ProtoReflect.Descriptor instead.
func (*LogicalFingerprint) Descriptor() ([]byte, []int) {
return file_serialize_FingerprintProtocol_proto_rawDescGZIP(), []int{0}
}
func (x *LogicalFingerprint) GetContent() []byte {
if x != nil {
return x.Content
}
return nil
}
func (x *LogicalFingerprint) GetIdentifier() []byte {
if x != nil {
return x.Identifier
}
return nil
}
type CombinedFingerprints struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Version *uint32 `protobuf:"varint,1,opt,name=version" json:"version,omitempty"`
LocalFingerprint *LogicalFingerprint `protobuf:"bytes,2,opt,name=localFingerprint" json:"localFingerprint,omitempty"`
RemoteFingerprint *LogicalFingerprint `protobuf:"bytes,3,opt,name=remoteFingerprint" json:"remoteFingerprint,omitempty"`
}
func (x *CombinedFingerprints) Reset() {
*x = CombinedFingerprints{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_FingerprintProtocol_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *CombinedFingerprints) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*CombinedFingerprints) ProtoMessage() {}
func (x *CombinedFingerprints) ProtoReflect() protoreflect.Message {
mi := &file_serialize_FingerprintProtocol_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use CombinedFingerprints.ProtoReflect.Descriptor instead.
func (*CombinedFingerprints) Descriptor() ([]byte, []int) {
return file_serialize_FingerprintProtocol_proto_rawDescGZIP(), []int{1}
}
func (x *CombinedFingerprints) GetVersion() uint32 {
if x != nil && x.Version != nil {
return *x.Version
}
return 0
}
func (x *CombinedFingerprints) GetLocalFingerprint() *LogicalFingerprint {
if x != nil {
return x.LocalFingerprint
}
return nil
}
func (x *CombinedFingerprints) GetRemoteFingerprint() *LogicalFingerprint {
if x != nil {
return x.RemoteFingerprint
}
return nil
}
var File_serialize_FingerprintProtocol_proto protoreflect.FileDescriptor
var file_serialize_FingerprintProtocol_proto_rawDesc = []byte{
0x0a, 0x23, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x2f, 0x46, 0x69, 0x6e, 0x67,
0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x73, 0x65, 0x63, 0x75, 0x72,
0x65, 0x22, 0x4e, 0x0a, 0x12, 0x4c, 0x6f, 0x67, 0x69, 0x63, 0x61, 0x6c, 0x46, 0x69, 0x6e, 0x67,
0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65,
0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e,
0x74, 0x12, 0x1e, 0x0a, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65, 0x72, 0x18,
0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x66, 0x69, 0x65,
0x72, 0x22, 0xca, 0x01, 0x0a, 0x14, 0x43, 0x6f, 0x6d, 0x62, 0x69, 0x6e, 0x65, 0x64, 0x46, 0x69,
0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x73, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x76, 0x65, 0x72,
0x73, 0x69, 0x6f, 0x6e, 0x12, 0x4a, 0x0a, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x46, 0x69, 0x6e,
0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e,
0x2e, 0x74, 0x65, 0x78, 0x74, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x69,
0x63, 0x61, 0x6c, 0x46, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x52, 0x10,
0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x46, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74,
0x12, 0x4c, 0x0a, 0x11, 0x72, 0x65, 0x6d, 0x6f, 0x74, 0x65, 0x46, 0x69, 0x6e, 0x67, 0x65, 0x72,
0x70, 0x72, 0x69, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x74, 0x65,
0x78, 0x74, 0x73, 0x65, 0x63, 0x75, 0x72, 0x65, 0x2e, 0x4c, 0x6f, 0x67, 0x69, 0x63, 0x61, 0x6c,
0x46, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74, 0x52, 0x11, 0x72, 0x65, 0x6d,
0x6f, 0x74, 0x65, 0x46, 0x69, 0x6e, 0x67, 0x65, 0x72, 0x70, 0x72, 0x69, 0x6e, 0x74,
}
var (
file_serialize_FingerprintProtocol_proto_rawDescOnce sync.Once
file_serialize_FingerprintProtocol_proto_rawDescData = file_serialize_FingerprintProtocol_proto_rawDesc
)
func file_serialize_FingerprintProtocol_proto_rawDescGZIP() []byte {
file_serialize_FingerprintProtocol_proto_rawDescOnce.Do(func() {
file_serialize_FingerprintProtocol_proto_rawDescData = protoimpl.X.CompressGZIP(file_serialize_FingerprintProtocol_proto_rawDescData)
})
return file_serialize_FingerprintProtocol_proto_rawDescData
}
var file_serialize_FingerprintProtocol_proto_msgTypes = make([]protoimpl.MessageInfo, 2)
var file_serialize_FingerprintProtocol_proto_goTypes = []interface{}{
(*LogicalFingerprint)(nil), // 0: textsecure.LogicalFingerprint
(*CombinedFingerprints)(nil), // 1: textsecure.CombinedFingerprints
}
var file_serialize_FingerprintProtocol_proto_depIdxs = []int32{
0, // 0: textsecure.CombinedFingerprints.localFingerprint:type_name -> textsecure.LogicalFingerprint
0, // 1: textsecure.CombinedFingerprints.remoteFingerprint:type_name -> textsecure.LogicalFingerprint
2, // [2:2] is the sub-list for method output_type
2, // [2:2] is the sub-list for method input_type
2, // [2:2] is the sub-list for extension type_name
2, // [2:2] is the sub-list for extension extendee
0, // [0:2] is the sub-list for field type_name
}
func init() { file_serialize_FingerprintProtocol_proto_init() }
func file_serialize_FingerprintProtocol_proto_init() {
if File_serialize_FingerprintProtocol_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_serialize_FingerprintProtocol_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*LogicalFingerprint); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_FingerprintProtocol_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*CombinedFingerprints); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_serialize_FingerprintProtocol_proto_rawDesc,
NumEnums: 0,
NumMessages: 2,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_serialize_FingerprintProtocol_proto_goTypes,
DependencyIndexes: file_serialize_FingerprintProtocol_proto_depIdxs,
MessageInfos: file_serialize_FingerprintProtocol_proto_msgTypes,
}.Build()
File_serialize_FingerprintProtocol_proto = out.File
file_serialize_FingerprintProtocol_proto_rawDesc = nil
file_serialize_FingerprintProtocol_proto_goTypes = nil
file_serialize_FingerprintProtocol_proto_depIdxs = nil
}

View File

@ -0,0 +1,14 @@
// From https://github.com/signalapp/libsignal-protocol-c/blob/master/protobuf/FingerprintProtocol.proto
syntax = "proto2";
package textsecure;
message LogicalFingerprint {
optional bytes content = 1;
optional bytes identifier = 2; // Version 0
}
message CombinedFingerprints {
optional uint32 version = 1;
optional LogicalFingerprint localFingerprint = 2;
optional LogicalFingerprint remoteFingerprint = 3;
}

View File

@ -0,0 +1,303 @@
package serialize
import (
"encoding/json"
groupRecord "go.mau.fi/libsignal/groups/state/record"
"go.mau.fi/libsignal/logger"
"go.mau.fi/libsignal/protocol"
"go.mau.fi/libsignal/state/record"
)
// NewJSONSerializer will return a serializer for all Signal objects that will
// be responsible for converting objects to and from JSON bytes.
func NewJSONSerializer() *Serializer {
serializer := NewSerializer()
serializer.SignalMessage = &JSONSignalMessageSerializer{}
serializer.PreKeySignalMessage = &JSONPreKeySignalMessageSerializer{}
serializer.SignedPreKeyRecord = &JSONSignedPreKeyRecordSerializer{}
serializer.PreKeyRecord = &JSONPreKeyRecordSerializer{}
serializer.State = &JSONStateSerializer{}
serializer.Session = &JSONSessionSerializer{}
serializer.SenderKeyMessage = &JSONSenderKeyMessageSerializer{}
serializer.SenderKeyDistributionMessage = &JSONSenderKeyDistributionMessageSerializer{}
serializer.SenderKeyRecord = &JSONSenderKeySessionSerializer{}
serializer.SenderKeyState = &JSONSenderKeyStateSerializer{}
return serializer
}
// JSONSignalMessageSerializer is a structure for serializing signal messages into
// and from JSON.
type JSONSignalMessageSerializer struct{}
// Serialize will take a signal message structure and convert it to JSON bytes.
func (j *JSONSignalMessageSerializer) Serialize(signalMessage *protocol.SignalMessageStructure) []byte {
serialized, err := json.Marshal(*signalMessage)
if err != nil {
logger.Error("Error serializing signal message: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a signal message structure.
func (j *JSONSignalMessageSerializer) Deserialize(serialized []byte) (*protocol.SignalMessageStructure, error) {
var signalMessage protocol.SignalMessageStructure
err := json.Unmarshal(serialized, &signalMessage)
if err != nil {
logger.Error("Error deserializing signal message: ", err)
return nil, err
}
return &signalMessage, nil
}
// JSONPreKeySignalMessageSerializer is a structure for serializing prekey signal messages
// into and from JSON.
type JSONPreKeySignalMessageSerializer struct{}
// Serialize will take a prekey signal message structure and convert it to JSON bytes.
func (j *JSONPreKeySignalMessageSerializer) Serialize(signalMessage *protocol.PreKeySignalMessageStructure) []byte {
serialized, err := json.Marshal(signalMessage)
if err != nil {
logger.Error("Error serializing prekey signal message: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a prekey signal message structure.
func (j *JSONPreKeySignalMessageSerializer) Deserialize(serialized []byte) (*protocol.PreKeySignalMessageStructure, error) {
var preKeySignalMessage protocol.PreKeySignalMessageStructure
err := json.Unmarshal(serialized, &preKeySignalMessage)
if err != nil {
logger.Error("Error deserializing prekey signal message: ", err)
return nil, err
}
return &preKeySignalMessage, nil
}
// JSONSignedPreKeyRecordSerializer is a structure for serializing signed prekey records
// into and from JSON.
type JSONSignedPreKeyRecordSerializer struct{}
// Serialize will take a signed prekey record structure and convert it to JSON bytes.
func (j *JSONSignedPreKeyRecordSerializer) Serialize(signedPreKey *record.SignedPreKeyStructure) []byte {
serialized, err := json.Marshal(signedPreKey)
if err != nil {
logger.Error("Error serializing signed prekey record: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a signed prekey record structure.
func (j *JSONSignedPreKeyRecordSerializer) Deserialize(serialized []byte) (*record.SignedPreKeyStructure, error) {
var signedPreKeyStructure record.SignedPreKeyStructure
err := json.Unmarshal(serialized, &signedPreKeyStructure)
if err != nil {
logger.Error("Error deserializing signed prekey record: ", err)
return nil, err
}
return &signedPreKeyStructure, nil
}
// JSONPreKeyRecordSerializer is a structure for serializing prekey records
// into and from JSON.
type JSONPreKeyRecordSerializer struct{}
// Serialize will take a prekey record structure and convert it to JSON bytes.
func (j *JSONPreKeyRecordSerializer) Serialize(preKey *record.PreKeyStructure) []byte {
serialized, err := json.Marshal(preKey)
if err != nil {
logger.Error("Error serializing prekey record: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a prekey record structure.
func (j *JSONPreKeyRecordSerializer) Deserialize(serialized []byte) (*record.PreKeyStructure, error) {
var preKeyStructure record.PreKeyStructure
err := json.Unmarshal(serialized, &preKeyStructure)
if err != nil {
logger.Error("Error deserializing prekey record: ", err)
return nil, err
}
return &preKeyStructure, nil
}
// JSONStateSerializer is a structure for serializing session states into
// and from JSON.
type JSONStateSerializer struct{}
// Serialize will take a session state structure and convert it to JSON bytes.
func (j *JSONStateSerializer) Serialize(state *record.StateStructure) []byte {
serialized, err := json.Marshal(state)
if err != nil {
logger.Error("Error serializing session state: ", err)
}
logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a session state structure.
func (j *JSONStateSerializer) Deserialize(serialized []byte) (*record.StateStructure, error) {
var stateStructure record.StateStructure
err := json.Unmarshal(serialized, &stateStructure)
if err != nil {
logger.Error("Error deserializing session state: ", err)
return nil, err
}
return &stateStructure, nil
}
// JSONSessionSerializer is a structure for serializing session records into
// and from JSON.
type JSONSessionSerializer struct{}
// Serialize will take a session structure and convert it to JSON bytes.
func (j *JSONSessionSerializer) Serialize(session *record.SessionStructure) []byte {
serialized, err := json.Marshal(session)
if err != nil {
logger.Error("Error serializing session: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a session structure, which can be
// used to create a new Session Record object.
func (j *JSONSessionSerializer) Deserialize(serialized []byte) (*record.SessionStructure, error) {
var sessionStructure record.SessionStructure
err := json.Unmarshal(serialized, &sessionStructure)
if err != nil {
logger.Error("Error deserializing session: ", err)
return nil, err
}
return &sessionStructure, nil
}
// JSONSenderKeyDistributionMessageSerializer is a structure for serializing senderkey
// distribution records to and from JSON.
type JSONSenderKeyDistributionMessageSerializer struct{}
// Serialize will take a senderkey distribution message and convert it to JSON bytes.
func (j *JSONSenderKeyDistributionMessageSerializer) Serialize(message *protocol.SenderKeyDistributionMessageStructure) []byte {
serialized, err := json.Marshal(message)
if err != nil {
logger.Error("Error serializing senderkey distribution message: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a message structure, which can be
// used to create a new SenderKey Distribution object.
func (j *JSONSenderKeyDistributionMessageSerializer) Deserialize(serialized []byte) (*protocol.SenderKeyDistributionMessageStructure, error) {
var msgStructure protocol.SenderKeyDistributionMessageStructure
err := json.Unmarshal(serialized, &msgStructure)
if err != nil {
logger.Error("Error deserializing senderkey distribution message: ", err)
return nil, err
}
return &msgStructure, nil
}
// JSONSenderKeyMessageSerializer is a structure for serializing senderkey
// messages to and from JSON.
type JSONSenderKeyMessageSerializer struct{}
// Serialize will take a senderkey message and convert it to JSON bytes.
func (j *JSONSenderKeyMessageSerializer) Serialize(message *protocol.SenderKeyMessageStructure) []byte {
serialized, err := json.Marshal(message)
if err != nil {
logger.Error("Error serializing senderkey distribution message: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a message structure, which can be
// used to create a new SenderKey message object.
func (j *JSONSenderKeyMessageSerializer) Deserialize(serialized []byte) (*protocol.SenderKeyMessageStructure, error) {
var msgStructure protocol.SenderKeyMessageStructure
err := json.Unmarshal(serialized, &msgStructure)
if err != nil {
logger.Error("Error deserializing senderkey message: ", err)
return nil, err
}
return &msgStructure, nil
}
// JSONSenderKeyStateSerializer is a structure for serializing group session states into
// and from JSON.
type JSONSenderKeyStateSerializer struct{}
// Serialize will take a session state structure and convert it to JSON bytes.
func (j *JSONSenderKeyStateSerializer) Serialize(state *groupRecord.SenderKeyStateStructure) []byte {
serialized, err := json.Marshal(state)
if err != nil {
logger.Error("Error serializing session state: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a session state structure.
func (j *JSONSenderKeyStateSerializer) Deserialize(serialized []byte) (*groupRecord.SenderKeyStateStructure, error) {
var stateStructure groupRecord.SenderKeyStateStructure
err := json.Unmarshal(serialized, &stateStructure)
if err != nil {
logger.Error("Error deserializing session state: ", err)
return nil, err
}
return &stateStructure, nil
}
// JSONSenderKeySessionSerializer is a structure for serializing session records into
// and from JSON.
type JSONSenderKeySessionSerializer struct{}
// Serialize will take a session structure and convert it to JSON bytes.
func (j *JSONSenderKeySessionSerializer) Serialize(session *groupRecord.SenderKeyStructure) []byte {
serialized, err := json.Marshal(session)
if err != nil {
logger.Error("Error serializing session: ", err)
}
// logger.Debug("Serialize result: ", string(serialized))
return serialized
}
// Deserialize will take in JSON bytes and return a session structure, which can be
// used to create a new Session Record object.
func (j *JSONSenderKeySessionSerializer) Deserialize(serialized []byte) (*groupRecord.SenderKeyStructure, error) {
var sessionStructure groupRecord.SenderKeyStructure
err := json.Unmarshal(serialized, &sessionStructure)
if err != nil {
logger.Error("Error deserializing session: ", err)
return nil, err
}
return &sessionStructure, nil
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,114 @@
// From https://github.com/signalapp/libsignal-protocol-c/blob/master/protobuf/LocalStorageProtocol.proto
syntax = "proto2";
package textsecure;
option java_package = "org.whispersystems.libsignal.state";
option java_outer_classname = "StorageProtos";
message SessionStructure {
message Chain {
optional bytes senderRatchetKey = 1;
optional bytes senderRatchetKeyPrivate = 2;
message ChainKey {
optional uint32 index = 1;
optional bytes key = 2;
}
optional ChainKey chainKey = 3;
message MessageKey {
optional uint32 index = 1;
optional bytes cipherKey = 2;
optional bytes macKey = 3;
optional bytes iv = 4;
}
repeated MessageKey messageKeys = 4;
}
message PendingKeyExchange {
optional uint32 sequence = 1;
optional bytes localBaseKey = 2;
optional bytes localBaseKeyPrivate = 3;
optional bytes localRatchetKey = 4;
optional bytes localRatchetKeyPrivate = 5;
optional bytes localIdentityKey = 7;
optional bytes localIdentityKeyPrivate = 8;
}
message PendingPreKey {
optional uint32 preKeyId = 1;
optional int32 signedPreKeyId = 3;
optional bytes baseKey = 2;
}
optional uint32 sessionVersion = 1;
optional bytes localIdentityPublic = 2;
optional bytes remoteIdentityPublic = 3;
optional bytes rootKey = 4;
optional uint32 previousCounter = 5;
optional Chain senderChain = 6;
repeated Chain receiverChains = 7;
optional PendingKeyExchange pendingKeyExchange = 8;
optional PendingPreKey pendingPreKey = 9;
optional uint32 remoteRegistrationId = 10;
optional uint32 localRegistrationId = 11;
optional bool needsRefresh = 12;
optional bytes aliceBaseKey = 13;
}
message RecordStructure {
optional SessionStructure currentSession = 1;
repeated SessionStructure previousSessions = 2;
}
message PreKeyRecordStructure {
optional uint32 id = 1;
optional bytes publicKey = 2;
optional bytes privateKey = 3;
}
message SignedPreKeyRecordStructure {
optional uint32 id = 1;
optional bytes publicKey = 2;
optional bytes privateKey = 3;
optional bytes signature = 4;
optional fixed64 timestamp = 5;
}
message IdentityKeyPairStructure {
optional bytes publicKey = 1;
optional bytes privateKey = 2;
}
message SenderKeyStateStructure {
message SenderChainKey {
optional uint32 iteration = 1;
optional bytes seed = 2;
}
message SenderMessageKey {
optional uint32 iteration = 1;
optional bytes seed = 2;
}
message SenderSigningKey {
optional bytes public = 1;
optional bytes private = 2;
}
optional uint32 senderKeyId = 1;
optional SenderChainKey senderChainKey = 2;
optional SenderSigningKey senderSigningKey = 3;
repeated SenderMessageKey senderMessageKeys = 4;
}
message SenderKeyRecordStructure {
repeated SenderKeyStateStructure senderKeyStates = 1;
}

View File

@ -0,0 +1,262 @@
package serialize
import (
"fmt"
"strconv"
"go.mau.fi/libsignal/logger"
"go.mau.fi/libsignal/protocol"
"go.mau.fi/libsignal/util/bytehelper"
"go.mau.fi/libsignal/util/optional"
proto "google.golang.org/protobuf/proto"
)
// NewProtoBufSerializer will return a serializer for all Signal objects that will
// be responsible for converting objects to and from ProtoBuf bytes.
func NewProtoBufSerializer() *Serializer {
serializer := NewSerializer()
serializer.SignalMessage = &ProtoBufSignalMessageSerializer{}
serializer.PreKeySignalMessage = &ProtoBufPreKeySignalMessageSerializer{}
serializer.SenderKeyMessage = &ProtoBufSenderKeyMessageSerializer{}
serializer.SenderKeyDistributionMessage = &ProtoBufSenderKeyDistributionMessageSerializer{}
serializer.SignedPreKeyRecord = &JSONSignedPreKeyRecordSerializer{}
serializer.PreKeyRecord = &JSONPreKeyRecordSerializer{}
serializer.State = &JSONStateSerializer{}
serializer.Session = &JSONSessionSerializer{}
serializer.SenderKeyRecord = &JSONSenderKeySessionSerializer{}
serializer.SenderKeyState = &JSONSenderKeyStateSerializer{}
return serializer
}
func highBitsToInt(value byte) int {
return int((value & 0xFF) >> 4)
}
func intsToByteHighAndLow(highValue, lowValue int) byte {
return byte((highValue<<4 | lowValue) & 0xFF)
}
// ProtoBufSignalMessageSerializer is a structure for serializing signal messages into
// and from ProtoBuf.
type ProtoBufSignalMessageSerializer struct{}
// Serialize will take a signal message structure and convert it to ProtoBuf bytes.
func (j *ProtoBufSignalMessageSerializer) Serialize(signalMessage *protocol.SignalMessageStructure) []byte {
sm := &SignalMessage{
RatchetKey: signalMessage.RatchetKey,
Counter: &signalMessage.Counter,
PreviousCounter: &signalMessage.PreviousCounter,
Ciphertext: signalMessage.CipherText,
}
var serialized []byte
message, err := proto.Marshal(sm)
if err != nil {
logger.Error("Error serializing signal message: ", err)
}
if signalMessage.Version != 0 {
serialized = append(serialized, []byte(strconv.Itoa(signalMessage.Version))...)
}
serialized = append(serialized, message...)
if signalMessage.Mac != nil {
serialized = append(serialized, signalMessage.Mac...)
}
return serialized
}
// Deserialize will take in ProtoBuf bytes and return a signal message structure.
func (j *ProtoBufSignalMessageSerializer) Deserialize(serialized []byte) (*protocol.SignalMessageStructure, error) {
parts, err := bytehelper.SplitThree(serialized, 1, len(serialized)-1-protocol.MacLength, protocol.MacLength)
if err != nil {
logger.Error("Error split signal message: ", err)
return nil, err
}
version := highBitsToInt(parts[0][0])
message := parts[1]
mac := parts[2]
var sm SignalMessage
err = proto.Unmarshal(message, &sm)
if err != nil {
logger.Error("Error deserializing signal message: ", err)
return nil, err
}
signalMessage := protocol.SignalMessageStructure{
Version: version,
RatchetKey: sm.GetRatchetKey(),
Counter: sm.GetCounter(),
PreviousCounter: sm.GetPreviousCounter(),
CipherText: sm.GetCiphertext(),
Mac: mac,
}
return &signalMessage, nil
}
// ProtoBufPreKeySignalMessageSerializer is a structure for serializing prekey signal messages
// into and from ProtoBuf.
type ProtoBufPreKeySignalMessageSerializer struct{}
// Serialize will take a prekey signal message structure and convert it to ProtoBuf bytes.
func (j *ProtoBufPreKeySignalMessageSerializer) Serialize(signalMessage *protocol.PreKeySignalMessageStructure) []byte {
preKeyMessage := &PreKeySignalMessage{
RegistrationId: &signalMessage.RegistrationID,
SignedPreKeyId: &signalMessage.SignedPreKeyID,
BaseKey: signalMessage.BaseKey,
IdentityKey: signalMessage.IdentityKey,
Message: signalMessage.Message,
}
if !signalMessage.PreKeyID.IsEmpty {
preKeyMessage.PreKeyId = &signalMessage.PreKeyID.Value
}
message, err := proto.Marshal(preKeyMessage)
if err != nil {
logger.Error("Error serializing prekey signal message: ", err)
}
serialized := append([]byte(strconv.Itoa(signalMessage.Version)), message...)
logger.Debug("Serialize PreKeySignalMessage result: ", serialized)
return serialized
}
// Deserialize will take in ProtoBuf bytes and return a prekey signal message structure.
func (j *ProtoBufPreKeySignalMessageSerializer) Deserialize(serialized []byte) (*protocol.PreKeySignalMessageStructure, error) {
version := highBitsToInt(serialized[0])
message := serialized[1:]
var sm PreKeySignalMessage
err := proto.Unmarshal(message, &sm)
if err != nil {
logger.Error("Error deserializing prekey signal message: ", err)
return nil, err
}
preKeyId := optional.NewEmptyUint32()
if sm.GetPreKeyId() != 0 {
preKeyId = optional.NewOptionalUint32(sm.GetPreKeyId())
}
preKeySignalMessage := protocol.PreKeySignalMessageStructure{
Version: version,
RegistrationID: sm.GetRegistrationId(),
BaseKey: sm.GetBaseKey(),
IdentityKey: sm.GetIdentityKey(),
SignedPreKeyID: sm.GetSignedPreKeyId(),
Message: sm.GetMessage(),
PreKeyID: preKeyId,
}
return &preKeySignalMessage, nil
}
// ProtoBufSenderKeyDistributionMessageSerializer is a structure for serializing senderkey
// distribution records to and from ProtoBuf.
type ProtoBufSenderKeyDistributionMessageSerializer struct{}
// Serialize will take a senderkey distribution message and convert it to ProtoBuf bytes.
func (j *ProtoBufSenderKeyDistributionMessageSerializer) Serialize(message *protocol.SenderKeyDistributionMessageStructure) []byte {
senderDis := SenderKeyDistributionMessage{
Id: &message.ID,
Iteration: &message.Iteration,
ChainKey: message.ChainKey,
SigningKey: message.SigningKey,
}
serialized, err := proto.Marshal(&senderDis)
if err != nil {
logger.Error("Error serializing senderkey distribution message: ", err)
}
version := strconv.Itoa(int(message.Version))
serialized = append([]byte(version), serialized...)
logger.Debug("Serialize result: ", serialized)
return serialized
}
// Deserialize will take in ProtoBuf bytes and return a message structure, which can be
// used to create a new SenderKey Distribution object.
func (j *ProtoBufSenderKeyDistributionMessageSerializer) Deserialize(serialized []byte) (*protocol.SenderKeyDistributionMessageStructure, error) {
version := uint32(highBitsToInt(serialized[0]))
message := serialized[1:]
var senderKeyDis SenderKeyDistributionMessage
err := proto.Unmarshal(message, &senderKeyDis)
if err != nil {
logger.Error("Error deserializing senderkey distribution message: ", err)
return nil, err
}
msgStructure := protocol.SenderKeyDistributionMessageStructure{
ID: senderKeyDis.GetId(),
Iteration: senderKeyDis.GetIteration(),
ChainKey: senderKeyDis.GetChainKey(),
SigningKey: senderKeyDis.GetSigningKey(),
Version: version,
}
return &msgStructure, nil
}
// ProtoBufSenderKeyMessageSerializer is a structure for serializing senderkey
// messages to and from ProtoBuf.
type ProtoBufSenderKeyMessageSerializer struct{}
// Serialize will take a senderkey message and convert it to ProtoBuf bytes.
func (j *ProtoBufSenderKeyMessageSerializer) Serialize(message *protocol.SenderKeyMessageStructure) []byte {
senderMessage := &SenderKeyMessage{
Id: &message.ID,
Iteration: &message.Iteration,
Ciphertext: message.CipherText,
}
var serialized []byte
m, err := proto.Marshal(senderMessage)
if err != nil {
logger.Error("Error serializing signal message: ", err)
}
if message.Version != 0 {
serialized = append([]byte(fmt.Sprint(message.Version)), m...)
}
if message.Signature != nil {
serialized = append(serialized, message.Signature...)
}
logger.Debug("Serialize result: ", serialized)
return serialized
}
// Deserialize will take in ProtoBuf bytes and return a message structure, which can be
// used to create a new SenderKey message object.
func (j *ProtoBufSenderKeyMessageSerializer) Deserialize(serialized []byte) (*protocol.SenderKeyMessageStructure, error) {
parts, err := bytehelper.SplitThree(serialized, 1, len(serialized)-1-64, 64)
if err != nil {
logger.Error("Error split signal message: ", err)
return nil, err
}
version := uint32(highBitsToInt(parts[0][0]))
message := parts[1]
signature := parts[2]
var senderKey SenderKeyMessage
err = proto.Unmarshal(message, &senderKey)
if err != nil {
logger.Error("Error deserializing senderkey message: ", err)
return nil, err
}
msgStructure := protocol.SenderKeyMessageStructure{
Version: version,
ID: senderKey.GetId(),
Iteration: senderKey.GetIteration(),
CipherText: senderKey.GetCiphertext(),
Signature: signature,
}
return &msgStructure, nil
}

View File

@ -0,0 +1,31 @@
// Package serialize provides a serialization structure to serialize and
// deserialize Signal objects into storeable and transportable bytes.
package serialize
import (
groupRecord "go.mau.fi/libsignal/groups/state/record"
"go.mau.fi/libsignal/protocol"
"go.mau.fi/libsignal/state/record"
)
// NewSerializer will return a new serializer object that will be used
// to encode/decode Signal objects into bytes.
func NewSerializer() *Serializer {
return &Serializer{}
}
// Serializer is a structure to serialize Signal objects
// into bytes. This allows you to use any serialization format
// to store or send Signal objects.
type Serializer struct {
SenderKeyRecord groupRecord.SenderKeySerializer
SenderKeyState groupRecord.SenderKeyStateSerializer
SignalMessage protocol.SignalMessageSerializer
PreKeySignalMessage protocol.PreKeySignalMessageSerializer
SenderKeyMessage protocol.SenderKeyMessageSerializer
SenderKeyDistributionMessage protocol.SenderKeyDistributionMessageSerializer
SignedPreKeyRecord record.SignedPreKeySerializer
PreKeyRecord record.PreKeySerializer
State record.StateSerializer
Session record.SessionSerializer
}

View File

@ -0,0 +1,640 @@
// From https://github.com/signalapp/libsignal-protocol-c/blob/master/protobuf/WhisperTextProtocol.proto
// Code generated by protoc-gen-go. DO NOT EDIT.
// versions:
// protoc-gen-go v1.26.0
// protoc v3.12.4
// source: serialize/WhisperTextProtocol.proto
package serialize
import (
protoreflect "google.golang.org/protobuf/reflect/protoreflect"
protoimpl "google.golang.org/protobuf/runtime/protoimpl"
reflect "reflect"
sync "sync"
)
const (
// Verify that this generated code is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion)
// Verify that runtime/protoimpl is sufficiently up-to-date.
_ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20)
)
type SignalMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
RatchetKey []byte `protobuf:"bytes,1,opt,name=ratchetKey" json:"ratchetKey,omitempty"`
Counter *uint32 `protobuf:"varint,2,opt,name=counter" json:"counter,omitempty"`
PreviousCounter *uint32 `protobuf:"varint,3,opt,name=previousCounter" json:"previousCounter,omitempty"`
Ciphertext []byte `protobuf:"bytes,4,opt,name=ciphertext" json:"ciphertext,omitempty"`
}
func (x *SignalMessage) Reset() {
*x = SignalMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[0]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SignalMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SignalMessage) ProtoMessage() {}
func (x *SignalMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[0]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SignalMessage.ProtoReflect.Descriptor instead.
func (*SignalMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{0}
}
func (x *SignalMessage) GetRatchetKey() []byte {
if x != nil {
return x.RatchetKey
}
return nil
}
func (x *SignalMessage) GetCounter() uint32 {
if x != nil && x.Counter != nil {
return *x.Counter
}
return 0
}
func (x *SignalMessage) GetPreviousCounter() uint32 {
if x != nil && x.PreviousCounter != nil {
return *x.PreviousCounter
}
return 0
}
func (x *SignalMessage) GetCiphertext() []byte {
if x != nil {
return x.Ciphertext
}
return nil
}
type PreKeySignalMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
RegistrationId *uint32 `protobuf:"varint,5,opt,name=registrationId" json:"registrationId,omitempty"`
PreKeyId *uint32 `protobuf:"varint,1,opt,name=preKeyId" json:"preKeyId,omitempty"`
SignedPreKeyId *uint32 `protobuf:"varint,6,opt,name=signedPreKeyId" json:"signedPreKeyId,omitempty"`
BaseKey []byte `protobuf:"bytes,2,opt,name=baseKey" json:"baseKey,omitempty"`
IdentityKey []byte `protobuf:"bytes,3,opt,name=identityKey" json:"identityKey,omitempty"`
Message []byte `protobuf:"bytes,4,opt,name=message" json:"message,omitempty"` // SignalMessage
}
func (x *PreKeySignalMessage) Reset() {
*x = PreKeySignalMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[1]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *PreKeySignalMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*PreKeySignalMessage) ProtoMessage() {}
func (x *PreKeySignalMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[1]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use PreKeySignalMessage.ProtoReflect.Descriptor instead.
func (*PreKeySignalMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{1}
}
func (x *PreKeySignalMessage) GetRegistrationId() uint32 {
if x != nil && x.RegistrationId != nil {
return *x.RegistrationId
}
return 0
}
func (x *PreKeySignalMessage) GetPreKeyId() uint32 {
if x != nil && x.PreKeyId != nil {
return *x.PreKeyId
}
return 0
}
func (x *PreKeySignalMessage) GetSignedPreKeyId() uint32 {
if x != nil && x.SignedPreKeyId != nil {
return *x.SignedPreKeyId
}
return 0
}
func (x *PreKeySignalMessage) GetBaseKey() []byte {
if x != nil {
return x.BaseKey
}
return nil
}
func (x *PreKeySignalMessage) GetIdentityKey() []byte {
if x != nil {
return x.IdentityKey
}
return nil
}
func (x *PreKeySignalMessage) GetMessage() []byte {
if x != nil {
return x.Message
}
return nil
}
type KeyExchangeMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id *uint32 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
BaseKey []byte `protobuf:"bytes,2,opt,name=baseKey" json:"baseKey,omitempty"`
RatchetKey []byte `protobuf:"bytes,3,opt,name=ratchetKey" json:"ratchetKey,omitempty"`
IdentityKey []byte `protobuf:"bytes,4,opt,name=identityKey" json:"identityKey,omitempty"`
BaseKeySignature []byte `protobuf:"bytes,5,opt,name=baseKeySignature" json:"baseKeySignature,omitempty"`
}
func (x *KeyExchangeMessage) Reset() {
*x = KeyExchangeMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[2]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *KeyExchangeMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*KeyExchangeMessage) ProtoMessage() {}
func (x *KeyExchangeMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[2]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use KeyExchangeMessage.ProtoReflect.Descriptor instead.
func (*KeyExchangeMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{2}
}
func (x *KeyExchangeMessage) GetId() uint32 {
if x != nil && x.Id != nil {
return *x.Id
}
return 0
}
func (x *KeyExchangeMessage) GetBaseKey() []byte {
if x != nil {
return x.BaseKey
}
return nil
}
func (x *KeyExchangeMessage) GetRatchetKey() []byte {
if x != nil {
return x.RatchetKey
}
return nil
}
func (x *KeyExchangeMessage) GetIdentityKey() []byte {
if x != nil {
return x.IdentityKey
}
return nil
}
func (x *KeyExchangeMessage) GetBaseKeySignature() []byte {
if x != nil {
return x.BaseKeySignature
}
return nil
}
type SenderKeyMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id *uint32 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
Iteration *uint32 `protobuf:"varint,2,opt,name=iteration" json:"iteration,omitempty"`
Ciphertext []byte `protobuf:"bytes,3,opt,name=ciphertext" json:"ciphertext,omitempty"`
}
func (x *SenderKeyMessage) Reset() {
*x = SenderKeyMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[3]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SenderKeyMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SenderKeyMessage) ProtoMessage() {}
func (x *SenderKeyMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[3]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SenderKeyMessage.ProtoReflect.Descriptor instead.
func (*SenderKeyMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{3}
}
func (x *SenderKeyMessage) GetId() uint32 {
if x != nil && x.Id != nil {
return *x.Id
}
return 0
}
func (x *SenderKeyMessage) GetIteration() uint32 {
if x != nil && x.Iteration != nil {
return *x.Iteration
}
return 0
}
func (x *SenderKeyMessage) GetCiphertext() []byte {
if x != nil {
return x.Ciphertext
}
return nil
}
type SenderKeyDistributionMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Id *uint32 `protobuf:"varint,1,opt,name=id" json:"id,omitempty"`
Iteration *uint32 `protobuf:"varint,2,opt,name=iteration" json:"iteration,omitempty"`
ChainKey []byte `protobuf:"bytes,3,opt,name=chainKey" json:"chainKey,omitempty"`
SigningKey []byte `protobuf:"bytes,4,opt,name=signingKey" json:"signingKey,omitempty"`
}
func (x *SenderKeyDistributionMessage) Reset() {
*x = SenderKeyDistributionMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[4]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *SenderKeyDistributionMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*SenderKeyDistributionMessage) ProtoMessage() {}
func (x *SenderKeyDistributionMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[4]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use SenderKeyDistributionMessage.ProtoReflect.Descriptor instead.
func (*SenderKeyDistributionMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{4}
}
func (x *SenderKeyDistributionMessage) GetId() uint32 {
if x != nil && x.Id != nil {
return *x.Id
}
return 0
}
func (x *SenderKeyDistributionMessage) GetIteration() uint32 {
if x != nil && x.Iteration != nil {
return *x.Iteration
}
return 0
}
func (x *SenderKeyDistributionMessage) GetChainKey() []byte {
if x != nil {
return x.ChainKey
}
return nil
}
func (x *SenderKeyDistributionMessage) GetSigningKey() []byte {
if x != nil {
return x.SigningKey
}
return nil
}
type DeviceConsistencyCodeMessage struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
unknownFields protoimpl.UnknownFields
Generation *uint32 `protobuf:"varint,1,opt,name=generation" json:"generation,omitempty"`
Signature []byte `protobuf:"bytes,2,opt,name=signature" json:"signature,omitempty"`
}
func (x *DeviceConsistencyCodeMessage) Reset() {
*x = DeviceConsistencyCodeMessage{}
if protoimpl.UnsafeEnabled {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[5]
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
ms.StoreMessageInfo(mi)
}
}
func (x *DeviceConsistencyCodeMessage) String() string {
return protoimpl.X.MessageStringOf(x)
}
func (*DeviceConsistencyCodeMessage) ProtoMessage() {}
func (x *DeviceConsistencyCodeMessage) ProtoReflect() protoreflect.Message {
mi := &file_serialize_WhisperTextProtocol_proto_msgTypes[5]
if protoimpl.UnsafeEnabled && x != nil {
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
if ms.LoadMessageInfo() == nil {
ms.StoreMessageInfo(mi)
}
return ms
}
return mi.MessageOf(x)
}
// Deprecated: Use DeviceConsistencyCodeMessage.ProtoReflect.Descriptor instead.
func (*DeviceConsistencyCodeMessage) Descriptor() ([]byte, []int) {
return file_serialize_WhisperTextProtocol_proto_rawDescGZIP(), []int{5}
}
func (x *DeviceConsistencyCodeMessage) GetGeneration() uint32 {
if x != nil && x.Generation != nil {
return *x.Generation
}
return 0
}
func (x *DeviceConsistencyCodeMessage) GetSignature() []byte {
if x != nil {
return x.Signature
}
return nil
}
var File_serialize_WhisperTextProtocol_proto protoreflect.FileDescriptor
var file_serialize_WhisperTextProtocol_proto_rawDesc = []byte{
0x0a, 0x23, 0x73, 0x65, 0x72, 0x69, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x2f, 0x57, 0x68, 0x69, 0x73,
0x70, 0x65, 0x72, 0x54, 0x65, 0x78, 0x74, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x2e,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x0a, 0x74, 0x65, 0x78, 0x74, 0x73, 0x65, 0x63, 0x75, 0x72,
0x65, 0x22, 0x93, 0x01, 0x0a, 0x0d, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x61, 0x74, 0x63, 0x68, 0x65, 0x74, 0x4b, 0x65,
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x72, 0x61, 0x74, 0x63, 0x68, 0x65, 0x74,
0x4b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x18, 0x02,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x07, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x28, 0x0a,
0x0f, 0x70, 0x72, 0x65, 0x76, 0x69, 0x6f, 0x75, 0x73, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0f, 0x70, 0x72, 0x65, 0x76, 0x69, 0x6f, 0x75, 0x73,
0x43, 0x6f, 0x75, 0x6e, 0x74, 0x65, 0x72, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65,
0x72, 0x74, 0x65, 0x78, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x69, 0x70,
0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74, 0x22, 0xd7, 0x01, 0x0a, 0x13, 0x50, 0x72, 0x65, 0x4b,
0x65, 0x79, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x6c, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12,
0x26, 0x0a, 0x0e, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49,
0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x72, 0x65, 0x67, 0x69, 0x73, 0x74, 0x72,
0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x65, 0x4b, 0x65,
0x79, 0x49, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x08, 0x70, 0x72, 0x65, 0x4b, 0x65,
0x79, 0x49, 0x64, 0x12, 0x26, 0x0a, 0x0e, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x50, 0x72, 0x65,
0x4b, 0x65, 0x79, 0x49, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x73, 0x69, 0x67,
0x6e, 0x65, 0x64, 0x50, 0x72, 0x65, 0x4b, 0x65, 0x79, 0x49, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62,
0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x62, 0x61,
0x73, 0x65, 0x4b, 0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
0x79, 0x4b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x69, 0x64, 0x65, 0x6e,
0x74, 0x69, 0x74, 0x79, 0x4b, 0x65, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61,
0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67,
0x65, 0x22, 0xac, 0x01, 0x0a, 0x12, 0x4b, 0x65, 0x79, 0x45, 0x78, 0x63, 0x68, 0x61, 0x6e, 0x67,
0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01,
0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x12, 0x18, 0x0a, 0x07, 0x62, 0x61, 0x73, 0x65,
0x4b, 0x65, 0x79, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x07, 0x62, 0x61, 0x73, 0x65, 0x4b,
0x65, 0x79, 0x12, 0x1e, 0x0a, 0x0a, 0x72, 0x61, 0x74, 0x63, 0x68, 0x65, 0x74, 0x4b, 0x65, 0x79,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x72, 0x61, 0x74, 0x63, 0x68, 0x65, 0x74, 0x4b,
0x65, 0x79, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x4b, 0x65,
0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0b, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74,
0x79, 0x4b, 0x65, 0x79, 0x12, 0x2a, 0x0a, 0x10, 0x62, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x53,
0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x10,
0x62, 0x61, 0x73, 0x65, 0x4b, 0x65, 0x79, 0x53, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65,
0x22, 0x60, 0x0a, 0x10, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x4b, 0x65, 0x79, 0x4d, 0x65, 0x73,
0x73, 0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d,
0x52, 0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65, 0x78, 0x74,
0x18, 0x03, 0x20, 0x01, 0x28, 0x0c, 0x52, 0x0a, 0x63, 0x69, 0x70, 0x68, 0x65, 0x72, 0x74, 0x65,
0x78, 0x74, 0x22, 0x88, 0x01, 0x0a, 0x1c, 0x53, 0x65, 0x6e, 0x64, 0x65, 0x72, 0x4b, 0x65, 0x79,
0x44, 0x69, 0x73, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x69, 0x6f, 0x6e, 0x4d, 0x65, 0x73, 0x73,
0x61, 0x67, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, 0x52,
0x02, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e,
0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x09, 0x69, 0x74, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f,
0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x18, 0x03, 0x20,
0x01, 0x28, 0x0c, 0x52, 0x08, 0x63, 0x68, 0x61, 0x69, 0x6e, 0x4b, 0x65, 0x79, 0x12, 0x1e, 0x0a,
0x0a, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28,
0x0c, 0x52, 0x0a, 0x73, 0x69, 0x67, 0x6e, 0x69, 0x6e, 0x67, 0x4b, 0x65, 0x79, 0x22, 0x5c, 0x0a,
0x1c, 0x44, 0x65, 0x76, 0x69, 0x63, 0x65, 0x43, 0x6f, 0x6e, 0x73, 0x69, 0x73, 0x74, 0x65, 0x6e,
0x63, 0x79, 0x43, 0x6f, 0x64, 0x65, 0x4d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1e, 0x0a,
0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28,
0x0d, 0x52, 0x0a, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1c, 0x0a,
0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0c,
0x52, 0x09, 0x73, 0x69, 0x67, 0x6e, 0x61, 0x74, 0x75, 0x72, 0x65,
}
var (
file_serialize_WhisperTextProtocol_proto_rawDescOnce sync.Once
file_serialize_WhisperTextProtocol_proto_rawDescData = file_serialize_WhisperTextProtocol_proto_rawDesc
)
func file_serialize_WhisperTextProtocol_proto_rawDescGZIP() []byte {
file_serialize_WhisperTextProtocol_proto_rawDescOnce.Do(func() {
file_serialize_WhisperTextProtocol_proto_rawDescData = protoimpl.X.CompressGZIP(file_serialize_WhisperTextProtocol_proto_rawDescData)
})
return file_serialize_WhisperTextProtocol_proto_rawDescData
}
var file_serialize_WhisperTextProtocol_proto_msgTypes = make([]protoimpl.MessageInfo, 6)
var file_serialize_WhisperTextProtocol_proto_goTypes = []interface{}{
(*SignalMessage)(nil), // 0: textsecure.SignalMessage
(*PreKeySignalMessage)(nil), // 1: textsecure.PreKeySignalMessage
(*KeyExchangeMessage)(nil), // 2: textsecure.KeyExchangeMessage
(*SenderKeyMessage)(nil), // 3: textsecure.SenderKeyMessage
(*SenderKeyDistributionMessage)(nil), // 4: textsecure.SenderKeyDistributionMessage
(*DeviceConsistencyCodeMessage)(nil), // 5: textsecure.DeviceConsistencyCodeMessage
}
var file_serialize_WhisperTextProtocol_proto_depIdxs = []int32{
0, // [0:0] is the sub-list for method output_type
0, // [0:0] is the sub-list for method input_type
0, // [0:0] is the sub-list for extension type_name
0, // [0:0] is the sub-list for extension extendee
0, // [0:0] is the sub-list for field type_name
}
func init() { file_serialize_WhisperTextProtocol_proto_init() }
func file_serialize_WhisperTextProtocol_proto_init() {
if File_serialize_WhisperTextProtocol_proto != nil {
return
}
if !protoimpl.UnsafeEnabled {
file_serialize_WhisperTextProtocol_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SignalMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_WhisperTextProtocol_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*PreKeySignalMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_WhisperTextProtocol_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*KeyExchangeMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_WhisperTextProtocol_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SenderKeyMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_WhisperTextProtocol_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*SenderKeyDistributionMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
file_serialize_WhisperTextProtocol_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} {
switch v := v.(*DeviceConsistencyCodeMessage); i {
case 0:
return &v.state
case 1:
return &v.sizeCache
case 2:
return &v.unknownFields
default:
return nil
}
}
}
type x struct{}
out := protoimpl.TypeBuilder{
File: protoimpl.DescBuilder{
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
RawDescriptor: file_serialize_WhisperTextProtocol_proto_rawDesc,
NumEnums: 0,
NumMessages: 6,
NumExtensions: 0,
NumServices: 0,
},
GoTypes: file_serialize_WhisperTextProtocol_proto_goTypes,
DependencyIndexes: file_serialize_WhisperTextProtocol_proto_depIdxs,
MessageInfos: file_serialize_WhisperTextProtocol_proto_msgTypes,
}.Build()
File_serialize_WhisperTextProtocol_proto = out.File
file_serialize_WhisperTextProtocol_proto_rawDesc = nil
file_serialize_WhisperTextProtocol_proto_goTypes = nil
file_serialize_WhisperTextProtocol_proto_depIdxs = nil
}

View File

@ -0,0 +1,45 @@
// From https://github.com/signalapp/libsignal-protocol-c/blob/master/protobuf/WhisperTextProtocol.proto
syntax = "proto2";
package textsecure;
message SignalMessage {
optional bytes ratchetKey = 1;
optional uint32 counter = 2;
optional uint32 previousCounter = 3;
optional bytes ciphertext = 4;
}
message PreKeySignalMessage {
optional uint32 registrationId = 5;
optional uint32 preKeyId = 1;
optional uint32 signedPreKeyId = 6;
optional bytes baseKey = 2;
optional bytes identityKey = 3;
optional bytes message = 4; // SignalMessage
}
message KeyExchangeMessage {
optional uint32 id = 1;
optional bytes baseKey = 2;
optional bytes ratchetKey = 3;
optional bytes identityKey = 4;
optional bytes baseKeySignature = 5;
}
message SenderKeyMessage {
optional uint32 id = 1;
optional uint32 iteration = 2;
optional bytes ciphertext = 3;
}
message SenderKeyDistributionMessage {
optional uint32 id = 1;
optional uint32 iteration = 2;
optional bytes chainKey = 3;
optional bytes signingKey = 4;
}
message DeviceConsistencyCodeMessage {
optional uint32 generation = 1;
optional bytes signature = 2;
}