retrieveIdentityFromRawKeys method
Retrieve the identity stored on the SSKS server for the given userId, and decrypt it with the given raw keys.
If you use an incorrect password multiple times, the server may throttle your requests. In this case, you will
receive an error Request throttled, retry after {N}s
, with {N}
the number of seconds during which you
cannot try again.
userId
- The ID of the user.
rawStorageKey
- The key under which identity keys are stored. This MUST be a secret known only to this user of your app, and never to other users, as learning it will allow deleting the stored identities. Useful to change if you want to store multiple identities for the same userId
. Allowed characters : A-Za-z0-9+/=-_@.
. Max length is 256 characters.
rawEncryptionKey
- The raw encryption key used to encrypt / decrypt the stored identity keys. This MUST be a cryptographically random buffer of 64 bytes.
Returns a Uint8List containing the retrieved identity.
Implementation
Uint8List retrieveIdentityFromRawKeys(
String userId, String rawStorageKey, Uint8List rawEncryptionKey) {
final Pointer<Utf8> nativeUserId = userId.toNativeUtf8();
final Pointer<Utf8> nativeRawStorageKey = rawStorageKey.toNativeUtf8();
// Dart FFI forces us to copy the data from Uint8List to a newly allocated Pointer<Uint8>
final Pointer<Uint8> nativeRawEncryptionKey =
calloc<Uint8>(rawEncryptionKey.length);
final pointerListRawEncryptionKey =
nativeRawEncryptionKey.asTypedList(rawEncryptionKey.length);
pointerListRawEncryptionKey.setAll(0, rawEncryptionKey);
final Pointer<Pointer<Uint8>> result = calloc<Pointer<Uint8>>();
final Pointer<Int> resultLen = calloc<Int>();
final Pointer<Pointer<NativeSealdError>> err =
calloc<Pointer<NativeSealdError>>();
final int resultCode =
_bindings.SealdSsksPasswordPlugin_RetrieveIdentityFromRawKeys(
_ptr.pointer(),
nativeUserId,
nativeRawStorageKey,
nativeRawEncryptionKey,
rawEncryptionKey.length,
result,
resultLen,
err);
calloc.free(nativeUserId);
calloc.free(nativeRawStorageKey);
calloc.free(nativeRawEncryptionKey);
if (resultCode != 0) {
calloc.free(result);
calloc.free(resultLen);
throw SealdException._fromCPtr(err);
} else {
final Uint8List cIdentityExport =
result.value.asTypedList(resultLen.value);
// Copying the data in a Dart-created Uint8List, to avoid having to free memory later
final Uint8List res = Uint8List.fromList(cIdentityExport);
calloc.free(result.value);
calloc.free(result);
calloc.free(resultLen);
calloc.free(err);
return res;
}
}