Preserve data across the Straywild transition
This commit is contained in:
parent
737d1cf2e0
commit
98a27e2f53
28 changed files with 577 additions and 94 deletions
|
|
@ -6,6 +6,7 @@ const FINGERPRINT_LENGTH: int = 64
|
|||
const MAX_PUBLIC_KEY_BYTES: int = 8192
|
||||
const MAX_SIGNATURE_BYTES: int = 1024
|
||||
const DOMAIN_PREFIX: String = "straywild"
|
||||
const LEGACY_DOMAIN_PREFIX: String = "NETFISHING"
|
||||
const IDENTITY_VERSION: String = "identity_v1"
|
||||
|
||||
|
||||
|
|
@ -50,8 +51,16 @@ static func secure_id(byte_count: int = 16) -> String:
|
|||
|
||||
|
||||
static func canonical_bytes(domain: String, fields: Array) -> PackedByteArray:
|
||||
return canonical_bytes_for_prefix(DOMAIN_PREFIX, domain, fields)
|
||||
|
||||
|
||||
static func canonical_bytes_for_prefix(
|
||||
prefix: String,
|
||||
domain: String,
|
||||
fields: Array,
|
||||
) -> PackedByteArray:
|
||||
var output := PackedByteArray()
|
||||
_append_string(output, DOMAIN_PREFIX)
|
||||
_append_string(output, prefix)
|
||||
_append_string(output, IDENTITY_VERSION)
|
||||
_append_string(output, domain)
|
||||
for value: Variant in fields:
|
||||
|
|
@ -117,6 +126,37 @@ static func verify_fields(
|
|||
)
|
||||
|
||||
|
||||
static func verify_legacy_fields(
|
||||
public_key: CryptoKey,
|
||||
domain: String,
|
||||
fields: Array,
|
||||
signature: PackedByteArray,
|
||||
) -> bool:
|
||||
if (
|
||||
public_key == null
|
||||
or signature.is_empty()
|
||||
or signature.size() > MAX_SIGNATURE_BYTES
|
||||
):
|
||||
return false
|
||||
var bytes: PackedByteArray = canonical_bytes_for_prefix(
|
||||
LEGACY_DOMAIN_PREFIX,
|
||||
domain,
|
||||
fields,
|
||||
)
|
||||
if bytes.is_empty():
|
||||
return false
|
||||
var context := HashingContext.new()
|
||||
if context.start(HashingContext.HASH_SHA256) != OK:
|
||||
return false
|
||||
context.update(bytes)
|
||||
return Crypto.new().verify(
|
||||
HashingContext.HASH_SHA256,
|
||||
context.finish(),
|
||||
signature,
|
||||
public_key,
|
||||
)
|
||||
|
||||
|
||||
static func load_public_key(public_pem: String) -> CryptoKey:
|
||||
var normalized := normalize_public_pem(public_pem)
|
||||
if normalized.is_empty() or normalized.to_utf8_buffer().size() > MAX_PUBLIC_KEY_BYTES:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue