Example #1
0
// SendAuthenticationResult responds to an existed authentication Proof
// Prerequisites:
//              * Must have previously connected to a service
//              * channel must be of type auth
func (oc *OpenConnection) SendAuthenticationResult(channel int32, accepted bool, isKnownContact bool) {
	defer utils.RecoverFromError()
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.AuthResult(accepted, isKnownContact)
	utils.CheckError(err)
	oc.rni.SendRicochetPacket(oc.conn, channel, data)
}
Example #2
0
// SendMessage sends a Chat Message (message) to a give Channel (channel).
// Prerequisites:
//             * Must have previously connected and authenticated to a service
//             * Must have established a known contact status with the other service
//             * Must have previously opened channel with OpenChanel of type im.ricochet.chat
func (oc *OpenConnection) SendMessage(channel int32, message string) {
	defer utils.RecoverFromError()
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.ChatMessage(message, 0)
	utils.CheckError(err)
	oc.rni.SendRicochetPacket(oc.conn, channel, data)
}
Example #3
0
// RejectOpenChannel acknowledges a rejects a previously received open channel message
// Prerequisites:
//             * Must have previously connected
func (oc *OpenConnection) RejectOpenChannel(channel int32, errortype string) {
	defer utils.RecoverFromError()
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.RejectOpenChannel(channel, errortype)
	utils.CheckError(err)

	oc.rni.SendRicochetPacket(oc.conn, 0, data)
}
Example #4
0
// OpenChatChannel opens a new chat channel with the given id
// Prerequisites:
//              * Must have previously connected to a service
//              * If acting as the client, id must be odd, else even
func (oc *OpenConnection) OpenChatChannel(channel int32) {
	defer utils.RecoverFromError()
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.OpenChannel(channel, "im.ricochet.chat")
	utils.CheckError(err)

	oc.setChannel(channel, "im.ricochet.chat")
	oc.rni.SendRicochetPacket(oc.conn, 0, data)
}
Example #5
0
// AckContactRequest responds to contact request from a client
// Prerequisites:
//             * Must have previously connected and authenticated to a service
//             * Must have previously received a Contact Request
func (oc *OpenConnection) AckContactRequest(channel int32, status string) {
	defer utils.RecoverFromError()

	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.ReplyToContactRequest(channel, status)
	utils.CheckError(err)

	oc.setChannel(channel, "im.ricochet.contact.request")
	oc.rni.SendRicochetPacket(oc.conn, channel, data)
}
Example #6
0
// SendContactRequest initiates a contact request to the server.
// Prerequisites:
//             * Must have previously connected and authenticated to a service
func (oc *OpenConnection) SendContactRequest(channel int32, nick string, message string) {
	defer utils.RecoverFromError()

	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.OpenContactRequestChannel(channel, nick, message)
	utils.CheckError(err)

	oc.setChannel(channel, "im.ricochet.contact.request")
	oc.rni.SendRicochetPacket(oc.conn, 0, data)
}
Example #7
0
// Authenticate opens an Authentication Channel and send a client cookie
// Prerequisites:
//              * Must have previously connected to a service
func (oc *OpenConnection) Authenticate(channel int32) {
	defer utils.RecoverFromError()

	oc.authHandler[channel] = new(AuthenticationHandler)
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.OpenAuthenticationChannel(channel, oc.authHandler[channel].GenClientCookie())
	utils.CheckError(err)

	oc.setChannel(channel, "im.ricochet.auth.hidden-service")
	oc.rni.SendRicochetPacket(oc.conn, 0, data)
}
Example #8
0
// SendProof sends an authentication proof in response to a challenge.
// Prerequisites:
//              * Must have previously connected to a service
//              * channel must be of type auth
func (oc *OpenConnection) SendProof(channel int32, serverCookie [16]byte, publicKeyBytes []byte, privateKey *rsa.PrivateKey) {

	if oc.authHandler[channel] == nil {
		return // NoOp
	}

	oc.authHandler[channel].AddServerCookie(serverCookie[:])

	challenge := oc.authHandler[channel].GenChallenge(oc.MyHostname, oc.OtherHostname)
	signature, _ := rsa.SignPKCS1v15(nil, privateKey, crypto.SHA256, challenge)

	defer utils.RecoverFromError()
	messageBuilder := new(MessageBuilder)
	data, err := messageBuilder.Proof(publicKeyBytes, signature)
	utils.CheckError(err)

	oc.rni.SendRicochetPacket(oc.conn, channel, data)
}