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
f257580c
Commit
f257580c
authored
Jan 09, 2017
by
ylecollen
Browse files
verifyEd25519Signature triggers an exception instead of filling an error buffer
parent
03396102
Changes
3
Hide whitespace changes
Inline
Side-by-side
java/android/OlmLibSdk/olm-sdk/src/androidTest/java/org/matrix/olm/OlmUtilityTest.java
View file @
f257580c
...
@@ -58,7 +58,7 @@ public class OlmUtilityTest {
...
@@ -58,7 +58,7 @@ public class OlmUtilityTest {
@Test
@Test
public
void
test01VerifyEd25519Signing
()
{
public
void
test01VerifyEd25519Signing
()
{
String
fingerPrintKey
=
null
;
String
fingerPrintKey
=
null
;
String
Buffer
errorMsg
=
n
ew
StringBuffer
()
;
String
errorMsg
=
n
ull
;
String
message
=
"{\"algorithms\":[\"m.megolm.v1.aes-sha2\",\"m.olm.v1.curve25519-aes-sha2\"],\"device_id\":\"YMBYCWTWCG\",\"keys\":{\"curve25519:YMBYCWTWCG\":\"KZFa5YUXV2EOdhK8dcGMMHWB67stdgAP4+xwiS69mCU\",\"ed25519:YMBYCWTWCG\":\"0cEgQJJqjgtXUGp4ZXQQmh36RAxwxr8HJw2E9v1gvA0\"},\"user_id\":\"@mxBob14774891254276b253f42-f267-43ec-bad9-767142bfea30:localhost:8480\"}"
;
String
message
=
"{\"algorithms\":[\"m.megolm.v1.aes-sha2\",\"m.olm.v1.curve25519-aes-sha2\"],\"device_id\":\"YMBYCWTWCG\",\"keys\":{\"curve25519:YMBYCWTWCG\":\"KZFa5YUXV2EOdhK8dcGMMHWB67stdgAP4+xwiS69mCU\",\"ed25519:YMBYCWTWCG\":\"0cEgQJJqjgtXUGp4ZXQQmh36RAxwxr8HJw2E9v1gvA0\"},\"user_id\":\"@mxBob14774891254276b253f42-f267-43ec-bad9-767142bfea30:localhost:8480\"}"
;
OlmAccount
account
=
null
;
OlmAccount
account
=
null
;
...
@@ -98,22 +98,43 @@ public class OlmUtilityTest {
...
@@ -98,22 +98,43 @@ public class OlmUtilityTest {
OlmUtility
utility
=
new
OlmUtility
();
OlmUtility
utility
=
new
OlmUtility
();
// verify signature
// verify signature
errorMsg
.
append
(
"init with anything"
);
boolean
isVerified
;
boolean
isVerified
=
utility
.
verifyEd25519Signature
(
messageSignature
,
fingerPrintKey
,
message
,
errorMsg
);
isVerified
=
false
;
errorMsg
=
null
;
try
{
isVerified
=
utility
.
verifyEd25519Signature
(
messageSignature
,
fingerPrintKey
,
message
);
}
catch
(
Exception
e
)
{
errorMsg
=
e
.
getMessage
();
}
assertTrue
(
isVerified
);
assertTrue
(
isVerified
);
assertTrue
(
String
.
valueOf
(
errorMsg
)
.
isEmpty
());
assertTrue
(
TextUtils
.
isEmpty
(
errorMsg
));
// check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC
// check a bad signature is detected => errorMsg = BAD_MESSAGE_MAC
String
badSignature
=
"Bad signature Bad signature Bad signature.."
;
String
badSignature
=
"Bad signature Bad signature Bad signature.."
;
isVerified
=
utility
.
verifyEd25519Signature
(
badSignature
,
fingerPrintKey
,
message
,
errorMsg
);
isVerified
=
false
;
errorMsg
=
null
;
try
{
isVerified
=
utility
.
verifyEd25519Signature
(
badSignature
,
fingerPrintKey
,
message
);
}
catch
(
Exception
e
)
{
errorMsg
=
e
.
getMessage
();
}
assertFalse
(
isVerified
);
assertFalse
(
isVerified
);
assert
False
(
String
.
valueOf
(
errorMsg
)
.
isEmpty
());
assert
True
(!
TextUtils
.
isEmpty
(
errorMsg
));
// check bad fingerprint size => errorMsg = INVALID_BASE64
// check bad fingerprint size => errorMsg = INVALID_BASE64
String
badSizeFingerPrintKey
=
fingerPrintKey
.
substring
(
fingerPrintKey
.
length
()/
2
);
String
badSizeFingerPrintKey
=
fingerPrintKey
.
substring
(
fingerPrintKey
.
length
()/
2
);
isVerified
=
utility
.
verifyEd25519Signature
(
messageSignature
,
badSizeFingerPrintKey
,
message
,
errorMsg
);
isVerified
=
false
;
errorMsg
=
null
;
try
{
isVerified
=
utility
.
verifyEd25519Signature
(
messageSignature
,
badSizeFingerPrintKey
,
message
);
}
catch
(
Exception
e
)
{
errorMsg
=
e
.
getMessage
();
}
assertFalse
(
isVerified
);
assertFalse
(
isVerified
);
assert
False
(
String
.
valueOf
(
errorMsg
)
.
isEmpty
());
assert
True
(!
TextUtils
.
isEmpty
(
errorMsg
));
utility
.
releaseUtility
();
utility
.
releaseUtility
();
assertTrue
(
utility
.
isReleased
());
assertTrue
(
utility
.
isReleased
());
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmException.java
View file @
f257580c
...
@@ -27,33 +27,35 @@ public class OlmException extends IOException {
...
@@ -27,33 +27,35 @@ public class OlmException extends IOException {
public
static
final
int
EXCEPTION_CODE_INIT_ACCOUNT_CREATION
=
10
;
public
static
final
int
EXCEPTION_CODE_INIT_ACCOUNT_CREATION
=
10
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_SERIALIZATION
=
2
0
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_SERIALIZATION
=
10
0
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_DESERIALIZATION
=
2
1
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_DESERIALIZATION
=
10
1
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_IDENTITY_KEYS
=
2
2
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_IDENTITY_KEYS
=
10
2
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_GENERATE_ONE_TIME_KEYS
=
2
3
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_GENERATE_ONE_TIME_KEYS
=
10
3
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_ONE_TIME_KEYS
=
2
4
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_ONE_TIME_KEYS
=
10
4
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS
=
2
5
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_REMOVE_ONE_TIME_KEYS
=
10
5
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED
=
2
6
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_MARK_ONE_KEYS_AS_PUBLISHED
=
10
6
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE
=
2
7
;
public
static
final
int
EXCEPTION_CODE_ACCOUNT_SIGN_MESSAGE
=
10
7
;
public
static
final
int
EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION
=
3
0
;
public
static
final
int
EXCEPTION_CODE_CREATE_INBOUND_GROUP_SESSION
=
20
0
;
public
static
final
int
EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION
=
3
1
;
public
static
final
int
EXCEPTION_CODE_INIT_INBOUND_GROUP_SESSION
=
20
1
;
public
static
final
int
EXCEPTION_CODE_INBOUND_GROUP_SESSION_IDENTIFIER
=
3
2
;
public
static
final
int
EXCEPTION_CODE_INBOUND_GROUP_SESSION_IDENTIFIER
=
20
2
;
public
static
final
int
EXCEPTION_CODE_INBOUND_GROUP_SESSION_DECRYPT_SESSION
=
3
3
;
public
static
final
int
EXCEPTION_CODE_INBOUND_GROUP_SESSION_DECRYPT_SESSION
=
20
3
;
public
static
final
int
EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION
=
4
0
;
public
static
final
int
EXCEPTION_CODE_CREATE_OUTBOUND_GROUP_SESSION
=
30
0
;
public
static
final
int
EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION
=
4
1
;
public
static
final
int
EXCEPTION_CODE_INIT_OUTBOUND_GROUP_SESSION
=
30
1
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER
=
4
2
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_IDENTIFIER
=
30
2
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY
=
4
3
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_SESSION_KEY
=
30
3
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE
=
4
4
;
public
static
final
int
EXCEPTION_CODE_OUTBOUND_GROUP_ENCRYPT_MESSAGE
=
30
4
;
public
static
final
int
EXCEPTION_CODE_INIT_SESSION_CREATION
=
50
;
public
static
final
int
EXCEPTION_CODE_INIT_SESSION_CREATION
=
400
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_OUTBOUND_SESSION
=
51
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_OUTBOUND_SESSION
=
401
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION
=
52
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION
=
402
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION_FROM
=
53
;
public
static
final
int
EXCEPTION_CODE_SESSION_INIT_INBOUND_SESSION_FROM
=
403
;
public
static
final
int
EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE
=
54
;
public
static
final
int
EXCEPTION_CODE_SESSION_ENCRYPT_MESSAGE
=
404
;
public
static
final
int
EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE
=
55
;
public
static
final
int
EXCEPTION_CODE_SESSION_DECRYPT_MESSAGE
=
405
;
public
static
final
int
EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER
=
56
;
public
static
final
int
EXCEPTION_CODE_SESSION_SESSION_IDENTIFIER
=
406
;
public
static
final
int
EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE
=
500
;
// exception human readable messages
// exception human readable messages
public
static
final
String
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
=
"createNewSession() failed"
;
public
static
final
String
EXCEPTION_MSG_NEW_OUTBOUND_GROUP_SESSION
=
"createNewSession() failed"
;
...
...
java/android/OlmLibSdk/olm-sdk/src/main/java/org/matrix/olm/OlmUtility.java
View file @
f257580c
...
@@ -70,33 +70,28 @@ public class OlmUtility {
...
@@ -70,33 +70,28 @@ public class OlmUtility {
* @param aSignature the base64-encoded message signature to be checked.
* @param aSignature the base64-encoded message signature to be checked.
* @param aFingerprintKey the ed25519 key (fingerprint key)
* @param aFingerprintKey the ed25519 key (fingerprint key)
* @param aMessage the signed message
* @param aMessage the signed message
* @param aError error message description
* @return true if the signature is verified, false otherwise
* @return true if the signature is verified, false otherwise
* @exception OlmException the failure reason
*/
*/
public
boolean
verifyEd25519Signature
(
String
aSignature
,
String
aFingerprintKey
,
String
aMessage
,
StringBuffer
aError
)
{
public
boolean
verifyEd25519Signature
(
String
aSignature
,
String
aFingerprintKey
,
String
aMessage
)
throws
OlmException
{
boolean
retCode
=
false
;
String
errorMessage
=
null
;
String
jniError
;
try
{
if
(
null
==
aError
)
{
if
(
TextUtils
.
isEmpty
(
aSignature
)
||
TextUtils
.
isEmpty
(
aFingerprintKey
)
||
TextUtils
.
isEmpty
(
aMessage
))
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): invalid input error parameter"
);
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): invalid input parameters"
);
}
else
{
errorMessage
=
"JAVA sanity check failure - invalid input parameters"
;
aError
.
setLength
(
0
);
}
else
{
errorMessage
=
verifyEd25519SignatureJni
(
aSignature
.
getBytes
(
"UTF-8"
),
aFingerprintKey
.
getBytes
(
"UTF-8"
),
aMessage
.
getBytes
(
"UTF-8"
));
try
{
if
(
TextUtils
.
isEmpty
(
aSignature
)
||
TextUtils
.
isEmpty
(
aFingerprintKey
)
||
TextUtils
.
isEmpty
(
aMessage
))
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): invalid input parameters"
);
aError
.
append
(
"JAVA sanity check failure - invalid input parameters"
);
}
else
if
(
null
==
(
jniError
=
verifyEd25519SignatureJni
(
aSignature
.
getBytes
(
"UTF-8"
),
aFingerprintKey
.
getBytes
(
"UTF-8"
),
aMessage
.
getBytes
(
"UTF-8"
))))
{
retCode
=
true
;
}
else
{
aError
.
append
(
jniError
);
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): failed "
+
e
.
getMessage
());
}
}
}
catch
(
Exception
e
)
{
Log
.
e
(
LOG_TAG
,
"## verifyEd25519Signature(): failed "
+
e
.
getMessage
());
}
}
return
retCode
;
if
(!
TextUtils
.
isEmpty
(
errorMessage
))
{
throw
new
OlmException
(
OlmException
.
EXCEPTION_CODE_UTILITY_VERIFY_SIGNATURE
,
errorMessage
);
}
return
true
;
}
}
/**
/**
...
...
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