|
@@ -1,5 +1,5 @@
|
|
|
using Invercargill;
|
|
using Invercargill;
|
|
|
-using Invercargill.Convert;
|
|
|
|
|
|
|
+using Invercargill.DataStructures;
|
|
|
|
|
|
|
|
namespace Ppub {
|
|
namespace Ppub {
|
|
|
|
|
|
|
@@ -135,12 +135,12 @@ namespace Ppub {
|
|
|
|
|
|
|
|
// Verify authoratative section
|
|
// Verify authoratative section
|
|
|
if(verify) {
|
|
if(verify) {
|
|
|
- var checksum = new BinaryData.from_byte_array(get_string_checksum(signed_portion));
|
|
|
|
|
|
|
+ var checksum = Wrap.byte_array(get_string_checksum(signed_portion));
|
|
|
var signed_checksum = Sodium.Asymmetric.Signing.verify(collection_signature, id);
|
|
var signed_checksum = Sodium.Asymmetric.Signing.verify(collection_signature, id);
|
|
|
if(signed_checksum == null) {
|
|
if(signed_checksum == null) {
|
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Could not verify authoratative signature");
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Could not verify authoratative signature");
|
|
|
}
|
|
}
|
|
|
- if(!checksum.equals(ate(signed_checksum))) {
|
|
|
|
|
|
|
+ if(!checksum.equals(Wrap.array(signed_checksum))) {
|
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Authoratative signature checksum does not match calculated checksum");
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Authoratative signature checksum does not match calculated checksum");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -180,7 +180,7 @@ namespace Ppub {
|
|
|
if(signed_checksum == null) {
|
|
if(signed_checksum == null) {
|
|
|
throw new CollectionError.INVALID_SHARED_SIGNATURE("Could not verify shared signature");
|
|
throw new CollectionError.INVALID_SHARED_SIGNATURE("Could not verify shared signature");
|
|
|
}
|
|
}
|
|
|
- if(!checksum.equals(ate(signed_checksum))) {
|
|
|
|
|
|
|
+ if(!checksum.equals(Wrap.array(signed_checksum))) {
|
|
|
throw new CollectionError.INVALID_SHARED_SIGNATURE("Shared signature checksum does not match calculated checksum");
|
|
throw new CollectionError.INVALID_SHARED_SIGNATURE("Shared signature checksum does not match calculated checksum");
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -244,12 +244,12 @@ namespace Ppub {
|
|
|
return @"$authoritative_section\n$shared_section\nSSG $(Base64.encode(shared_signature))";
|
|
return @"$authoritative_section\n$shared_section\nSSG $(Base64.encode(shared_signature))";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- private BinaryData get_checksum() {
|
|
|
|
|
- return new BinaryData.from_byte_array(get_string_checksum(@"$authoritative_section\n$shared_section"));
|
|
|
|
|
|
|
+ private ReadOnlyAddressableBytes get_checksum() {
|
|
|
|
|
+ return Wrap.byte_array(get_string_checksum(@"$authoritative_section\n$shared_section"));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
internal static uint8[] get_string_checksum(string data) {
|
|
internal static uint8[] get_string_checksum(string data) {
|
|
|
- var signed_data = new BinaryData();
|
|
|
|
|
|
|
+ var signed_data = new ByteComposition();
|
|
|
signed_data.append_string(data);
|
|
signed_data.append_string(data);
|
|
|
var checksum_calculator = new Checksum(ChecksumType.SHA512);
|
|
var checksum_calculator = new Checksum(ChecksumType.SHA512);
|
|
|
var arr = signed_data.to_array();
|
|
var arr = signed_data.to_array();
|
|
@@ -358,7 +358,7 @@ namespace Ppub {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
public string to_string() {
|
|
public string to_string() {
|
|
|
- var combined = new BinaryData.from_byte_array(signing_key);
|
|
|
|
|
|
|
+ var combined = new ByteComposition.from_byte_array(signing_key);
|
|
|
combined.append_byte_array(sealing_key);
|
|
combined.append_byte_array(sealing_key);
|
|
|
return @"CLMPK:$(Base64.encode(combined.to_array()))";
|
|
return @"CLMPK:$(Base64.encode(combined.to_array()))";
|
|
|
}
|
|
}
|
|
@@ -481,7 +481,7 @@ namespace Ppub {
|
|
|
private void sign(CollectionMemberCredentials member_credentials) {
|
|
private void sign(CollectionMemberCredentials member_credentials) {
|
|
|
var signed_portion = get_signed_portion();
|
|
var signed_portion = get_signed_portion();
|
|
|
var line_checksum = Collection.get_string_checksum(signed_portion);
|
|
var line_checksum = Collection.get_string_checksum(signed_portion);
|
|
|
- var to_sign = new BinaryData.from_byte_array(line_checksum);
|
|
|
|
|
|
|
+ var to_sign = new ByteComposition.from_byte_array(line_checksum);
|
|
|
to_sign.append_byte_array(publication_checksum);
|
|
to_sign.append_byte_array(publication_checksum);
|
|
|
|
|
|
|
|
signature = Sodium.Asymmetric.Signing.sign(to_sign.to_array(), member_credentials.secret_signing_key);
|
|
signature = Sodium.Asymmetric.Signing.sign(to_sign.to_array(), member_credentials.secret_signing_key);
|
|
@@ -510,12 +510,12 @@ namespace Ppub {
|
|
|
throw new CollectionError.INVALID_MEMBER(@"Undeclared member \"$member\" on publication entry");
|
|
throw new CollectionError.INVALID_MEMBER(@"Undeclared member \"$member\" on publication entry");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- var checksum = new BinaryData.from_byte_array(Collection.get_string_checksum(get_signed_portion()));
|
|
|
|
|
|
|
+ var checksum = Wrap.byte_array(Collection.get_string_checksum(get_signed_portion()));
|
|
|
var signature_data = Sodium.Asymmetric.Signing.verify(signature, collection_member.public_keys.signing_key);
|
|
var signature_data = Sodium.Asymmetric.Signing.verify(signature, collection_member.public_keys.signing_key);
|
|
|
if(signature_data == null) {
|
|
if(signature_data == null) {
|
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Invalid publication signature");
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Invalid publication signature");
|
|
|
}
|
|
}
|
|
|
- if(!checksum.equals(ate(signature_data[0:64]))) {
|
|
|
|
|
|
|
+ if(!checksum.equals(Wrap.array(signature_data[0:64]))) {
|
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Publication signature does not match metadata");
|
|
throw new CollectionError.INVALID_COLLECTION_SIGNATURE("Publication signature does not match metadata");
|
|
|
}
|
|
}
|
|
|
|
|
|