public void ReceiveSessionSetup(EntityId from, ChatSetupHeader header) { var partner = GetEncrypt(from); var p2 = new LibsodiumEncryption(); if (header == null) { throw new NullReferenceException("Error:/ message doesn't contain setup headers and session keys are missing"); } if (header.publicOneTimeKey != null) { KeyPair oneTimeKeyPair = FindOneTimeKey(header.publicOneTimeKey); partner.SetServerKeys(header, oneTimeKeyPair); } else { partner.SetServerKeys(header, null); } if (partner.DeriveKeysServer()) { // save that we received the session, prevents resending requests partner.ReceivedSetup(); // deriving was successful, send confirmation SendCommand <ReceivedSetup, EntityId> (from, from); } else { throw new Exception("key deriviation failed"); } }
public void GenerateAndSetSignature(KeyPair keys) { if (keys == null || keys.secretKey == null) { throw new NullReferenceException($"{nameof(keys)} has to be set"); } signature = LibsodiumEncryption.SignByteDetached(TokenContent, keys); }
/// <summary> /// Validate the Token. /// </summary> /// <returns>The validate.</returns> /// <param name="publicKey">Public key.</param> public bool Validate(byte[] publicKey, EntityId currentServer) { var TimeAmount = new TimeSpan(1, 0, 0); if (time < DateTime.Now.Subtract(TimeAmount)) { throw new LoginFailedException($"The signed DateTime timed out, it is older than {TimeAmount.TotalMinutes} miniutes"); } if (currentServer != targetServerId) { throw new LoginFailedException("The token wasn't made for this server"); } return(LibsodiumEncryption.SignVertifyDetached(signature, TokenContent, publicKey)); }
/// <inheritdoc/> public override bool ValidateSignature(byte[] data,byte[] signature, byte[] publicKey) { return LibsodiumEncryption.SignVertifyDetached(signature,data,publicKey); }
/// <inheritdoc/> public override byte[] GenerateSignature(byte[] data,KeyPair keyPair) { return LibsodiumEncryption.SignByteDetached(data,keyPair); }