public override Task <KeyResponse> GetKeys(CacheVM request, ServerCallContext context) { var result = new KeyResponse(); foreach (var item in cache) { result.Keys.Add(item.Key); } return(Task.FromResult(result)); }
/// <summary>Retrieves the user's application key</summary> public KeyResponse GetKey(string MobileKey) { string url = "http://api.ping.fm/v1/user.key"; string postdata = "api_key={0}&mobile_key={1}"; postdata = string.Format(postdata, api_key, MobileKey); string response = GetWebResponse(url, postdata); XmlReader xr = XmlReader.Create(new System.IO.StringReader(response)); KeyResponse r = (KeyResponse)DeserializeObject(xr, typeof(KeyResponse)); xr.Close(); mLastResponse = r; return(r); }
public Task <KeyResponse <KeyRegisterResponse> > RegisterAsync(KeyRegisterRequest request, CancellationToken cancellationToken = new CancellationToken(), bool invididualAttestation = false) { if (request == null) { throw new ArgumentNullException(nameof(request)); } log.Info(">> register"); var applicationSha256 = request.ApplicationSha256; var challengeSha256 = request.ChallengeSha256; log.Info(" -- Inputs --"); log.Info(" applicationSha256: " + applicationSha256.ToHexString()); log.Info(" challengeSha256: " + challengeSha256.ToHexString()); var userPresent = userPresenceVerifier.VerifyUserPresence(); if ((userPresent & UserPresenceVerifierConstants.UserPresentFlag) == 0) { return(TestOfUserPresenceRequired <KeyRegisterResponse>()); } var keyPair = keyPairGenerator.GenerateKeyPair(applicationSha256, challengeSha256); var keyHandle = keyHandleGenerator.GenerateKeyHandle(applicationSha256, keyPair); dataStore.StoreKeyPair(keyHandle, keyPair); var userPublicKey = keyPairGenerator.EncodePublicKey(keyPair.PublicKey); var signedData = RawMessageCodec.EncodeKeyRegisterSignedBytes(applicationSha256, challengeSha256, keyHandle, userPublicKey); log.Info("Signing bytes " + signedData.ToHexString()); var signature = crypto.Sign(signedData, certificatePrivateKey); log.Info(" -- Outputs --"); log.Info(" userPublicKey: " + userPublicKey.ToHexString()); log.Info(" keyHandle: " + keyHandle.ToHexString()); log.Info(" vendorCertificate: " + vendorCertificate); log.Info(" signature: " + signature.ToHexString()); log.Info("<< register"); var response = new KeyRegisterResponse(userPublicKey, keyHandle, vendorCertificate, signature); var responseData = RawMessageCodec.EncodeKeyRegisterResponse(response).Segment(); var apdu = new ApduResponse(ApduResponseStatus.NoError, responseData); var keyResponse = new KeyResponse <KeyRegisterResponse>(apdu, response, KeyResponseStatus.Success); return(TaskEx.FromResult(keyResponse)); }
public Task <KeyResponse <KeySignResponse> > SignAsync(KeySignRequest request, CancellationToken cancellationToken = new CancellationToken(), bool noWink = false) { if (request == null) { throw new ArgumentNullException(nameof(request)); } log.Info(">> authenticate"); var applicationSha256 = request.ApplicationSha256; var challengeSha256 = request.ChallengeSha256; var keyHandle = request.KeyHandle; log.Info(" -- Inputs --"); log.Info(" applicationSha256: " + applicationSha256.ToHexString()); log.Info(" challengeSha256: " + challengeSha256.ToHexString()); log.Info(" keyHandle: " + keyHandle.ToHexString()); var keyPair = dataStore.GetKeyPair(keyHandle); var counter = dataStore.IncrementCounter(); var userPresent = userPresenceVerifier.VerifyUserPresence(); if ((userPresent & UserPresenceVerifierConstants.UserPresentFlag) == 0) { return(TestOfUserPresenceRequired <KeySignResponse>()); } var signedData = RawMessageCodec.EncodeKeySignSignedBytes(applicationSha256, userPresent, counter, challengeSha256); log.Info("Signing bytes " + signedData.ToHexString()); var signature = crypto.Sign(signedData, keyPair.PrivateKey); log.Info(" -- Outputs --"); log.Info(" userPresence: " + userPresent); log.Info(" counter: " + counter); log.Info(" signature: " + signature.ToHexString()); log.Info("<< authenticate"); var response = new KeySignResponse(userPresent, counter, signature); var responseData = RawMessageCodec.EncodeKeySignResponse(response).Segment(); var apdu = new ApduResponse(ApduResponseStatus.NoError, responseData); var keyResponse = new KeyResponse <KeySignResponse>(apdu, response, KeyResponseStatus.Success); return(TaskEx.FromResult(keyResponse)); }
/// <summary> /// Generates new private/public key pair from brian key. /// </summary> /// <param name="brainKey"></param> /// <param name="privateKey"></param> /// <param name="publicKey"></param> /// <returns></returns> public KeyResponse GenerateKeyPairFromBrainKey(string brainKey, byte[] privateKey, byte[] publicKey) { KeyResponse result = null; try { if (generate_key_pair_from_brain_key(brainKey, privateKey, publicKey)) { result = new KeyResponse { PrivateKey = System.Text.Encoding.Default.GetString(privateKey), PublicKey = System.Text.Encoding.Default.GetString(publicKey) }; } } catch (Exception ex) { throw; } return(result); }
/// <summary> /// Generates private_key in WIF format based on random seed. /// </summary> /// <param name="privatekey">returns parameter of size 51</param> /// <param name="publickey">returns parameter of size 53</param> /// <returns>Returns true if success or false for failed try</returns> public KeyResponse GeneratePrivateKey(byte[] privatekey, byte[] publickey) { KeyResponse result = null; try { if (generate_private_key(privatekey, publickey)) { result = new KeyResponse { PrivateKey = System.Text.Encoding.Default.GetString(privatekey), PublicKey = System.Text.Encoding.Default.GetString(publickey) }; } } catch (Exception ex) { throw; } return(result); }
/// <summary> /// Generates new private/public key pair from brian key. /// </summary> /// <param name="brainKey"></param> /// <param name="privateKey"></param> /// <param name="publicKey"></param> /// <returns></returns> public KeyResponse GenerateKeyPairFromBrainKey(string brainKey, byte[] privateKey, byte[] publicKey) { KeyResponse result = null; try { if (generate_key_pair_from_brain_key(brainKey, privateKey, publicKey)) { result = new KeyResponse { PrivateKey = System.Text.Encoding.Default.GetString(privateKey), PublicKey = System.Text.Encoding.Default.GetString(publicKey) }; } } catch (Exception ex) { _logger.WriteError($"Message:{ex.Message} | StackTrace:{ex.StackTrace}"); throw; } return(result); }
public Task <KeyResponse <string> > GetVersionAsync(CancellationToken cancellationToken = new CancellationToken()) { var keyResponse = new KeyResponse <string>(ApduResponse.Empty(ApduResponseStatus.NoError), U2FConsts.U2Fv2, KeyResponseStatus.Success); return(TaskEx.FromResult(keyResponse)); }
private static Task <KeyResponse <TData> > TestOfUserPresenceRequired <TData>() where TData : class { return(TaskEx.FromResult(KeyResponse <TData> .Empty(ApduResponseStatus.NoError, KeyResponseStatus.TestOfuserPresenceRequired))); }