Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
matrix-org
Olm
Commits
eb7347bb
Commit
eb7347bb
authored
Apr 10, 2019
by
Valere
Browse files
Return string instead of byte array for b64 encoded data
parent
16a28f29
Changes
3
Hide whitespace changes
Inline
Side-by-side
android/olm-sdk/src/androidTest/java/org/matrix/olm/OlmSasTest.java
View file @
eb7347bb
...
...
@@ -72,26 +72,22 @@ public class OlmSasTest {
assertEquals
(
codeLength
,
bob_sas
.
length
);
assertArrayEquals
(
alice_sas
,
bob_sas
);
byte
[]
aliceMac
=
aliceSas
.
calculateMac
(
"Hello world!"
,
"SAS"
);
byte
[]
bobMac
=
bobSas
.
calculateMac
(
"Hello world!"
,
"SAS"
);
String
aliceMac
=
aliceSas
.
calculateMac
(
"Hello world!"
,
"SAS"
);
String
bobMac
=
bobSas
.
calculateMac
(
"Hello world!"
,
"SAS"
);
assertTrue
(
aliceMac
.
length
>
0
&&
bobMac
.
length
>
0
);
assertEquals
(
aliceMac
.
length
,
bobMac
.
length
);
assertArrayEquals
(
aliceMac
,
bobMac
);
assertEquals
(
aliceMac
,
bobMac
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Alice Mac is "
+
new
String
(
aliceMac
,
"UTF-8"
)
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Bob Mac is "
+
new
String
(
bobMac
,
"UTF-8"
)
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Alice Mac is "
+
aliceMac
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Bob Mac is "
+
bobMac
);
byte
[]
aliceLongKdfMac
=
aliceSas
.
calculateMacLongKdf
(
"Hello world!"
,
"SAS"
);
byte
[]
bobLongKdfMac
=
bobSas
.
calculateMacLongKdf
(
"Hello world!"
,
"SAS"
);
String
aliceLongKdfMac
=
aliceSas
.
calculateMacLongKdf
(
"Hello world!"
,
"SAS"
);
String
bobLongKdfMac
=
bobSas
.
calculateMacLongKdf
(
"Hello world!"
,
"SAS"
);
assertTrue
(
aliceLongKdfMac
.
length
>
0
&&
bobLongKdfMac
.
length
>
0
);
assertEquals
(
aliceLongKdfMac
.
length
,
bobLongKdfMac
.
length
);
assertArrayEquals
(
aliceLongKdfMac
,
bobLongKdfMac
);
assertEquals
(
"Mac should be the same"
,
aliceLongKdfMac
,
bobLongKdfMac
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Alice lkdf Mac is "
+
new
String
(
aliceLongKdfMac
,
"UTF-8"
)
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Bob lkdf Mac is "
+
new
String
(
bobLongKdfMac
,
"UTF-8"
)
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Alice lkdf Mac is "
+
aliceLongKdfMac
);
Log
.
e
(
OlmSasTest
.
class
.
getSimpleName
(),
"#### Bob lkdf Mac is "
+
bobLongKdfMac
);
}
catch
(
Exception
e
)
{
...
...
android/olm-sdk/src/main/java/org/matrix/olm/OlmSAS.java
View file @
eb7347bb
...
...
@@ -86,8 +86,7 @@ public class OlmSAS {
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_SAS_MISSING_THEIR_PKEY
,
"call setTheirPublicKey first"
);
}
try
{
byte
[]
shortBuffer
=
generateShortCodeJni
(
info
.
getBytes
(
"UTF-8"
),
byteNumber
);
return
shortBuffer
;
return
generateShortCodeJni
(
info
.
getBytes
(
"UTF-8"
),
byteNumber
);
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## sessionIdentifier(): "
+
e
.
getMessage
());
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_SAS_GENERATE_SHORT_CODE
,
e
.
getMessage
());
...
...
@@ -95,20 +94,24 @@ public class OlmSAS {
}
public
byte
[]
calculateMac
(
String
message
,
String
info
)
throws
OlmException
{
public
String
calculateMac
(
String
message
,
String
info
)
throws
OlmException
{
try
{
return
calculateMacJni
(
message
.
getBytes
(
"UTF-8"
),
info
.
getBytes
(
"UTF-8"
));
byte
[]
bytes
=
calculateMacJni
(
message
.
getBytes
(
"UTF-8"
),
info
.
getBytes
(
"UTF-8"
));
if
(
bytes
!=
null
)
return
new
String
(
bytes
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_SAS_ERROR
,
e
.
getMessage
());
}
return
null
;
}
public
byte
[]
calculateMacLongKdf
(
String
message
,
String
info
)
throws
OlmException
{
public
String
calculateMacLongKdf
(
String
message
,
String
info
)
throws
OlmException
{
try
{
return
calculateMacLongKdfJni
(
message
.
getBytes
(
"UTF-8"
),
info
.
getBytes
(
"UTF-8"
));
byte
[]
bytes
=
calculateMacLongKdfJni
(
message
.
getBytes
(
"UTF-8"
),
info
.
getBytes
(
"UTF-8"
));
if
(
bytes
!=
null
)
return
new
String
(
bytes
,
"UTF-8"
);
}
catch
(
UnsupportedEncodingException
e
)
{
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_SAS_ERROR
,
e
.
getMessage
());
}
return
null
;
}
/**
...
...
android/olm-sdk/src/main/jni/olm_sas.cpp
View file @
eb7347bb
...
...
@@ -148,7 +148,7 @@ JNIEXPORT void OLM_SAS_FUNC_DEF(setTheirPubKey)(JNIEnv *env, jobject thiz,jbyteA
}
else
if
(
!
(
pubKeyPtr
=
env
->
GetByteArrayElements
(
pubKeyBuffer
,
&
pubKeyWasCopied
)))
{
LOGE
(
" ##
generateShortCodeJni
(): failure - info JNI allocation OOM"
);
LOGE
(
" ##
setTheirPubKey
(): failure - info JNI allocation OOM"
);
errorMessage
=
"info JNI allocation OOM"
;
}
else
...
...
@@ -230,7 +230,7 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(generateShortCodeJni)(JNIEnv *env, jobject
JNIEXPORT
jbyteArray
OLM_SAS_FUNC_DEF
(
calculateMacJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
messageBuffer
,
jbyteArray
infoBuffer
)
{
LOGD
(
"## calculateMacJni(): IN"
);
LOGD
(
"## calculateMacJni(): IN"
);
const
char
*
errorMessage
=
NULL
;
jbyteArray
returnValue
=
0
;
OlmSAS
*
sasPtr
=
getOlmSasInstanceId
(
env
,
thiz
);
...
...
@@ -310,7 +310,7 @@ JNIEXPORT jbyteArray OLM_SAS_FUNC_DEF(calculateMacJni)(JNIEnv *env, jobject thiz
}
JNIEXPORT
jbyteArray
OLM_SAS_FUNC_DEF
(
calculateMacLongKdfJni
)(
JNIEnv
*
env
,
jobject
thiz
,
jbyteArray
messageBuffer
,
jbyteArray
infoBuffer
)
{
LOGD
(
"## calculateMacLongKdfJni(): IN"
);
LOGD
(
"## calculateMacLongKdfJni(): IN"
);
const
char
*
errorMessage
=
NULL
;
jbyteArray
returnValue
=
0
;
OlmSAS
*
sasPtr
=
getOlmSasInstanceId
(
env
,
thiz
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment