Skip to content
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

Updated to latest API version - added LicenceKey parameter #29

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@
# o3

Re-implementation of the [Threema](https://threema.ch) protocol. GoDoc [here](https://godoc.org/github.com/o3ma/o3), better documentation will follow.

Requires a threema license from: https://shop.threema.ch/ (only for new
identities)
14 changes: 7 additions & 7 deletions communicationhandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,18 @@ func (sc *SessionContext) sendLoop() {

// SendTextMessage sends a Text Message to the specified ID
// Enqueued messages will be received, not acknowledged and discarded
func (sc *SessionContext) SendTextMessage(recipient string, text string, sendMsgChan chan<- Message) error {
func (sc *SessionContext) SendTextMessage(recipient string, text string, sendMsgChan chan<- Message) (uint64, error) {
// build a message
tm, err := NewTextMessage(sc, recipient, text)

// TODO: error handling
if err != nil {
return err
return 0, err
}

sendMsgChan <- tm

return nil
return tm.ID(), nil
}

// SendImageMessage sends a Image Message to the specified ID
Expand Down Expand Up @@ -223,17 +223,17 @@ func (sc *SessionContext) SendAudioMessage(recipient string, filename string, se
}

// SendGroupTextMessage Sends a text message to all members
func (sc *SessionContext) SendGroupTextMessage(group Group, text string, sendMsgChan chan<- Message) (err error) {
func (sc *SessionContext) SendGroupTextMessage(group Group, text string, sendMsgChan chan<- Message) (tms []GroupTextMessage, err error) {

tms, err := NewGroupTextMessages(sc, group, text)
tms, err = NewGroupTextMessages(sc, group, text)
if err != nil {
return err
return nil, err
}
for _, msg := range tms {
sendMsgChan <- msg
}

return nil
return tms, nil
}

// CreateNewGroup Creates a new group and notifies all members
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module github.com/o3ma/o3
8 changes: 7 additions & 1 deletion identity.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,13 +174,19 @@ func ParseIDBackupString(idstr string, password []byte) (ThreemaID, error) {
// will always look different even if using the same password and ID because the salt is re-generated
// with each backup.
func (thid ThreemaID) SaveToFile(filename string, password []byte) error {
idstr, err := encryptID(thid.ID[:], thid.LSK[:], password)
idstr, err := thid.CreateIDBackupString(password)
if err != nil {
return err
}
return ioutil.WriteFile(filename, []byte(idstr+"\n"), 0600)
}

// CreateIDBackupString encodes the base32-encoded encrypted ID string contained to a threema backup.
func (thid ThreemaID) CreateIDBackupString(password []byte) (string, error) {
idstr, err := encryptID(thid.ID[:], thid.LSK[:], password)
return idstr, err
}

// NewThreemaID creates a ThreemaID from a given id strnig and a 256-bit private key
func NewThreemaID(id string, lsk [32]byte, contacts AddressBook) (ThreemaID, error) {
var tid ThreemaID
Expand Down
11 changes: 7 additions & 4 deletions messagetypes.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,16 @@ type MsgType uint8

// MsgType mock enum
const (
TEXTMESSAGE MsgType = 0x1 //indicates a text message
IMAGEMESSAGE MsgType = 0x2 //indicates a image message
TEXTMESSAGE MsgType = 0x01 //indicates a text message
IMAGEMESSAGE MsgType = 0x02 //indicates a image message
LOCATIONMESSAGE MsgType = 0x10 //indicates a location message
AUDIOMESSAGE MsgType = 0x14 //indicates a audio message
POLLMESSAGE MsgType = 0x15 //indicates a poll message
LOCATIONMESSAGE MsgType = 0x16 //indicates a location message
POLL_CREATE_MESSAGE MsgType = 0x15 //indicates a poll message
POLL_VOTE_MESSAGE MsgType = 0x16 //indicates a poll message
Comment on lines +22 to +23
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can see why underlines are more readable but I'd personally prefer to have them all in the same pattern.

Not sure how noisy it would be to change them all. Maybe as a follow-up?

FILEMESSAGE MsgType = 0x17 //indicates a file message
CONTACT_REQ_PHOTO MsgType = 0x1A //indicates a text message
GROUPTEXTMESSAGE MsgType = 0x41 //indicates a group text message
GROUPLOCATIONMESSAGE MsgType = 0x42 //indicates a group image message
GROUPIMAGEMESSAGE MsgType = 0x43 //indicates a group image message
GROUPSETMEMEBERSMESSAGE MsgType = 0x4A //indicates a set group member message
GROUPSETNAMEMESSAGE MsgType = 0x4B //indicates a set group name message
Expand Down
4 changes: 4 additions & 0 deletions packethandler.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ func (sc *SessionContext) handleMessagePacket(mp messagePacket) (Message, error)
message = AudioMessage{
messageHeader: newMsgHdrFromPkt(mp),
audioMessageBody: parseAudioMessage(buf)}
case CONTACT_REQ_PHOTO:
message = TextMessage{
messageHeader: newMsgHdrFromPkt(mp),
textMessageBody: parseTextMessage(buf)}
case GROUPTEXTMESSAGE:
message = GroupTextMessage{
groupMessageHeader: parseGroupMessageHeader(buf),
Expand Down
10 changes: 6 additions & 4 deletions rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ type ThreemaRest struct {
}

// CreateIdentity generates a new NaCl Keypair, registers it with the Three servers and returns the assigned ID
func (tr ThreemaRest) CreateIdentity() (ThreemaID, error) {
func (tr ThreemaRest) CreateIdentity(deviceUUID string, licenseKey string) (ThreemaID, error) {
// Get Keypair and nonce ready
publicKey, privateKey, err := box.GenerateKey(rand.Reader)
if err != nil {
Expand Down Expand Up @@ -55,9 +55,11 @@ func (tr ThreemaRest) CreateIdentity() (ThreemaID, error) {
tokenResponse := base64.StdEncoding.EncodeToString(box.Seal(nil, []byte(token), &nonce, &tokenPubKey, privateKey))

response := models_pkg.CreateStage2Request{
PublicKey: &pubkey,
Response: &tokenResponse,
Token: challenge.Token}
PublicKey: &pubkey,
Response: &tokenResponse,
Token: challenge.Token,
DeviceId: &deviceUUID,
LicenseKey: &licenseKey}

finalResult, err := tr.client.IdentityCreateStage2(&response)
if err != nil {
Expand Down