-
Notifications
You must be signed in to change notification settings - Fork 83
Expand file tree
/
Copy pathIE2eEndpoint.cs
More file actions
220 lines (193 loc) · 5.96 KB
/
IE2eEndpoint.cs
File metadata and controls
220 lines (193 loc) · 5.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
using System;
using System.IO;
using System.Text;
using System.Xml;
namespace Waher.Networking.XMPP
{
/// <summary>
/// Abstract base class for End-to-End encryption schemes.
/// </summary>
public interface IE2eEndpoint : IDisposable
{
/// <summary>
/// Security strength of End-to-End encryption scheme.
/// </summary>
int SecurityStrength
{
get;
}
/// <summary>
/// Local name of the E2E endpoint
/// </summary>
string LocalName
{
get;
}
/// <summary>
/// Namespace of the E2E endpoint
/// </summary>
string Namespace
{
get;
}
/// <summary>
/// Previous keys.
/// </summary>
IE2eEndpoint Previous
{
get;
set;
}
/// <summary>
/// Remote public key.
/// </summary>
byte[] PublicKey
{
get;
}
/// <summary>
/// Remote public key, as a Base64 string.
/// </summary>
string PublicKeyBase64
{
get;
}
/// <summary>
/// Creates a new key.
/// </summary>
/// <param name="SecurityStrength">Overall desired security strength, if applicable.</param>
/// <returns>New E2E endpoint.</returns>
IE2eEndpoint Create(int SecurityStrength);
/// <summary>
/// Creates a new endpoint given a private key.
/// </summary>
/// <param name="Secret">Secret.</param>
/// <returns>Endpoint object.</returns>
IE2eEndpoint CreatePrivate(byte[] Secret);
/// <summary>
/// Creates a new endpoint given a public key.
/// </summary>
/// <param name="PublicKey">Remote public key.</param>
/// <returns>Endpoint object.</returns>
IE2eEndpoint CreatePublic(byte[] PublicKey);
/// <summary>
/// Parses endpoint information from an XML element.
/// </summary>
/// <param name="Xml">XML element.</param>
/// <returns>Parsed key information, if possible, null if XML is not well-defined.</returns>
IE2eEndpoint Parse(XmlElement Xml);
/// <summary>
/// Exports the public key information to XML.
/// </summary>
string ToXml();
/// <summary>
/// Exports the public key information to XML.
/// </summary>
/// <param name="ParentNamespace">Namespace of parent element.</param>
string ToXml(string ParentNamespace);
/// <summary>
/// Exports the public key information to XML.
/// </summary>
/// <param name="Xml">XML output</param>
/// <param name="ParentNamespace">Namespace of parent element.</param>
void ToXml(StringBuilder Xml, string ParentNamespace);
/// <summary>
/// Gets a shared secret for encryption, and optionally a corresponding cipher text.
/// </summary>
/// <param name="RemoteEndpoint">Remote endpoint</param>
/// <param name="Cipher">Symmetric cipher to use for encryption.</param>
/// <param name="CipherText">Optional cipher text required by the recipient to
/// be able to generate the same shared secret.</param>
/// <returns>Shared secret.</returns>
byte[] GetSharedSecretForEncryption(IE2eEndpoint RemoteEndpoint,
IE2eSymmetricCipher Cipher, out byte[] CipherText);
/// <summary>
/// Gets a shared secret for decryption.
/// </summary>
/// <param name="RemoteEndpoint">Remote endpoint</param>
/// <param name="CipherText">Optional cipher text required by the recipient to
/// be able to generate the same shared secret.</param>
/// <returns>Shared secret.</returns>
byte[] GetSharedSecretForDecryption(IE2eEndpoint RemoteEndpoint, byte[] CipherText);
/// <summary>
/// If the recipient needs a cipher text to generate the same shared secret.
/// </summary>
bool SharedSecretUseCipherText
{
get;
}
/// <summary>
/// If signatures are supported.
/// </summary>
bool SupportsSignatures
{
get;
}
/// <summary>
/// Signs binary data using the local private key.
/// </summary>
/// <param name="Data">Binary data</param>
/// <returns>Digital signature.</returns>
byte[] Sign(byte[] Data);
/// <summary>
/// Signs binary data using the local private key.
/// </summary>
/// <param name="Data">Binary data</param>
/// <returns>Digital signature.</returns>
byte[] Sign(Stream Data);
/// <summary>
/// Verifies a signature.
/// </summary>
/// <param name="Data">Data that is signed.</param>
/// <param name="Signature">Digital signature.</param>
/// <returns>If signature is valid.</returns>
bool Verify(byte[] Data, byte[] Signature);
/// <summary>
/// Verifies a signature.
/// </summary>
/// <param name="Data">Data that is signed.</param>
/// <param name="Signature">Digital signature.</param>
/// <returns>If signature is valid.</returns>
bool Verify(Stream Data, byte[] Signature);
/// <summary>
/// If endpoint is considered safe (i.e. there are no suspected backdoors)
/// </summary>
bool Safe
{
get;
}
/// <summary>
/// If implementation is slow, compared to other options.
/// </summary>
bool Slow
{
get;
}
/// <summary>
/// If post-quantum cryptography is used.
/// </summary>
bool PostQuantumCryptography
{
get;
}
/// <summary>
/// Provides a score for the endpoint. More features, higher score (comparable to alternatives with the same security strength).
/// </summary>
int Score
{
get;
}
/// <summary>
/// Default symmetric cipher.
/// </summary>
IE2eSymmetricCipher DefaultSymmetricCipher
{
get;
}
/// <summary>
/// Gets the next counter value.
/// </summary>
/// <returns>Counter value.</returns>
uint GetNextCounter();
}
}