Skip to content

Commit c39566b

Browse files
committed
Add some checks and public method
1 parent 5194182 commit c39566b

File tree

6 files changed

+56
-25
lines changed

6 files changed

+56
-25
lines changed

libsignal-protocol-dotnet/InvalidMacException.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright (C) 2016 smndtrl, langboost
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -19,7 +19,7 @@
1919

2020
namespace TextSecure.libsignal
2121
{
22-
class InvalidMacException : Exception
22+
public class InvalidMacException : Exception
2323
{
2424

2525
public InvalidMacException(String detailMessage)

libsignal-protocol-dotnet/SessionCipher.cs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,3 @@
1-
/**
2-
* Copyright (C) 2016 smndtrl, langboost
3-
*
4-
* This program is free software: you can redistribute it and/or modify
5-
* it under the terms of the GNU General Public License as published by
6-
* the Free Software Foundation, either version 3 of the License, or
7-
* (at your option) any later version.
8-
*
9-
* This program is distributed in the hope that it will be useful,
10-
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11-
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12-
* GNU General Public License for more details.
13-
*
14-
* You should have received a copy of the GNU General Public License
15-
* along with this program. If not, see <http://www.gnu.org/licenses/>.
16-
*/
17-
181
using libsignal.ecc;
192
using libsignal.exceptions;
203
using libsignal.protocol;
@@ -40,7 +23,7 @@ namespace libsignal
4023
public class SessionCipher
4124
{
4225

43-
public static readonly Object SESSION_LOCK = new Object();
26+
public static readonly object SESSION_LOCK = new object();
4427

4528
private readonly SessionStore sessionStore;
4629
private readonly IdentityKeyStore identityKeyStore;

libsignal-protocol-dotnet/ecc/Curve.cs

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright (C) 2017 smndtrl, langboost, golf1052
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -36,7 +36,7 @@ public static ECKeyPair generateKeyPair()
3636

3737
public static ECPublicKey decodePoint(byte[] bytes, int offset)
3838
{
39-
if (bytes.Length - offset < 1)
39+
if (bytes == null || bytes.Length - offset < 1)
4040
{
4141
throw new InvalidKeyException("No key type identifier");
4242
}
@@ -65,6 +65,16 @@ public static ECPrivateKey decodePrivatePoint(byte[] bytes)
6565

6666
public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey privateKey)
6767
{
68+
if (publicKey == null)
69+
{
70+
throw new InvalidKeyException("public value is null");
71+
}
72+
73+
if (privateKey == null)
74+
{
75+
throw new InvalidKeyException("private value is null");
76+
}
77+
6878
if (publicKey.getType() != privateKey.getType())
6979
{
7080
throw new InvalidKeyException("Public and private keys must be of the same type!");
@@ -84,6 +94,11 @@ public static byte[] calculateAgreement(ECPublicKey publicKey, ECPrivateKey priv
8494

8595
public static bool verifySignature(ECPublicKey signingKey, byte[] message, byte[] signature)
8696
{
97+
if (signingKey == null || message == null || signature == null)
98+
{
99+
throw new InvalidKeyException("Values must not be null");
100+
}
101+
87102
if (signingKey.getType() == DJB_TYPE)
88103
{
89104
return Curve25519.getInstance(Curve25519ProviderType.BEST)
@@ -97,6 +112,11 @@ public static bool verifySignature(ECPublicKey signingKey, byte[] message, byte[
97112

98113
public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)
99114
{
115+
if (signingKey == null || message == null)
116+
{
117+
throw new InvalidKeyException("Values must not be null");
118+
}
119+
100120
if (signingKey.getType() == DJB_TYPE)
101121
{
102122
return Curve25519.getInstance(Curve25519ProviderType.BEST)
@@ -110,6 +130,11 @@ public static byte[] calculateSignature(ECPrivateKey signingKey, byte[] message)
110130

111131
public static byte[] calculateVrfSignature(ECPrivateKey signingKey, byte[] message)
112132
{
133+
if (signingKey == null || message == null)
134+
{
135+
throw new InvalidKeyException("Values must not be null");
136+
}
137+
113138
if (signingKey.getType() == DJB_TYPE)
114139
{
115140
return Curve25519.getInstance(Curve25519ProviderType.BEST)
@@ -123,6 +148,11 @@ public static byte[] calculateVrfSignature(ECPrivateKey signingKey, byte[] messa
123148

124149
public static byte[] verifyVrfSignature(ECPublicKey signingKey, byte[] message, byte[] signature)
125150
{
151+
if (signingKey == null || message == null || signature == null)
152+
{
153+
throw new InvalidKeyException("Values must not be null");
154+
}
155+
126156
if (signingKey.getType() == DJB_TYPE)
127157
{
128158
return Curve25519.getInstance(Curve25519ProviderType.BEST)

libsignal-protocol-dotnet/state/IdentityKeyStore.cs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright (C) 2016 smndtrl, langboost
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -82,5 +82,12 @@ public interface IdentityKeyStore
8282
*/
8383
bool IsTrustedIdentity(SignalProtocolAddress address, IdentityKey identityKey, Direction direction);
8484

85+
/// <summary>
86+
/// Return the saved public identity key for a remote client
87+
/// </summary>
88+
/// <param name="address">The address of the remote client</param>
89+
/// <returns>The public identity key, or null if absent</returns>
90+
IdentityKey GetIdentity(SignalProtocolAddress address);
91+
8592
}
8693
}

libsignal-protocol-dotnet/state/impl/InMemoryIdentityKeyStore.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright (C) 2016 smndtrl, langboost
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -73,5 +73,11 @@ public bool IsTrustedIdentity(SignalProtocolAddress address, IdentityKey identit
7373
trustedKeys.TryGetValue(address, out trusted); // get(name)
7474
return (trusted == null || trusted.Equals(identityKey));
7575
}
76+
77+
public IdentityKey GetIdentity(SignalProtocolAddress address)
78+
{
79+
trustedKeys.TryGetValue(address, out var identity);
80+
return identity;
81+
}
7682
}
7783
}

libsignal-protocol-dotnet/state/impl/InMemorySignalProtocolStore.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/**
1+
/**
22
* Copyright (C) 2016 smndtrl, langboost
33
*
44
* This program is free software: you can redistribute it and/or modify
@@ -147,5 +147,10 @@ public void RemoveSignedPreKey(uint signedPreKeyId)
147147
{
148148
signedPreKeyStore.RemoveSignedPreKey(signedPreKeyId);
149149
}
150+
151+
public IdentityKey GetIdentity(SignalProtocolAddress address)
152+
{
153+
return identityKeyStore.GetIdentity(address);
154+
}
150155
}
151156
}

0 commit comments

Comments
 (0)