ENABLE X3DH WITH ED25519 KEYS
This commit is contained in:
parent
0565cdef81
commit
34df73c929
21
LICENSE.md
Normal file
21
LICENSE.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2022 Alexander "PapaTutuWawa"
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
41
README.md
41
README.md
@ -1,39 +1,4 @@
|
|||||||
<!--
|
# omemo_dart
|
||||||
This README describes the package. If you publish this package to pub.dev,
|
|
||||||
this README's contents appear on the landing page for your package.
|
|
||||||
|
|
||||||
For information about how to write a good package README, see the guide for
|
Hopefully, a library enabling developers to build OMEMO-supporting
|
||||||
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
|
XMPP clients in Dart and Flutter.
|
||||||
|
|
||||||
For general information about developing packages, see the Dart guide for
|
|
||||||
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
|
|
||||||
and the Flutter guide for
|
|
||||||
[developing packages and plugins](https://flutter.dev/developing-packages).
|
|
||||||
-->
|
|
||||||
|
|
||||||
TODO: Put a short description of the package here that helps potential users
|
|
||||||
know whether this package might be useful for them.
|
|
||||||
|
|
||||||
## Features
|
|
||||||
|
|
||||||
TODO: List what your package can do. Maybe include images, gifs, or videos.
|
|
||||||
|
|
||||||
## Getting started
|
|
||||||
|
|
||||||
TODO: List prerequisites and provide or point to information on how to
|
|
||||||
start using the package.
|
|
||||||
|
|
||||||
## Usage
|
|
||||||
|
|
||||||
TODO: Include short and useful examples for package users. Add longer examples
|
|
||||||
to `/example` folder.
|
|
||||||
|
|
||||||
```dart
|
|
||||||
const like = 'sample';
|
|
||||||
```
|
|
||||||
|
|
||||||
## Additional information
|
|
||||||
|
|
||||||
TODO: Tell users more about the package: where to find more information, how to
|
|
||||||
contribute to the package, how to file issues, what response they can expect
|
|
||||||
from the package authors, and more.
|
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
|
import 'dart:typed_data';
|
||||||
import 'package:cryptography/cryptography.dart';
|
import 'package:cryptography/cryptography.dart';
|
||||||
import 'package:cryptography/dart.dart';
|
import 'package:pinenacl/api.dart';
|
||||||
|
import 'package:pinenacl/tweetnacl.dart';
|
||||||
|
|
||||||
/// The overarching assumption is that we use Ed25519 keys for the identity keys
|
/// The overarching assumption is that we use Ed25519 keys for the identity keys
|
||||||
|
|
||||||
@ -31,15 +33,31 @@ Future<List<int>> dh(SimpleKeyPair kp, SimplePublicKey pk, int identityKey) asyn
|
|||||||
var ckp = kp;
|
var ckp = kp;
|
||||||
var cpk = pk;
|
var cpk = pk;
|
||||||
|
|
||||||
/*
|
|
||||||
if (identityKey == 1) {
|
if (identityKey == 1) {
|
||||||
final pkc = await DartEd25519.publicKeyToCurve25519(kp);
|
final pubkeyBytes = (await kp.extractPublicKey()).bytes;
|
||||||
final skc = await DartEd25519.privateKeyToCurve25519(kp);
|
final pkc = Uint8List(32);
|
||||||
ckp = SimpleKeyPairData(skc, publicKey: pkc, type: KeyPairType.x25519);
|
TweetNaClExt.crypto_sign_ed25519_pk_to_x25519_pk(pkc, Uint8List.fromList(pubkeyBytes));
|
||||||
|
|
||||||
|
final keyPairData = await kp.extract();
|
||||||
|
final privateKeyBytes = await keyPairData.extractPrivateKeyBytes();
|
||||||
|
final skc = Uint8List(32);
|
||||||
|
TweetNaClExt.crypto_sign_ed25519_sk_to_x25519_sk(skc, Uint8List.fromList(privateKeyBytes));
|
||||||
|
|
||||||
|
ckp = SimpleKeyPairData(
|
||||||
|
List<int>.from(skc),
|
||||||
|
publicKey: SimplePublicKey(List<int>.from(pkc), type: KeyPairType.x25519),
|
||||||
|
type: KeyPairType.x25519,
|
||||||
|
);
|
||||||
} else if (identityKey == 2) {
|
} else if (identityKey == 2) {
|
||||||
cpk = await DartEd25519.publicKeyToCurve25519(fromPublicKey(pk));
|
final pubkeyBytes = pk.bytes;
|
||||||
|
final pkc = Uint8List(32);
|
||||||
|
TweetNaClExt.crypto_sign_ed25519_pk_to_x25519_pk(pkc, Uint8List.fromList(pubkeyBytes));
|
||||||
|
|
||||||
|
cpk = SimplePublicKey(
|
||||||
|
List<int>.from(pkc),
|
||||||
|
type: KeyPairType.x25519,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
final shared = await Cryptography.instance.x25519().sharedSecretKey(
|
final shared = await Cryptography.instance.x25519().sharedSecretKey(
|
||||||
keyPair: ckp,
|
keyPair: ckp,
|
||||||
|
@ -8,7 +8,6 @@ environment:
|
|||||||
|
|
||||||
dependencies:
|
dependencies:
|
||||||
cryptography:
|
cryptography:
|
||||||
path: ../cryptography/cryptography
|
|
||||||
pinenacl:
|
pinenacl:
|
||||||
|
|
||||||
dev_dependencies:
|
dev_dependencies:
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import 'package:cryptography/cryptography.dart';
|
import 'package:cryptography/cryptography.dart';
|
||||||
import 'package:cryptography/dart.dart';
|
|
||||||
import 'package:test/test.dart';
|
import 'package:test/test.dart';
|
||||||
import 'package:omemo_dart/src/x3dh/x3dh.dart';
|
import 'package:omemo_dart/src/x3dh/x3dh.dart';
|
||||||
|
|
||||||
@ -8,26 +7,14 @@ Future<List<int>> publicKeyBytes(SimpleKeyPair kp) async {
|
|||||||
return pk.bytes;
|
return pk.bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<SimplePublicKey> publicKey(SimpleKeyPair kp) async {
|
|
||||||
//return await DartEd25519.publicKeyToCurve25519(kp);
|
|
||||||
return kp.extractPublicKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<SimpleKeyPair> toCurve(SimpleKeyPair kp) async {
|
|
||||||
//final pk = await DartEd25519.publicKeyToCurve25519(kp);
|
|
||||||
//final sk = await DartEd25519.privateKeyToCurve25519(kp);
|
|
||||||
//return SimpleKeyPairData(sk, publicKey: pk, type: KeyPairType.x25519);
|
|
||||||
return kp;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
test("X3DH", () async {
|
test("X3DH", () async {
|
||||||
final ed = Ed25519();
|
final ed = Ed25519();
|
||||||
final x = Cryptography.instance.x25519();
|
final x = Cryptography.instance.x25519();
|
||||||
|
|
||||||
// Generate IKs for Alice and Bob
|
// Generate IKs for Alice and Bob
|
||||||
final ikAlice = await x.newKeyPair();
|
final ikAlice = await ed.newKeyPair();
|
||||||
final ikBob = await x.newKeyPair();
|
final ikBob = await ed.newKeyPair();
|
||||||
|
|
||||||
// Generate SPKs for Alice and Bob
|
// Generate SPKs for Alice and Bob
|
||||||
final spkAlice = await x.newKeyPair();
|
final spkAlice = await x.newKeyPair();
|
||||||
|
Loading…
Reference in New Issue
Block a user