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

support get_remote_id in gothemis #272

Merged
merged 1 commit into from
Dec 29, 2017
Merged
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
16 changes: 16 additions & 0 deletions gothemis/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,3 +193,19 @@ func (ss *SecureSession) Unwrap(data []byte) ([]byte, bool, error) {

return nil, false, errors.New("Failed to unwrap data")
}

func (ss *SecureSession) GetRemoteId()([]byte, error){
// secure_session_get_remote_id
var outLength C.size_t
if C.secure_session_get_remote_id(ss.ctx.session, nil, &outLength) != C.THEMIS_BUFFER_TOO_SMALL{
return nil, errors.NewCallbackError("Failed to get session remote id length")
}
if outLength == 0{
return nil, errors.NewCallbackError("Incorrect remote id length (0)")
}
out := make([]byte, int(outLength))
if C.secure_session_get_remote_id(ss.ctx.session, (*C.uint8_t)(&out[0]), &outLength) != C.THEMIS_SUCCESS{
return nil, errors.NewCallbackError("Failed to get session remote id")
}
return out, nil
}
42 changes: 28 additions & 14 deletions gothemis/session/session_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ type testCallbacks struct {
b *keys.Keypair
}

var clientId = []byte("client a")
var serverId = []byte("client b")

func (clb *testCallbacks) GetPublicKeyForId(ss *SecureSession, id []byte) *keys.PublicKey {
switch {
case 1 == id[0]:
if bytes.Equal(clientId, id){
return clb.a.Public
case 2 == id[0]:
} else if bytes.Equal(serverId, id){
return clb.b.Public
}

return nil
}

Expand Down Expand Up @@ -79,6 +80,16 @@ func clientService(client *SecureSession, ch chan []byte, finCh chan int, t *tes
return
}

remoteId, err := client.GetRemoteId()
if err != nil{
t.Error(err)
return
}
if !bytes.Equal(remoteId, serverId){
t.Error("incorrect remote id")
return
}

if sendPeer {
ch <- buf
continue
Expand Down Expand Up @@ -122,6 +133,15 @@ func serverService(server *SecureSession, ch chan []byte, finCh chan int, t *tes
t.Error(err)
return
}
remoteId, err := server.GetRemoteId()
if err != nil{
t.Error(err)
return
}
if !bytes.Equal(remoteId, clientId){
t.Error("incorrect remote id")
return
}

if !sendPeer {
if server.GetState() != STATE_ESTABLISHED {
Expand Down Expand Up @@ -157,21 +177,15 @@ func testSession(keytype int, t *testing.T) {

clb := &testCallbacks{kpa, kpb}

ida := make([]byte, 1)
ida[0] = 1

idb := make([]byte, 1)
idb[0] = 2

empty_key := keys.PrivateKey{[]byte{}}

client, err := New(ida, nil, clb)
client, err := New(clientId, nil, clb)
if nil == err {
t.Error("Creating Secure session object with empty private key")
return
}

client, err = New(ida, &empty_key, clb)
client, err = New(clientId, &empty_key, clb)
if nil == err {
t.Error("Creating Secure session object with empty private key")
return
Expand All @@ -189,13 +203,13 @@ func testSession(keytype int, t *testing.T) {
return
}

client, err = New(ida, kpa.Private, clb)
client, err = New(clientId, kpa.Private, clb)
if nil != err {
t.Error(err)
return
}

server, err := New(idb, kpb.Private, clb)
server, err := New(serverId, kpb.Private, clb)
if nil != err {
t.Error(err)
return
Expand Down