public static SignedCertificate CreateCertificate(string userAddress, string testCentreId, string privateKey, string photoUserId) { var ethEcKey = new Nethereum.Signer.EthECKey(privateKey); var signer = new Nethereum.Signer.EthereumMessageSigner(); var signerAddress = ethEcKey.GetPublicAddress(); var signature = signer.EncodeUTF8AndSign(SignedCertificate.GetRawCertificate(userAddress, signerAddress, testCentreId, photoUserId), ethEcKey); return(new SignedCertificate(userAddress, signerAddress, testCentreId, photoUserId, signature)); }
public const char ResponseSeparator = '|'; // Different for the certificate separator to make our lives easier /// <summary> /// Validates the signature matches the users in certificate, /// Validates the certificate signer is including in the smart contract registry /// Validates the certificate is still valid (ie not in the expired certificates) /// </summary> public async Task <SignedCertificate> ValidateCertificateAsync(string challenge, string response) { var responseValues = response.Split(ResponseSeparator); var fullCertificate = responseValues[0]; var signature = responseValues[1]; var certificate = new SignedCertificate(fullCertificate); if (!certificate.IsCertificateValid()) { return(null); // Invalid certificate } if (!ValidChallengeSignature(challenge, signature, certificate.UserAddress)) { return(null); //Signature does not match certificates signature } //Smart contract registry validation return(await Task.FromResult(certificate)); }